comparison Framework/Deprecated/Radiography/RadiographyLayerMoveTracker.cpp @ 1398:c5403d52078c

moved Radiography into Deprecated
author Alain Mazy <alain@mazy.be>
date Wed, 29 Apr 2020 20:43:09 +0200
parents Framework/Radiography/RadiographyLayerMoveTracker.cpp@2d8ab34c8c91
children 30deba7bc8e2
comparison
equal deleted inserted replaced
1397:1c2d065ba372 1398:c5403d52078c
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 <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().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 }