+
+def createSubShape(thePartDoc, theModel, theSelection):
+ """ Create feature according to the type of the given subshape
+ """
+ if theSelection.shapeType() == "VERTEX":
+ return theModel.addVertex(thePartDoc, [theSelection])
+ elif theSelection.shapeType() == "EDGE":
+ return theModel.addEdge(thePartDoc, [theSelection])
+ elif theSelection.shapeType() == "FACE":
+ return theModel.addFace(thePartDoc, [theSelection])
+
+def checkFilter(thePartDoc, theModel, theFilter, theShapesList):
+ """ Check filter's work on specified shape.
+ Shapes given as a dictionary of selection and expected result.
+ """
+ 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()
+ 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()
+
+def checkFeaturesValidity(thePartDoc):
+ """ Check that the features are not in error
+ """
+ aFactory = ModelAPI_Session.get().validators()
+
+ nbFeatures = thePartDoc.size("Features")
+
+ assert nbFeatures>0, "No features found in part doc"
+
+ for i in range(nbFeatures):
+ partObject = thePartDoc.object("Features", i)
+ # Check the data
+ partObjectData = partObject.data()
+ name = partObjectData.name()
+ error = partObjectData.error()
+ # raise the error message if there is one
+ assert error == '', "The feature data {0} is in error: {1}".format(name, error)
+ # raise an error if the the feature is not valid (without error message)
+ assert partObject.data().isValid(), "The feature data {0} is in error.".format(name)
+ # Same checks for the feature itself
+ feature = objectToFeature(partObject)
+ if feature is None:
+ # Folders are not real features
+ continue
+ # raise the error message if there is one
+ assert error == '', "The feature {0} is in error: {1}".format(name, error)
+ # raise an error if the the feature is not valid (without error message)
+ assert aFactory.validate(feature), "The feature {0} is in error.".format(name)