diff Applications/Samples/SingleFrameEditorApplication.h @ 414:f7616c010056

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Nov 2018 18:00:48 +0100
parents 18b707fb8620
children c0589c3173fd
line wrap: on
line diff
--- a/Applications/Samples/SingleFrameEditorApplication.h	Mon Nov 12 17:17:25 2018 +0100
+++ b/Applications/Samples/SingleFrameEditorApplication.h	Mon Nov 12 18:00:48 2018 +0100
@@ -23,7 +23,10 @@
 
 #include "SampleApplicationBase.h"
 
+#include "../../Framework/Radiography/RadiographyLayerMoveTracker.h"
+#include "../../Framework/Radiography/RadiographyLayerRotateTracker.h"
 #include "../../Framework/Radiography/RadiographyScene.h"
+#include "../../Framework/Radiography/RadiographySceneCommand.h"
 #include "../../Framework/Radiography/RadiographyWidget.h"
 
 #include "../../Framework/Toolbox/UndoRedoStack.h"
@@ -46,308 +49,11 @@
 #define EXPORT_USING_PAM  1
 
 
-#include <boost/math/constants/constants.hpp>
 #include <boost/math/special_functions/round.hpp>
 
 
 namespace OrthancStone
 {
-  class RadiographySceneCommand : public UndoRedoStack::ICommand
-  {
-  private:
-    RadiographyScene&  scene_;
-    size_t             layer_;
-
-  protected:
-    virtual void UndoInternal(RadiographyLayer& layer) const = 0;
-
-    virtual void RedoInternal(RadiographyLayer& layer) const = 0;
-
-  public:
-    RadiographySceneCommand(RadiographyScene& scene,
-                            size_t layer) :
-      scene_(scene),
-      layer_(layer)
-    {
-    }
-
-    RadiographySceneCommand(const RadiographyScene::LayerAccessor& accessor) :
-      scene_(accessor.GetScene()),
-      layer_(accessor.GetIndex())
-    {
-    }
-
-    virtual void Undo() const
-    {
-      RadiographyScene::LayerAccessor accessor(scene_, layer_);
-
-      if (accessor.IsValid())
-      {
-        UndoInternal(accessor.GetLayer());
-      }
-    }
-
-    virtual void Redo() const
-    {
-      RadiographyScene::LayerAccessor accessor(scene_, layer_);
-
-      if (accessor.IsValid())
-      {
-        RedoInternal(accessor.GetLayer());
-      }
-    }
-  };
-
-
-  class RadiographyLayerRotateTracker : public IWorldSceneMouseTracker
-  {
-  private:
-    UndoRedoStack&                 undoRedoStack_;
-    RadiographyScene::LayerAccessor  accessor_;
-    double                         centerX_;
-    double                         centerY_;
-    double                         originalAngle_;
-    double                         clickAngle_;
-    bool                           roundAngles_;
-
-    bool ComputeAngle(double& angle /* out */,
-                      double sceneX,
-                      double sceneY) const
-    {
-      Vector u;
-      LinearAlgebra::AssignVector(u, sceneX - centerX_, sceneY - centerY_);
-
-      double nu = boost::numeric::ublas::norm_2(u);
-
-      if (!LinearAlgebra::IsCloseToZero(nu))
-      {
-        u /= nu;
-        angle = atan2(u[1], u[0]);
-        return true;
-      }
-      else
-      {
-        return false;
-      }
-    }
-
-
-    class UndoRedoCommand : public RadiographySceneCommand
-    {
-    private:
-      double  sourceAngle_;
-      double  targetAngle_;
-
-      static int ToDegrees(double angle)
-      {
-        return boost::math::iround(angle * 180.0 / boost::math::constants::pi<double>());
-      }
-      
-    protected:
-      virtual void UndoInternal(RadiographyLayer& layer) const
-      {
-        LOG(INFO) << "Undo - Set angle to " << ToDegrees(sourceAngle_) << " degrees";
-        layer.SetAngle(sourceAngle_);
-      }
-
-      virtual void RedoInternal(RadiographyLayer& layer) const
-      {
-        LOG(INFO) << "Redo - Set angle to " << ToDegrees(sourceAngle_) << " degrees";
-        layer.SetAngle(targetAngle_);
-      }
-
-    public:
-      UndoRedoCommand(const RadiographyLayerRotateTracker& tracker) :
-        RadiographySceneCommand(tracker.accessor_),
-        sourceAngle_(tracker.originalAngle_),
-        targetAngle_(tracker.accessor_.GetLayer().GetAngle())
-      {
-      }
-    };
-
-      
-  public:
-    RadiographyLayerRotateTracker(UndoRedoStack& undoRedoStack,
-                                  RadiographyScene& scene,
-                                  const ViewportGeometry& view,
-                                  size_t layer,
-                                  double x,
-                                  double y,
-                                  bool roundAngles) :
-      undoRedoStack_(undoRedoStack),
-      accessor_(scene, layer),
-      roundAngles_(roundAngles)
-    {
-      if (accessor_.IsValid())
-      {
-        accessor_.GetLayer().GetCenter(centerX_, centerY_);
-        originalAngle_ = accessor_.GetLayer().GetAngle();
-
-        double sceneX, sceneY;
-        view.MapDisplayToScene(sceneX, sceneY, x, y);
-
-        if (!ComputeAngle(clickAngle_, x, y))
-        {
-          accessor_.Invalidate();
-        }
-      }
-    }
-
-    virtual bool HasRender() const
-    {
-      return false;
-    }
-
-    virtual void Render(CairoContext& context,
-                        double zoom)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-    }
-
-    virtual void MouseUp()
-    {
-      if (accessor_.IsValid())
-      {
-        undoRedoStack_.Add(new UndoRedoCommand(*this));
-      }
-    }
-
-    virtual void MouseMove(int displayX,
-                           int displayY,
-                           double sceneX,
-                           double sceneY)
-    {
-      static const double ROUND_ANGLE = 15.0 / 180.0 * boost::math::constants::pi<double>(); 
-        
-      double angle;
-        
-      if (accessor_.IsValid() &&
-          ComputeAngle(angle, sceneX, sceneY))
-      {
-        angle = angle - clickAngle_ + originalAngle_;
-
-        if (roundAngles_)
-        {
-          angle = boost::math::round<double>((angle / ROUND_ANGLE) * ROUND_ANGLE);
-        }
-          
-        accessor_.GetLayer().SetAngle(angle);
-      }
-    }
-  };
-    
-    
-  class RadiographyLayerMoveTracker : public IWorldSceneMouseTracker
-  {
-  private:
-    UndoRedoStack&                   undoRedoStack_;
-    RadiographyScene::LayerAccessor  accessor_;
-    double                           clickX_;
-    double                           clickY_;
-    double                           panX_;
-    double                           panY_;
-    bool                             oneAxis_;
-
-    class UndoRedoCommand : public RadiographySceneCommand
-    {
-    private:
-      double  sourceX_;
-      double  sourceY_;
-      double  targetX_;
-      double  targetY_;
-
-    protected:
-      virtual void UndoInternal(RadiographyLayer& layer) const
-      {
-        layer.SetPan(sourceX_, sourceY_);
-      }
-
-      virtual void RedoInternal(RadiographyLayer& layer) const
-      {
-        layer.SetPan(targetX_, targetY_);
-      }
-
-    public:
-      UndoRedoCommand(const RadiographyLayerMoveTracker& tracker) :
-        RadiographySceneCommand(tracker.accessor_),
-        sourceX_(tracker.panX_),
-        sourceY_(tracker.panY_),
-        targetX_(tracker.accessor_.GetLayer().GetPanX()),
-        targetY_(tracker.accessor_.GetLayer().GetPanY())
-      {
-      }
-    };
-
-
-  public:
-    RadiographyLayerMoveTracker(UndoRedoStack& undoRedoStack,
-                                RadiographyScene& scene,
-                                size_t layer,
-                                double x,
-                                double y,
-                                bool oneAxis) :
-      undoRedoStack_(undoRedoStack),
-      accessor_(scene, layer),
-      clickX_(x),
-      clickY_(y),
-      oneAxis_(oneAxis)
-    {
-      if (accessor_.IsValid())
-      {
-        panX_ = accessor_.GetLayer().GetPanX();
-        panY_ = accessor_.GetLayer().GetPanY();
-      }
-    }
-
-    virtual bool HasRender() const
-    {
-      return false;
-    }
-
-    virtual void Render(CairoContext& context,
-                        double zoom)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-    }
-
-    virtual void MouseUp()
-    {
-      if (accessor_.IsValid())
-      {
-        undoRedoStack_.Add(new UndoRedoCommand(*this));
-      }
-    }
-
-    virtual void MouseMove(int displayX,
-                           int displayY,
-                           double sceneX,
-                           double sceneY)
-    {
-      if (accessor_.IsValid())
-      {
-        double dx = sceneX - clickX_;
-        double dy = sceneY - clickY_;
-
-        if (oneAxis_)
-        {
-          if (fabs(dx) > fabs(dy))
-          {
-            accessor_.GetLayer().SetPan(dx + panX_, panY_);
-          }
-          else
-          {
-            accessor_.GetLayer().SetPan(panX_, dy + panY_);
-          }
-        }
-        else
-        {
-          accessor_.GetLayer().SetPan(dx + panX_, dy + panY_);
-        }
-      }
-    }
-  };
-
-
   class RadiographyLayerCropTracker : public IWorldSceneMouseTracker
   {
   private: