comparison Framework/Scene2DViewport/ViewportController.cpp @ 858:e3c56d4f863f

GuiAdapter : mouse event routing in SDL + split the undo stack from the ViewportController for multi-canvas apps + adapted the samples to this change
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 24 Jun 2019 10:31:04 +0200
parents 2b245953b44b
children a29c13497557
comparison
equal deleted inserted replaced
855:41d22389a7d2 858:e3c56d4f863f
17 * You should have received a copy of the GNU Affero General Public License 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/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 20
21 #include "ViewportController.h" 21 #include "ViewportController.h"
22
23 #include "UndoStack.h"
22 #include "MeasureCommands.h" 24 #include "MeasureCommands.h"
23 25
24 #include "../StoneException.h" 26 #include "../StoneException.h"
25 27
26 #include <boost/make_shared.hpp> 28 #include <boost/make_shared.hpp>
27 29
28 namespace OrthancStone 30 namespace OrthancStone
29 { 31 {
30 ViewportController::ViewportController(MessageBroker& broker) 32 ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW, MessageBroker& broker)
31 : IObservable(broker) 33 : IObservable(broker)
32 , numAppliedCommands_(0) 34 , undoStackW_(undoStackW)
33 , canvasToSceneFactor_(0.0) 35 , canvasToSceneFactor_(0.0)
34 { 36 {
35 scene_ = boost::make_shared<Scene2D>(); 37 scene_ = boost::make_shared<Scene2D>();
36 } 38 }
37 39
40 boost::shared_ptr<UndoStack> ViewportController::GetUndoStack()
41 {
42 return undoStackW_.lock();
43 }
44
45 boost::shared_ptr<const UndoStack> ViewportController::GetUndoStack() const
46 {
47 return undoStackW_.lock();
48 }
49
50 void ViewportController::PushCommand(boost::shared_ptr<TrackerCommand> command)
51 {
52 GetUndoStack()->PushCommand(command);
53 }
54
55 void ViewportController::Undo()
56 {
57 GetUndoStack()->Undo();
58 }
59
60 void ViewportController::Redo()
61 {
62 GetUndoStack()->Redo();
63 }
64
65 bool ViewportController::CanUndo() const
66 {
67 return GetUndoStack()->CanUndo();
68 }
69
70 bool ViewportController::CanRedo() const
71 {
72 return GetUndoStack()->CanRedo();
73 }
74
38 boost::shared_ptr<const Scene2D> ViewportController::GetScene() const 75 boost::shared_ptr<const Scene2D> ViewportController::GetScene() const
39 { 76 {
40 return scene_; 77 return scene_;
41 } 78 }
42 79
89 { 126 {
90 scene_->FitContent(canvasWidth, canvasHeight); 127 scene_->FitContent(canvasWidth, canvasHeight);
91 BroadcastMessage(SceneTransformChanged(*this)); 128 BroadcastMessage(SceneTransformChanged(*this));
92 } 129 }
93 130
94 void ViewportController::PushCommand(boost::shared_ptr<TrackerCommand> command)
95 {
96 commandStack_.erase(
97 commandStack_.begin() + numAppliedCommands_,
98 commandStack_.end());
99
100 ORTHANC_ASSERT(std::find(commandStack_.begin(), commandStack_.end(), command)
101 == commandStack_.end(), "Duplicate command");
102 commandStack_.push_back(command);
103 numAppliedCommands_++;
104 }
105
106 void ViewportController::Undo()
107 {
108 ORTHANC_ASSERT(CanUndo(), "");
109 commandStack_[numAppliedCommands_-1]->Undo();
110 numAppliedCommands_--;
111 }
112
113 void ViewportController::Redo()
114 {
115 ORTHANC_ASSERT(CanRedo(), "");
116 commandStack_[numAppliedCommands_]->Redo();
117 numAppliedCommands_++;
118 }
119
120 bool ViewportController::CanUndo() const
121 {
122 return numAppliedCommands_ > 0;
123 }
124
125 bool ViewportController::CanRedo() const
126 {
127 return numAppliedCommands_ < commandStack_.size();
128 }
129
130 void ViewportController::AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool) 131 void ViewportController::AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool)
131 { 132 {
132 ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool) 133 ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool)
133 == measureTools_.end(), "Duplicate measure tool"); 134 == measureTools_.end(), "Duplicate measure tool");
134 measureTools_.push_back(measureTool); 135 measureTools_.push_back(measureTool);