from GeomAlgoAPI import *
+from GeomAPI import *
import math
+aShapeTypes = {
+ GeomAPI_Shape.SOLID: "GeomAPI_Shape.SOLID",
+ GeomAPI_Shape.FACE: "GeomAPI_Shape.FACE",
+ GeomAPI_Shape.EDGE: "GeomAPI_Shape.EDGE",
+ GeomAPI_Shape.VERTEX: "GeomAPI_Shape.VERTEX"}
+
+
def generateTests(theFeature, theFeatureName, theTestsList = []):
""" Generates tests for theFeature.
:param theFeature: feature to test. Should be ModelHighAPI_Interface.
aNbSubResults.append(theFeature.results()[anIndex].numberOfSubs())
print "model.testNbSubResults({}, {})".format(theFeatureName, aNbSubResults)
+ if "testNbSubShapes" in theTestsList or len(theTestsList) == 0:
+ aNbResults = len(theFeature.results())
+ for aShapeType in aShapeTypes:
+ aNbSubShapes = []
+ for anIndex in range(0, aNbResults):
+ aShape = theFeature.results()[anIndex].resultSubShapePair()[0].shape()
+ aNbResultSubShapes = 0
+ aShapeExplorer = GeomAPI_ShapeExplorer(aShape, aShapeType)
+ while aShapeExplorer.more():
+ aNbResultSubShapes += 1
+ aShapeExplorer.next();
+ aNbSubShapes.append(aNbResultSubShapes)
+ print "model.testNbSubShapes({}, {}, {})".format(theFeatureName, aShapeTypes[aShapeType], aNbSubShapes)
+
if "testResultsVolumes" in theTestsList or len(theTestsList) == 0:
aNbResults = len(theFeature.results())
aResultsVolumes = []
assert (aNbSubResults == anExpectedNbSubResults), "Number of sub-results for result[{}]: {}. Expected: {}.".format(anIndex, aNbSubResults, anExpectedNbSubResults)
+def testNbSubShapes(theFeature, theShapeType, theExpectedNbSubShapes):
+ """ Tests number of feature sub-shapes of passed type for each result.
+ :param theFeature: feature to test.
+ :param theShapeType: shape type of sub-shapes to test.
+ :param theExpectedNbSubShapes: list of sub-shapes numbers. Size of list should be equal to len(theFeature.results()).
+ """
+ aNbResults = len(theFeature.results())
+ aListSize = len(theExpectedNbSubShapes)
+ assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
+ for anIndex in range(0, aNbResults):
+ aNbResultSubShapes = 0
+ anExpectedNbSubShapes = theExpectedNbSubShapes[anIndex]
+ aShape = theFeature.results()[anIndex].resultSubShapePair()[0].shape()
+ aShapeExplorer = GeomAPI_ShapeExplorer(aShape, theShapeType)
+ while aShapeExplorer.more():
+ aNbResultSubShapes += 1
+ aShapeExplorer.next();
+ assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes)
+
+
def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDigits = 10):
""" Tests results volumes.
:param theFeature: feature to test.
ExtrusionCut_3 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_8/Face-SketchLine_7r-SketchLine_8r-SketchLine_10f-SketchLine_11f"), model.selection("FACE", "Sketch_8/Face-SketchLine_16f-SketchLine_17f-SketchLine_18r-SketchLine_19r"), model.selection("FACE", "Sketch_8/Face-SketchLine_12f-SketchLine_13f-SketchLine_14r-SketchLine_15r")], model.selection(), model.selection("FACE", "ExtrusionCut_2_1/Modfied_23"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_2_1")])
model.end()
+from GeomAPI import GeomAPI_Shape
+
model.testNbResults(ExtrusionCut_3, 1)
model.testNbSubResults(ExtrusionCut_3, [0])
+model.testNbSubShapes(ExtrusionCut_3, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(ExtrusionCut_3, GeomAPI_Shape.FACE, [50])
+model.testNbSubShapes(ExtrusionCut_3, GeomAPI_Shape.EDGE, [300])
+model.testNbSubShapes(ExtrusionCut_3, GeomAPI_Shape.VERTEX, [600])
model.testResultsVolumes(ExtrusionCut_3, [34439.077343526856566313654184341])