-# Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+# Copyright (C) 2014-2022 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
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())
+ aResultsAreas = []
+ 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 aResultsAreas)))
+
def testNbResults(theFeature, theExpectedNbResults):
""" Tests number of feature results.
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), "Volume of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits)
+ 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, theExpectedResultsVolumes, theNbSignificantDigits = 7):
+ """ Tests results areas.
+ :param theFeature: feature to test.
+ :param theExpectedResultsAreas: list of results areas. 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
aFiltersFactory = ModelAPI_Session.get().filters()
for sel, res in theShapesList.items():
needUndo = False
+ shapeName = ""
+ shapeType = "UNKNOWN"
if sel.variantType() == ModelHighAPI_Selection.VT_ResultSubShapePair:
+ parent = sel.resultSubShapePair()[0]
shape = sel.resultSubShapePair()[1]
+ if shape.isNull():
+ shape = sel.resultSubShapePair()[0].shape()
+ shapeName = sel.name()
+ shapeType = shape.shapeTypeStr()
else:
needUndo = True
theModel.begin()
subShapeFeature = createSubShape(thePartDoc, theModel, sel)
theModel.end()
+ parent = subShapeFeature.results()[0].resultSubShapePair()[0]
shape = subShapeFeature.results()[0].resultSubShapePair()[0].shape()
- assert(aFiltersFactory.isValid(theFilter.feature(), shape) == res)
+ shapeType = sel.typeSubShapeNamePair()[0]
+ shapeName = sel.typeSubShapeNamePair()[1]
+ assert aFiltersFactory.isValid(theFilter.feature(), parent, shape) == res, "Filter result for {} \"{}\" incorrect. Expected {}.".format(shapeType, shapeName, res)
if needUndo:
theModel.undo()