comparison Framework/Scene2DViewport/ViewportController.cpp @ 722:28b9e3a54200

Undo mechanism implemented (not connected to UI yet). Undo stack and measuring tools are now handled by the ViewportController. Multi-touch does not crash trackers anymore.
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 21 May 2019 10:27:54 +0200
parents af0aa0c149fa
children c0fcb2757b0a 712ff6ff3c19
comparison
equal deleted inserted replaced
721:af0aa0c149fa 722:28b9e3a54200
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 #include "MeasureCommands.h"
22 23
23 #include <Framework/StoneException.h> 24 #include <Framework/StoneException.h>
24 25
25 #include <boost/make_shared.hpp> 26 #include <boost/make_shared.hpp>
26 27
28 29
29 namespace OrthancStone 30 namespace OrthancStone
30 { 31 {
31 ViewportController::ViewportController(MessageBroker& broker) 32 ViewportController::ViewportController(MessageBroker& broker)
32 : IObservable(broker) 33 : IObservable(broker)
34 , numAppliedCommands_(0)
33 { 35 {
34 scene_ = boost::make_shared<Scene2D>(); 36 scene_ = boost::make_shared<Scene2D>();
35 } 37 }
36 38
37 Scene2DPtr ViewportController::GetScene() 39 Scene2DPtr ViewportController::GetScene()
79 { 81 {
80 scene_->FitContent(canvasWidth, canvasHeight); 82 scene_->FitContent(canvasWidth, canvasHeight);
81 BroadcastMessage(SceneTransformChanged(*this)); 83 BroadcastMessage(SceneTransformChanged(*this));
82 } 84 }
83 85
86 void ViewportController::PushCommand(TrackerCommandPtr command)
87 {
88 commandStack_.erase(
89 commandStack_.begin() + numAppliedCommands_,
90 commandStack_.end());
91
92 ORTHANC_ASSERT(std::find(commandStack_.begin(), commandStack_.end(), command)
93 == commandStack_.end(), "Duplicate command");
94 commandStack_.push_back(command);
95 numAppliedCommands_++;
96 }
97
98 void ViewportController::Undo()
99 {
100 ORTHANC_ASSERT(CanUndo(), "");
101 commandStack_[numAppliedCommands_-1]->Undo();
102 numAppliedCommands_--;
103 }
104
105 void ViewportController::Redo()
106 {
107 ORTHANC_ASSERT(CanRedo(), "");
108 commandStack_[numAppliedCommands_]->Redo();
109 numAppliedCommands_++;
110 }
111
112 bool ViewportController::CanUndo() const
113 {
114 return numAppliedCommands_ > 0;
115 }
116
117 bool ViewportController::CanRedo() const
118 {
119 return numAppliedCommands_ < commandStack_.size();
120 }
121
122 void ViewportController::AddMeasureTool(MeasureToolPtr measureTool)
123 {
124 ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool)
125 == measureTools_.end(), "Duplicate measure tool");
126 measureTools_.push_back(measureTool);
127 }
128
129 void ViewportController::RemoveMeasureTool(MeasureToolPtr measureTool)
130 {
131 ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool)
132 != measureTools_.end(), "Measure tool not found");
133 measureTools_.push_back(measureTool);
134 }
135
84 } 136 }
85 137