414
|
1 /**
|
|
2 * Stone of Orthanc
|
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
|
|
4 * Department, University Hospital of Liege, Belgium
|
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
|
|
6 *
|
|
7 * This program is free software: you can redistribute it and/or
|
|
8 * modify it under the terms of the GNU Affero General Public License
|
|
9 * as published by the Free Software Foundation, either version 3 of
|
|
10 * the License, or (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful, but
|
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 * Affero General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU Affero General Public License
|
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 **/
|
|
20
|
|
21
|
|
22 #include "RadiographyLayerMoveTracker.h"
|
|
23
|
|
24 #include "RadiographySceneCommand.h"
|
|
25
|
|
26 #include <Core/OrthancException.h>
|
|
27
|
|
28 namespace OrthancStone
|
|
29 {
|
|
30 class RadiographyLayerMoveTracker::UndoRedoCommand : public RadiographySceneCommand
|
|
31 {
|
|
32 private:
|
|
33 double sourceX_;
|
|
34 double sourceY_;
|
|
35 double targetX_;
|
|
36 double targetY_;
|
|
37
|
|
38 protected:
|
|
39 virtual void UndoInternal(RadiographyLayer& layer) const
|
|
40 {
|
|
41 layer.SetPan(sourceX_, sourceY_);
|
|
42 }
|
|
43
|
|
44 virtual void RedoInternal(RadiographyLayer& layer) const
|
|
45 {
|
|
46 layer.SetPan(targetX_, targetY_);
|
|
47 }
|
|
48
|
|
49 public:
|
|
50 UndoRedoCommand(const RadiographyLayerMoveTracker& tracker) :
|
|
51 RadiographySceneCommand(tracker.accessor_),
|
|
52 sourceX_(tracker.panX_),
|
|
53 sourceY_(tracker.panY_),
|
|
54 targetX_(tracker.accessor_.GetLayer().GetPanX()),
|
|
55 targetY_(tracker.accessor_.GetLayer().GetPanY())
|
|
56 {
|
|
57 }
|
|
58 };
|
|
59
|
|
60
|
|
61 RadiographyLayerMoveTracker::RadiographyLayerMoveTracker(UndoRedoStack& undoRedoStack,
|
|
62 RadiographyScene& scene,
|
|
63 size_t layer,
|
|
64 double x,
|
|
65 double y,
|
|
66 bool oneAxis) :
|
|
67 undoRedoStack_(undoRedoStack),
|
|
68 accessor_(scene, layer),
|
|
69 clickX_(x),
|
|
70 clickY_(y),
|
|
71 oneAxis_(oneAxis)
|
|
72 {
|
|
73 if (accessor_.IsValid())
|
|
74 {
|
|
75 panX_ = accessor_.GetLayer().GetPanX();
|
|
76 panY_ = accessor_.GetLayer().GetPanY();
|
|
77 }
|
|
78 }
|
|
79
|
|
80
|
|
81 void RadiographyLayerMoveTracker::Render(CairoContext& context,
|
|
82 double zoom)
|
|
83 {
|
|
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
|
|
85 }
|
|
86
|
|
87
|
|
88 void RadiographyLayerMoveTracker::MouseUp()
|
|
89 {
|
|
90 if (accessor_.IsValid())
|
|
91 {
|
|
92 undoRedoStack_.Add(new UndoRedoCommand(*this));
|
|
93 }
|
|
94 }
|
|
95
|
|
96
|
|
97 void RadiographyLayerMoveTracker::MouseMove(int displayX,
|
|
98 int displayY,
|
|
99 double sceneX,
|
|
100 double sceneY)
|
|
101 {
|
|
102 if (accessor_.IsValid())
|
|
103 {
|
|
104 double dx = sceneX - clickX_;
|
|
105 double dy = sceneY - clickY_;
|
|
106
|
|
107 if (oneAxis_)
|
|
108 {
|
|
109 if (fabs(dx) > fabs(dy))
|
|
110 {
|
|
111 accessor_.GetLayer().SetPan(dx + panX_, panY_);
|
|
112 }
|
|
113 else
|
|
114 {
|
|
115 accessor_.GetLayer().SetPan(panX_, dy + panY_);
|
|
116 }
|
|
117 }
|
|
118 else
|
|
119 {
|
|
120 accessor_.GetLayer().SetPan(dx + panX_, dy + panY_);
|
|
121 }
|
|
122 }
|
|
123 }
|
|
124 }
|