//=================================================================================================
void FeaturesPlugin_BoundingBox::execute()
{
- updateValues();
+ if (!updateValues())
+ return;
+
createBoxByTwoPoints();
if (boolean(CREATEBOX_ID())->value()) {
}
//=================================================================================================
-void FeaturesPlugin_BoundingBox::updateValues()
+bool FeaturesPlugin_BoundingBox::updateValues()
{
AttributeSelectionPtr aSelection = selection(OBJECT_ID());
if (aSelection->isInitialized()) {
}
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;
string(Z_MAX_COORD_ID() )->setValue( "Z = " + streamzmax.str() );
}
}
+ return true;
}
//=================================================================================================
virtual AttributePtr attributResultValues();
/// Update values displayed.
- void updateValues();
+ bool updateValues();
/// Create Box
void createBox();
/// Update Box
//=================================================================================================
void FeaturesPlugin_CreateBoundingBox::execute()
{
- updateValues();
+ if (!updateValues())
+ return;
+
createBoxByTwoPoints();
}
}
//=================================================================================================
-void FeaturesPlugin_CreateBoundingBox::updateValues()
+bool FeaturesPlugin_CreateBoundingBox::updateValues()
{
AttributeSelectionPtr aSelection = selection(OBJECT_ID());
AttributeDoubleArrayPtr aValues =
}
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);
string(Y_MAX_COORD_ID() )->setValue( "Y = " + streamymax.str() );
string(Z_MAX_COORD_ID() )->setValue( "Z = " + streamzmax.str() );
}
+ return true;
}
//=================================================================================================
private:
/// Update values displayed.
- void updateValues();
+ bool updateValues();
};
#include <Config_PropManager.h>
#include <GeomAPI_Shape.h>
-#include <GeomAlgoAPI_GeometryCalculation.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <iomanip>
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);
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
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)
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()
GeomAlgoAPI_Projection.h
GeomAlgoAPI_Chamfer.h
GeomAlgoAPI_Defeaturing.h
- GeomAlgoAPI_GeometryCalculation.h
GeomAlgoAPI_BoundingBox.h
)
GeomAlgoAPI_Projection.cpp
GeomAlgoAPI_Chamfer.cpp
GeomAlgoAPI_Defeaturing.cpp
- GeomAlgoAPI_GeometryCalculation.cpp
GeomAlgoAPI_BoundingBox.cpp
)
//=======================================================================
// 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;
//=================================================================================================
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,
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);
/// \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,
+++ /dev/null
-// 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
+++ /dev/null
-// 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
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)
{
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;
}
//==================================================================================================
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);