Mercurial > hg > orthanc-stone
changeset 1791:9b650ab68d4c
replaced unneeded use of boost::share_ptr for MeasureCommand mementos by std::unique_ptr
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 17 May 2021 16:11:17 +0200 |
parents | b325761e0bd3 |
children | 373d7f7e796e |
files | OrthancStone/Sources/Scene2D/MacroSceneLayer.h OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.cpp OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.h OrthancStone/Sources/Scene2DViewport/EditAngleMeasureCommand.cpp OrthancStone/Sources/Scene2DViewport/EditAngleMeasureTracker.cpp OrthancStone/Sources/Scene2DViewport/EditLineMeasureCommand.cpp OrthancStone/Sources/Scene2DViewport/EditLineMeasureTracker.cpp OrthancStone/Sources/Scene2DViewport/LineMeasureTool.cpp OrthancStone/Sources/Scene2DViewport/LineMeasureTool.h OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp OrthancStone/Sources/Scene2DViewport/MeasureCommands.h OrthancStone/Sources/Scene2DViewport/MeasureTool.h |
diffstat | 12 files changed, 133 insertions(+), 93 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2D/MacroSceneLayer.h Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2D/MacroSceneLayer.h Mon May 17 16:11:17 2021 +0200 @@ -32,7 +32,7 @@ { /** * A "macro layer" is a group of sublayers that are handled as a - * whole. + * whole, and that share the same depth in the scene. **/ class MacroSceneLayer : public ISceneLayer {
--- a/OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.cpp Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.cpp Mon May 17 16:11:17 2021 +0200 @@ -105,24 +105,21 @@ } - boost::shared_ptr<MeasureToolMemento> AngleMeasureTool::GetMemento() const + MeasureToolMemento* AngleMeasureTool::CreateMemento() const { - boost::shared_ptr<AngleMeasureToolMemento> memento(new AngleMeasureToolMemento()); + std::unique_ptr<AngleMeasureToolMemento> memento(new AngleMeasureToolMemento()); memento->center_ = center_; memento->side1End_ = side1End_; memento->side2End_ = side2End_; - return memento; + return memento.release(); } - void AngleMeasureTool::SetMemento(boost::shared_ptr<MeasureToolMemento> mementoBase) + void AngleMeasureTool::SetMemento(const MeasureToolMemento& mementoBase) { - boost::shared_ptr<AngleMeasureToolMemento> memento = - boost::dynamic_pointer_cast<AngleMeasureToolMemento>(mementoBase); - - ORTHANC_ASSERT(memento.get() != NULL, "Internal error: wrong (or bad) memento"); - center_ = memento->center_; - side1End_ = memento->side1End_; - side2End_ = memento->side2End_; + const AngleMeasureToolMemento& memento = dynamic_cast<const AngleMeasureToolMemento&>(mementoBase); + center_ = memento.center_; + side1End_ = memento.side1End_; + side2End_ = memento.side2End_; RefreshScene(); } @@ -352,7 +349,7 @@ double pointY = center_.GetY() + oy; char buf[64]; - double angleDeg = RadiansToDegrees(delta); + double angleDeg = std::abs(RadiansToDegrees(delta)); // http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=00B0&mode=hex sprintf(buf, "%0.02f\xc2\xb0", angleDeg);
--- a/OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.h Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.h Mon May 17 16:11:17 2021 +0200 @@ -53,8 +53,8 @@ virtual void Highlight(ScenePoint2D p) ORTHANC_OVERRIDE; virtual void ResetHighlightState() ORTHANC_OVERRIDE; virtual boost::shared_ptr<IFlexiblePointerTracker> CreateEditionTracker(const PointerEvent& e) ORTHANC_OVERRIDE; - virtual boost::shared_ptr<MeasureToolMemento> GetMemento() const ORTHANC_OVERRIDE; - virtual void SetMemento(boost::shared_ptr<MeasureToolMemento>) ORTHANC_OVERRIDE; + virtual MeasureToolMemento* CreateMemento() const ORTHANC_OVERRIDE; + virtual void SetMemento(const MeasureToolMemento& memento) ORTHANC_OVERRIDE; virtual std::string GetDescription() ORTHANC_OVERRIDE; enum AngleHighlightArea
--- a/OrthancStone/Sources/Scene2DViewport/EditAngleMeasureCommand.cpp Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/EditAngleMeasureCommand.cpp Mon May 17 16:11:17 2021 +0200 @@ -34,20 +34,20 @@ void EditAngleMeasureCommand::SetCenter(ScenePoint2D scenePos) { dynamic_cast<AngleMeasureTool&>(*measureTool_).SetCenter(scenePos); - mementoModified_ = measureTool_->GetMemento(); + SetMementoModified(measureTool_->CreateMemento()); } void EditAngleMeasureCommand::SetSide1End(ScenePoint2D scenePos) { dynamic_cast<AngleMeasureTool&>(*measureTool_).SetSide1End(scenePos); - mementoModified_ = measureTool_->GetMemento(); + SetMementoModified(measureTool_->CreateMemento()); } void EditAngleMeasureCommand::SetSide2End(ScenePoint2D scenePos) { dynamic_cast<AngleMeasureTool&>(*measureTool_).SetSide2End(scenePos); - mementoModified_ = measureTool_->GetMemento(); + SetMementoModified(measureTool_->CreateMemento()); } }
--- a/OrthancStone/Sources/Scene2DViewport/EditAngleMeasureTracker.cpp Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/EditAngleMeasureTracker.cpp Mon May 17 16:11:17 2021 +0200 @@ -61,42 +61,44 @@ ScenePoint2D delta = scenePos - GetOriginalClickPosition(); - boost::shared_ptr<AngleMeasureToolMemento> memento = - boost::dynamic_pointer_cast<AngleMeasureToolMemento>(command_->mementoOriginal_); - - ORTHANC_ASSERT(memento.get() != NULL); + const AngleMeasureToolMemento& memento = + dynamic_cast<const AngleMeasureToolMemento&>(command_->GetMementoOriginal()); switch (modifiedZone_) { case AngleMeasureTool::AngleHighlightArea_Center: { - ScenePoint2D newCenter = memento->center_ + delta; + ScenePoint2D newCenter = memento.center_ + delta; GetCommand()->SetCenter(newCenter); + break; } - break; + case AngleMeasureTool::AngleHighlightArea_Side1: case AngleMeasureTool::AngleHighlightArea_Side2: { - ScenePoint2D newCenter = memento->center_ + delta; - ScenePoint2D newSide1End = memento->side1End_ + delta; - ScenePoint2D newSide2End = memento->side2End_ + delta; + ScenePoint2D newCenter = memento.center_ + delta; + ScenePoint2D newSide1End = memento.side1End_ + delta; + ScenePoint2D newSide2End = memento.side2End_ + delta; GetCommand()->SetCenter(newCenter); GetCommand()->SetSide1End(newSide1End); GetCommand()->SetSide2End(newSide2End); + break; } - break; + case AngleMeasureTool::AngleHighlightArea_Side1End: { - ScenePoint2D newSide1End = memento->side1End_ + delta; + ScenePoint2D newSide1End = memento.side1End_ + delta; GetCommand()->SetSide1End(newSide1End); + break; } - break; + case AngleMeasureTool::AngleHighlightArea_Side2End: { - ScenePoint2D newSide2End = memento->side2End_ + delta; + ScenePoint2D newSide2End = memento.side2End_ + delta; GetCommand()->SetSide2End(newSide2End); + break; } - break; + default: LOG(WARNING) << "Warning: please retry the measuring tool editing operation!"; break;
--- a/OrthancStone/Sources/Scene2DViewport/EditLineMeasureCommand.cpp Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/EditLineMeasureCommand.cpp Mon May 17 16:11:17 2021 +0200 @@ -35,13 +35,13 @@ void EditLineMeasureCommand::SetStart(ScenePoint2D scenePos) { dynamic_cast<LineMeasureTool&>(*measureTool_).SetStart(scenePos); - mementoModified_ = measureTool_->GetMemento(); + SetMementoModified(measureTool_->CreateMemento()); } void EditLineMeasureCommand::SetEnd(ScenePoint2D scenePos) { dynamic_cast<LineMeasureTool&>(*measureTool_).SetEnd(scenePos); - mementoModified_ = measureTool_->GetMemento(); + SetMementoModified(measureTool_->CreateMemento()); } }
--- a/OrthancStone/Sources/Scene2DViewport/EditLineMeasureTracker.cpp Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/EditLineMeasureTracker.cpp Mon May 17 16:11:17 2021 +0200 @@ -56,36 +56,37 @@ ScenePoint2D delta = scenePos - GetOriginalClickPosition(); - boost::shared_ptr<LineMeasureToolMemento> memento = - boost::dynamic_pointer_cast<LineMeasureToolMemento>(command_->mementoOriginal_); - - ORTHANC_ASSERT(memento.get() != NULL); + const LineMeasureToolMemento& memento = + dynamic_cast<const LineMeasureToolMemento&>(command_->GetMementoOriginal()); switch (modifiedZone_) { - case LineMeasureTool::LineHighlightArea_Start: - { - ScenePoint2D newStart = memento->start_ + delta; - GetCommand()->SetStart(newStart); - } - break; - case LineMeasureTool::LineHighlightArea_End: - { - ScenePoint2D newEnd = memento->end_ + delta; - GetCommand()->SetEnd(newEnd); - } - break; - case LineMeasureTool::LineHighlightArea_Segment: - { - ScenePoint2D newStart = memento->start_ + delta; - ScenePoint2D newEnd = memento->end_ + delta; - GetCommand()->SetStart(newStart); - GetCommand()->SetEnd(newEnd); - } - break; - default: - LOG(WARNING) << "Warning: please retry the measuring tool editing operation!"; - break; + case LineMeasureTool::LineHighlightArea_Start: + { + ScenePoint2D newStart = memento.start_ + delta; + GetCommand()->SetStart(newStart); + break; + } + + case LineMeasureTool::LineHighlightArea_End: + { + ScenePoint2D newEnd = memento.end_ + delta; + GetCommand()->SetEnd(newEnd); + break; + } + + case LineMeasureTool::LineHighlightArea_Segment: + { + ScenePoint2D newStart = memento.start_ + delta; + ScenePoint2D newEnd = memento.end_ + delta; + GetCommand()->SetStart(newStart); + GetCommand()->SetEnd(newEnd); + break; + } + + default: + LOG(WARNING) << "Warning: please retry the measuring tool editing operation!"; + break; } } @@ -106,5 +107,4 @@ ORTHANC_ASSERT(ret.get() != NULL, "Internal error in EditLineMeasureTracker::GetCommand()"); return ret; } - }
--- a/OrthancStone/Sources/Scene2DViewport/LineMeasureTool.cpp Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/LineMeasureTool.cpp Mon May 17 16:11:17 2021 +0200 @@ -178,24 +178,19 @@ } } - boost::shared_ptr<MeasureToolMemento> LineMeasureTool::GetMemento() const + MeasureToolMemento* LineMeasureTool::CreateMemento() const { - boost::shared_ptr<LineMeasureToolMemento> memento(new LineMeasureToolMemento()); + std::unique_ptr<LineMeasureToolMemento> memento(new LineMeasureToolMemento()); memento->start_ = start_; memento->end_ = end_; - return memento; + return memento.release(); } - void LineMeasureTool::SetMemento( - boost::shared_ptr<MeasureToolMemento> mementoBase) + void LineMeasureTool::SetMemento(const MeasureToolMemento& mementoBase) { - boost::shared_ptr<LineMeasureToolMemento> memento = - boost::dynamic_pointer_cast<LineMeasureToolMemento>(mementoBase); - - ORTHANC_ASSERT(memento.get() != NULL, "Internal error: wrong (or bad) memento"); - - start_ = memento->start_; - end_ = memento->end_; + const LineMeasureToolMemento& memento = dynamic_cast<const LineMeasureToolMemento&>(mementoBase); + start_ = memento.start_; + end_ = memento.end_; RefreshScene(); }
--- a/OrthancStone/Sources/Scene2DViewport/LineMeasureTool.h Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/LineMeasureTool.h Mon May 17 16:11:17 2021 +0200 @@ -52,8 +52,8 @@ virtual void Highlight(ScenePoint2D p) ORTHANC_OVERRIDE; virtual void ResetHighlightState() ORTHANC_OVERRIDE; virtual boost::shared_ptr<IFlexiblePointerTracker> CreateEditionTracker(const PointerEvent& e) ORTHANC_OVERRIDE; - virtual boost::shared_ptr<MeasureToolMemento> GetMemento() const ORTHANC_OVERRIDE; - virtual void SetMemento(boost::shared_ptr<MeasureToolMemento>) ORTHANC_OVERRIDE; + virtual MeasureToolMemento* CreateMemento() const ORTHANC_OVERRIDE; + virtual void SetMemento(const MeasureToolMemento& memento) ORTHANC_OVERRIDE; virtual std::string GetDescription() ORTHANC_OVERRIDE; enum LineHighlightArea
--- a/OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/MeasureCommands.cpp Mon May 17 16:11:17 2021 +0200 @@ -90,8 +90,8 @@ boost::weak_ptr<IViewport> viewport) : MeasureCommand(viewport), measureTool_(measureTool), - mementoModified_(measureTool->GetMemento()), - mementoOriginal_(measureTool->GetMemento()) + mementoModified_(measureTool->CreateMemento()), + mementoOriginal_(measureTool->CreateMemento()) { std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); GetMeasureTool()->Disable(); @@ -101,8 +101,8 @@ EditMeasureCommand::EditMeasureCommand(boost::shared_ptr<MeasureTool> measureTool, boost::weak_ptr<IViewport> viewport) : MeasureCommand(viewport), - mementoModified_(measureTool->GetMemento()), - mementoOriginal_(measureTool->GetMemento()) + mementoModified_(measureTool->CreateMemento()), + mementoOriginal_(measureTool->CreateMemento()) { } @@ -113,11 +113,49 @@ void EditMeasureCommand::Undo() { // simply disable the measure tool upon undo - GetMeasureTool()->SetMemento(mementoOriginal_); + assert(mementoOriginal_.get() != NULL); + GetMeasureTool()->SetMemento(*mementoOriginal_); } void EditMeasureCommand::Redo() { - GetMeasureTool()->SetMemento(mementoModified_); + assert(mementoModified_.get() != NULL); + GetMeasureTool()->SetMemento(*mementoModified_); + } + + const MeasureToolMemento& EditMeasureCommand::GetMementoOriginal() const + { + assert(mementoOriginal_.get() != NULL); + return *mementoOriginal_; + } + + void EditMeasureCommand::SetMementoModified(MeasureToolMemento* memento) + { + if (memento == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); + } + else + { + mementoModified_.reset(memento); + } + } + + const MeasureToolMemento& DeleteMeasureCommand::GetMementoOriginal() const + { + assert(mementoOriginal_.get() != NULL); + return *mementoOriginal_; + } + + void DeleteMeasureCommand::SetMementoModified(MeasureToolMemento* memento) + { + if (memento == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); + } + else + { + mementoModified_.reset(memento); + } } }
--- a/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h Mon May 17 16:11:17 2021 +0200 @@ -84,9 +84,14 @@ /** Must be implemented by the subclasses that edit the actual tool */ virtual boost::shared_ptr<MeasureTool> GetMeasureTool() = 0; + /** This memento is updated by the subclasses upon modifications */ + std::unique_ptr<MeasureToolMemento> mementoModified_; + + /** This memento is the original object state */ + std::unique_ptr<MeasureToolMemento> mementoOriginal_; + protected: - /** This memento is updated by the subclasses upon modifications */ - boost::shared_ptr<MeasureToolMemento> mementoModified_; + void SetMementoModified(MeasureToolMemento* memento); // takes ownership public: EditMeasureCommand(boost::shared_ptr<MeasureTool> measureTool, @@ -97,9 +102,8 @@ virtual void Undo() ORTHANC_OVERRIDE; virtual void Redo() ORTHANC_OVERRIDE; - - /** This memento is the original object state */ - boost::shared_ptr<MeasureToolMemento> mementoOriginal_; + + const MeasureToolMemento& GetMementoOriginal() const; }; @@ -114,9 +118,14 @@ boost::shared_ptr<MeasureTool> measureTool_; + /** This memento is updated by the subclasses upon modifications */ + std::unique_ptr<MeasureToolMemento> mementoModified_; + + /** This memento is the original object state */ + std::unique_ptr<MeasureToolMemento> mementoOriginal_; + protected: - /** This memento is updated by the subclasses upon modifications */ - boost::shared_ptr<MeasureToolMemento> mementoModified_; + void SetMementoModified(MeasureToolMemento* memento); // takes ownership public: DeleteMeasureCommand(boost::shared_ptr<MeasureTool> measureTool, @@ -128,8 +137,7 @@ virtual void Redo() ORTHANC_OVERRIDE; - /** This memento is the original object state */ - boost::shared_ptr<MeasureToolMemento> mementoOriginal_; + const MeasureToolMemento& GetMementoOriginal() const; }; }
--- a/OrthancStone/Sources/Scene2DViewport/MeasureTool.h Mon May 17 13:57:25 2021 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/MeasureTool.h Mon May 17 16:11:17 2021 +0200 @@ -124,13 +124,13 @@ This method must return a memento the captures the tool state (not including the highlighting state */ - virtual boost::shared_ptr<MeasureToolMemento> GetMemento() const = 0; + virtual MeasureToolMemento* CreateMemento() const = 0; /** This method must apply the supplied memento (this requires RTTI to check the type) */ - virtual void SetMemento(boost::shared_ptr<MeasureToolMemento>) = 0; + virtual void SetMemento(const MeasureToolMemento& memento) = 0; /** This must create an edition tracker suitable for the supplied click position,