Salome HOME
Corrections (#20619) CEA_2020_Lot2_1
authorcg246364 <clarisse.genrault@cea.fr>
Tue, 9 Feb 2021 15:47:15 +0000 (16:47 +0100)
committercg246364 <clarisse.genrault@cea.fr>
Tue, 9 Feb 2021 15:47:15 +0000 (16:47 +0100)
14 files changed:
src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp
src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h
src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp
src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h
src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp
src/FeaturesPlugin/Test/TestBoundingBox.py
src/FeaturesPlugin/doc/examples/create_bounding_box.py
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.cpp
src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.h
src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp [deleted file]
src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h [deleted file]
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h

index 6e30b6f5469853c0f6bf62b3d3e7d5c64854cbc8..82f8089c0c0b8c33cee07b8891dbcc4961081f17 100644 (file)
@@ -74,7 +74,9 @@ void FeaturesPlugin_BoundingBox::initAttributes()
 //=================================================================================================
 void FeaturesPlugin_BoundingBox::execute()
 {
-  updateValues();
+  if (!updateValues())
+    return;
+
   createBoxByTwoPoints();
 
   if (boolean(CREATEBOX_ID())->value()) {
@@ -108,7 +110,7 @@ AttributePtr FeaturesPlugin_BoundingBox::attributResultValues()
 }
 
 //=================================================================================================
-void FeaturesPlugin_BoundingBox::updateValues()
+bool FeaturesPlugin_BoundingBox::updateValues()
 {
   AttributeSelectionPtr aSelection = selection(OBJECT_ID());
   if (aSelection->isInitialized()) {
@@ -129,15 +131,16 @@ void FeaturesPlugin_BoundingBox::updateValues()
     }
 
     if (aShape && !aShape->isEqual(myShape)) {
-      double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax;
-      std::string aError;
+      double aXmin, aXmax, aYmin, aYmax, aZmin, aZmax;
+      std::string anError;
       if (!GetBoundingBox(aShape,
-                          true,
                           aXmin, aXmax,
-                          aYmin,aYmax,
-                          aZmin,aZmax,
-                          aError))
-          setError("Error in bounding box calculation :" +  aError);
+                          aYmin, aYmax,
+                          aZmin, aZmax,
+                          anError)) {
+        setError("Error in bounding box calculation :" +  anError);
+        return false;
+      }
 
       myShape = aShape;
       streamxmin << std::setprecision(14) << aXmin;
@@ -160,6 +163,7 @@ void FeaturesPlugin_BoundingBox::updateValues()
       string(Z_MAX_COORD_ID() )->setValue( "Z = " +  streamzmax.str() );
     }
   }
+  return true;
 }
 
 //=================================================================================================
index ef12a579f71b154e8995c866bdf237a841002eaf..e81dacef8c97f5db6c6e478c4279de928a3f7591 100644 (file)
@@ -126,7 +126,7 @@ private:
   virtual AttributePtr attributResultValues();
 
   /// Update values displayed.
-  void updateValues();
+  bool updateValues();
   /// Create Box
   void createBox();
   /// Update Box
index f59d98b94fb420056619eab92cc70e7ed6bc6d81..636ef66fa0563983c4eb45f51bc04bbde93e078c 100644 (file)
@@ -73,7 +73,9 @@ void FeaturesPlugin_CreateBoundingBox::initAttributes()
 //=================================================================================================
 void FeaturesPlugin_CreateBoundingBox::execute()
 {
-  updateValues();
+  if (!updateValues())
+    return;
+
   createBoxByTwoPoints();
 }
 
@@ -83,7 +85,7 @@ void FeaturesPlugin_CreateBoundingBox::attributeChanged(const std::string& theID
 }
 
 //=================================================================================================
-void FeaturesPlugin_CreateBoundingBox::updateValues()
+bool FeaturesPlugin_CreateBoundingBox::updateValues()
 {
   AttributeSelectionPtr aSelection = selection(OBJECT_ID());
   AttributeDoubleArrayPtr aValues =
@@ -111,15 +113,16 @@ void FeaturesPlugin_CreateBoundingBox::updateValues()
     }
 
     if (aShape && !aShape->isEqual(myShape)) {
-      double aXmin, aXmax, aYmin,aYmax,aZmin,aZmax;
-      std::string aError;
+      double aXmin, aXmax, aYmin, aYmax, aZmin, aZmax;
+      std::string anError;
       if (!GetBoundingBox(aShape,
-                          true,
                           aXmin, aXmax,
-                          aYmin,aYmax,
-                          aZmin,aZmax,
-                          aError))
-          setError("Error in bounding box calculation :" +  aError);
+                          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);
@@ -149,6 +152,7 @@ void FeaturesPlugin_CreateBoundingBox::updateValues()
     string(Y_MAX_COORD_ID() )->setValue( "Y = " +  streamymax.str() );
     string(Z_MAX_COORD_ID() )->setValue( "Z = " +  streamzmax.str() );
   }
+  return true;
 }
 
 //=================================================================================================
index 6884ac0db27b4f2f5d9824efef6c98972f0d64b5..be797af76927c4d70c0cdcbb70755fd3b9c8396a 100644 (file)
@@ -123,7 +123,7 @@ public:
 
 private:
   /// Update values displayed.
-  void updateValues();
+  bool updateValues();
 
 };
 
index 2f94c04da031b046e68e531f4e53923697120fdb..648e88bcde1c76ce40039353f0e3f00108f56d1e 100644 (file)
@@ -29,7 +29,7 @@
 #include <Config_PropManager.h>
 
 #include <GeomAPI_Shape.h>
-#include <GeomAlgoAPI_GeometryCalculation.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
 
 #include <iomanip>
@@ -85,14 +85,10 @@ void FeaturesPlugin_GeometryCalculation::attributeChanged(const std::string& the
       double aLength;
       double aSurfArea;
       double aVolume;
-      std::string aError;
-      if (!getGeometryCalculation(aShape,
-                                  aTolerance,
-                                  aLength,
-                                  aSurfArea,
-                                  aVolume,
-                                  aError))
-         setError("Error in Geometry calculation :" +  aError);
+
+      aLength = GeomAlgoAPI_ShapeTools::length(aShape);
+      aSurfArea = GeomAlgoAPI_ShapeTools::area(aShape);
+      aVolume = GeomAlgoAPI_ShapeTools::volume(aShape);
 
       streamL << std::setprecision(14) << aLength;
       aValues->setValue(0, aLength);
index 673445e8641e016a3ef9be1ca9ba6a5c82c3be76..49f90f8e06854893c03dd687b7ccbddf5eaf13ff 100644 (file)
@@ -41,14 +41,15 @@ __updated__ = "2020-11-12"
 def test_Bounding_Box():
 
     model.begin()
-    file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Step","screw.step")
     partSet = model.moduleDocument()
     Part_1 = model.addPart(partSet)
     Part_1_doc = Part_1.document()
-    Import_1 = model.addImport(Part_1_doc,file_path)
+    ### Create Cone
+    Cone_1 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 5, 10)
+
     model.do()
     ### Create BoundingBox
-    BoundingBox_1 = model.getBoundingBox(Part_1_doc, model.selection("SOLID", "screw_1"))
+    BoundingBox_1 = model.getBoundingBox(Part_1_doc, model.selection("SOLID", "Cone_1_1"))
     model.end()
 
     myDelta = 1e-6
@@ -59,15 +60,15 @@ def test_Bounding_Box():
     print(" Surface area: ", Props[1])
     print(" Volume      : ", Props[2]) 
     
-    aReflength = 0.32855301948678
+    aReflength = 200
     aReslength = Props[0]
     assert (math.fabs(aReslength - aReflength) < myDelta), "The surface is wrong: expected = {0}, real = {1}".format(aReflength, aReslength)
 
-    aRefSurface = 0.0041640657342782
+    aRefSurface = 1600
     aResSurface = Props[1]
     assert (math.fabs(aResSurface - aRefSurface) < myDelta), "The surface is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
 
-    aRefVolume = 1.6785355394103e-05
+    aRefVolume = 4000
     aResVolume = Props[2]
     assert (math.fabs(aResVolume - aRefVolume) < myDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefVolume, aResVolume)
 
index d904006ae6003b76f0f136ee89e4dde3d31fc05f..fa14ebaf2cd0fb4114ec03cb1650d8b8581abc8e 100644 (file)
@@ -2,12 +2,13 @@ from salome.shaper import model
 import os
 
 model.begin()
-file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Step","screw.step")
 partSet = model.moduleDocument()
 Part_1 = model.addPart(partSet)
 Part_1_doc = Part_1.document()
-Import_1 = model.addImport(Part_1_doc,file_path)
+### Create Cone
+Cone_1 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 5, 10)
+
 model.do()
 ### Create BoundingBox
-BoundingBox_1 = model.getBoundingBox(Part_1_doc, model.selection("SOLID", "screw_1"))
+BoundingBox_1 = model.getBoundingBox(Part_1_doc, model.selection("SOLID", "Cone_1_1"))
 model.end()
index e3ea735fbb2e6b9cb0ef3a654de23d3958c19c30..9ff70d95d5994c0fc2fc4ac912e7cc3015adfa02 100644 (file)
@@ -88,7 +88,6 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_Projection.h
     GeomAlgoAPI_Chamfer.h
     GeomAlgoAPI_Defeaturing.h
-    GeomAlgoAPI_GeometryCalculation.h
     GeomAlgoAPI_BoundingBox.h
 )
 
@@ -157,7 +156,6 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_Projection.cpp
     GeomAlgoAPI_Chamfer.cpp
     GeomAlgoAPI_Defeaturing.cpp
-    GeomAlgoAPI_GeometryCalculation.cpp
     GeomAlgoAPI_BoundingBox.cpp
 )
 
index 856b2eb4d2aadde1a2792e7a47341d66ad87ab9b..157823bb9e788e2ba55989a72e1596c80e4c73e6 100644 (file)
@@ -278,8 +278,7 @@ Standard_Real GetMinDistance(const TopoDS_Shape& theShape1,
 //=======================================================================
 // function : PreciseBoundingBox
 //=======================================================================
-Standard_Boolean PreciseBoundingBox
-                          (const TopoDS_Shape &theShape, Bnd_Box &theBox)
+Standard_Boolean PreciseBoundingBox(const TopoDS_Shape &theShape, Bnd_Box &theBox)
 {
   if (theBox.IsVoid()) BRepBndLib::Add( theShape, theBox );
   if (theBox.IsVoid()) return Standard_False;
@@ -343,7 +342,6 @@ Standard_Boolean PreciseBoundingBox
 
 //=================================================================================================
 bool GetBoundingBox(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                    const bool thePrecise,
                     Standard_Real& theXmin,Standard_Real& theXmax,
                     Standard_Real& theYmin,Standard_Real& theYmax,
                     Standard_Real& theZmin,Standard_Real& theZmax,
@@ -377,11 +375,9 @@ bool GetBoundingBox(const std::shared_ptr<GeomAPI_Shape>& theShape,
 
     BRepBndLib::Add(aShape, B);
 
-    if (thePrecise) {
-      if (!PreciseBoundingBox(aShape, B)) {
-        theError = "GetBoundingBox Error: Bounding box cannot be precised";
-        return false;
-      }
+    if (!PreciseBoundingBox(aShape, B)) {
+      theError = "GetBoundingBox Error: Bounding box cannot be precised";
+      return false;
     }
 
     B.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
index 010c3a30b380fb96c534203b040b64ffe476ad7e..66336bcce6ea68ac5d967b6f64f8108f78616441 100644 (file)
@@ -36,7 +36,6 @@
   /// \param theError  error
 GEOMALGOAPI_EXPORT
 bool GetBoundingBox(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                    const bool thePrecise,
                     Standard_Real& theXmin,Standard_Real& theXmax,
                     Standard_Real& theYmin,Standard_Real& theYmax,
                     Standard_Real& theZmin,Standard_Real& theZmax,
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp
deleted file mode 100644 (file)
index 43af83c..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2014-2020  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 "GeomAlgoAPI_GeometryCalculation.h"
-
-#include <GProp_GProps.hxx>
-#include <TopoDS_Shape.hxx>
-#include <BRepGProp.hxx>
-#include <TopExp_Explorer.hxx>
-#include <Standard_ErrorHandler.hxx>
-
-//=================================================================================================
-bool getGeometryCalculation(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                            const double theTolerance,
-                            Standard_Real& theLength,
-                            Standard_Real& theSurfArea,
-                            Standard_Real& theVolume,
-                            std::string& theError)
-{
-
-  #ifdef _DEBUG
-  std::cout << "getGeometryCalculation " << std::endl;
-  #endif
-
-  if (!theShape.get()) {
-    theError = "getGeometryCalculation : An invalid argument";
-    return false;
-  }
-
-  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
-
-  //Compute the parameters
-  GProp_GProps aLProps, aSProps;
-  Standard_Real anEps = theTolerance >= 0 ? theTolerance : 1.e-6;
-  try {
-    OCC_CATCH_SIGNALS;
-    BRepGProp::LinearProperties(aShape, aLProps, Standard_True);
-    theLength = aLProps.Mass();
-
-    BRepGProp::SurfaceProperties(aShape, aSProps, anEps, Standard_True);
-    theSurfArea = aSProps.Mass();
-
-    theVolume = 0.0;
-    if (aShape.ShapeType() < TopAbs_SHELL) {
-      for (TopExp_Explorer anExp (aShape, TopAbs_SOLID); anExp.More(); anExp.Next()) {
-        GProp_GProps aVProps;
-        BRepGProp::VolumeProperties(anExp.Current(), aVProps, anEps, Standard_True);
-        theVolume += aVProps.Mass();
-      }
-    }
-  }
-  catch (Standard_Failure& aFail) {
-    theError = aFail.GetMessageString();
-    return false;
-  }
-
-  return true;
-
-}
\ No newline at end of file
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h b/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h
deleted file mode 100644 (file)
index df1f2f2..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (C) 2014-2020  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 GeomAlgoAPI_GeometryCalculation_H_
-#define GeomAlgoAPI_GeometryCalculation_H_
-
-#include <GeomAlgoAPI.h>
-#include <GeomAPI_Shape.h>
-#include <Standard_TypeDef.hxx>
-
-/// Run chamfer operation with two distances or with a distance and an angle .
-  /// \param theShape      the shape
-  /// \param theTolerance  tolerance desirated
-  /// \param theLength     length calculated
-  /// \param theSurfArea   Surface Area calculated
-  /// \param theVolume     Volume calculated
-  /// \param theError      error
-GEOMALGOAPI_EXPORT
-bool getGeometryCalculation(const std::shared_ptr<GeomAPI_Shape>& theShape,
-                            const Standard_Real theTolerance,
-                            Standard_Real& theLength,
-                            Standard_Real& theSurfArea,
-                            Standard_Real& theVolume,
-                            std::string& theError);
-
-#endif
index 89133a06bb74d0f3ff21fb5802178589ef8f5184..fdeb6d8d366312eea4c12f1eba3b636704ba2a4a 100644 (file)
@@ -122,6 +122,22 @@ static GProp_GProps props(const TopoDS_Shape& theShape)
   return aGProps;
 }
 
+//==================================================================================================
+double GeomAlgoAPI_ShapeTools::length(const std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  GProp_GProps aGProps;
+  if(!theShape.get()) {
+    return 0.0;
+  }
+  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+  if(aShape.IsNull()) {
+    return 0.0;
+  }
+
+  BRepGProp::LinearProperties(aShape, aGProps, Standard_True);
+  return  aGProps.Mass();
+}
+
 //==================================================================================================
 double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
 {
@@ -133,20 +149,13 @@ double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theSh
     return 0.0;
   }
   const Standard_Real anEps = 1.e-6;
-  TopExp_Explorer anExp(aShape, TopAbs_SOLID);
-  if (anExp.More()) { // return volume if there is at least one solid
-    double aVolume = 0.0;
-    for (; anExp.More(); anExp.Next()) {
-      GProp_GProps aGProps;
-      BRepGProp::VolumeProperties(anExp.Current(), aGProps, anEps);
-      aVolume += aGProps.Mass();
-    }
-    return aVolume;
+  double aVolume = 0.0;
+  for (TopExp_Explorer anExp(aShape, TopAbs_SOLID); anExp.More(); anExp.Next()) {
+    GProp_GProps aGProps;
+    BRepGProp::VolumeProperties(anExp.Current(), aGProps, anEps);
+    aVolume += aGProps.Mass();
   }
-  // return surfaces area
-  GProp_GProps aGProps;
-  BRepGProp::SurfaceProperties(aShape, aGProps, anEps);
-  return aGProps.Mass();
+  return aVolume;
 }
 
 //==================================================================================================
index 4e1e6523a0d95ce80cc6223af87da34f8c672c2e..267a98acaa052c601cd1f97d9e3b85f17189e55d 100644 (file)
@@ -45,6 +45,9 @@ class ModelAPI_Object;
 class GeomAlgoAPI_ShapeTools
 {
 public:
+  /// \return the lenth of the edges of the current shape or 0.0 if it can be computed.
+  GEOMALGOAPI_EXPORT static double length(const std::shared_ptr<GeomAPI_Shape> theShape);
+
   /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
   GEOMALGOAPI_EXPORT static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);