Salome HOME
Merge commit 'refs/tags/V9_2_0^{}'
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBooleanCompSolids.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 #=========================================================================
22 # Initialization of the test
23 #=========================================================================
24 from ModelAPI import *
25 from GeomDataAPI import *
26 from GeomAlgoAPI import *
27 from GeomAPI import *
28
29 __updated__ = "2014-12-16"
30
31 aSession = ModelAPI_Session.get()
32 # Create a part for extrusions & boolean
33 aSession.startOperation()
34 aPartFeature = aSession.moduleDocument().addFeature("Part")
35 aSession.finishOperation()
36 aPart = aSession.activeDocument()
37 #=========================================================================
38 # Create a sketch with circle to extrude
39 #=========================================================================
40 aSession.startOperation()
41 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
42 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
43 origin.setValue(0, 0, 0)
44 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
45 dirx.setValue(1, 0, 0)
46 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
47 norm.setValue(0, 0, 1)
48
49 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
50 aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
51 aCircleRadius = aSketchCircle.real("circle_radius")
52 aCircleCentr.setValue(0, 0)
53 aCircleRadius.setValue(50)
54
55 aSketchLine = aCircleSketchFeature.addFeature("SketchLine")
56 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
57 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
58 aLineStartPoint.setValue(0, -50)
59 aLineEndPoint.setValue(0, 50)
60 aSession.finishOperation()
61 #=========================================================================
62 # Create a sketch with triangle to extrude
63 #=========================================================================
64 aSession.startOperation()
65 aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
66 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
67 origin.setValue(0, 0, 0)
68 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
69 dirx.setValue(1, 0, 0)
70 norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
71 norm.setValue(0, 0, 1)
72 aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
73 aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
74 aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
75 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
76 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
77 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
78 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
79 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
80 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
81 aLineAStartPoint.setValue(25., 25.)
82 aLineAEndPoint.setValue(100., 25.)
83 aLineBStartPoint.setValue(100., 25.)
84 aLineBEndPoint.setValue(60., 75.)
85 aLineCStartPoint.setValue(60., 75.)
86 aLineCEndPoint.setValue(25., 25.)
87 aSession.finishOperation()
88 #=========================================================================
89 # Make extrusion on circle (cylinder) and triangle (prism)
90 #=========================================================================
91 # Build shape from sketcher results
92 aSession.startOperation()
93 extrudedObjects = []
94 for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
95     # Build sketch faces
96     aSketchResult = modelAPI_ResultConstruction(eachSketchFeature.firstResult())
97     # Create extrusion on them
98     anExtrusionFt = aPart.addFeature("Extrusion")
99     anExtrusionFt.selectionList("base").append(
100         aSketchResult, None)
101     anExtrusionFt.string("CreationMethod").setValue("BySizes")
102     anExtrusionFt.real("from_size").setValue(0)
103     anExtrusionFt.real("to_size").setValue(50)
104     anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
105     anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
106     anExtrusionFt.execute()
107     extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
108 aSession.finishOperation()
109 #=========================================================================
110 # Create a pacman as boolean cut of the prism from the cylinder
111 #=========================================================================
112 aSession.startOperation()
113 aBooleanFt = aPart.addFeature("Cut")
114 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0].subResult(1), None)
115 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
116 aBooleanFt.execute()
117 aSession.finishOperation()
118
119 assert (len(aBooleanFt.results()) > 0)
120 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
121 assert (aBooleanResult is not None)
122 aSession.undo()
123
124 #=========================================================================
125 # Fuse
126 #=========================================================================
127 aSession.startOperation()
128 aBooleanFt = aPart.addFeature("Fuse")
129 aBooleanFt.string("creation_method").setValue("advanced")
130 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0].subResult(1), None)
131 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
132 aBooleanFt.boolean("remove_intersection_edges").setValue(False)
133 aBooleanFt.execute()
134 aSession.finishOperation()
135
136 assert (len(aBooleanFt.results()) > 0)
137 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
138 assert (aBooleanResult is not None)
139 #=========================================================================
140 # End of test
141 #=========================================================================
142
143 from salome.shaper import model
144 assert(model.checkPythonDump())