Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographyLayerMoveTracker.cpp @ 1039:3a35d8397559
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 07 Oct 2019 22:37:24 +0200 |
parents | 4f2416d519b4 |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
414 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
414 | 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_), | |
430 | 54 targetX_(tracker.accessor_.GetLayer().GetGeometry().GetPanX()), |
55 targetY_(tracker.accessor_.GetLayer().GetGeometry().GetPanY()) | |
414 | 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 { | |
430 | 75 panX_ = accessor_.GetLayer().GetGeometry().GetPanX(); |
76 panY_ = accessor_.GetLayer().GetGeometry().GetPanY(); | |
414 | 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, | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
440
diff
changeset
|
100 double sceneY, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
101 const std::vector<Deprecated::Touch>& displayTouches, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
102 const std::vector<Deprecated::Touch>& sceneTouches) |
414 | 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 } |