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