From: dbv Date: Tue, 16 Feb 2016 09:33:17 +0000 (+0300) Subject: Python test for intersection X-Git-Tag: V_2.2.0~115 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=903d9a47a5daa27b2bd30194f369041505b1cca6;p=modules%2Fshaper.git Python test for intersection --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 31a4c1c4c..bdce2cafb 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -109,4 +109,5 @@ ADD_UNIT_TESTS(TestExtrusion.py TestBooleanCompSolids.py TestMultiBoolean.py TestSerialBoolean.py - TestGroup.py) + TestGroup.py + TestIntersection.py) diff --git a/src/FeaturesPlugin/Test/TestIntersection.py b/src/FeaturesPlugin/Test/TestIntersection.py new file mode 100644 index 000000000..04490b0f7 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestIntersection.py @@ -0,0 +1,148 @@ +#========================================================================= +# 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) +# Another way is: +# aPart = aSession.activeDocument() +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +#========================================================================= +# Create a sketch circle to extrude 1 +#========================================================================= +aSession.startOperation() +aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +# Create circle +aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(-10, 0) +aCircleRadius.setValue(50) +aSession.finishOperation() + +#========================================================================= +# Make extrusion on circle 1 +#========================================================================= +# Build shape from sketcher results +aCircleSketchResult = aCircleSketchFeature.firstResult() +aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape() +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt() +dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir() +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir() +aCircleSketchFaces = ShapeList() +GeomAlgoAPI_SketchBuilder.createFaces( + origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces) +assert (len(aCircleSketchFaces) > 0) +assert (aCircleSketchFaces[0] is not None) +# Create extrusion +aSession.startOperation() +anExtrusionFt = aPart.addFeature("Extrusion") +assert (anExtrusionFt.getKind() == "Extrusion") +# selection type FACE=4 +anExtrusionFt.selectionList("base").append( + aCircleSketchResult, aCircleSketchFaces[0]) +anExtrusionFt.string("CreationMethod").setValue("BySizes") +anExtrusionFt.real("to_size").setValue(50) +anExtrusionFt.real("from_size").setValue(0) +anExtrusionFt.real("to_offset").setValue(0) #TODO: remove +anExtrusionFt.real("from_offset").setValue(0) #TODO: remove +anExtrusionFt.execute() +aSession.finishOperation() +assert (anExtrusionFt.real("to_size").value() == 50) + +# Check extrusion results +assert (len(anExtrusionFt.results()) > 0) +anExtrusionResult1 = modelAPI_ResultBody(anExtrusionFt.firstResult()) +assert (anExtrusionResult1 is not None) + +#========================================================================= +# Create a sketch circle to extrude 2 +#========================================================================= +aSession.startOperation() +aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +# Create circle +aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(10, 0) +aCircleRadius.setValue(50) +aSession.finishOperation() + +#========================================================================= +# Make extrusion on circle 2 +#========================================================================= +# Build shape from sketcher results +aCircleSketchResult = aCircleSketchFeature.firstResult() +aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape() +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt() +dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir() +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir() +aCircleSketchFaces = ShapeList() +GeomAlgoAPI_SketchBuilder.createFaces( + origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces) +assert (len(aCircleSketchFaces) > 0) +assert (aCircleSketchFaces[0] is not None) +# Create extrusion +aSession.startOperation() +anExtrusionFt = aPart.addFeature("Extrusion") +assert (anExtrusionFt.getKind() == "Extrusion") +# selection type FACE=4 +anExtrusionFt.selectionList("base").append( + aCircleSketchResult, aCircleSketchFaces[0]) +anExtrusionFt.string("CreationMethod").setValue("BySizes") +anExtrusionFt.real("to_size").setValue(50) +anExtrusionFt.real("from_size").setValue(0) +anExtrusionFt.real("to_offset").setValue(0) #TODO: remove +anExtrusionFt.real("from_offset").setValue(0) #TODO: remove +anExtrusionFt.execute() +aSession.finishOperation() +assert (anExtrusionFt.real("to_size").value() == 50) + +# Check extrusion results +assert (len(anExtrusionFt.results()) > 0) +anExtrusionResult2 = modelAPI_ResultBody(anExtrusionFt.firstResult()) +assert (anExtrusionResult2 is not None) + +#========================================================================= +# Create an intersection +#========================================================================= +aSession.startOperation() +anIntersectionFt = aPart.addFeature("Intersection") +assert (anIntersectionFt.getKind() == "Intersection") +anIntersectionFt.selectionList("main_objects").append(anExtrusionResult1, None) +anIntersectionFt.selectionList("tool_objects").append(anExtrusionResult2, None) +anIntersectionFt.execute() +aSession.finishOperation() + +#========================================================================= +# Test results +#========================================================================= +aFactory = ModelAPI_Session.get().validators() +assert (aFactory.validate(anIntersectionFt)) +assert (len(anIntersectionFt.results()) > 0) +anItersectionResult = modelAPI_ResultBody(anIntersectionFt.firstResult()) +assert (anItersectionResult is not None)