Salome HOME
Increasing test coverage of Model/ModelAPI
authorsbh <sergey.belash@opencascade.com>
Tue, 16 Dec 2014 10:12:28 +0000 (13:12 +0300)
committersbh <sergey.belash@opencascade.com>
Tue, 16 Dec 2014 10:12:28 +0000 (13:12 +0300)
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/Test/TestGroup.py [new file with mode: 0644]
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_AttributeSelectionList.h
src/ModelAPI/Test/TestDocument.py [new file with mode: 0644]

index 1c14a498c1dc6e6ecaa3a80afda336746342f8c4..1d10d183c22cf2b3db37c288987293cb79649d2f 100644 (file)
@@ -50,4 +50,5 @@ INSTALL(TARGETS FeaturesPlugin DESTINATION plugins)
 INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
 
 ADD_UNIT_TESTS(TestExtrusion.py
-               TestBoolean.py)
+               TestBoolean.py
+               TestGroup.py)
diff --git a/src/FeaturesPlugin/Test/TestGroup.py b/src/FeaturesPlugin/Test/TestGroup.py
new file mode 100644 (file)
index 0000000..b8eddc9
--- /dev/null
@@ -0,0 +1,100 @@
+"""
+      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
+#=========================================================================
index 32aba38ab450af3e4b6787ad79ed2c38d85c897c..9729cc4b9f7dfc171a0832fe0c82ca79bb4dd7e0 100644 (file)
@@ -93,4 +93,5 @@ INSTALL(TARGETS ModelAPI DESTINATION bin)
 INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig)
 
 ADD_UNIT_TESTS(TestConstants.py
-               TestUndoRedo.py)
+               TestUndoRedo.py
+               TestDocument.py)
index 3017bac28f2df63cc839566b92a669091918014b..f601d1b11ea2317844500fba0bdee5e2de0eeba7 100644 (file)
 
 %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>;
index 04be8a9a8d2a0b69322d75e9170b1bb3d7a63787..fec280f37ece835150537c58ec98a6e44d01ffd7 100644 (file)
@@ -20,8 +20,8 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
 {
  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;
diff --git a/src/ModelAPI/Test/TestDocument.py b/src/ModelAPI/Test/TestDocument.py
new file mode 100644 (file)
index 0000000..fd94154
--- /dev/null
@@ -0,0 +1,105 @@
+"""
+      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
+#=========================================================================