model.testNbSubShapes(Face_1, GeomAPI_Shape.FACE, [1])
model.testNbSubShapes(Face_1, GeomAPI_Shape.EDGE, [3])
model.testNbSubShapes(Face_1, GeomAPI_Shape.VERTEX, [6])
-model.testResultsVolumes(Face_1, [441.0539215686274])
+model.testResultsAreas(Face_1, [441.0539215686274])
assert(model.checkPythonDump())
model.testNbSubShapes(Face_1, GeomAPI_Shape.FACE, [1, 1, 1])
model.testNbSubShapes(Face_1, GeomAPI_Shape.EDGE, [3, 2, 2])
model.testNbSubShapes(Face_1, GeomAPI_Shape.VERTEX, [6, 4, 4])
-model.testResultsVolumes(Face_1, [441.0539215686274, 628.318530717958, 628.318530717958])
+model.testResultsAreas(Face_1, [441.0539215686274, 628.318530717958, 628.318530717958])
assert(model.checkPythonDump())
model.testNbSubShapes(Shell_1, GeomAPI_Shape.FACE, [1])
model.testNbSubShapes(Shell_1, GeomAPI_Shape.EDGE, [3])
model.testNbSubShapes(Shell_1, GeomAPI_Shape.VERTEX, [6])
-model.testResultsVolumes(Shell_1, [441.0539215686274])
+model.testResultsAreas(Shell_1, [441.0539215686274])
assert(model.checkPythonDump())
model.testNbSubShapes(Shell_1, GeomAPI_Shape.FACE, [1, 2])
model.testNbSubShapes(Shell_1, GeomAPI_Shape.EDGE, [3, 4])
model.testNbSubShapes(Shell_1, GeomAPI_Shape.VERTEX, [6, 8])
-model.testResultsVolumes(Shell_1, [441.0539215686274, 1256.637061435917])
+model.testResultsAreas(Shell_1, [441.0539215686274, 1256.637061435917])
assert(model.checkPythonDump())
std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(
new GeomAlgoAPI_Boolean(aOneObjectList, aShapesToAdd, GeomAlgoAPI_Tools::BOOL_CUT));
- if (GeomAlgoAPI_ShapeTools::volume(aCutAlgo->shape()) > 1.e-27) {
+ if (GeomAlgoAPI_ShapeTools::area(aCutAlgo->shape()) > 1.e-27) {
aSolidsToFuse.push_back(aCutAlgo->shape());
aMakeShapeList->appendAlgo(aCutAlgo);
}
aShapesToAdd,
GeomAlgoAPI_Tools::BOOL_CUT));
- if (GeomAlgoAPI_ShapeTools::volume(anObjectsCutAlgo->shape()) > 1.e-27) {
+ if (GeomAlgoAPI_ShapeTools::area(anObjectsCutAlgo->shape()) > 1.e-27) {
aShapesToSmash.clear();
aShapesToSmash.push_back(anObjectsCutAlgo->shape());
aMakeShapeList->appendAlgo(anObjectsCutAlgo);
aShapesToAdd,
GeomAlgoAPI_Tools::BOOL_CUT));
- if (GeomAlgoAPI_ShapeTools::volume(aToolsCutAlgo->shape()) > 1.e-27) {
+ if (GeomAlgoAPI_ShapeTools::area(aToolsCutAlgo->shape()) > 1.e-27) {
aTools.clear();
aTools.push_back(aToolsCutAlgo->shape());
aMakeShapeList->appendAlgo(aToolsCutAlgo);
return false;
}
- if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo->shape()) > 1.e-27) {
+ if(GeomAlgoAPI_ShapeTools::area(aBoolAlgo->shape()) > 1.e-27) {
theObjects.push_back(anObject);
theMakeShapes.push_back(aBoolAlgo);
}
aMakeShapeList->appendAlgo(aFillerAlgo);
}
- if(GeomAlgoAPI_ShapeTools::volume(aBoolRes) > 1.e-27) {
+ if(GeomAlgoAPI_ShapeTools::area(aBoolRes) > 1.e-27) {
theObjects.push_back(aCompSolid);
theMakeShapes.push_back(aMakeShapeList);
}
std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(new GeomAlgoAPI_Boolean(aSolidsToFuse,
aShapesToAdd,
GeomAlgoAPI_Tools::BOOL_CUT));
- if(aCutAlgo->isDone() && GeomAlgoAPI_ShapeTools::volume(aCutAlgo->shape()) > 1.e-27) {
+ if(aCutAlgo->isDone() && GeomAlgoAPI_ShapeTools::area(aCutAlgo->shape()) > 1.e-27) {
aSolidsToFuse.clear();
aSolidsToFuse.push_back(aCutAlgo->shape());
aMakeShapeList->appendAlgo(aCutAlgo);
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;
}
//==================================================================================================
aResult<<std::fixed<<std::setprecision(3);
aResult<<aVolume<<std::endl;
}
+ double anArea = GeomAlgoAPI_ShapeTools::area(theShape);
+ if (anArea > 1.e-5) {
+ aResult << "Area: ";
+ // volumes of too huge shapes write in the scientific format
+ if (anArea >= 1.e5)
+ aResult << std::scientific << std::setprecision(7);
+ else
+ aResult << std::fixed << std::setprecision(3);
+ aResult << anArea << std::endl;
+ }
std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
aResult<<"Center of mass: ";
double aCenterVals[3] = {aCenter->x(), aCenter->y(), aCenter->z()};
aResultsVolumes.append(GeomAlgoAPI_ShapeTools_volume(theFeature.results()[anIndex].resultSubShapePair()[0].shape()))
print("model.testResultsVolumes({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes)))
+ if "testResultsAreas" in theTestsList or len(theTestsList) == 0:
+ aNbResults = len(theFeature.results())
+ aResultsVolumes = []
+ for anIndex in range(0, aNbResults):
+ aResultsAreas.append(GeomAlgoAPI_ShapeTools_area(theFeature.results()[anIndex].resultSubShapePair()[0].shape()))
+ print("model.testResultsAreas({}, [{}])".format(theFeatureName, ", ".join("{:0.27f}".format(i) for i in aResultsVolumes)))
+
def testNbResults(theFeature, theExpectedNbResults):
""" Tests number of feature results.
anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0")
assert math.fabs(aResultVolume - anExpectedResultVolume) <= aTolerance * math.fabs(anExpectedResultVolume), "Volume of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits)
+
+def testResultsAreas(theFeature, theExpectedResultsAreas, theNbSignificantDigits = 7):
+ """ Tests results areas.
+ :param theFeature: feature to test.
+ :param theExpectedResultsAreas: list of results volumes. Size of list should be equal to len(theFeature.results()).
+ """
+ aTolerance = 10**(-theNbSignificantDigits)
+ aNbResults = len(theFeature.results())
+ aListSize = len(theExpectedResultsVolumes)
+ assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
+ for anIndex in range(0, aNbResults):
+ aResultVolume = GeomAlgoAPI_ShapeTools_area(theFeature.results()[anIndex].resultSubShapePair()[0].shape())
+ aResultVolumeStr = "{:0.27f}".format(aResultVolume).lstrip("0").lstrip(".").lstrip("0")
+ anExpectedResultVolume = theExpectedResultsVolumes[anIndex]
+ anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0")
+ assert math.fabs(aResultVolume - anExpectedResultVolume) <= aTolerance * math.fabs(anExpectedResultVolume), "Area of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits)
+
+
def testHaveNamingFaces(theFeature, theModel, thePartDoc) :
""" Tests if all faces of result have a name
:param theFeature: feature to test.