Salome HOME
Refactoring of the Bounding Box feature (change names of classes to be more evident)
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Mon, 16 Aug 2021 14:42:39 +0000 (17:42 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 17 Aug 2021 15:05:45 +0000 (18:05 +0300)
14 files changed:
src/FeaturesAPI/FeaturesAPI_BoundingBox.cpp
src/FeaturesAPI/FeaturesAPI_BoundingBox.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp
src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h
src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.cpp [deleted file]
src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h [deleted file]
src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp [deleted file]
src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h [deleted file]
src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp

index 123a0a4a2cef61471e7b5300fd41336e89fd0365..ff60f54f3df3c7633f99749de8df49ae0d08d47e 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "FeaturesAPI_BoundingBox.h"
 
-#include <FeaturesPlugin_CreateBoundingBox.h>
+#include <FeaturesPlugin_BoundingBox.h>
 #include <ModelAPI_AttributeDoubleArray.h>
 #include <ModelHighAPI_Services.h>
 #include <ModelHighAPI_Tools.h>
@@ -60,7 +60,7 @@ void FeaturesAPI_BoundingBox::dump(ModelHighAPI_Dumper& theDumper) const
   const std::string& aDocName = theDumper.name(aBase->document());
 
   AttributeSelectionPtr anAttrObject;
-    anAttrObject = aBase->selection(FeaturesPlugin_CreateBoundingBox::OBJECT_ID());
+    anAttrObject = aBase->selection(FeaturesPlugin_BoundingBox::OBJECT_ID());
 
   theDumper << aBase << " = model.getBoundingBox(" << aDocName << ", " << anAttrObject;
 
@@ -73,7 +73,7 @@ BoundingBoxPtr getBoundingBox(const std::shared_ptr<ModelAPI_Document>& thePart,
 {
 
   FeaturePtr aFeature =
-      thePart->addFeature(FeaturesPlugin_CreateBoundingBox::ID());
+      thePart->addFeature(FeaturesPlugin_BoundingBox::ID());
 
   BoundingBoxPtr aBoundingBox;
 
index 959d0d41ca7a0d76db087a2f26969536c998b465..488563dcd17070d687cabefa185af68cf10b854b 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "FeaturesAPI.h"
 
-#include "FeaturesPlugin_CreateBoundingBox.h"
+#include "FeaturesPlugin_BoundingBox.h"
 
 #include <ModelHighAPI_Interface.h>
 #include <ModelHighAPI_Macro.h>
@@ -50,8 +50,8 @@ public:
   FEATURESAPI_EXPORT
   virtual ~FeaturesAPI_BoundingBox();
 
-  INTERFACE_1(FeaturesPlugin_CreateBoundingBox::ID(),
-              objectSelected, FeaturesPlugin_CreateBoundingBox::OBJECT_ID(),
+  INTERFACE_1(FeaturesPlugin_BoundingBox::ID(),
+              objectSelected, FeaturesPlugin_BoundingBox::OBJECT_ID(),
               ModelAPI_AttributeSelection, /** object selected*/)
 
   /// Dump wrapped feature
index 4d52c6119e6e61c640b6db860caec407c006988c..91dee176f30532891ab0bfbe256eb3fc29aa52c0 100644 (file)
@@ -70,8 +70,8 @@ SET(PROJECT_HEADERS
     FeaturesPlugin_PointCoordinates.h
     FeaturesPlugin_GeometryCalculation.h
     FeaturesPlugin_BoundingBox.h
-    FeaturesPlugin_CommonBoundingBox.h
-    FeaturesPlugin_CreateBoundingBox.h
+    FeaturesPlugin_BoundingBoxBase.h
+    FeaturesPlugin_InspectBoundingBox.h
 )
 
 SET(PROJECT_SOURCES
@@ -122,8 +122,8 @@ SET(PROJECT_SOURCES
     FeaturesPlugin_PointCoordinates.cpp
     FeaturesPlugin_GeometryCalculation.cpp
     FeaturesPlugin_BoundingBox.cpp
-    FeaturesPlugin_CommonBoundingBox.cpp
-    FeaturesPlugin_CreateBoundingBox.cpp
+    FeaturesPlugin_BoundingBoxBase.cpp
+    FeaturesPlugin_InspectBoundingBox.cpp
 )
 
 SET(XML_RESOURCES
index f2867fec989d79b510452f2724bcdfcc0783315e..158f9013db4ac6d432b35cac188df88c2716385c 100644 (file)
 
 #include "FeaturesPlugin_BoundingBox.h"
 
-#include <Config_PropManager.h>
-
-#include <FeaturesPlugin_CreateBoundingBox.h>
-
-#include <GeomAlgoAPI_BoundingBox.h>
-
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeDoubleArray.h>
-#include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeBoolean.h>
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <GeomAlgoAPI_BoundingBox.h>
+
+#include <Config_PropManager.h>
+#include <ModelAPI_ResultBody.h>
+
 #include <iomanip>
 #include <sstream>
 
@@ -54,7 +54,7 @@ void FeaturesPlugin_BoundingBox::initAttributes()
   data()->addAttribute(X_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(Y_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(Z_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(CREATEBOX_ID(), ModelAPI_AttributeBoolean::typeId());
+  data()->addAttribute(COMPUTE_ID(), ModelAPI_AttributeBoolean::typeId());
 
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MIN_COORD_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MIN_COORD_ID());
@@ -62,13 +62,12 @@ void FeaturesPlugin_BoundingBox::initAttributes()
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MAX_COORD_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MAX_COORD_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MAX_COORD_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATEBOX_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RESULT_VALUES_ID());
-
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_ID());
   data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId());
 
   data()->realArray(RESULT_VALUES_ID())->setSize(6);
-
+  data()->boolean(COMPUTE_ID())->setValue(true);
 }
 
 //=================================================================================================
@@ -78,44 +77,21 @@ void FeaturesPlugin_BoundingBox::execute()
     return;
 
   createBoxByTwoPoints();
-
-  if (boolean(CREATEBOX_ID())->value()) {
-    if (!myCreateFeature.get())
-      createBox();
-    updateBox();
-  } else {
-    if (myCreateFeature.get()) {
-      myCreateFeature->eraseResults();
-      SessionPtr aSession = ModelAPI_Session::get();
-      DocumentPtr aDoc =  aSession->activeDocument();
-      aDoc->removeFeature(myCreateFeature);
-      myCreateFeature.reset();
-    }
-  }
-}
-
-//=================================================================================================
-void FeaturesPlugin_BoundingBox::attributeChanged(const std::string& theID)
-{
-  if (theID == OBJECT_ID()) {
-    if (myCreateFeature.get())
-      updateBox();
-  }
 }
 
 //=================================================================================================
-AttributePtr FeaturesPlugin_BoundingBox::attributResultValues()
+void FeaturesPlugin_BoundingBox::attributeChanged(const std::string&)
 {
-   return attribute(RESULT_VALUES_ID());
 }
 
 //=================================================================================================
 bool FeaturesPlugin_BoundingBox::updateValues()
 {
   AttributeSelectionPtr aSelection = selection(OBJECT_ID());
-  if (aSelection->isInitialized()) {
-    AttributeDoubleArrayPtr aValues =
+  AttributeDoubleArrayPtr aValues =
       std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
+
+  if (aSelection->isInitialized()) {
     std::stringstream streamxmin;
     std::stringstream streamymin;
     std::stringstream streamzmin;
@@ -130,6 +106,12 @@ bool FeaturesPlugin_BoundingBox::updateValues()
         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 anError;
@@ -141,7 +123,6 @@ bool FeaturesPlugin_BoundingBox::updateValues()
         setError("Error in bounding box calculation :" +  anError);
         return false;
       }
-
       myShape = aShape;
       streamxmin << std::setprecision(14) << aXmin;
       aValues->setValue(0, aXmin);
@@ -155,45 +136,27 @@ bool FeaturesPlugin_BoundingBox::updateValues()
       aValues->setValue(4, aZmin);
       streamzmax << std::setprecision(14) << aZmax;
       aValues->setValue(5, aZmax);
-      string(X_MIN_COORD_ID() )->setValue( "X = " +  streamxmin.str() );
-      string(Y_MIN_COORD_ID() )->setValue( "Y = " +  streamymin.str() );
-      string(Z_MIN_COORD_ID() )->setValue( "Z = " +  streamzmin.str() );
-      string(X_MAX_COORD_ID() )->setValue( "X = " +  streamxmax.str() );
-      string(Y_MAX_COORD_ID() )->setValue( "Y = " +  streamymax.str() );
-      string(Z_MAX_COORD_ID() )->setValue( "Z = " +  streamzmax.str() );
+    } 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);
     }
-  }
-  return true;
-}
-
-//=================================================================================================
-void FeaturesPlugin_BoundingBox::createBox()
-{
-  SessionPtr aSession = ModelAPI_Session::get();
-
-  DocumentPtr aDoc =  aSession->activeDocument();
 
-  if (aDoc.get()) {
-    myCreateFeature = aDoc->addFeature(FeaturesPlugin_CreateBoundingBox::ID());
+    string(X_MIN_COORD_ID() )->setValue( "X = " +  streamxmin.str() );
+    string(Y_MIN_COORD_ID() )->setValue( "Y = " +  streamymin.str() );
+    string(Z_MIN_COORD_ID() )->setValue( "Z = " +  streamzmin.str() );
+    string(X_MAX_COORD_ID() )->setValue( "X = " +  streamxmax.str() );
+    string(Y_MAX_COORD_ID() )->setValue( "Y = " +  streamymax.str() );
+    string(Z_MAX_COORD_ID() )->setValue( "Z = " +  streamzmax.str() );
   }
+  return true;
 }
 
 //=================================================================================================
-void FeaturesPlugin_BoundingBox::updateBox()
+AttributePtr FeaturesPlugin_BoundingBox::attributResultValues()
 {
-  myCreateFeature->boolean(FeaturesPlugin_CreateBoundingBox::COMPUTE_ID())->setValue(false);
-  myCreateFeature->selection(FeaturesPlugin_CreateBoundingBox::OBJECT_ID())
-                        ->setValue(selection(OBJECT_ID())->context(),
-                                   selection(OBJECT_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);
+   return attribute(RESULT_VALUES_ID());
 }
index 9238942c4325280c2d64f0c3cf1524d27471220d..0f8f14dcea04a87259502b8074ec1f314b88c507 100644 (file)
 #ifndef FeaturesPlugin_BoundingBox_H_
 #define FeaturesPlugin_BoundingBox_H_
 
-#include <FeaturesPlugin_CommonBoundingBox.h>
+#include <FeaturesPlugin_BoundingBoxBase.h>
 
 /// \class FeaturesPlugin_BoundingBox
 /// \ingroup Plugins
-/// \brief Feature to view the Bounding Box.
+/// \brief Persistence feature to create the bounding box.
 
-class FeaturesPlugin_BoundingBox : public FeaturesPlugin_CommonBoundingBox
+class FeaturesPlugin_BoundingBox : public FeaturesPlugin_BoundingBoxBase
 {
 public:
-  /// Bounding box macro kind.
+  /// Bounding box kind.
   inline static const std::string& ID()
   {
-    static const std::string MY_ID("BoundingBoxMacro");
+    static const std::string MY_ID("BoundingBox");
     return MY_ID;
   }
 
@@ -85,13 +85,6 @@ public:
     return MY_Z_MAX_COORD_ID;
   }
 
-  /// Attribute name for checkbox create box.
-  inline static const std::string& CREATEBOX_ID()
-  {
-    static const std::string MY_CREATEBOX_ID("createbox");
-    return MY_CREATEBOX_ID;
-  }
-
   /// Attribute name for values of result.
   inline static const std::string& RESULT_VALUES_ID()
   {
@@ -99,6 +92,13 @@ public:
     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;
+  }
+
   /// \return the kind of a feature.
   virtual const std::string& getKind()
   {
@@ -115,25 +115,15 @@ public:
   /// \param theID identifier of changed attribute
   FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 
-  /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
-  FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+  /// Return Attribut values of result.
+  FEATURESPLUGIN_EXPORT virtual AttributePtr attributResultValues();
 
   /// Use plugin manager for features creation
   FeaturesPlugin_BoundingBox();
 
 private:
-  /// Return Attribut values of result.
-  virtual AttributePtr attributResultValues();
-
   /// Update values displayed.
   bool updateValues();
-  /// Create Box
-  void createBox();
-  /// Update Box
-  void updateBox();
-
-  /// Feature to create box
-  FeaturePtr myCreateFeature;
 
 };
 
diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.cpp b/src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.cpp
new file mode 100644 (file)
index 0000000..7da95c8
--- /dev/null
@@ -0,0 +1,115 @@
+// Copyright (C) 2018-2021  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "FeaturesPlugin_BoundingBoxBase.h"
+
+#include <ModelAPI_AttributeDoubleArray.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+#include <GeomAPI_Vertex.h>
+
+#include <GeomAlgoAPI_BoundingBox.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
+#include <Config_PropManager.h>
+
+#include <iomanip>
+#include <sstream>
+
+
+
+//=================================================================================================
+void FeaturesPlugin_BoundingBoxBase::createBoxByTwoPoints()
+{
+  AttributeDoubleArrayPtr aValues =
+      std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attributResultValues());
+
+  SessionPtr aSession = ModelAPI_Session::get();
+
+  DocumentPtr aDoc =  aSession->activeDocument();
+
+  GeomVertexPtr vertexFirst =
+          GeomAlgoAPI_PointBuilder::vertex(aValues->value(0),
+                                           aValues->value(2),
+                                           aValues->value(4));
+
+  GeomVertexPtr  vertexSecond =
+          GeomAlgoAPI_PointBuilder::vertex(aValues->value(1),
+                                           aValues->value(3),
+                                           aValues->value(5));
+
+
+  std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo;
+
+
+  aBoxAlgo = std::shared_ptr<GeomAlgoAPI_Box>(
+                          new GeomAlgoAPI_Box(vertexFirst->point(),vertexSecond->point()));
+
+
+  // These checks should be made to the GUI for the feature but
+  // the corresponding validator does not exist yet.
+  if (!aBoxAlgo->check()) {
+    setError(aBoxAlgo->getError());
+    return;
+  }
+
+  // Build the box
+  aBoxAlgo->build();
+
+  // Check if the creation of the box
+  if (!aBoxAlgo->isDone()) {
+    // The error is not displayed in a popup window. It must be in the message console.
+    setError(aBoxAlgo->getError());
+    return;
+  }
+  if (!aBoxAlgo->checkValid("Box builder with two points")) {
+    // The error is not displayed in a popup window. It must be in the message console.
+    setError(aBoxAlgo->getError());
+    return;
+  }
+
+  int aResultIndex = 0;
+  ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
+  loadNamingDS(aBoxAlgo, aResultBox);
+  setResult(aResultBox, aResultIndex);
+}
+
+//=================================================================================================
+void FeaturesPlugin_BoundingBoxBase::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
+                                        std::shared_ptr<ModelAPI_ResultBody> theResultBox)
+{
+  // Load the result
+  theResultBox->store(theBoxAlgo->shape());
+
+  // Prepare the naming
+  theBoxAlgo->prepareNamingFaces();
+
+  // Insert to faces
+  std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
+    theBoxAlgo->getCreatedFaces();
+  for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator it = listOfFaces.begin();
+       it != listOfFaces.end();
+       ++it) {
+    theResultBox->generated((*it).second, (*it).first);
+  }
+}
diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.h b/src/FeaturesPlugin/FeaturesPlugin_BoundingBoxBase.h
new file mode 100644 (file)
index 0000000..862aae8
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2018-2021  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef FeaturesPlugin_BoundingBoxBase_H_
+#define FeaturesPlugin_BoundingBoxBase_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+
+#include <GeomAlgoAPI_Box.h>
+
+#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_IScreenParams.h>
+
+#include <ModelAPI_Attribute.h>
+
+/// \class FeaturesPlugin_BoundingBoxBase
+/// \ingroup Plugins
+/// \brief Base feature to inspect properties of bounding box
+///        and create that box for the selected shape.
+class FeaturesPlugin_BoundingBoxBase : public ModelAPI_Feature
+{
+public:
+  /// Performs the algorithm and stores results it in the data structure.
+  FEATURESPLUGIN_EXPORT virtual void execute(){};
+
+  /// Return Attribut values of result.
+  virtual AttributePtr attributResultValues() = 0;
+
+protected:
+  FeaturesPlugin_BoundingBoxBase() {}
+
+  /// Create box with two points
+  void createBoxByTwoPoints();
+
+  /// Create namming
+  void loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
+                    std::shared_ptr<ModelAPI_ResultBody> theResultBox);
+
+  GeomShapePtr myShape;
+};
+
+#endif
diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.cpp
deleted file mode 100644 (file)
index 531616f..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (C) 2018-2021  CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-#include "FeaturesPlugin_CommonBoundingBox.h"
-
-#include <ModelAPI_AttributeDoubleArray.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_ResultBody.h>
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Validator.h>
-#include <GeomAPI_Vertex.h>
-
-#include <GeomAlgoAPI_BoundingBox.h>
-#include <GeomAlgoAPI_PointBuilder.h>
-#include <GeomAlgoAPI_ShapeTools.h>
-
-#include <Config_PropManager.h>
-
-#include <iomanip>
-#include <sstream>
-
-
-
-//=================================================================================================
-void FeaturesPlugin_CommonBoundingBox::createBoxByTwoPoints()
-{
-  AttributeDoubleArrayPtr aValues =
-      std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attributResultValues());
-
-  SessionPtr aSession = ModelAPI_Session::get();
-
-  DocumentPtr aDoc =  aSession->activeDocument();
-
-  GeomVertexPtr vertexFirst =
-          GeomAlgoAPI_PointBuilder::vertex(aValues->value(0),
-                                           aValues->value(2),
-                                           aValues->value(4));
-
-  GeomVertexPtr  vertexSecond =
-          GeomAlgoAPI_PointBuilder::vertex(aValues->value(1),
-                                           aValues->value(3),
-                                           aValues->value(5));
-
-
-  std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo;
-
-
-  aBoxAlgo = std::shared_ptr<GeomAlgoAPI_Box>(
-                          new GeomAlgoAPI_Box(vertexFirst->point(),vertexSecond->point()));
-
-
-  // These checks should be made to the GUI for the feature but
-  // the corresponding validator does not exist yet.
-  if (!aBoxAlgo->check()) {
-    setError(aBoxAlgo->getError());
-    return;
-  }
-
-  // Build the box
-  aBoxAlgo->build();
-
-  // Check if the creation of the box
-  if (!aBoxAlgo->isDone()) {
-    // The error is not displayed in a popup window. It must be in the message console.
-    setError(aBoxAlgo->getError());
-    return;
-  }
-  if (!aBoxAlgo->checkValid("Box builder with two points")) {
-    // The error is not displayed in a popup window. It must be in the message console.
-    setError(aBoxAlgo->getError());
-    return;
-  }
-
-  int aResultIndex = 0;
-  ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
-  loadNamingDS(aBoxAlgo, aResultBox);
-  setResult(aResultBox, aResultIndex);
-}
-
-//=================================================================================================
-void FeaturesPlugin_CommonBoundingBox::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
-                                        std::shared_ptr<ModelAPI_ResultBody> theResultBox)
-{
-  // Load the result
-  theResultBox->store(theBoxAlgo->shape());
-
-  // Prepare the naming
-  theBoxAlgo->prepareNamingFaces();
-
-  // Insert to faces
-  std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
-    theBoxAlgo->getCreatedFaces();
-  for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator it = listOfFaces.begin();
-       it != listOfFaces.end();
-       ++it) {
-    theResultBox->generated((*it).second, (*it).first);
-  }
-}
diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_CommonBoundingBox.h
deleted file mode 100644 (file)
index c461535..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2018-2021  CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-#ifndef FeaturesPlugin_CommonBoundingBox_H_
-#define FeaturesPlugin_CommonBoundingBox_H_
-
-#include "FeaturesPlugin.h"
-#include <ModelAPI_Feature.h>
-
-#include <GeomAlgoAPI_Box.h>
-
-#include <GeomAPI_IPresentable.h>
-#include <GeomAPI_IScreenParams.h>
-
-#include <ModelAPI_Attribute.h>
-
-/// \class FeaturesPlugin_CommonBoundingBox
-/// \ingroup Plugins
-/// \brief Feature to view the Bounding Box.
-
-class FeaturesPlugin_CommonBoundingBox : public ModelAPI_Feature
-{
-public:
-  /// Performs the algorithm and stores results it in the data structure.
-  FEATURESPLUGIN_EXPORT virtual void execute(){};
-
-  /// Return Attribut values of result.
-  virtual AttributePtr attributResultValues() = 0;
-
-protected:
-  FeaturesPlugin_CommonBoundingBox() {}
-
-  /// Create box with two points
-  void createBoxByTwoPoints();
-
-  /// Create namming
-  void loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
-                    std::shared_ptr<ModelAPI_ResultBody> theResultBox);
-
-  GeomShapePtr myShape;
-};
-
-#endif
diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp
deleted file mode 100644 (file)
index c3c9bea..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-// Copyright (C) 2018-2021  CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-#include "FeaturesPlugin_CreateBoundingBox.h"
-
-#include <ModelAPI_AttributeSelection.h>
-#include <ModelAPI_AttributeDoubleArray.h>
-#include <ModelAPI_AttributeString.h>
-#include <ModelAPI_AttributeBoolean.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Validator.h>
-
-#include <GeomAlgoAPI_BoundingBox.h>
-
-#include <Config_PropManager.h>
-#include <ModelAPI_ResultBody.h>
-
-#include <iomanip>
-#include <sstream>
-
-//=================================================================================================
-FeaturesPlugin_CreateBoundingBox::FeaturesPlugin_CreateBoundingBox()
-{
-}
-
-//=================================================================================================
-void FeaturesPlugin_CreateBoundingBox::initAttributes()
-{
-  // attribute for object selected
-  data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
-
-  // attributes for result message and values
-  data()->addAttribute(X_MIN_COORD_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(Y_MIN_COORD_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(Z_MIN_COORD_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(X_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(Y_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(Z_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(COMPUTE_ID(), ModelAPI_AttributeBoolean::typeId());
-
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MIN_COORD_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MIN_COORD_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MIN_COORD_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MAX_COORD_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MAX_COORD_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MAX_COORD_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_ID());
-  data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId());
-
-  data()->realArray(RESULT_VALUES_ID())->setSize(6);
-  data()->boolean(COMPUTE_ID())->setValue(true);
-}
-
-//=================================================================================================
-void FeaturesPlugin_CreateBoundingBox::execute()
-{
-  if (!updateValues())
-    return;
-
-  createBoxByTwoPoints();
-}
-
-//=================================================================================================
-void FeaturesPlugin_CreateBoundingBox::attributeChanged(const std::string& theID)
-{
-}
-
-//=================================================================================================
-bool FeaturesPlugin_CreateBoundingBox::updateValues()
-{
-  AttributeSelectionPtr aSelection = selection(OBJECT_ID());
-  AttributeDoubleArrayPtr aValues =
-      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 anError;
-      if (!GetBoundingBox(aShape,
-                          aXmin, aXmax,
-                          aYmin, aYmax,
-                          aZmin, aZmax,
-                          anError)) {
-        setError("Error in bounding box calculation :" +  anError);
-        return false;
-      }
-      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_COORD_ID() )->setValue( "X = " +  streamxmin.str() );
-    string(Y_MIN_COORD_ID() )->setValue( "Y = " +  streamymin.str() );
-    string(Z_MIN_COORD_ID() )->setValue( "Z = " +  streamzmin.str() );
-    string(X_MAX_COORD_ID() )->setValue( "X = " +  streamxmax.str() );
-    string(Y_MAX_COORD_ID() )->setValue( "Y = " +  streamymax.str() );
-    string(Z_MAX_COORD_ID() )->setValue( "Z = " +  streamzmax.str() );
-  }
-  return true;
-}
-
-//=================================================================================================
-AttributePtr FeaturesPlugin_CreateBoundingBox::attributResultValues()
-{
-   return attribute(RESULT_VALUES_ID());
-}
diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h
deleted file mode 100644 (file)
index c7ead90..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-// Copyright (C) 2018-2021  CEA/DEN, EDF R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-#ifndef FeaturesPlugin_CreateBoundingBox_H_
-#define FeaturesPlugin_CreateBoundingBox_H_
-
-#include <FeaturesPlugin_CommonBoundingBox.h>
-
-/// \class FeaturesPlugin_BoundingBox
-/// \ingroup Plugins
-/// \brief Feature to view the Bounding Box.
-
-class FeaturesPlugin_CreateBoundingBox : public FeaturesPlugin_CommonBoundingBox
-{
-public:
-  /// Bounding box kind.
-  inline static const std::string& ID()
-  {
-    static const std::string MY_ID("BoundingBox");
-    return MY_ID;
-  }
-
-  /// Attribute name for object selected.
-  inline static const std::string& OBJECT_ID()
-  {
-    static const std::string MY_OBJECT_ID("main_object");
-    return MY_OBJECT_ID;
-  }
-
-  /// Attribute name for x coodinate.
-  inline static const std::string& X_MIN_COORD_ID()
-  {
-    static const std::string MY_X_MIN_COORD_ID("xmincoordinate");
-    return MY_X_MIN_COORD_ID;
-  }
-
-  /// Attribute name for y coodinate.
-  inline static const std::string& Y_MIN_COORD_ID()
-  {
-    static const std::string MY_Y_MIN_COORD_ID("ymincoordinate");
-    return MY_Y_MIN_COORD_ID;
-  }
-
-  /// Attribute name for z coodinate.
-  inline static const std::string& Z_MIN_COORD_ID()
-  {
-    static const std::string MY_Z_MIN_COORD_ID("zmincoordinate");
-    return MY_Z_MIN_COORD_ID;
-  }
-
-  /// Attribute name for x max coodinate.
-  inline static const std::string& X_MAX_COORD_ID()
-  {
-    static const std::string MY_X_MAX_COORD_ID("xmaxcoordinate");
-    return MY_X_MAX_COORD_ID;
-  }
-
-  /// Attribute name for y max coodinate.
-  inline static const std::string& Y_MAX_COORD_ID()
-  {
-    static const std::string MY_Y_MAX_COORD_ID("ymaxcoordinate");
-    return MY_Y_MAX_COORD_ID;
-  }
-
-  /// Attribute name for z max coodinate.
-  inline static const std::string& Z_MAX_COORD_ID()
-  {
-    static const std::string MY_Z_MAX_COORD_ID("zmaxcoordinate");
-    return MY_Z_MAX_COORD_ID;
-  }
-
-  /// 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;
-  }
-
-  /// \return the kind of a feature.
-  virtual const std::string& getKind()
-  {
-    return ID();
-  }
-
-  /// Performs the algorithm and stores results it in the data structure.
-  FEATURESPLUGIN_EXPORT virtual void execute();
-
-  /// Request for initialization of data model of the feature: adding all attributes
-  FEATURESPLUGIN_EXPORT virtual void initAttributes();
-
-  /// Called on change of any argument-attribute of this object
-  /// \param theID identifier of changed attribute
-  FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-
-  /// Return Attribut values of result.
-  FEATURESPLUGIN_EXPORT virtual AttributePtr attributResultValues();
-
-  /// Use plugin manager for features creation
-  FeaturesPlugin_CreateBoundingBox();
-
-private:
-  /// Update values displayed.
-  bool updateValues();
-
-};
-
-#endif
diff --git a/src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.cpp
new file mode 100644 (file)
index 0000000..aed9de0
--- /dev/null
@@ -0,0 +1,199 @@
+// Copyright (C) 2018-2021  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "FeaturesPlugin_InspectBoundingBox.h"
+
+#include <Config_PropManager.h>
+
+#include <FeaturesPlugin_CreateBoundingBox.h>
+
+#include <GeomAlgoAPI_BoundingBox.h>
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <iomanip>
+#include <sstream>
+
+//=================================================================================================
+FeaturesPlugin_InspectBoundingBox::FeaturesPlugin_InspectBoundingBox()
+{
+}
+
+//=================================================================================================
+void FeaturesPlugin_InspectBoundingBox::initAttributes()
+{
+  // attribute for object selected
+  data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+
+  // attributes for result message and values
+  data()->addAttribute(X_MIN_COORD_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(Y_MIN_COORD_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(Z_MIN_COORD_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(X_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(Y_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(Z_MAX_COORD_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(CREATEBOX_ID(), ModelAPI_AttributeBoolean::typeId());
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MIN_COORD_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MIN_COORD_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MIN_COORD_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), X_MAX_COORD_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Y_MAX_COORD_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), Z_MAX_COORD_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATEBOX_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), RESULT_VALUES_ID());
+
+  data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId());
+
+  data()->realArray(RESULT_VALUES_ID())->setSize(6);
+
+}
+
+//=================================================================================================
+void FeaturesPlugin_InspectBoundingBox::execute()
+{
+  if (!updateValues())
+    return;
+
+  createBoxByTwoPoints();
+
+  if (boolean(CREATEBOX_ID())->value()) {
+    if (!myCreateFeature.get())
+      createBox();
+    updateBox();
+  } else {
+    if (myCreateFeature.get()) {
+      myCreateFeature->eraseResults();
+      SessionPtr aSession = ModelAPI_Session::get();
+      DocumentPtr aDoc =  aSession->activeDocument();
+      aDoc->removeFeature(myCreateFeature);
+      myCreateFeature.reset();
+    }
+  }
+}
+
+//=================================================================================================
+void FeaturesPlugin_InspectBoundingBox::attributeChanged(const std::string& theID)
+{
+  if (theID == OBJECT_ID()) {
+    if (myCreateFeature.get())
+      updateBox();
+  }
+}
+
+//=================================================================================================
+AttributePtr FeaturesPlugin_InspectBoundingBox::attributResultValues()
+{
+   return attribute(RESULT_VALUES_ID());
+}
+
+//=================================================================================================
+bool FeaturesPlugin_InspectBoundingBox::updateValues()
+{
+  AttributeSelectionPtr aSelection = selection(OBJECT_ID());
+  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 anError;
+      if (!GetBoundingBox(aShape,
+                          aXmin, aXmax,
+                          aYmin, aYmax,
+                          aZmin, aZmax,
+                          anError)) {
+        setError("Error in bounding box calculation :" +  anError);
+        return false;
+      }
+
+      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_COORD_ID() )->setValue( "X = " +  streamxmin.str() );
+      string(Y_MIN_COORD_ID() )->setValue( "Y = " +  streamymin.str() );
+      string(Z_MIN_COORD_ID() )->setValue( "Z = " +  streamzmin.str() );
+      string(X_MAX_COORD_ID() )->setValue( "X = " +  streamxmax.str() );
+      string(Y_MAX_COORD_ID() )->setValue( "Y = " +  streamymax.str() );
+      string(Z_MAX_COORD_ID() )->setValue( "Z = " +  streamzmax.str() );
+    }
+  }
+  return true;
+}
+
+//=================================================================================================
+void FeaturesPlugin_InspectBoundingBox::createBox()
+{
+  SessionPtr aSession = ModelAPI_Session::get();
+
+  DocumentPtr aDoc =  aSession->activeDocument();
+
+  if (aDoc.get()) {
+    myCreateFeature = aDoc->addFeature(FeaturesPlugin_CreateBoundingBox::ID());
+  }
+}
+
+//=================================================================================================
+void FeaturesPlugin_InspectBoundingBox::updateBox()
+{
+  myCreateFeature->boolean(FeaturesPlugin_CreateBoundingBox::COMPUTE_ID())->setValue(false);
+  myCreateFeature->selection(FeaturesPlugin_CreateBoundingBox::OBJECT_ID())
+                        ->setValue(selection(OBJECT_ID())->context(),
+                                   selection(OBJECT_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);
+}
diff --git a/src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_InspectBoundingBox.h
new file mode 100644 (file)
index 0000000..3e224d4
--- /dev/null
@@ -0,0 +1,140 @@
+// Copyright (C) 2018-2021  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef FeaturesPlugin_InspectBoundingBox_H_
+#define FeaturesPlugin_InspectBoundingBox_H_
+
+#include <FeaturesPlugin_BoundingBoxBase.h>
+
+/// \class FeaturesPlugin_InspectBoundingBox
+/// \ingroup Plugins
+/// \brief Feature to view the Bounding Box.
+
+class FeaturesPlugin_InspectBoundingBox : public FeaturesPlugin_BoundingBoxBase
+{
+public:
+  /// Bounding box macro kind.
+  inline static const std::string& ID()
+  {
+    static const std::string MY_ID("BoundingBoxMacro");
+    return MY_ID;
+  }
+
+  /// Attribute name for object selected.
+  inline static const std::string& OBJECT_ID()
+  {
+    static const std::string MY_OBJECT_ID("main_object");
+    return MY_OBJECT_ID;
+  }
+
+  /// Attribute name for x coodinate.
+  inline static const std::string& X_MIN_COORD_ID()
+  {
+    static const std::string MY_X_MIN_COORD_ID("xmincoordinate");
+    return MY_X_MIN_COORD_ID;
+  }
+
+  /// Attribute name for y coodinate.
+  inline static const std::string& Y_MIN_COORD_ID()
+  {
+    static const std::string MY_Y_MIN_COORD_ID("ymincoordinate");
+    return MY_Y_MIN_COORD_ID;
+  }
+
+  /// Attribute name for z coodinate.
+  inline static const std::string& Z_MIN_COORD_ID()
+  {
+    static const std::string MY_Z_MIN_COORD_ID("zmincoordinate");
+    return MY_Z_MIN_COORD_ID;
+  }
+
+  /// Attribute name for x max coodinate.
+  inline static const std::string& X_MAX_COORD_ID()
+  {
+    static const std::string MY_X_MAX_COORD_ID("xmaxcoordinate");
+    return MY_X_MAX_COORD_ID;
+  }
+
+  /// Attribute name for y max coodinate.
+  inline static const std::string& Y_MAX_COORD_ID()
+  {
+    static const std::string MY_Y_MAX_COORD_ID("ymaxcoordinate");
+    return MY_Y_MAX_COORD_ID;
+  }
+
+  /// Attribute name for z max coodinate.
+  inline static const std::string& Z_MAX_COORD_ID()
+  {
+    static const std::string MY_Z_MAX_COORD_ID("zmaxcoordinate");
+    return MY_Z_MAX_COORD_ID;
+  }
+
+  /// Attribute name for checkbox create box.
+  inline static const std::string& CREATEBOX_ID()
+  {
+    static const std::string MY_CREATEBOX_ID("createbox");
+    return MY_CREATEBOX_ID;
+  }
+
+  /// 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;
+  }
+
+  /// \return the kind of a feature.
+  virtual const std::string& getKind()
+  {
+    return ID();
+  }
+
+  /// Performs the algorithm and stores results it in the data structure.
+  FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+  /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
+  FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+
+  /// Use plugin manager for features creation
+  FeaturesPlugin_InspectBoundingBox();
+
+private:
+  /// Return Attribut values of result.
+  virtual AttributePtr attributResultValues();
+
+  /// Update values displayed.
+  bool updateValues();
+  /// Create Box
+  void createBox();
+  /// Update Box
+  void updateBox();
+
+  /// Feature to create box
+  FeaturePtr myCreateFeature;
+
+};
+
+#endif
index 63d0241e38f1ac7174eef1b543568ae9ba544113..20121610e7e96e3466a2c23b7f22cb95b466ad10 100644 (file)
@@ -26,7 +26,6 @@
 #include <FeaturesPlugin_BooleanFill.h>
 #include <FeaturesPlugin_BoundingBox.h>
 #include <FeaturesPlugin_Chamfer.h>
-#include <FeaturesPlugin_CreateBoundingBox.h>
 #include <FeaturesPlugin_Defeaturing.h>
 #include <FeaturesPlugin_Extrusion.h>
 #include <FeaturesPlugin_ExtrusionCut.h>
@@ -34,6 +33,7 @@
 #include <FeaturesPlugin_Fillet.h>
 #include <FeaturesPlugin_Fillet1D.h>
 #include <FeaturesPlugin_GeometryCalculation.h>
+#include <FeaturesPlugin_InspectBoundingBox.h>
 #include <FeaturesPlugin_Intersection.h>
 #include <FeaturesPlugin_Measurement.h>
 #include <FeaturesPlugin_PointCoordinates.h>
@@ -205,10 +205,10 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID)
     return FeaturePtr(new FeaturesPlugin_PointCoordinates);
   } else if (theFeatureID == FeaturesPlugin_GeometryCalculation::ID()) {
     return FeaturePtr(new FeaturesPlugin_GeometryCalculation);
+  } else if (theFeatureID == FeaturesPlugin_InspectBoundingBox::ID()) {
+    return FeaturePtr(new FeaturesPlugin_InspectBoundingBox);
   } else if (theFeatureID == FeaturesPlugin_BoundingBox::ID()) {
     return FeaturePtr(new FeaturesPlugin_BoundingBox);
-  } else if (theFeatureID == FeaturesPlugin_CreateBoundingBox::ID()) {
-    return FeaturePtr(new FeaturesPlugin_CreateBoundingBox);
   }