annotate Framework/Radiography/RadiographyLayerMoveTracker.cpp @ 421:f87f28624b96 cache-in-radiography

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