changeset 2402:a7ae81526abe refactoring

using new messages in SimpleViewerCore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 12 Nov 2026 21:27:48 +0100
parents 255887af90a1
children 6ee42446c1b1
files Applications/Samples/Common/SimpleViewerCore.cpp Applications/Samples/Common/SimpleViewerCore.h Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Loaders/OrthancSeriesVolumeProgressiveLoader.h OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h
diffstat 6 files changed, 74 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/Common/SimpleViewerCore.cpp	Thu Nov 12 20:43:57 2026 +0100
+++ b/Applications/Samples/Common/SimpleViewerCore.cpp	Thu Nov 12 21:27:48 2026 +0100
@@ -152,7 +152,7 @@
     annotations_->SetActiveTool(AnnotationsSceneLayer::Tool_Edit);
     annotations_->SetProbedLayer(0);
 
-    OldRegister<AnnotationsSceneLayer::AnnotationRemovedMessage>(*annotations_, &SimpleViewerCore::Handle);
+    New::IObservable::Bind<AnnotationRemovedMessage>(annotations_, shared_from_this());
 
     controller_->SetUndoStack(boost::make_shared<UndoStack>());
 
--- a/Applications/Samples/Common/SimpleViewerCore.h	Thu Nov 12 20:43:57 2026 +0100
+++ b/Applications/Samples/Common/SimpleViewerCore.h	Thu Nov 12 21:27:48 2026 +0100
@@ -33,10 +33,10 @@
 {
   class SimpleViewerCore :
     public ISingleViewportApplicationCore,
-    //public boost::enable_shared_from_this<SimpleViewerCore>,  // TODO Refactoring - Revert
+    public boost::enable_shared_from_this<SimpleViewerCore>,
     public New::TypedObserver<FrameDecodedMessage>,
     public New::TypedObserver<DicomResourcesLoadedMessage>,
-    public OrthancStone::Old::ObserverBase<SimpleViewerCore>  // TODO Refactoring - Remove
+    public New::TypedObserver<AnnotationRemovedMessage>
   {
   protected:
     boost::shared_ptr<StoneApplication::Context>  context_;
@@ -56,7 +56,8 @@
     virtual void Handle(const New::IObservable& observable,
                         const DicomResourcesLoadedMessage& message) ORTHANC_OVERRIDE;
 
-    void Handle(const AnnotationsSceneLayer::AnnotationRemovedMessage& message)
+    virtual void Handle(const New::IObservable& observable,
+                        const AnnotationRemovedMessage& message) ORTHANC_OVERRIDE
     {
       RenderAnnotations();
     }
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Thu Nov 12 20:43:57 2026 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Thu Nov 12 21:27:48 2026 +0100
@@ -3372,12 +3372,12 @@
     RefreshAnnotations(false /* don't save */);
   }
 
-  void Handle(const OrthancStone::AnnotationsSceneLayer::AnnotationChangedMessage& message)
+  void Handle(const OrthancStone::AnnotationChangedMessage& message)
   {
     RefreshAnnotations(true /* save */);
   }
 
-  void Handle(const OrthancStone::AnnotationsSceneLayer::AnnotationAddedMessage& message)
+  void Handle(const OrthancStone::AnnotationAddedMessage& message)
   {
     RefreshAnnotations(true /* save */);
 
@@ -3387,7 +3387,7 @@
     }
   }
 
-  void Handle(const OrthancStone::AnnotationsSceneLayer::AnnotationRemovedMessage& message)
+  void Handle(const OrthancStone::AnnotationRemovedMessage& message)
   {
     RefreshAnnotations(true /* save */);
 
@@ -3397,7 +3397,7 @@
     }
   }
 
-  void Handle(const OrthancStone::AnnotationsSceneLayer::TextAnnotationRequiredMessage& message)
+  void Handle(const OrthancStone::TextAnnotationRequiredMessage& message)
   {
     if (observer_.get() != NULL)
     {
@@ -3448,16 +3448,16 @@
       viewport->OldRegister<OrthancStone::ParseDicomSuccessMessage>(
         context.GetOracleObservable(), &ViewerViewport::Handle);
 
-      viewport->OldRegister<OrthancStone::AnnotationsSceneLayer::AnnotationChangedMessage>(
+      viewport->OldRegister<OrthancStone::AnnotationChangedMessage>(
         *viewport->stoneAnnotations_, &ViewerViewport::Handle);
 
-      viewport->OldRegister<OrthancStone::AnnotationsSceneLayer::AnnotationAddedMessage>(
+      viewport->OldRegister<OrthancStone::AnnotationAddedMessage>(
         *viewport->stoneAnnotations_, &ViewerViewport::Handle);
 
-      viewport->OldRegister<OrthancStone::AnnotationsSceneLayer::AnnotationRemovedMessage>(
+      viewport->OldRegister<OrthancStone::AnnotationRemovedMessage>(
         *viewport->stoneAnnotations_, &ViewerViewport::Handle);
 
-      viewport->OldRegister<OrthancStone::AnnotationsSceneLayer::TextAnnotationRequiredMessage>(
+      viewport->OldRegister<OrthancStone::TextAnnotationRequiredMessage>(
         *viewport->stoneAnnotations_, &ViewerViewport::Handle);
     }
 
--- a/OrthancStone/Sources/Loaders/OrthancSeriesVolumeProgressiveLoader.h	Thu Nov 12 20:43:57 2026 +0100
+++ b/OrthancStone/Sources/Loaders/OrthancSeriesVolumeProgressiveLoader.h	Thu Nov 12 21:27:48 2026 +0100
@@ -45,15 +45,7 @@
 {
   class OrthancSeriesVolumeProgressiveLoader;
 
-  class VolumeImageReadyInHighQuality : public ::OrthancStone::OriginMessage<OrthancSeriesVolumeProgressiveLoader>
-  {
-    ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
-
-    explicit VolumeImageReadyInHighQuality(const OrthancSeriesVolumeProgressiveLoader& origin) :
-      OriginMessage(origin)
-    {
-    }
-  };
+  ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, VolumeImageReadyInHighQuality, OrthancSeriesVolumeProgressiveLoader);
 
   /**
     This class is used to manage the progressive loading of a volume that
--- a/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp	Thu Nov 12 20:43:57 2026 +0100
+++ b/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp	Thu Nov 12 21:27:48 2026 +0100
@@ -1057,6 +1057,7 @@
       primitive_.MovePreview(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_, scene);
 
       that_.BroadcastMessage(AnnotationChangedMessage(that_));
+      that_.TypedObservable<AnnotationChangedMessage>::Notify(that_, AnnotationChangedMessage(that_));
       that_.Render(scene);
 
       return true;
@@ -1069,6 +1070,7 @@
       alive_ = false;
 
       that_.BroadcastMessage(AnnotationChangedMessage(that_));
+      that_.TypedObservable<AnnotationChangedMessage>::Notify(that_, AnnotationChangedMessage(that_));
       that_.Render(scene);
     }
 
@@ -2407,6 +2409,7 @@
         annotation_->SignalMove(annotation_->GetHandle(1), scene);
 
         layer_.BroadcastMessage(AnnotationChangedMessage(layer_));
+        layer_.TypedObservable<AnnotationChangedMessage>::Notify(layer_, AnnotationChangedMessage(layer_));
         layer_.Render(scene);
         return true;
       }
@@ -2422,6 +2425,7 @@
       annotation_ = NULL;  // IsAlive() becomes false
 
       layer_.BroadcastMessage(AnnotationAddedMessage(layer_));
+      layer_.TypedObservable<AnnotationAddedMessage>::Notify(layer_, AnnotationAddedMessage(layer_));
       layer_.Render(scene);
     }
 
@@ -2476,6 +2480,7 @@
         length_->GetHandle(1).SetCenter(event.GetMainPosition().Apply(canvasToScene_));
         length_->SignalMove(length_->GetHandle(1), scene);
         that_.BroadcastMessage(AnnotationChangedMessage(that_));
+        that_.TypedObservable<AnnotationChangedMessage>::Notify(that_, AnnotationChangedMessage(that_));
         that_.Render(scene);
         redraw = true;
       }
@@ -2485,6 +2490,7 @@
         angle_->GetHandle(2).SetCenter(event.GetMainPosition().Apply(canvasToScene_));
         angle_->SignalMove(angle_->GetHandle(2), scene);
         that_.BroadcastMessage(AnnotationChangedMessage(that_));
+        that_.TypedObservable<AnnotationChangedMessage>::Notify(that_, AnnotationChangedMessage(that_));
         that_.Render(scene);
         redraw = true;
       }
@@ -2507,6 +2513,7 @@
         length_ = NULL;
 
         that_.BroadcastMessage(AnnotationChangedMessage(that_));
+        that_.TypedObservable<AnnotationChangedMessage>::Notify(that_, AnnotationChangedMessage(that_));
         that_.Render(scene);
       }
       else
@@ -2514,6 +2521,7 @@
         angle_ = NULL;  // IsAlive() becomes false
 
         that_.BroadcastMessage(AnnotationAddedMessage(that_));
+        that_.TypedObservable<AnnotationAddedMessage>::Notify(that_, AnnotationAddedMessage(that_));
         that_.Render(scene);
       }
     }
@@ -2557,6 +2565,7 @@
       annotation->UpdateProbe(scene);
 
       that.BroadcastMessage(AnnotationAddedMessage(that));
+      that.TypedObservable<AnnotationAddedMessage>::Notify(that, AnnotationAddedMessage(that));
       that.Render(scene);
     }
 
@@ -2609,9 +2618,12 @@
       }
       
       Cancel(scene);  // Warning: "annotation_" is now invalid!
-      
+
       GetLayer().BroadcastMessage(AnnotationChangedMessage(GetLayer()));
       GetLayer().BroadcastMessage(*request);
+
+      GetLayer().TypedObservable<AnnotationChangedMessage>::Notify(GetLayer(), AnnotationChangedMessage(GetLayer()));
+      GetLayer().TypedObservable<TextAnnotationRequiredMessage>::Notify(GetLayer(), *request);
       GetLayer().Render(scene);
     }
   };
@@ -2731,6 +2743,7 @@
   {
     annotations_.insert(new LengthAnnotation(*this, units_, true /* show label */, p1, p2));
     BroadcastMessage(AnnotationChangedMessage(*this));
+    TypedObservable<AnnotationChangedMessage>::Notify(*this, AnnotationChangedMessage(*this));
   }
   
 
@@ -2739,6 +2752,7 @@
   {
     annotations_.insert(new CircleAnnotation(*this, units_, p1, p2));
     BroadcastMessage(AnnotationChangedMessage(*this));
+    TypedObservable<AnnotationChangedMessage>::Notify(*this, AnnotationChangedMessage(*this));
   }
   
 
@@ -2748,6 +2762,7 @@
   {
     annotations_.insert(new AngleAnnotation(*this, p1, p2, p3));
     BroadcastMessage(AnnotationChangedMessage(*this));
+    TypedObservable<AnnotationChangedMessage>::Notify(*this, AnnotationChangedMessage(*this));
   }
   
 
@@ -2888,6 +2903,7 @@
         {
           DeleteAnnotation(&bestHit->GetParentAnnotation());
           BroadcastMessage(AnnotationRemovedMessage(*this));
+          TypedObservable<AnnotationRemovedMessage>::Notify(*this, AnnotationRemovedMessage(*this));
           return new RemoveTracker;
         }
         else
@@ -3055,5 +3071,6 @@
   {
     annotations_.insert(new TextAnnotation(*this, label, pointedPosition, labelPosition));
     BroadcastMessage(AnnotationChangedMessage(*this));
+    TypedObservable<AnnotationChangedMessage>::Notify(*this, AnnotationChangedMessage(*this));
   }
 }
--- a/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h	Thu Nov 12 20:43:57 2026 +0100
+++ b/OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h	Thu Nov 12 21:27:48 2026 +0100
@@ -30,42 +30,50 @@
 
 namespace OrthancStone
 {
-  class AnnotationsSceneLayer : public Old::IObservable
+  class AnnotationsSceneLayer;
+
+  ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, AnnotationAddedMessage, AnnotationsSceneLayer);
+  ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, AnnotationRemovedMessage, AnnotationsSceneLayer);
+  ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, AnnotationChangedMessage, AnnotationsSceneLayer);
+
+  class TextAnnotationRequiredMessage : public OriginMessage<AnnotationsSceneLayer>
+  {
+    ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
+
+  private:
+    ScenePoint2D pointedPosition_;
+    ScenePoint2D labelPosition_;
+
+  public:
+    TextAnnotationRequiredMessage(const AnnotationsSceneLayer& origin,
+                                  ScenePoint2D pointedPosition,
+                                  ScenePoint2D labelPosition) :
+      OriginMessage(origin),
+      pointedPosition_(pointedPosition),
+      labelPosition_(labelPosition)
+    {
+    }
+
+    const ScenePoint2D& GetPointedPosition() const
+    {
+      return pointedPosition_;
+    }
+
+    const ScenePoint2D& GetLabelPosition() const
+    {
+      return labelPosition_;
+    }
+  };
+
+  class AnnotationsSceneLayer :
+    public Old::IObservable,
+    public New::IObservable,
+    public New::TypedObservable<AnnotationAddedMessage>,
+    public New::TypedObservable<AnnotationRemovedMessage>,
+    public New::TypedObservable<AnnotationChangedMessage>,
+    public New::TypedObservable<TextAnnotationRequiredMessage>
   {
   public:
-    ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, AnnotationAddedMessage, AnnotationsSceneLayer);
-    ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, AnnotationRemovedMessage, AnnotationsSceneLayer);
-    ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, AnnotationChangedMessage, AnnotationsSceneLayer);
-
-    class TextAnnotationRequiredMessage : public OriginMessage<AnnotationsSceneLayer>
-    {
-      ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
-
-    private:
-      ScenePoint2D pointedPosition_;
-      ScenePoint2D labelPosition_;
-
-    public:
-      TextAnnotationRequiredMessage(const AnnotationsSceneLayer& origin,
-                                    ScenePoint2D pointedPosition,
-                                    ScenePoint2D labelPosition) :
-        OriginMessage(origin),
-        pointedPosition_(pointedPosition),
-        labelPosition_(labelPosition)
-      {
-      }
-      
-      const ScenePoint2D& GetPointedPosition() const
-      {
-        return pointedPosition_;
-      }
-      
-      const ScenePoint2D& GetLabelPosition() const
-      {
-        return labelPosition_;
-      }
-    };
-    
     enum Tool
     {
       Tool_Edit,