From 51d557cd9aba1ec53569bb55c6b9a956e48182e1 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 21 Jun 2016 15:16:25 +0300 Subject: [PATCH] Issue #1366: Added test cases for "Union" and "Remove Sub-Shapes" features. --- src/FeaturesPlugin/CMakeLists.txt | 4 +- .../Test/TestRemoveSubShapes.py | 74 +++++++++++++++++++ .../remove_subshapes_widget.xml | 2 +- 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/FeaturesPlugin/Test/TestRemoveSubShapes.py diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 2ffaf860d..70f4fc632 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -126,4 +126,6 @@ ADD_UNIT_TESTS(TestExtrusion.py TestSerialBoolean.py TestGroup.py TestIntersection.py - TestPipe.py) + TestPipe.py + TestUnion.py + TestRemoveSubShapes.py) diff --git a/src/FeaturesPlugin/Test/TestRemoveSubShapes.py b/src/FeaturesPlugin/Test/TestRemoveSubShapes.py new file mode 100644 index 000000000..6685760da --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRemoveSubShapes.py @@ -0,0 +1,74 @@ +#========================================================================= +# Initialization of the test +#========================================================================= +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * +from GeomAPI import * +import math + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() + +# Create a part for extrusion +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +assert (len(aPartFeature.results()) == 1) + +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +#========================================================================= +# Create a sketch to extrude +#========================================================================= +aSession.startOperation() +aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) + +# Create circles +aSketchCircle = aSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(-25, 0) +aCircleRadius.setValue(50) +aSketchCircle = aSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(25, 0) +aCircleRadius.setValue(50) +aSession.finishOperation() +aSketchResult = aSketchFeature.firstResult() + +#========================================================================= +# Make extrusion on sketch +#========================================================================= +# Create extrusion +aSession.startOperation() +anExtrusionFeature = aPart.addFeature("Extrusion") +anExtrusionFeature.selectionList("base").append(aSketchResult, None) +anExtrusionFeature.string("CreationMethod").setValue("BySizes") +anExtrusionFeature.real("to_size").setValue(50) +anExtrusionFeature.real("from_size").setValue(0) +anExtrusionFeature.real("to_offset").setValue(0) #TODO: remove +anExtrusionFeature.real("from_offset").setValue(0) #TODO: remove +anExtrusionFeature.execute() +aSession.finishOperation() +anExtrusionResult = modelAPI_ResultCompSolid(modelAPI_ResultBody(anExtrusionFeature.firstResult())) + +#========================================================================= +# Remove sub-shapes +#========================================================================= +aSession.startOperation() +aRemoveSubShapesFeature = aPart.addFeature("Remove_SubShapes") +aRemoveSubShapesFeature.selection("base_shape").setValue(anExtrusionResult, None) +aRemoveSubShapesFeature.selectionList("subshapes").removeLast(); +aSession.finishOperation() +assert (len(aRemoveSubShapesFeature.results()) > 0) +anUnionResult = modelAPI_ResultCompSolid(modelAPI_ResultBody(aRemoveSubShapesFeature.firstResult())) +assert (anUnionResult.numberOfSubs() == 2) diff --git a/src/FeaturesPlugin/remove_subshapes_widget.xml b/src/FeaturesPlugin/remove_subshapes_widget.xml index 9300b9a2f..93d3ac973 100644 --- a/src/FeaturesPlugin/remove_subshapes_widget.xml +++ b/src/FeaturesPlugin/remove_subshapes_widget.xml @@ -11,7 +11,7 @@ -- 2.39.2