Mercurial > hg > orthanc-stone
diff 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 |
line wrap: on
line diff
--- a/Framework/Scene2DViewport/ViewportController.cpp Mon May 20 12:49:29 2019 +0200 +++ b/Framework/Scene2DViewport/ViewportController.cpp Tue May 21 10:27:54 2019 +0200 @@ -19,6 +19,7 @@ **/ #include "ViewportController.h" +#include "MeasureCommands.h" #include <Framework/StoneException.h> @@ -30,6 +31,7 @@ { ViewportController::ViewportController(MessageBroker& broker) : IObservable(broker) + , numAppliedCommands_(0) { scene_ = boost::make_shared<Scene2D>(); } @@ -81,5 +83,55 @@ BroadcastMessage(SceneTransformChanged(*this)); } + void ViewportController::PushCommand(TrackerCommandPtr command) + { + commandStack_.erase( + commandStack_.begin() + numAppliedCommands_, + commandStack_.end()); + + ORTHANC_ASSERT(std::find(commandStack_.begin(), commandStack_.end(), command) + == commandStack_.end(), "Duplicate command"); + commandStack_.push_back(command); + numAppliedCommands_++; + } + + void ViewportController::Undo() + { + ORTHANC_ASSERT(CanUndo(), ""); + commandStack_[numAppliedCommands_-1]->Undo(); + numAppliedCommands_--; + } + + void ViewportController::Redo() + { + ORTHANC_ASSERT(CanRedo(), ""); + commandStack_[numAppliedCommands_]->Redo(); + numAppliedCommands_++; + } + + bool ViewportController::CanUndo() const + { + return numAppliedCommands_ > 0; + } + + bool ViewportController::CanRedo() const + { + return numAppliedCommands_ < commandStack_.size(); + } + + void ViewportController::AddMeasureTool(MeasureToolPtr measureTool) + { + ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool) + == measureTools_.end(), "Duplicate measure tool"); + measureTools_.push_back(measureTool); + } + + void ViewportController::RemoveMeasureTool(MeasureToolPtr measureTool) + { + ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool) + != measureTools_.end(), "Measure tool not found"); + measureTools_.push_back(measureTool); + } + }