Mercurial > hg > orthanc-stone
comparison Samples/Shared/RadiographyEditorApp.h @ 882:31319fe867b9 am-dev
Merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Tue, 09 Jul 2019 11:46:43 +0200 |
parents | 80829436ce0c |
children |
comparison
equal
deleted
inserted
replaced
881:a8cd3755db21 | 882:31319fe867b9 |
---|---|
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-2019 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 "../../Framework/Messages/IObserver.h" | |
23 #include "../../Framework/Oracle/IOracle.h" | |
24 #include "../../Framework/Scene2D/OpenGLCompositor.h" | |
25 #include "../../Framework/Scene2D/Internals/CompositorHelper.h" | |
26 #include "../../Framework/Scene2DViewport/IFlexiblePointerTracker.h" | |
27 #include "../../Framework/Scene2DViewport/MeasureTool.h" | |
28 #include "../../Framework/Scene2DViewport/PredeclaredTypes.h" | |
29 #include "../../Framework/Scene2DViewport/ViewportController.h" | |
30 | |
31 #include <SDL.h> | |
32 | |
33 #include <boost/make_shared.hpp> | |
34 #include <boost/shared_ptr.hpp> | |
35 #include <boost/enable_shared_from_this.hpp> | |
36 | |
37 | |
38 namespace OrthancStone | |
39 { | |
40 class ICompositorFactory | |
41 { | |
42 public: | |
43 virtual OrthancStone::ICompositor* GetCompositor(const OrthancStone::Scene2D& scene) = 0; | |
44 }; | |
45 | |
46 class IInteractor | |
47 { | |
48 public: | |
49 virtual void OnMouseDown(int x, int y, OrthancStone::KeyboardModifiers modifiers, OrthancStone::MouseButton button) = 0; | |
50 virtual void OnMouseMove(int x, int y, OrthancStone::KeyboardModifiers modifiers) = 0; | |
51 virtual void OnMouseUp(int x, int y, OrthancStone::KeyboardModifiers modifiers, OrthancStone::MouseButton button) = 0; | |
52 virtual void OnKeyPressed(char keyChar, OrthancStone::KeyboardModifiers modifiers) = 0; | |
53 }; | |
54 | |
55 | |
56 | |
57 | |
58 enum GuiTool | |
59 { | |
60 GuiTool_Rotate = 0, | |
61 GuiTool_Pan, | |
62 GuiTool_Zoom, | |
63 GuiTool_LineMeasure, | |
64 GuiTool_CircleMeasure, | |
65 GuiTool_AngleMeasure, | |
66 GuiTool_EllipseMeasure, | |
67 GuiTool_LAST | |
68 }; | |
69 | |
70 const char* MeasureToolToString(size_t i); | |
71 | |
72 static const unsigned int FONT_SIZE_0 = 32; | |
73 static const unsigned int FONT_SIZE_1 = 24; | |
74 | |
75 class Scene2D; | |
76 | |
77 class RadiographyEditorApp : public IObserver | |
78 , public IInteractor, public boost::enable_shared_from_this<RadiographyEditorApp> | |
79 { | |
80 OrthancStone::IOracle& oracle_; | |
81 std::auto_ptr<ICompositorFactory> compositorFactory_; | |
82 std::auto_ptr<ICompositor> compositor_; | |
83 | |
84 public: | |
85 // 12 because. | |
86 RadiographyEditorApp(OrthancStone::IOracle& oracle, IObservable& oracleObservable, ICompositorFactory* compositorFactory); | |
87 | |
88 void PrepareScene(); | |
89 void FitContent(unsigned int width, unsigned int height); | |
90 void Refresh(); | |
91 void UpdateSize(); | |
92 void SetInfoDisplayMessage(std::string key, std::string value); | |
93 void DisableTracker(); | |
94 | |
95 virtual void OnMouseMove(int x, int y, OrthancStone::KeyboardModifiers modifiers); | |
96 virtual void OnKeyPressed(char keyChar, OrthancStone::KeyboardModifiers modifiers); | |
97 virtual void OnMouseDown(int x, int y, OrthancStone::KeyboardModifiers modifiers, OrthancStone::MouseButton button); | |
98 virtual void OnMouseUp(int x, int y, OrthancStone::KeyboardModifiers modifiers, OrthancStone::MouseButton button); | |
99 | |
100 boost::shared_ptr<Scene2D> GetScene(); | |
101 boost::shared_ptr<const Scene2D> GetScene() const; | |
102 | |
103 void HandleApplicationEvent(const SDL_Event& event); | |
104 | |
105 /** | |
106 This method is called when the scene transform changes. It allows to | |
107 recompute the visual elements whose content depend upon the scene transform | |
108 */ | |
109 void OnSceneTransformChanged( | |
110 const ViewportController::SceneTransformChanged& message); | |
111 | |
112 private: | |
113 void SelectNextTool(); | |
114 void CreateRandomMeasureTool(); | |
115 | |
116 /** | |
117 This returns a random point in the canvas part of the scene, but in | |
118 scene coordinates | |
119 */ | |
120 ScenePoint2D GetRandomPointInScene() const; | |
121 | |
122 boost::shared_ptr<IFlexiblePointerTracker> TrackerHitTest(const PointerEvent& e); | |
123 | |
124 boost::shared_ptr<IFlexiblePointerTracker> CreateSuitableTracker( | |
125 OrthancStone::MouseButton button, | |
126 const PointerEvent& e); | |
127 | |
128 void TakeScreenshot( | |
129 const std::string& target, | |
130 unsigned int canvasWidth, | |
131 unsigned int canvasHeight); | |
132 | |
133 /** | |
134 This adds the command at the top of the undo stack | |
135 */ | |
136 void Commit(boost::shared_ptr<TrackerCommand> cmd); | |
137 void Undo(); | |
138 void Redo(); | |
139 | |
140 private: | |
141 void DisplayFloatingCtrlInfoText(const PointerEvent& e); | |
142 void DisplayInfoText(); | |
143 void HideInfoText(); | |
144 | |
145 private: | |
146 /** | |
147 WARNING: the measuring tools do store a reference to the scene, and it | |
148 paramount that the scene gets destroyed AFTER the measurement tools. | |
149 */ | |
150 boost::shared_ptr<ViewportController> controller_; | |
151 | |
152 std::map<std::string, std::string> infoTextMap_; | |
153 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_; | |
154 | |
155 //static const int LAYER_POSITION = 150; | |
156 | |
157 int TEXTURE_2x2_1_ZINDEX; | |
158 int TEXTURE_1x1_ZINDEX; | |
159 int TEXTURE_2x2_2_ZINDEX; | |
160 int LINESET_1_ZINDEX; | |
161 int LINESET_2_ZINDEX; | |
162 int FLOATING_INFOTEXT_LAYER_ZINDEX; | |
163 int FIXED_INFOTEXT_LAYER_ZINDEX; | |
164 | |
165 GuiTool currentTool_; | |
166 }; | |
167 | |
168 } |