]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#20500 fixed issue for performance
authorJérôme <jerome.lucas@cesgenslab.fr>
Wed, 16 Dec 2020 17:47:06 +0000 (18:47 +0100)
committerJérôme <jerome.lucas@cesgenslab.fr>
Wed, 16 Dec 2020 17:47:06 +0000 (18:47 +0100)
src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp
src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h
src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp
src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h

index e105a419c5f2c9a72db561772cedab0fab249471..b2a3c1580ac3b17c7a06bf1223ba15078bd51833 100644 (file)
@@ -95,8 +95,6 @@ void FeaturesPlugin_BoundingBox::execute()
 void FeaturesPlugin_BoundingBox::attributeChanged(const std::string& theID)
 {
   if (theID == OBJECTS_LIST_ID()) {
-    updateValues();
-    createBoxByTwoPoints();
     if (myCreateFeature.get())
       updateBox();
   }
@@ -112,51 +110,52 @@ AttributePtr FeaturesPlugin_BoundingBox::attributResultValues()
 void FeaturesPlugin_BoundingBox::updateValues()
 {
   AttributeSelectionPtr aSelection = selection(OBJECTS_LIST_ID());
-  AttributeDoubleArrayPtr aValues =
-    std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
-  std::stringstream streamxmin;
-  std::stringstream streamymin;
-  std::stringstream streamzmin;
-  std::stringstream streamxmax;
-  std::stringstream streamymax;
-  std::stringstream streamzmax;
-  GeomShapePtr aShape;
-  if (aSelection && aSelection->isInitialized()) {
-    aShape = aSelection->value();
-    if (!aShape && aSelection->context())
-      aShape = aSelection->context()->shape();
-  }
-  if (aShape) {
-    double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax;
-          std::string aError;
-    if (!GetBoundingBox(aShape,
-                        true,
-                        aXmin, aXmax,
-                        aYmin,aYmax,
-                        aZmin,aZmax,
-                        aError))
-        setError("Error in bounding box calculation :" +  aError);
-
-    streamxmin << std::setprecision(14) << aXmin;
-    aValues->setValue(0, aXmin);
-    streamxmax << std::setprecision(14) << aXmax;
-    aValues->setValue(1, aXmax);
-    streamymin << std::setprecision(14) << aYmin;
-    aValues->setValue(2, aYmin);
-    streamymax << std::setprecision(14) << aYmax;
-    aValues->setValue(3, aYmax);
-    streamzmin << std::setprecision(14) << aZmin;
-    aValues->setValue(4, aZmin);
-    streamzmax << std::setprecision(14) << aZmax;
-    aValues->setValue(5, aZmax);
+  if (aSelection->isInitialized()) {
+    AttributeDoubleArrayPtr aValues =
+      std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
+    std::stringstream streamxmin;
+    std::stringstream streamymin;
+    std::stringstream streamzmin;
+    std::stringstream streamxmax;
+    std::stringstream streamymax;
+    std::stringstream streamzmax;
+    GeomShapePtr aShape;
+    if (aSelection && aSelection->isInitialized()) {
+      aShape = aSelection->value();
+      if (!aShape && aSelection->context())
+        aShape = aSelection->context()->shape();
+    }
+    if (aShape && !aShape->isEqual(myShape)) {
+      double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax;
+      std::string aError;
+      if (!GetBoundingBox(aShape,
+                          true,
+                          aXmin, aXmax,
+                          aYmin,aYmax,
+                          aZmin,aZmax,
+                          aError))
+          setError("Error in bounding box calculation :" +  aError);
+      myShape = aShape;
+      streamxmin << std::setprecision(14) << aXmin;
+      aValues->setValue(0, aXmin);
+      streamxmax << std::setprecision(14) << aXmax;
+      aValues->setValue(1, aXmax);
+      streamymin << std::setprecision(14) << aYmin;
+      aValues->setValue(2, aYmin);
+      streamymax << std::setprecision(14) << aYmax;
+      aValues->setValue(3, aYmax);
+      streamzmin << std::setprecision(14) << aZmin;
+      aValues->setValue(4, aZmin);
+      streamzmax << std::setprecision(14) << aZmax;
+      aValues->setValue(5, aZmax);
+      string(X_MIN_COOD_ID() )->setValue( "X = " +  streamxmin.str() );
+      string(Y_MIN_COOD_ID() )->setValue( "Y = " +  streamymin.str() );
+      string(Z_MIN_COOD_ID() )->setValue( "Z = " +  streamzmin.str() );
+      string(X_MAX_COOD_ID() )->setValue( "X = " +  streamxmax.str() );
+      string(Y_MAX_COOD_ID() )->setValue( "Y = " +  streamymax.str() );
+      string(Z_MAX_COOD_ID() )->setValue( "Z = " +  streamzmax.str() );
+    }
   }
-
-  string(X_MIN_COOD_ID() )->setValue( "X = " +  streamxmin.str() );
-  string(Y_MIN_COOD_ID() )->setValue( "Y = " +  streamymin.str() );
-  string(Z_MIN_COOD_ID() )->setValue( "Z = " +  streamzmin.str() );
-  string(X_MAX_COOD_ID() )->setValue( "X = " +  streamxmax.str() );
-  string(Y_MAX_COOD_ID() )->setValue( "Y = " +  streamymax.str() );
-  string(Z_MAX_COOD_ID() )->setValue( "Z = " +  streamzmax.str() );
 }
 
 //=================================================================================================
@@ -174,9 +173,18 @@ void FeaturesPlugin_BoundingBox::createBox()
 //=================================================================================================
 void FeaturesPlugin_BoundingBox::updateBox()
 {
+    myCreateFeature->boolean(FeaturesPlugin_CreateBoundingBox::COMPUTE_ID())->setValue(false);
     myCreateFeature->selection(FeaturesPlugin_CreateBoundingBox::OBJECTS_LIST_ID())
-                          ->setValue( selection(OBJECTS_LIST_ID())->context() ,
+                          ->setValue( selection(OBJECTS_LIST_ID())->context(),
                                       selection(OBJECTS_LIST_ID())->value() );
+    
+    AttributeDoubleArrayPtr aValuesFeatures =
+      std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(myCreateFeature->attribute(RESULT_VALUES_ID()));
+    AttributeDoubleArrayPtr aValues =
+      std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
+    for (int anI=0; anI < 6; anI++)
+      aValuesFeatures->setValue(anI,aValues->value(anI));
 
     myCreateFeature->execute();
+    myCreateFeature->boolean(FeaturesPlugin_CreateBoundingBox::COMPUTE_ID())->setValue(true);
 }
index dc6e7b125a68542036c62f964659a02d8f632122..9bd2d79e26b510498d0acae581f81f181ee100f1 100644 (file)
@@ -54,6 +54,7 @@ public:
   void loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
                     std::shared_ptr<ModelAPI_ResultBody> theResultBox);
 
+  GeomShapePtr myShape;
 };
 
 #endif
index 5a4b8ba46f3ea05e309f7a342497771af4176ae0..fc5f5cf642768c980227456880477f1b7f82d163 100644 (file)
@@ -22,6 +22,7 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeDoubleArray.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeBoolean.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Session.h>
@@ -52,6 +53,7 @@ void FeaturesPlugin_CreateBoundingBox::initAttributes()
   data()->addAttribute(X_MAX_COOD_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(Y_MAX_COOD_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(Z_MAX_COOD_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(COMPUTE_ID(), ModelAPI_AttributeBoolean::typeId());
 
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MIN_COOD_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MIN_COOD_ID());
@@ -59,11 +61,12 @@ void FeaturesPlugin_CreateBoundingBox::initAttributes()
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MAX_COOD_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MAX_COOD_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MAX_COOD_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RESULT_VALUES_ID());
-
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECTS_LIST_ID());
   data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId());
 
   data()->realArray(RESULT_VALUES_ID())->setSize(6);
+  data()->boolean(COMPUTE_ID())->setValue(true);
 
 }
 
@@ -77,9 +80,6 @@ void FeaturesPlugin_CreateBoundingBox::execute()
 //=================================================================================================
 void FeaturesPlugin_CreateBoundingBox::attributeChanged(const std::string& theID)
 {
-  if (theID == OBJECTS_LIST_ID()) {
-    updateValues();
-  }
 }
 
 //=================================================================================================
@@ -87,50 +87,65 @@ void FeaturesPlugin_CreateBoundingBox::updateValues()
 {
   AttributeSelectionPtr aSelection = selection(OBJECTS_LIST_ID());
   AttributeDoubleArrayPtr aValues =
-    std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
-  std::stringstream streamxmin;
-  std::stringstream streamymin;
-  std::stringstream streamzmin;
-  std::stringstream streamxmax;
-  std::stringstream streamymax;
-  std::stringstream streamzmax;
-  GeomShapePtr aShape;
-  if (aSelection && aSelection->isInitialized()) {
-    aShape = aSelection->value();
-    if (!aShape && aSelection->context())
-      aShape = aSelection->context()->shape();
+      std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
+
+  if (aSelection->isInitialized()) {
+    std::stringstream streamxmin;
+    std::stringstream streamymin;
+    std::stringstream streamzmin;
+    std::stringstream streamxmax;
+    std::stringstream streamymax;
+    std::stringstream streamzmax;
+    GeomShapePtr aShape;
+    if (aSelection && aSelection->isInitialized()) {
+      aShape = aSelection->value();
+      if (!aShape && aSelection->context())
+        aShape = aSelection->context()->shape();
+    }
+    AttributeBooleanPtr anIsCompute = boolean(COMPUTE_ID());
+    if (!anIsCompute->value()) {
+      myShape = aShape;
+      anIsCompute->setValue(true);
+    } 
+
+    if (aShape && !aShape->isEqual(myShape)) {
+      double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax;
+      std::string aError;
+      if (!GetBoundingBox(aShape,
+                          true,
+                          aXmin, aXmax,
+                          aYmin,aYmax,
+                          aZmin,aZmax,
+                          aError))
+          setError("Error in bounding box calculation :" +  aError);
+      myShape = aShape;
+      streamxmin << std::setprecision(14) << aXmin;
+      aValues->setValue(0, aXmin);
+      streamxmax << std::setprecision(14) << aXmax;
+      aValues->setValue(1, aXmax);
+      streamymin << std::setprecision(14) << aYmin;
+      aValues->setValue(2, aYmin);
+      streamymax << std::setprecision(14) << aYmax;
+      aValues->setValue(3, aYmax);
+      streamzmin << std::setprecision(14) << aZmin;
+      aValues->setValue(4, aZmin);
+      streamzmax << std::setprecision(14) << aZmax;
+      aValues->setValue(5, aZmax);
+    } else {
+      streamxmin << std::setprecision(14) << aValues->value(0);
+      streamxmax << std::setprecision(14) << aValues->value(1);
+      streamymin << std::setprecision(14) << aValues->value(2);
+      streamymax << std::setprecision(14) << aValues->value(3);
+      streamzmin << std::setprecision(14) << aValues->value(4);
+      streamzmax << std::setprecision(14) << aValues->value(5);
+    }
+    string(X_MIN_COOD_ID() )->setValue( "X = " +  streamxmin.str() );
+    string(Y_MIN_COOD_ID() )->setValue( "Y = " +  streamymin.str() );
+    string(Z_MIN_COOD_ID() )->setValue( "Z = " +  streamzmin.str() );
+    string(X_MAX_COOD_ID() )->setValue( "X = " +  streamxmax.str() );
+    string(Y_MAX_COOD_ID() )->setValue( "Y = " +  streamymax.str() );
+    string(Z_MAX_COOD_ID() )->setValue( "Z = " +  streamzmax.str() );
   }
-  if (aShape) {
-    double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax;
-          std::string aError;
-    if (!GetBoundingBox(aShape,
-                        true,
-                        aXmin, aXmax,
-                        aYmin,aYmax,
-                        aZmin,aZmax,
-                        aError))
-        setError("Error in bounding box calculation :" +  aError);
-
-    streamxmin << std::setprecision(14) << aXmin;
-    aValues->setValue(0, aXmin);
-    streamxmax << std::setprecision(14) << aXmax;
-    aValues->setValue(1, aXmax);
-    streamymin << std::setprecision(14) << aYmin;
-    aValues->setValue(2, aYmin);
-    streamymax << std::setprecision(14) << aYmax;
-    aValues->setValue(3, aYmax);
-    streamzmin << std::setprecision(14) << aZmin;
-    aValues->setValue(4, aZmin);
-    streamzmax << std::setprecision(14) << aZmax;
-    aValues->setValue(5, aZmax);
-  }
-
-  string(X_MIN_COOD_ID() )->setValue( "X = " +  streamxmin.str() );
-  string(Y_MIN_COOD_ID() )->setValue( "Y = " +  streamymin.str() );
-  string(Z_MIN_COOD_ID() )->setValue( "Z = " +  streamzmin.str() );
-  string(X_MAX_COOD_ID() )->setValue( "X = " +  streamxmax.str() );
-  string(Y_MAX_COOD_ID() )->setValue( "Y = " +  streamymax.str() );
-  string(Z_MAX_COOD_ID() )->setValue( "Z = " +  streamzmax.str() );
 }
 
 //=================================================================================================
index d06732c26ffb62aa23bff49973545320f76b5f1c..cac4347eaa4c8082decba69167c767d6c5893429 100644 (file)
@@ -90,13 +90,20 @@ public:
     return MY_Z_MAX_COOD_ID;
   }
 
-   /// Attribute name for values of result.
+  /// Attribute name for values of result.
   inline static const std::string& RESULT_VALUES_ID()
   {
     static const std::string MY_RESULT_VALUES_ID("result_values");
     return MY_RESULT_VALUES_ID;
   }
 
+  /// Attribute name for indicate to compute the bounding box.
+  inline static const std::string& COMPUTE_ID()
+  {
+    static const std::string MY_COMPUTE_ID("compute");
+    return MY_COMPUTE_ID;
+  }
+
   /// Performs the algorithm and stores results it in the data structure.
   FEATURESPLUGIN_EXPORT virtual void execute();