Salome HOME
Merge branch 'Results_Hierarchy'
[modules/shaper.git] / src / FeaturesPlugin / Test / TestCompositeFeaturesOnCompSolids.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 #=========================================================================
39 # Create a sketch with circle to extrude
40 #=========================================================================
41 aSession.startOperation()
42 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
43 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
44 origin.setValue(0, 0, 0)
45 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
46 dirx.setValue(1, 0, 0)
47 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
48 norm.setValue(0, 0, 1)
49
50 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
51 aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
52 aCircleRadius = aSketchCircle.real("circle_radius")
53 aCircleCentr.setValue(0, 0)
54 aCircleRadius.setValue(50)
55
56 aSketchLine = aCircleSketchFeature.addFeature("SketchLine")
57 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
58 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
59 aLineStartPoint.setValue(0, -50)
60 aLineEndPoint.setValue(0, 50)
61 aSession.finishOperation()
62
63 #=========================================================================
64 # Make extrusion on circle
65 #=========================================================================
66 # Build shape from sketcher results
67 aCircleSketchResult = aCircleSketchFeature.firstResult()
68 aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape()
69 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt()
70 dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir()
71 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir()
72 aCircleSketchFaces = ShapeList()
73 GeomAlgoAPI_SketchBuilder.createFaces(
74     origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces)
75 assert (len(aCircleSketchFaces) > 0)
76 assert (aCircleSketchFaces[0] is not None)
77 # Create extrusion
78 aSession.startOperation()
79 anExtrusionFt = aPart.addFeature("Extrusion")
80 assert (anExtrusionFt.getKind() == "Extrusion")
81 # selection type FACE=4
82 anExtrusionFt.selectionList("base").append(
83     aCircleSketchResult, None)
84 anExtrusionFt.string("CreationMethod").setValue("BySizes")
85 anExtrusionFt.real("to_size").setValue(50)
86 anExtrusionFt.real("from_size").setValue(0)
87 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
88 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
89 anExtrusionFt.execute()
90 aSession.finishOperation()
91 assert (anExtrusionFt.real("to_size").value() == 50.0)
92
93 # Check extrusion results
94 assert (len(anExtrusionFt.results()) > 0)
95 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
96 assert (anExtrusionResult is not None)
97
98 #=========================================================================
99 # Test extrusion cut between bounding planes
100 #=========================================================================
101 # Create from plane
102 aSession.startOperation()
103 aFromPlaneFeature = aPart.addFeature("Plane")
104 aFromPlaneFeature.string("creation_method").setValue("by_general_equation")
105 aFromPlaneFeature.string("by_other_plane_option").setValue("by_distance_from_other") # TODO: remove
106 aFromPlaneFeature.real("A").setValue(0.)
107 aFromPlaneFeature.real("B").setValue(0.)
108 aFromPlaneFeature.real("C").setValue(1.)
109 aFromPlaneFeature.real("D").setValue(-25.)
110 aSession.finishOperation()
111
112 # Create to plane
113 aSession.startOperation()
114 aToPlaneFeature = aPart.addFeature("Plane")
115 aToPlaneFeature.string("creation_method").setValue("by_general_equation")
116 aToPlaneFeature.string("by_other_plane_option").setValue("by_distance_from_other") # TODO: remove
117 aToPlaneFeature.real("A").setValue(0.)
118 aToPlaneFeature.real("B").setValue(0.)
119 aToPlaneFeature.real("C").setValue(1.)
120 aToPlaneFeature.real("D").setValue(-60.)
121 aSession.finishOperation()
122
123 #=========================================================================
124 # Make extrusion cut
125 #=========================================================================
126 aSession.startOperation()
127 anExtrusionCutFt = featureToCompositeFeature(aPart.addFeature("ExtrusionCut"))
128 assert (anExtrusionCutFt.getKind() == "ExtrusionCut")
129 # selection type FACE=4
130 aSession.startOperation()
131 aCircleSketchFeature = featureToCompositeFeature(anExtrusionCutFt.addFeature("Sketch"))
132 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
133 origin.setValue(0, 0, 50)
134 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
135 dirx.setValue(1, 0, 0)
136 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
137 norm.setValue(0, 0, 1)
138 aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
139 aSession.startOperation()
140 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
141 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
142 aCircleRadius = aSketchCircle.real("circle_radius")
143 anCircleCentr.setValue(0, 0)
144 aCircleRadius.setValue(10)
145 aSession.finishOperation()
146 aSession.finishOperation()
147 aSession.startOperation()
148 aCircleSketchFeature.execute() # execute for sketch should be called here, because it is not set as current feature, so it is disabled.
149 anExtrusionCutFt.selectionList("base").append(aCircleSketchFeature.firstResult(), None)
150 anExtrusionCutFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
151 anExtrusionCutFt.real("to_size").setValue(0)
152 anExtrusionCutFt.real("from_size").setValue(0)
153 aToResult = aToPlaneFeature.firstResult()
154 aToShape = modelAPI_ResultConstruction(aToResult).shape()
155 anExtrusionCutFt.selection("to_object").setValue(aToResult, aToShape)
156 anExtrusionCutFt.real("to_offset").setValue(0)
157 aFromResult = aFromPlaneFeature.firstResult()
158 aFromShape = modelAPI_ResultConstruction(aFromResult).shape()
159 anExtrusionCutFt.selection("from_object").setValue(aFromResult, aFromShape)
160 anExtrusionCutFt.real("from_offset").setValue(0)
161 anExtrusionCutFt.selectionList("main_objects").append(anExtrusionResult.subResult(1), None)
162 aSession.finishOperation()
163 aSession.finishOperation()
164
165 #=========================================================================
166 # Test results
167 #=========================================================================
168 aFactory = ModelAPI_Session.get().validators()
169 assert (aFactory.validate(anExtrusionCutFt))
170 assert (len(anExtrusionCutFt.results()) > 0)
171 aCurrentResult = modelAPI_ResultBody(anExtrusionCutFt.firstResult())
172 assert (aCurrentResult is not None)
173 aSession.undo()
174
175 #=========================================================================
176 # Create a sketch line to revol
177 #=========================================================================
178 aSession.startOperation()
179 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
180 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
181 origin.setValue(0, 0, 0)
182 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
183 dirx.setValue(1, 0, 0)
184 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
185 norm.setValue(0, 0, 1)
186
187 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
188 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
189 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
190 aLineStartPoint.setValue(-50., 50.)
191 aLineEndPoint.setValue(-50., -50.)
192 aSession.finishOperation()
193
194 # Build shape from sketcher results
195 aLineSketchResult = aLineSketchFeature.firstResult()
196 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
197 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
198 aLineEdge = aShapeExplorer.current()
199
200 #=========================================================================
201 # Make revolution fuse
202 #=========================================================================
203 aSession.startOperation()
204 anRevolutionFuseFt = featureToCompositeFeature(aPart.addFeature("RevolutionFuse"))
205 assert (anRevolutionFuseFt.getKind() == "RevolutionFuse")
206 # selection type FACE=4
207 aSession.startOperation()
208 aCircleSketchFeature = featureToCompositeFeature(anRevolutionFuseFt.addFeature("Sketch"))
209 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
210 origin.setValue(0, 0, 50)
211 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
212 dirx.setValue(1, 0, 0)
213 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
214 norm.setValue(0, 0, 1)
215 aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
216 aSession.startOperation()
217 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
218 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
219 aCircleRadius = aSketchCircle.real("circle_radius")
220 anCircleCentr.setValue(0, 0)
221 aCircleRadius.setValue(10)
222 aSession.finishOperation()
223 aSession.finishOperation()
224 aSession.startOperation()
225 aCircleSketchFeature.execute() # execute for sketch should be called here, because it is not set as current feature, so it is disabled.
226 anRevolutionFuseFt.selectionList("base").append(aCircleSketchFeature.firstResult(), None)
227 anRevolutionFuseFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
228 anRevolutionFuseFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
229 anRevolutionFuseFt.real("from_angle").setValue(0) #TODO: remove
230 anRevolutionFuseFt.real("to_angle").setValue(0) #TODO: remove
231 anRevolutionFuseFt.selection("to_object").setValue(aToResult, None)
232 anRevolutionFuseFt.real("to_offset").setValue(0)
233 anRevolutionFuseFt.selection("from_object").setValue(None, None)
234 anRevolutionFuseFt.real("from_offset").setValue(0)
235 anRevolutionFuseFt.selectionList("main_objects").append(anExtrusionResult.subResult(1), None)
236 aSession.finishOperation()
237 aSession.finishOperation()
238
239 #=========================================================================
240 # Test results
241 #=========================================================================
242 aFactory = ModelAPI_Session.get().validators()
243 assert (aFactory.validate(anRevolutionFuseFt))
244 assert (len(anRevolutionFuseFt.results()) > 0)
245 aCurrentResult = modelAPI_ResultBody(anRevolutionFuseFt.firstResult())
246 assert (aCurrentResult is not None)
247
248 from salome.shaper import model
249 assert(model.checkPythonDump())