From b50f2e7197f799e272292692ab581b9e164848b2 Mon Sep 17 00:00:00 2001 From: sbh Date: Tue, 16 Dec 2014 13:12:28 +0300 Subject: [PATCH] Increasing test coverage of Model/ModelAPI --- src/FeaturesPlugin/CMakeLists.txt | 3 +- src/FeaturesPlugin/Test/TestGroup.py | 100 +++++++++++++++++ src/ModelAPI/CMakeLists.txt | 3 +- src/ModelAPI/ModelAPI.i | 1 + .../ModelAPI_AttributeSelectionList.h | 4 +- src/ModelAPI/Test/TestDocument.py | 105 ++++++++++++++++++ 6 files changed, 212 insertions(+), 4 deletions(-) create mode 100644 src/FeaturesPlugin/Test/TestGroup.py create mode 100644 src/ModelAPI/Test/TestDocument.py diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 1c14a498c..1d10d183c 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -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 index 000000000..b8eddc9a2 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestGroup.py @@ -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 +#========================================================================= diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 32aba38ab..9729cc4b9 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -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) diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 3017bac28..f601d1b11 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -114,6 +114,7 @@ %template(ObjectList) std::list >; %template(ResultList) std::list >; +%template(DocumentList) std::list >; template std::shared_ptr shared_ptr_cast(std::shared_ptr theObject); %template(modelAPI_CompositeFeature) shared_ptr_cast; diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h index 04be8a9a8..fec280f37 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelectionList.h +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -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& 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 index 000000000..fd9415488 --- /dev/null +++ b/src/ModelAPI/Test/TestDocument.py @@ -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 +#========================================================================= -- 2.39.2