Salome HOME
Make tests working on new results structure and selection of feature as argument
[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 = eachSketchFeature.firstResult()
97     aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
98     origin = geomDataAPI_Point(eachSketchFeature.attribute("Origin")).pnt()
99     dirX = geomDataAPI_Dir(eachSketchFeature.attribute("DirX")).dir()
100     norm = geomDataAPI_Dir(eachSketchFeature.attribute("Norm")).dir()
101     aSketchFaces = ShapeList()
102     GeomAlgoAPI_SketchBuilder.createFaces(
103         origin, dirX, norm, aSketchEdges, aSketchFaces)
104     # Create extrusion on them
105     anExtrusionFt = aPart.addFeature("Extrusion")
106     anExtrusionFt.selectionList("base").append(
107         aSketchResult, None)
108     anExtrusionFt.string("CreationMethod").setValue("BySizes")
109     anExtrusionFt.real("from_size").setValue(0)
110     anExtrusionFt.real("to_size").setValue(50)
111     anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
112     anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
113     anExtrusionFt.execute()
114     extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
115 aSession.finishOperation()
116 #=========================================================================
117 # Create a pacman as boolean cut of the prism from the cylinder
118 #=========================================================================
119 aSession.startOperation()
120 aBooleanFt = aPart.addFeature("Cut")
121 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0].subResult(1), None)
122 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
123 aBooleanFt.execute()
124 aSession.finishOperation()
125
126 assert (len(aBooleanFt.results()) > 0)
127 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
128 assert (aBooleanResult is not None)
129 aSession.undo()
130
131 #=========================================================================
132 # Fuse
133 #=========================================================================
134 aSession.startOperation()
135 aBooleanFt = aPart.addFeature("Fuse")
136 aBooleanFt.selectionList("main_objects").append(extrudedObjects[0].subResult(1), None)
137 aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
138 aBooleanFt.execute()
139 aSession.finishOperation()
140
141 assert (len(aBooleanFt.results()) > 0)
142 aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
143 assert (aBooleanResult is not None)
144 #=========================================================================
145 # End of test
146 #=========================================================================
147
148 from salome.shaper import model
149 assert(model.checkPythonDump())