Mercurial > hg > orthanc-stone
changeset 2363:c03e04878b15 refactoring
cont refactoring MeasureTool
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Thu, 08 Oct 2026 14:27:50 +0200 |
| parents | fd6db8542d10 |
| children | 23acf5a24806 |
| files | OrthancStone/Sources/Scene2DViewport/MeasureCommands.h OrthancStone/Sources/Scene2DViewport/UndoStack.cpp OrthancStone/Sources/Scene2DViewport/UndoStack.h OrthancStone/Sources/Scene2DViewport/ViewportController.cpp OrthancStone/Sources/Scene2DViewport/ViewportController.h |
| diffstat | 5 files changed, 39 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h Thu Oct 08 14:16:47 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h Thu Oct 08 14:27:50 2026 +0200 @@ -22,11 +22,10 @@ #pragma once #include "../Viewport/IViewport.h" - -// to be moved into Stone #include "MeasureTool.h" #include "LineMeasureTool.h" #include "AngleMeasureTool.h" +#include "UndoStack.h" #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> @@ -34,7 +33,7 @@ namespace OrthancStone { - class MeasureCommand : public boost::noncopyable + class MeasureCommand : public UndoStack::ICommand { protected: boost::weak_ptr<IViewport> viewport_;
--- a/OrthancStone/Sources/Scene2DViewport/UndoStack.cpp Thu Oct 08 14:16:47 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/UndoStack.cpp Thu Oct 08 14:27:50 2026 +0200 @@ -22,23 +22,17 @@ #include "UndoStack.h" -#include "MeasureCommands.h" - #include "../StoneException.h" namespace OrthancStone { - UndoStack::UndoStack() : numAppliedCommands_(0) - {} - - void UndoStack::PushCommand(const boost::shared_ptr<MeasureCommand>& command) + void UndoStack::PushCommand(const boost::shared_ptr<ICommand>& command) { commandStack_.erase( commandStack_.begin() + numAppliedCommands_, commandStack_.end()); - ORTHANC_ASSERT(std::find(commandStack_.begin(), commandStack_.end(), command) - == commandStack_.end(), "Duplicate command"); + ORTHANC_ASSERT(std::find(commandStack_.begin(), commandStack_.end(), command) == commandStack_.end(), "Duplicate command"); commandStack_.push_back(command); numAppliedCommands_++; } @@ -66,5 +60,4 @@ { return numAppliedCommands_ < commandStack_.size(); } - }
--- a/OrthancStone/Sources/Scene2DViewport/UndoStack.h Thu Oct 08 14:16:47 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/UndoStack.h Thu Oct 08 14:27:50 2026 +0200 @@ -24,17 +24,42 @@ #include <boost/noncopyable.hpp> #include <boost/shared_ptr.hpp> +#include <vector> -#include <vector> namespace OrthancStone { - class MeasureCommand; - class UndoStack : public boost::noncopyable { public: - UndoStack(); + class ICommand : public boost::noncopyable + { + public: + virtual ~ICommand() + { + } + + virtual void Undo() = 0; + + virtual void Redo() = 0; + }; + + private: + std::vector<boost::shared_ptr<ICommand> > commandStack_; + + /** + This is always between >= 0 and <= undoStack_.size() and gives the + position where the controller is in the undo stack. + - If numAppliedCommands_ > 0, one can undo + - If numAppliedCommands_ < numAppliedCommands_.size(), one can redo + */ + size_t numAppliedCommands_; + + public: + UndoStack() : + numAppliedCommands_(0) + { + } /** Stores a command : @@ -44,37 +69,24 @@ In other words, when a new command is pushed, all the undone (and not redone) commands are removed. */ - void PushCommand(const boost::shared_ptr<MeasureCommand>& command); + void PushCommand(const boost::shared_ptr<ICommand>& command); /** Undoes the command at the top of the undo stack, or throws if there is no command to undo. - You can check "CanUndo" first to protect against extraneous redo. + You can check "CanUndo()" first to protect against extraneous undo. */ void Undo(); /** Redoes the command that is just above the last applied command in the undo stack or throws if there is no command to redo. - You can check "CanRedo" first to protect against extraneous redo. + You can check "CanRedo()" first to protect against extraneous redo. */ void Redo(); - /** selfexpl */ bool CanUndo() const; - /** selfexpl */ bool CanRedo() const; - - private: - std::vector<boost::shared_ptr<MeasureCommand> > commandStack_; - - /** - This is always between >= 0 and <= undoStack_.size() and gives the - position where the controller is in the undo stack. - - If numAppliedCommands_ > 0, one can undo - - If numAppliedCommands_ < numAppliedCommands_.size(), one can redo - */ - size_t numAppliedCommands_; }; }
--- a/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp Thu Oct 08 14:16:47 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp Thu Oct 08 14:27:50 2026 +0200 @@ -38,7 +38,7 @@ // The controller must be able to cope with this. } - void ViewportController::PushCommand(const boost::shared_ptr<MeasureCommand>& command) + void ViewportController::PushCommand(const boost::shared_ptr<UndoStack::ICommand>& command) { if (undoStackW_) {
--- a/OrthancStone/Sources/Scene2DViewport/ViewportController.h Thu Oct 08 14:16:47 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.h Thu Oct 08 14:27:50 2026 +0200 @@ -27,6 +27,7 @@ #include "../Scene2DViewport/IFlexiblePointerTracker.h" #include "../Viewport/IViewport.h" #include "../Viewport/IViewportInteractor.h" +#include "UndoStack.h" #include <Compatibility.h> @@ -35,9 +36,7 @@ namespace OrthancStone { - class MeasureCommand; class MeasureTool; - class UndoStack; const double ARC_RADIUS_CANVAS_COORD = 30.0; const double TEXT_CENTER_DISTANCE_CANVAS_COORD = 90; @@ -163,7 +162,7 @@ /** forwarded to the UndoStack */ - void PushCommand(const boost::shared_ptr<MeasureCommand>& command); + void PushCommand(const boost::shared_ptr<UndoStack::ICommand>& command); /** forwarded to the UndoStack */ void Undo();
