Mercurial > hg > orthanc-stone
changeset 2367:1cd6717413bb refactoring
simplified DeleteMeasureCommand
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Thu, 08 Oct 2026 19:14:19 +0200 |
| parents | 0e47eebd492c |
| children | f510260c4ffa |
| files | Applications/Samples/Common/SimpleViewerCore.cpp OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp OrthancStone/Sources/Scene2DViewport/MeasureCommands.h |
| diffstat | 3 files changed, 45 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/Common/SimpleViewerCore.cpp Thu Oct 08 17:25:01 2026 +0200 +++ b/Applications/Samples/Common/SimpleViewerCore.cpp Thu Oct 08 19:14:19 2026 +0200 @@ -23,16 +23,12 @@ #include "SimpleViewerCore.h" // TODO Refactoring - Remove -#define TEST_LINE_MEASURE_TOOL 1 -#define TEST_ANGLE_MEASURE_TOOL 1 +#define TEST_MEASURE_TOOLS 1 #include "../../../OrthancStone/Sources/Scene2DViewport/UndoStack.h" #include "../../../OrthancStone/Sources/Viewport/DefaultViewportInteractor.h" - -#include "../../../OrthancStone/Sources/Scene2DViewport/LineMeasureTool.h" // TODO Refactoring - Remove -#include "../../../OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.h" // TODO Refactoring - Remove #include "../../../OrthancStone/Sources/Scene2DViewport/MeasureCommands.h" // TODO Refactoring - Remove @@ -161,7 +157,7 @@ viewportLock->GetController().SetUndoStack(boost::make_shared<UndoStack>()); } -#if TEST_LINE_MEASURE_TOOL == 1 +#if TEST_MEASURE_TOOLS == 1 { boost::shared_ptr<LineMeasureTool> tool = OrthancStone::LineMeasureTool::Create(viewport); tool->Enable(); @@ -171,9 +167,7 @@ std::unique_ptr<IViewport::ILock> viewportLock(viewport->Lock()); viewportLock->GetController().AddMeasureTool(boost::dynamic_pointer_cast<MeasureTool>(tool)); } -#endif -#if TEST_ANGLE_MEASURE_TOOL == 1 { boost::shared_ptr<AngleMeasureTool> tool = OrthancStone::AngleMeasureTool::Create(viewport); tool->Enable(); @@ -252,7 +246,7 @@ unsigned int viewportWidth, unsigned int viewportHeight) ORTHANC_OVERRIDE { -#if TEST_LINE_MEASURE_TOOL == 1 +#if TEST_MEASURE_TOOLS == 1 const ScenePoint2D p = event.GetMainPosition().Apply(scene.GetCanvasToSceneTransform()); std::vector< boost::shared_ptr<MeasureTool> > tools;
--- a/OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp Thu Oct 08 17:25:01 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp Thu Oct 08 19:14:19 2026 +0200 @@ -33,9 +33,22 @@ { boost::shared_ptr<IViewport> viewport = viewport_.lock(); if (viewport) + { return viewport->Lock(); + } else + { return NULL; + } + } + + + + CreateMeasureCommand::CreateMeasureCommand(const boost::shared_ptr<MeasureTool>& tool, + boost::weak_ptr<IViewport> viewport) : + MeasureCommand(viewport), + measureTool_(tool) + { } @@ -47,6 +60,7 @@ lock->GetController().RemoveMeasureTool(measureTool_); } + void CreateMeasureCommand::Redo() { std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); @@ -54,47 +68,8 @@ lock->GetController().AddMeasureTool(measureTool_); } - CreateMeasureCommand::CreateMeasureCommand(const boost::shared_ptr<MeasureTool>& tool, - boost::weak_ptr<IViewport> viewport) : - MeasureCommand(viewport), - measureTool_(tool) - { - - } - - void DeleteMeasureCommand::Redo() - { - std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); - // simply disable the measure tool upon undo - measureTool_->Disable(); - lock->GetController().RemoveMeasureTool(measureTool_); - } - void DeleteMeasureCommand::Undo() - { - std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); - measureTool_->Enable(); - lock->GetController().AddMeasureTool(measureTool_); - } - DeleteMeasureCommand::DeleteMeasureCommand(const boost::shared_ptr<MeasureTool>& measureTool, - boost::weak_ptr<IViewport> viewport) : - MeasureCommand(viewport), - measureTool_(measureTool), - mementoModified_(measureTool->CreateMemento()), // TODO Refactoring - Why this? - mementoOriginal_(measureTool->CreateMemento()) // TODO Refactoring - Why this? - { - if (!measureTool) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); - } - - { - std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); - measureTool_->Disable(); - lock->GetController().RemoveMeasureTool(measureTool_); // TODO Refactoring - Should probably be moved into ViewportController - } - } EditMeasureCommand::EditMeasureCommand(const boost::shared_ptr<MeasureTool>& measureTool, boost::weak_ptr<IViewport> viewport) : @@ -140,21 +115,39 @@ } } - const MeasureTool::IMemento& DeleteMeasureCommand::GetMementoOriginal() const + + + DeleteMeasureCommand::DeleteMeasureCommand(const boost::shared_ptr<MeasureTool>& measureTool, + boost::weak_ptr<IViewport> viewport) : + MeasureCommand(viewport), + measureTool_(measureTool) { - assert(mementoOriginal_.get() != NULL); - return *mementoOriginal_; - } - - void DeleteMeasureCommand::SetMementoModified(MeasureTool::IMemento* memento) - { - if (memento == NULL) + if (!measureTool) { throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); } - else + { - mementoModified_.reset(memento); + std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); + measureTool_->Disable(); + lock->GetController().RemoveMeasureTool(measureTool_); // TODO Refactoring - Should probably be moved into ViewportController } } + + + void DeleteMeasureCommand::Undo() + { + std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); + measureTool_->Enable(); + lock->GetController().AddMeasureTool(measureTool_); + } + + + void DeleteMeasureCommand::Redo() + { + std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); + // simply disable the measure tool upon undo + measureTool_->Disable(); + lock->GetController().RemoveMeasureTool(measureTool_); + } }
--- a/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h Thu Oct 08 17:25:01 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h Thu Oct 08 19:14:19 2026 +0200 @@ -111,15 +111,6 @@ private: boost::shared_ptr<MeasureTool> measureTool_; - /** This memento is updated by the subclasses upon modifications */ - std::unique_ptr<MeasureTool::IMemento> mementoModified_; // TODO Refactoring - Memento shouldn't be used on deletion - - /** This memento is the original object state */ - std::unique_ptr<MeasureTool::IMemento> mementoOriginal_; - - protected: - void SetMementoModified(MeasureTool::IMemento* memento); // takes ownership - public: DeleteMeasureCommand(const boost::shared_ptr<MeasureTool>& measureTool, boost::weak_ptr<IViewport> viewport); @@ -127,7 +118,5 @@ virtual void Undo() ORTHANC_OVERRIDE; virtual void Redo() ORTHANC_OVERRIDE; - - const MeasureTool::IMemento& GetMementoOriginal() const; }; }
