INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
ADD_UNIT_TESTS(TestExtrusion.py
- TestBoolean.py)
+ TestBoolean.py
+ TestGroup.py)
--- /dev/null
+"""
+ TestBoolean.py
+ Unit test of FeaturesPlugin_Group class
+
+ class FeaturesPlugin_Group
+ static const std::string MY_GROUP_ID("Group");
+ static const std::string MY_GROUP_LIST_ID("group_list");
+
+ data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::type());
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from ModelAPI import *
+from GeomDataAPI import *
+from GeomAlgoAPI import *
+
+__updated__ = "2014-12-16"
+
+aSession = ModelAPI_Session.get()
+# Create a part for extrusions & boolean
+aSession.startOperation()
+aPartFeature = aSession.moduleDocument().addFeature("Part")
+aPart = aSession.activeDocument()
+aSession.finishOperation()
+#=========================================================================
+# Create a sketch with triangle and extrude it
+#=========================================================================
+aSession.startOperation()
+aTriangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+diry = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirY"))
+diry.setValue(0, 1, 0)
+norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
+aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
+aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
+aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
+aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
+aLineAStartPoint.setValue(25., 25.)
+aLineAEndPoint.setValue(100., 25.)
+aLineBStartPoint.setValue(100., 25.)
+aLineBEndPoint.setValue(60., 75.)
+aLineCStartPoint.setValue(60., 75.)
+aLineCEndPoint.setValue(25., 25.)
+aSession.finishOperation()
+# Build sketch faces
+aSession.startOperation()
+aSketchResult = aTriangleSketchFeature.firstResult()
+aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
+origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin")).pnt()
+dirX = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX")).dir()
+dirY = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirY")).dir()
+norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm")).dir()
+aSketchFaces = ShapeList()
+GeomAlgoAPI_SketchBuilder.createFaces(
+ origin, dirX, dirY, norm, aSketchEdges, aSketchFaces)
+# Create extrusion on them
+anExtrusionFt = aPart.addFeature("Extrusion")
+anExtrusionFt.selection("extrusion_face").setValue(
+ aSketchResult, aSketchFaces[0])
+anExtrusionFt.real("extrusion_size").setValue(50)
+anExtrusionFt.boolean("extrusion_reverse").setValue(False)
+anExtrusionFt.execute()
+aSession.finishOperation()
+anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
+#=========================================================================
+# Create group of edges
+# TODO: After implementation of selection from batch script
+# update this test to have proper reslts in the group feature
+#=========================================================================
+aSession.startOperation()
+aGroupFeature = aSession.activeDocument().addFeature("Group")
+aSelectionListAttr = aGroupFeature.selectionList("group_list")
+aSelectionListAttr.clear()
+topAbs_EdgeType = 6
+aSelectionListAttr.setSelectionType(topAbs_EdgeType)
+
+for anEdge in [aSketchLineA, aSketchLineB, aSketchLineC]:
+ anEdgeResult = anEdge.firstResult()
+ assert(anEdgeResult)
+ assert(anEdgeResult.shape())
+ aSelectionListAttr.append(anEdgeResult, anEdgeResult.shape())
+aSession.finishOperation()
+#=========================================================================
+# Check results
+#=========================================================================
+aGroupResult = aGroupFeature.firstResult()
+assert(aGroupResult)
+#=========================================================================
+# End of test
+#=========================================================================
INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig)
ADD_UNIT_TESTS(TestConstants.py
- TestUndoRedo.py)
+ TestUndoRedo.py
+ TestDocument.py)
%template(ObjectList) std::list<std::shared_ptr<ModelAPI_Object> >;
%template(ResultList) std::list<std::shared_ptr<ModelAPI_Result> >;
+%template(DocumentList) std::list<std::shared_ptr<ModelAPI_Document> >;
template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr<T2> theObject);
%template(modelAPI_CompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
{
public:
/// Adds the new reference to the end of the list
- virtual void append(
- const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+ virtual void append(const ResultPtr& theContext,
+ const GeomShapePtr& theSubShape) = 0;
/// Returns the number ofselection attributes in the list
virtual int size() = 0;
--- /dev/null
+"""
+ TestDocument.py
+ Unit test for Model_Document/ModelAPI_Document class
+
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from ModelAPI import *
+# from GeomDataAPI import *
+# from GeomAlgoAPI import *
+
+__updated__ = "2014-12-16"
+
+#=========================================================================
+# Creation and activation of documents
+#=========================================================================
+aSession = ModelAPI_Session.get()
+# TODO: enable this assertion:
+assert(aSession.moduleDocument())
+assert(aSession.moduleDocument().id() == "root")
+assert(aSession.moduleDocument().kind() == "PartSet")
+assert(aSession.hasModuleDocument())
+# Create a new document
+aSession.startOperation()
+aSession.moduleDocument().addFeature("Part")
+aSession.finishOperation()
+
+assert(aSession.activeDocument())
+assert(aSession.activeDocument().id() == "Part_1")
+assert(aSession.activeDocument().kind() == "Part")
+# Activate root doc
+aRootDoc = aSession.document("root")
+assert(aRootDoc)
+aSession.startOperation()
+aSession.setActiveDocument(aRootDoc, False)
+aSession.finishOperation()
+assert(aSession.activeDocument())
+assert(aSession.activeDocument().id() == "root")
+# check all opened docs
+for aDoc in aSession.allOpenedDocuments():
+ assert(aDoc)
+# Activate Part_1 doc back for further testing
+aSession.startOperation()
+aSession.setActiveDocument(aSession.document("Part_1"), False)
+aSession.finishOperation()
+#=========================================================================
+# Duplication of a document
+#=========================================================================
+aPart = aSession.activeDocument()
+assert(aPart.size("Features") == 0)
+# Create a point in the current document to check if it is duplicated
+aSession.startOperation()
+aFeature = aPart.addFeature("Point")
+aFeatureData = aFeature.data()
+assert(aFeatureData is not None)
+aFeatureData.real("x").setValue(15.)
+aFeatureData.real("y").setValue(10.)
+aFeatureData.real("z").setValue(20.)
+aSession.finishOperation()
+assert(aPart.size("Features") == 1)
+# Duplicate the document
+assert(aSession.moduleDocument().size("Parts") == 1)
+aSession.startOperation()
+aSession.moduleDocument().addFeature("Duplicate")
+aSession.finishOperation()
+assert(aSession.moduleDocument().size("Parts") == 2)
+aCopyOfPart = aSession.activeDocument()
+assert(aCopyOfPart.id() == "Part_2")
+assert(aCopyOfPart.kind() == "Part")
+assert(aCopyOfPart.size("Features") == 1)
+assert(aCopyOfPart != aPart)
+#=========================================================================
+# Remove document
+#=========================================================================
+assert(aSession.moduleDocument().size("Parts") == 2)
+aSession.startOperation()
+aSession.moduleDocument().addFeature("Remove")
+aSession.finishOperation()
+assert(aSession.moduleDocument().size("Parts") == 1)
+assert(aSession.activeDocument().id() == aSession.moduleDocument().id())
+# Remove another one document
+aSession.startOperation()
+aDoc1 = aSession.document("Part_1")
+aSession.setActiveDocument(aDoc1, False)
+aSession.moduleDocument().addFeature("Remove")
+aSession.finishOperation()
+assert(aSession.moduleDocument().size("Parts") == 0)
+assert(aSession.activeDocument())
+#=========================================================================
+# Trying to duplicate/remove the root
+#=========================================================================
+aSession.startOperation()
+aSession.moduleDocument().addFeature("Duplicate")
+aSession.finishOperation()
+assert(aSession.activeDocument().id() == aSession.moduleDocument().id())
+assert(aSession.moduleDocument().size("Parts") == 0)
+aSession.startOperation()
+aSession.moduleDocument().addFeature("Remove")
+aSession.finishOperation()
+assert(aSession.activeDocument().id() == aSession.moduleDocument().id())
+assert(aSession.moduleDocument().size("Parts") == 0)
+#=========================================================================
+# End of test
+#=========================================================================