diff OrthancStone/Sources/Scene2DViewport/MeasureCommands.h @ 1606:874e178f34e9

- ViewportController now has weak ptr to Viewport - Measuring tools + related commands and all trackers now store only a weak_ptr to the Viewport and lock() on demand for usage - LayerHolder and FixedPoint aligner store only a weak_ptr to the Viewport, too - Fixed float/double warning in GrayscaleWindowingSceneTracker
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 28 Oct 2020 20:14:34 +0100
parents 8563ea5d8ae4
children 9ac2a65d4172
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h	Wed Oct 28 20:06:55 2020 +0100
+++ b/OrthancStone/Sources/Scene2DViewport/MeasureCommands.h	Wed Oct 28 20:14:34 2020 +0100
@@ -29,6 +29,7 @@
 #include "AngleMeasureTool.h"
 
 #include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
 #include <boost/noncopyable.hpp>
 
 namespace OrthancStone
@@ -36,10 +37,16 @@
   class MeasureCommand : public boost::noncopyable
   {
   protected:
-    boost::shared_ptr<IViewport> viewport_;
+    boost::weak_ptr<IViewport> viewport_;
+
+    /**
+    This will return a scoped lock to the viewport.
+    If the viewport does not exist anymore, then nullptr is returned.
+    */
+    IViewport::ILock* GetViewportLock();
 
   public:
-    explicit MeasureCommand(boost::shared_ptr<IViewport> viewport) :
+    explicit MeasureCommand(boost::weak_ptr<IViewport> viewport) :
       viewport_(viewport)
     {
     }
@@ -61,7 +68,7 @@
     virtual boost::shared_ptr<MeasureTool> GetMeasureTool() = 0;
 
   public:
-    explicit CreateMeasureCommand(boost::shared_ptr<IViewport> viewport);
+    explicit CreateMeasureCommand(boost::weak_ptr<IViewport> viewport);
     
     virtual ~CreateMeasureCommand();
     
@@ -83,7 +90,7 @@
 
   public:
     EditMeasureCommand(boost::shared_ptr<MeasureTool> measureTool,
-                       boost::shared_ptr<IViewport> viewport);
+                       boost::weak_ptr<IViewport> viewport);
 
     virtual ~EditMeasureCommand();
 
@@ -113,7 +120,7 @@
 
   public:
     DeleteMeasureCommand(boost::shared_ptr<MeasureTool> measureTool,
-                         boost::shared_ptr<IViewport> viewport);
+                         boost::weak_ptr<IViewport> viewport);
 
     virtual ~DeleteMeasureCommand();