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