Salome HOME
Issue #803: Put all the python modules in the same python package newgeom
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBooleanSmash.py
1 #=========================================================================
2 # Initialization of the test
3 #=========================================================================
4 from ModelAPI import *
5 from GeomDataAPI import *
6 from GeomAlgoAPI import *
7 from GeomAPI import *
8
9 aSession = ModelAPI_Session.get()
10 # Create a part for extrusions & boolean
11 aSession.startOperation()
12 aPartFeature = aSession.moduleDocument().addFeature("Part")
13 aSession.finishOperation()
14 aPart = aSession.activeDocument()
15 #=========================================================================
16 # Create a sketch with circle to extrude
17 #=========================================================================
18 aSession.startOperation()
19 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
20 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
21 origin.setValue(0, 0, 0)
22 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
23 dirx.setValue(1, 0, 0)
24 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
25 norm.setValue(0, 0, 1)
26 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
27 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
28 aCircleRadius = aSketchCircle.real("CircleRadius")
29 anCircleCentr.setValue(10., 10.)
30 aCircleRadius.setValue(50.)
31 aSession.finishOperation()
32 #=========================================================================
33 # Create a sketch with triangle to extrude
34 #=========================================================================
35 aSession.startOperation()
36 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
37 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
38 origin.setValue(0, 0, 0)
39 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
40 dirx.setValue(1, 0, 0)
41 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
42 norm.setValue(0, 0, 1)
43 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
44 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
45 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
46 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
47 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
48 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
49 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
50 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
51 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
52 aLineAStartPoint.setValue(25., 25.)
53 aLineAEndPoint.setValue(100., 25.)
54 aLineBStartPoint.setValue(100., 25.)
55 aLineBEndPoint.setValue(60., 75.)
56 aLineCStartPoint.setValue(60., 75.)
57 aLineCEndPoint.setValue(25., 25.)
58 aSession.finishOperation()
59 #=========================================================================
60 # Make extrusion on circle (cylinder) and triangle (prism)
61 #=========================================================================
62 # Build shape from sketcher results
63 aSession.startOperation()
64 extrudedObjects = []
65 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
66     # Build sketch faces
67     aSketchResult = eachSketchFeature.firstResult()
68     aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
69     origin = geomDataAPI_Point(eachSketchFeature.attribute("Origin")).pnt()
70     dirX = geomDataAPI_Dir(eachSketchFeature.attribute("DirX")).dir()
71     norm = geomDataAPI_Dir(eachSketchFeature.attribute("Norm")).dir()
72     aSketchFaces = ShapeList()
73     GeomAlgoAPI_SketchBuilder.createFaces(
74         origin, dirX, norm, aSketchEdges, aSketchFaces)
75     # Create extrusion on them
76     anExtrusionFt = aPart.addFeature("Extrusion")
77     anExtrusionFt.selectionList("base").append(
78         aSketchResult, aSketchFaces[0])
79     anExtrusionFt.string("CreationMethod").setValue("BySizes")
80     anExtrusionFt.real("from_size").setValue(0)
81     anExtrusionFt.real("to_size").setValue(50)
82     anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
83     anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
84     anExtrusionFt.execute()
85     extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
86 aSession.finishOperation()
87 #=========================================================================
88 # Smash prism into the cylinder
89 #=========================================================================
90 aSession.startOperation()
91 aBooleanFt = aPart.addFeature("Boolean")
92 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0], extrudedObjects[0].shape())
93 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], extrudedObjects[1].shape())
94 kBooleanTypeSmash = 3
95 aBooleanFt.integer("bool_type").setValue(kBooleanTypeSmash)
96 aBooleanFt.execute()
97 aSession.finishOperation()
98
99 assert (len(aBooleanFt.results()) > 0)
100 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
101 assert (aBooleanResult is not None)
102 #=========================================================================
103 # End of test
104 #=========================================================================
105
106 from salome.shaper import model
107 assert(model.checkPythonDump())