From 7bcd7b3ed1883db06ed0e47c29f54c868cc6296f Mon Sep 17 00:00:00 2001 From: cg246364 Date: Tue, 9 Feb 2021 16:47:15 +0100 Subject: [PATCH] Corrections (#20619) --- .../FeaturesPlugin_BoundingBox.cpp | 22 +++--- .../FeaturesPlugin_BoundingBox.h | 2 +- .../FeaturesPlugin_CreateBoundingBox.cpp | 22 +++--- .../FeaturesPlugin_CreateBoundingBox.h | 2 +- .../FeaturesPlugin_GeometryCalculation.cpp | 14 ++-- src/FeaturesPlugin/Test/TestBoundingBox.py | 13 ++-- .../doc/examples/create_bounding_box.py | 7 +- src/GeomAlgoAPI/CMakeLists.txt | 2 - src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.cpp | 12 +-- src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.h | 1 - .../GeomAlgoAPI_GeometryCalculation.cpp | 75 ------------------- .../GeomAlgoAPI_GeometryCalculation.h | 42 ----------- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 35 +++++---- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h | 3 + 14 files changed, 73 insertions(+), 179 deletions(-) delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp index 6e30b6f54..82f8089c0 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.cpp @@ -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; } //================================================================================================= diff --git a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h index ef12a579f..e81dacef8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_BoundingBox.h @@ -126,7 +126,7 @@ private: virtual AttributePtr attributResultValues(); /// Update values displayed. - void updateValues(); + bool updateValues(); /// Create Box void createBox(); /// Update Box diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp index f59d98b94..636ef66fa 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.cpp @@ -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; } //================================================================================================= diff --git a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h index 6884ac0db..be797af76 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CreateBoundingBox.h @@ -123,7 +123,7 @@ public: private: /// Update values displayed. - void updateValues(); + bool updateValues(); }; diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp index 2f94c04da..648e88bcd 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include @@ -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); diff --git a/src/FeaturesPlugin/Test/TestBoundingBox.py b/src/FeaturesPlugin/Test/TestBoundingBox.py index 673445e86..49f90f8e0 100644 --- a/src/FeaturesPlugin/Test/TestBoundingBox.py +++ b/src/FeaturesPlugin/Test/TestBoundingBox.py @@ -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) diff --git a/src/FeaturesPlugin/doc/examples/create_bounding_box.py b/src/FeaturesPlugin/doc/examples/create_bounding_box.py index d904006ae..fa14ebaf2 100644 --- a/src/FeaturesPlugin/doc/examples/create_bounding_box.py +++ b/src/FeaturesPlugin/doc/examples/create_bounding_box.py @@ -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() diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index e3ea735fb..9ff70d95d 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -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 ) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.cpp index 856b2eb4d..157823bb9 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.cpp @@ -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& 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& 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); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.h b/src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.h index 010c3a30b..66336bcce 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BoundingBox.h @@ -36,7 +36,6 @@ /// \param theError error GEOMALGOAPI_EXPORT bool GetBoundingBox(const std::shared_ptr& 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 index 43af83cf2..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp +++ /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 -#include -#include -#include -#include - -//================================================================================================= -bool getGeometryCalculation(const std::shared_ptr& 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(); - - //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 index df1f2f2b3..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h +++ /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 -#include -#include - -/// 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& theShape, - const Standard_Real theTolerance, - Standard_Real& theLength, - Standard_Real& theSurfArea, - Standard_Real& theVolume, - std::string& theError); - -#endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index 89133a06b..fdeb6d8d3 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -122,6 +122,22 @@ static GProp_GProps props(const TopoDS_Shape& theShape) return aGProps; } +//================================================================================================== +double GeomAlgoAPI_ShapeTools::length(const std::shared_ptr theShape) +{ + GProp_GProps aGProps; + if(!theShape.get()) { + return 0.0; + } + const TopoDS_Shape& aShape = theShape->impl(); + if(aShape.IsNull()) { + return 0.0; + } + + BRepGProp::LinearProperties(aShape, aGProps, Standard_True); + return aGProps.Mass(); +} + //================================================================================================== double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr theShape) { @@ -133,20 +149,13 @@ double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr 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; } //================================================================================================== diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h index 4e1e6523a..267a98aca 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h @@ -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 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 theShape); -- 2.39.2