# HG changeset patch # User Sebastien Jodogne # Date 1791462470 -7200 # Node ID c03e04878b15e80b126a4fb7c43cb8a59327e8db # Parent fd6db8542d106adb43a51675fd0b6dabbfce4794 cont refactoring MeasureTool diff -r fd6db8542d10 -r c03e04878b15 OrthancStone/Sources/Scene2DViewport/MeasureCommands.h --- 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 #include @@ -34,7 +33,7 @@ namespace OrthancStone { - class MeasureCommand : public boost::noncopyable + class MeasureCommand : public UndoStack::ICommand { protected: boost::weak_ptr viewport_; diff -r fd6db8542d10 -r c03e04878b15 OrthancStone/Sources/Scene2DViewport/UndoStack.cpp --- 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& command) + void UndoStack::PushCommand(const boost::shared_ptr& 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(); } - } diff -r fd6db8542d10 -r c03e04878b15 OrthancStone/Sources/Scene2DViewport/UndoStack.h --- 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 #include +#include -#include 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 > 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& command); + void PushCommand(const boost::shared_ptr& 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 > 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_; }; } diff -r fd6db8542d10 -r c03e04878b15 OrthancStone/Sources/Scene2DViewport/ViewportController.cpp --- 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& command) + void ViewportController::PushCommand(const boost::shared_ptr& command) { if (undoStackW_) { diff -r fd6db8542d10 -r c03e04878b15 OrthancStone/Sources/Scene2DViewport/ViewportController.h --- 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 @@ -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& command); + void PushCommand(const boost::shared_ptr& command); /** forwarded to the UndoStack */ void Undo();