Salome HOME
Issue #803: Put all the python modules in the same python package newgeom
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBooleanCompSolids.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 __updated__ = "2014-12-16"
10
11 aSession = ModelAPI_Session.get()
12 # Create a part for extrusions & boolean
13 aSession.startOperation()
14 aPartFeature = aSession.moduleDocument().addFeature("Part")
15 aSession.finishOperation()
16 aPart = aSession.activeDocument()
17 #=========================================================================
18 # Create a sketch with circle to extrude
19 #=========================================================================
20 aSession.startOperation()
21 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
22 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
23 origin.setValue(0, 0, 0)
24 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
25 dirx.setValue(1, 0, 0)
26 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
27 norm.setValue(0, 0, 1)
28
29 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
30 aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
31 aCircleRadius = aSketchCircle.real("CircleRadius")
32 aCircleCentr.setValue(0, 0)
33 aCircleRadius.setValue(50)
34
35 aSketchLine = aCircleSketchFeature.addFeature("SketchLine")
36 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
37 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
38 aLineStartPoint.setValue(0, -50)
39 aLineEndPoint.setValue(0, 50)
40 aSession.finishOperation()
41 #=========================================================================
42 # Create a sketch with triangle to extrude
43 #=========================================================================
44 aSession.startOperation()
45 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
46 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
47 origin.setValue(0, 0, 0)
48 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
49 dirx.setValue(1, 0, 0)
50 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
51 norm.setValue(0, 0, 1)
52 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
53 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
54 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
55 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
56 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
57 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
58 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
59 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
60 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
61 aLineAStartPoint.setValue(25., 25.)
62 aLineAEndPoint.setValue(100., 25.)
63 aLineBStartPoint.setValue(100., 25.)
64 aLineBEndPoint.setValue(60., 75.)
65 aLineCStartPoint.setValue(60., 75.)
66 aLineCEndPoint.setValue(25., 25.)
67 aSession.finishOperation()
68 #=========================================================================
69 # Make extrusion on circle (cylinder) and triangle (prism)
70 #=========================================================================
71 # Build shape from sketcher results
72 aSession.startOperation()
73 extrudedObjects = []
74 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
75     # Build sketch faces
76     aSketchResult = eachSketchFeature.firstResult()
77     aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
78     origin = geomDataAPI_Point(eachSketchFeature.attribute("Origin")).pnt()
79     dirX = geomDataAPI_Dir(eachSketchFeature.attribute("DirX")).dir()
80     norm = geomDataAPI_Dir(eachSketchFeature.attribute("Norm")).dir()
81     aSketchFaces = ShapeList()
82     GeomAlgoAPI_SketchBuilder.createFaces(
83         origin, dirX, norm, aSketchEdges, aSketchFaces)
84     # Create extrusion on them
85     anExtrusionFt = aPart.addFeature("Extrusion")
86     anExtrusionFt.selectionList("base").append(
87         aSketchResult, None)
88     anExtrusionFt.string("CreationMethod").setValue("BySizes")
89     anExtrusionFt.real("from_size").setValue(0)
90     anExtrusionFt.real("to_size").setValue(50)
91     anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
92     anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
93     anExtrusionFt.execute()
94     extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
95 aSession.finishOperation()
96 #=========================================================================
97 # Create a pacman as boolean cut of the prism from the cylinder
98 #=========================================================================
99 aSession.startOperation()
100 aBooleanFt = aPart.addFeature("Boolean")
101 aBooleanFt.selectionList("main_objects").append(modelAPI_ResultCompSolid(extrudedObjects[0]).subResult(1), None)
102 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
103 aBooleanType = 0
104 aBooleanFt.integer("bool_type").setValue(aBooleanType)
105 aBooleanFt.execute()
106 aSession.finishOperation()
107
108 assert (len(aBooleanFt.results()) > 0)
109 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
110 assert (aBooleanResult is not None)
111 aSession.undo()
112
113 #=========================================================================
114 # Fuse
115 #=========================================================================
116 aSession.startOperation()
117 aBooleanFt = aPart.addFeature("Boolean")
118 aBooleanFt.selectionList("main_objects").append(modelAPI_ResultCompSolid(extrudedObjects[0]).subResult(1), None)
119 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
120 aBooleanType = 1
121 aBooleanFt.integer("bool_type").setValue(aBooleanType)
122 aBooleanFt.execute()
123 aSession.finishOperation()
124
125 assert (len(aBooleanFt.results()) > 0)
126 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
127 assert (aBooleanResult is not None)
128 #=========================================================================
129 # End of test
130 #=========================================================================
131
132 from salome.shaper import model
133 assert(model.checkPythonDump())