comparison Framework/Scene2DViewport/ViewportController.h @ 728:8190213e2279 am-dev

Merged default into am-dev
author Alain Mazy <am@osimis.io>
date Tue, 21 May 2019 13:25:58 +0200
parents 28b9e3a54200
children c0fcb2757b0a
comparison
equal deleted inserted replaced
690:f185cfcb72a0 728:8190213e2279
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 #pragma once
22
23 #include "PointerTypes.h"
24
25 #include <Framework/Scene2D/Scene2D.h>
26 #include <Framework/Scene2D/PointerEvent.h>
27 #include <Framework/Scene2DViewport/IFlexiblePointerTracker.h>
28
29 #include <stack>
30
31 namespace OrthancStone
32 {
33 /**
34 This object is responsible for hosting a scene, responding to messages from
35 the model and updating the scene accordingly.
36
37 It contains the list of active measuring tools as well as the stack
38 where measuring tool commands are stored.
39
40 The active tracker is also stored in the viewport controller.
41
42 Each canvas or other GUI area where we want to display a 2D image, either
43 directly or through slicing must be assigned a ViewportController.
44 */
45 class ViewportController : public IObservable
46 {
47 public:
48 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, \
49 SceneTransformChanged, ViewportController);
50
51 ViewportController(MessageBroker& broker);
52
53 Scene2DPtr GetScene();
54
55 /**
56 This method is called by the GUI system and should update/delete the
57 current tracker
58 */
59 bool HandlePointerEvent(PointerEvent e);
60
61 /**
62 This method returns the list of measure tools containing the supplied point
63 (in scene coords). A tracker can then be requested from the chosen
64 measure tool, if needed
65 */
66 std::vector<MeasureToolPtr> HitTestMeasureTools(ScenePoint2D p);
67
68 /**
69 With this method, the object takes ownership of the supplied tracker and
70 updates it according to user interaction
71 */
72 void SetActiveTracker(FlexiblePointerTrackerPtr tracker);
73
74 /** Forwarded to the underlying scene */
75 const AffineTransform2D& GetCanvasToSceneTransform() const;
76
77 /** Forwarded to the underlying scene */
78 const AffineTransform2D& GetSceneToCanvasTransform() const;
79
80 /** Forwarded to the underlying scene, and broadcasted to the observers */
81 void SetSceneToCanvasTransform(const AffineTransform2D& transform);
82
83 /** Forwarded to the underlying scene, and broadcasted to the observers */
84 void FitContent(unsigned int canvasWidth, unsigned int canvasHeight);
85
86 /**
87 Stores a command :
88 - this first trims the undo stack to keep the first numAppliedCommands_
89 - then it adds the supplied command at the top of the undo stack
90
91 In other words, when a new command is pushed, all the undone (and not
92 redone) commands are removed.
93 */
94 void PushCommand(TrackerCommandPtr command);
95
96 /**
97 Undoes the command at the top of the undo stack, or throws if there is no
98 command to undo.
99 You can check "CanUndo" first to protect against extraneous redo.
100 */
101 void Undo();
102
103 /**
104 Redoes the command that is just above the last applied command in the undo
105 stack or throws if there is no command to redo.
106 You can check "CanRedo" first to protect against extraneous redo.
107 */
108 void Redo();
109
110 /** selfexpl */
111 bool CanUndo() const;
112
113 /** selfexpl */
114 bool CanRedo() const;
115
116 /** Adds a new measure tool */
117 void AddMeasureTool(MeasureToolPtr measureTool);
118
119 /** Removes a measure tool or throws if it cannot be found */
120 void RemoveMeasureTool(MeasureToolPtr measureTool);
121
122 private:
123 std::vector<TrackerCommandPtr> commandStack_;
124
125 /**
126 This is always between >= 0 and <= undoStack_.size() and gives the
127 position where the controller is in the undo stack.
128 - If numAppliedCommands_ > 0, one can undo
129 - If numAppliedCommands_ < numAppliedCommands_.size(), one can redo
130 */
131 size_t numAppliedCommands_;
132 std::vector<MeasureToolPtr> measureTools_;
133 Scene2DPtr scene_;
134 FlexiblePointerTrackerPtr tracker_;
135 };
136 }