Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Scene2DViewport/MeasureTool.h @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Scene2DViewport/MeasureTool.h@ab81ee8fce1f |
children | 85e117739eca |
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 #pragma once | |
22 | |
23 #include "../Messages/ObserverBase.h" | |
24 #include "../Scene2D/PolylineSceneLayer.h" | |
25 #include "../Scene2D/Scene2D.h" | |
26 #include "../Scene2D/ScenePoint2D.h" | |
27 #include "../Scene2D/TextSceneLayer.h" | |
28 #include "../Scene2DViewport/PredeclaredTypes.h" | |
29 #include "../Scene2DViewport/ViewportController.h" | |
30 | |
31 #include <boost/weak_ptr.hpp> | |
32 | |
33 #include <vector> | |
34 #include <cmath> | |
35 | |
36 namespace OrthancStone | |
37 { | |
38 class IFlexiblePointerTracker; | |
39 class MeasureToolMemento; | |
40 | |
41 class MeasureTool : public ObserverBase<MeasureTool> | |
42 { | |
43 public: | |
44 virtual ~MeasureTool() | |
45 { | |
46 } | |
47 | |
48 /** | |
49 Enabled tools are rendered in the scene. | |
50 */ | |
51 void Enable(); | |
52 | |
53 /** | |
54 Disabled tools are not rendered in the scene. This is useful to be able | |
55 to use them as their own memento in command stacks (when a measure tool | |
56 creation command has been undone, the measure remains alive in the | |
57 command object but is disabled so that it can be redone later on easily) | |
58 */ | |
59 void Disable(); | |
60 | |
61 /** | |
62 This method is called when the scene transform changes. It allows to | |
63 recompute the visual elements whose content depend upon the scene transform | |
64 */ | |
65 void OnSceneTransformChanged( | |
66 const ViewportController::SceneTransformChanged& message); | |
67 | |
68 /** | |
69 This function must be implemented by the measuring tool to return whether | |
70 a given point in scene coords is close to the measuring tool. | |
71 | |
72 This is used for mouse hover highlighting. | |
73 | |
74 It is assumed that if the pointer position leads to this function returning | |
75 true, then a click at that position will return a tracker to edit the | |
76 measuring tool | |
77 */ | |
78 virtual bool HitTest(ScenePoint2D p) = 0; | |
79 | |
80 /** | |
81 This method must return a memento the captures the tool state (not including | |
82 the highlighting state | |
83 */ | |
84 virtual boost::shared_ptr<MeasureToolMemento> GetMemento() const = 0; | |
85 | |
86 /** | |
87 This method must apply the supplied memento (this requires RTTI to check | |
88 the type) | |
89 */ | |
90 virtual void SetMemento(boost::shared_ptr<MeasureToolMemento>) = 0; | |
91 | |
92 /** | |
93 This must create an edition tracker suitable for the supplied click position, | |
94 or an empty pointer if no hit test (although this should have been checked | |
95 first) | |
96 */ | |
97 virtual boost::shared_ptr<IFlexiblePointerTracker> CreateEditionTracker(const PointerEvent& e) = 0; | |
98 | |
99 /** | |
100 Will change the measuring tool to provide visual feedback on the GUI | |
101 element that is in the pointer hit zone | |
102 */ | |
103 virtual void Highlight(ScenePoint2D p) = 0; | |
104 | |
105 /** | |
106 This function must reset the visual highlighted hot zone feedback | |
107 */ | |
108 virtual void ResetHighlightState() = 0; | |
109 | |
110 /** | |
111 A description of the measuring tool, useful in debug logs | |
112 */ | |
113 virtual std::string GetDescription() = 0; | |
114 | |
115 protected: | |
116 MeasureTool(boost::shared_ptr<IViewport> viewport); | |
117 | |
118 void PostConstructor(); | |
119 | |
120 /** | |
121 The measuring tool may exist in a standalone fashion, without any available | |
122 scene (because the controller is dead or dying). This call allows to check | |
123 before accessing the scene. | |
124 */ | |
125 bool IsSceneAlive() const; | |
126 | |
127 /** | |
128 This is the meat of the tool: this method must [create (if needed) and] | |
129 update the layers and their data according to the measure tool kind and | |
130 current state. This is repeatedly called during user interaction | |
131 */ | |
132 virtual void RefreshScene() = 0; | |
133 | |
134 /** | |
135 enabled_ is not accessible by subclasses because there is a state machine | |
136 that we do not wanna mess with | |
137 */ | |
138 bool IsEnabled() const; | |
139 | |
140 /** | |
141 Protected to allow sub-classes to use this weak pointer in factory methods | |
142 (pass them to created objects) | |
143 */ | |
144 boost::shared_ptr<IViewport> viewport_; | |
145 | |
146 | |
147 private: | |
148 bool enabled_; | |
149 }; | |
150 | |
151 class MeasureToolMemento | |
152 { | |
153 public: | |
154 virtual ~MeasureToolMemento() {}; | |
155 }; | |
156 | |
157 } | |
158 | |
159 //extern void TrackerSample_SetInfoDisplayMessage( | |
160 // std::string key, std::string value); |