Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Deprecated/Radiography/RadiographyLayerMoveTracker.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Deprecated/Radiography/RadiographyLayerMoveTracker.cpp@30deba7bc8e2 |
children |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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-2020 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 <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().GetGeometry().GetPanX()), | |
55 targetY_(tracker.accessor_.GetLayer().GetGeometry().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().GetGeometry().GetPanX(); | |
76 panY_ = accessor_.GetLayer().GetGeometry().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 const std::vector<Deprecated::Touch>& displayTouches, | |
102 const std::vector<Deprecated::Touch>& sceneTouches) | |
103 { | |
104 if (accessor_.IsValid()) | |
105 { | |
106 double dx = sceneX - clickX_; | |
107 double dy = sceneY - clickY_; | |
108 | |
109 if (oneAxis_) | |
110 { | |
111 if (fabs(dx) > fabs(dy)) | |
112 { | |
113 accessor_.GetLayer().SetPan(dx + panX_, panY_); | |
114 } | |
115 else | |
116 { | |
117 accessor_.GetLayer().SetPan(panX_, dy + panY_); | |
118 } | |
119 } | |
120 else | |
121 { | |
122 accessor_.GetLayer().SetPan(dx + panX_, dy + panY_); | |
123 } | |
124 } | |
125 } | |
126 } |