From 54f9293ff10c1ba51f83a7c0887b0234d4e799cc Mon Sep 17 00:00:00 2001 From: lucasjerome Date: Fri, 5 Feb 2021 17:01:06 +0100 Subject: [PATCH] Remove GeomAlgoAPI_GeometryCalculation and add function length() in ShapeTools --- .../FeaturesPlugin_GeometryCalculation.cpp | 14 ++-- src/GeomAlgoAPI/CMakeLists.txt | 2 - .../GeomAlgoAPI_GeometryCalculation.cpp | 75 ------------------- .../GeomAlgoAPI_GeometryCalculation.h | 42 ----------- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 14 ++++ src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h | 3 + 6 files changed, 22 insertions(+), 128 deletions(-) delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.cpp delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_GeometryCalculation.h diff --git a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp index 6a349920b..64762e811 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_GeometryCalculation.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include @@ -83,14 +83,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/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 3900e711b..c60586a11 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -33,7 +33,6 @@ SET(PROJECT_HEADERS GeomAlgoAPI_Prism.h GeomAlgoAPI_Revolution.h GeomAlgoAPI_Boolean.h - GeomAlgoAPI_GeometryCalculation.h GeomAlgoAPI_ThroughAll.h GeomAlgoAPI_Rotation.h GeomAlgoAPI_Translation.h @@ -99,7 +98,6 @@ SET(PROJECT_SOURCES GeomAlgoAPI_Prism.cpp GeomAlgoAPI_Revolution.cpp GeomAlgoAPI_Boolean.cpp - GeomAlgoAPI_GeometryCalculation.cpp GeomAlgoAPI_ThroughAll.cpp GeomAlgoAPI_Rotation.cpp GeomAlgoAPI_Translation.cpp 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 9a51a5ae7..e571a58d4 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -121,7 +121,21 @@ 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) { 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