changeset 1787:6e8105942146

safeguard in TextureBaseSceneLayer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 May 2021 11:47:55 +0200
parents 748bfa7df18b
children 4fd065ad1fc0
files OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.cpp OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.h
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.cpp	Sat May 15 11:41:58 2021 +0200
+++ b/OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.cpp	Sat May 15 11:47:55 2021 +0200
@@ -27,6 +27,16 @@
 
 namespace OrthancStone
 {
+  void TextureBaseSceneLayer::CheckNoManualTransform() const
+  {
+    if (transform_.get() != NULL)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
+                                      "A transform has been manually set, first call ClearTransform()");
+    }
+  }
+
+
   void TextureBaseSceneLayer::SetTexture(Orthanc::ImageAccessor* texture)
   {
     if (texture == NULL)
@@ -81,6 +91,8 @@
   void TextureBaseSceneLayer::SetOrigin(double x,
                                         double y)
   {
+    CheckNoManualTransform();
+    
     originX_ = x;
     originY_ = y;
     IncrementRevision();
@@ -90,6 +102,8 @@
   void TextureBaseSceneLayer::SetPixelSpacing(double sx,
                                               double sy)
   {
+    CheckNoManualTransform();
+    
     if (sx <= 0 ||
         sy <= 0)
     {
@@ -106,6 +120,8 @@
   
   void TextureBaseSceneLayer::SetAngle(double angle)
   {
+    CheckNoManualTransform();
+    
     angle_ = angle;
     IncrementRevision();
   }
@@ -120,6 +136,8 @@
 
   void TextureBaseSceneLayer::SetFlipX(bool flip)
   {
+    CheckNoManualTransform();
+    
     flipX_ = flip;
     IncrementRevision();
   }
@@ -127,6 +145,8 @@
     
   void TextureBaseSceneLayer::SetFlipY(bool flip)
   {
+    CheckNoManualTransform();
+    
     flipY_ = flip;
     IncrementRevision();
   }
--- a/OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.h	Sat May 15 11:41:58 2021 +0200
+++ b/OrthancStone/Sources/Scene2D/TextureBaseSceneLayer.h	Sat May 15 11:47:55 2021 +0200
@@ -46,6 +46,8 @@
     uint64_t                               revision_;
     std::unique_ptr<AffineTransform2D>     transform_;   // Manually-specified transformation
 
+    void CheckNoManualTransform() const;
+
   protected:
     void SetTexture(Orthanc::ImageAccessor* texture);