Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAPI / Test / TestCone.py
1 # Copyright (C) 2018-2023  CEA, EDF
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 from GeomAPI import *
21 from SketchAPI import *
22
23 from salome.shaper import model
24
25 import math
26
27 TOLERANCE = 1.e-7
28
29 def assertCircle(theEdge, theCenter, theRadius):
30     assert(theEdge.isCircle())
31     aCircle = theEdge.circle()
32     assert(aCircle.center().distance(theCenter) < TOLERANCE), "({}, {}, {}) != expected ({}, {}, {})".format(aCircle.center().x(), aCircle.center().y(), aCircle.center().z(), theCenter.x(), theCenter.y(), theCenter.z())
33     assert(math.fabs(aCircle.radius() - theRadius) < TOLERANCE), "Radius {} != {}".format(aCircle.radius(), theRadius)
34
35 def checkCircleEdge(theDocument, theEdgeName, theCenter, theRadius):
36     anEdge = model.addEdge(theDocument, [model.selection("EDGE", theEdgeName)])
37     aShape = anEdge.result().resultSubShapePair()[0].shape()
38     assert(aShape.isEdge())
39     assert(aShape.edge().isClosed())
40     assertCircle(aShape.edge(), theCenter, theRadius)
41     theDocument.removeFeature(anEdge.feature())
42
43 def checkCircleFace(theDocument, theFaceName, theCenter, theRadius):
44     aFaceFeature = model.addFace(theDocument, [model.selection("FACE", theFaceName)])
45     aShape = aFaceFeature.result().resultSubShapePair()[0].shape()
46     assert(aShape.isFace())
47     aFace = aShape.face();
48     aSubs = aFace.subShapes(GeomAPI.GeomAPI_Shape.EDGE)
49     assert(aSubs.size() == 1)
50     assertCircle(aSubs[0].edge(), theCenter, theRadius)
51     theDocument.removeFeature(aFaceFeature.feature())
52
53 def assertEllipse(theEdge, theFirstFocus, theSecondFocus, theMajorRadius, theMinorRadius, theNormal = None):
54     assert(theEdge.isEllipse())
55     anEllipse = theEdge.ellipse()
56     assert(anEllipse.firstFocus().distance(theFirstFocus) < TOLERANCE), "({}, {}, {}) != expected ({}, {}, {})".format(anEllipse.firstFocus().x(), anEllipse.firstFocus().y(), anEllipse.firstFocus().z(), theFirstFocus.x(), theFirstFocus.y(), theFirstFocus.z())
57     assert(anEllipse.secondFocus().distance(theSecondFocus) < TOLERANCE), "({}, {}, {}) != expected ({}, {}, {})".format(anEllipse.secondFocus().x(), anEllipse.secondFocus().y(), anEllipse.secondFocus().z(), theSecondFocus.x(), theSecondFocus.y(), theSecondFocus.z())
58     assert(math.fabs(anEllipse.majorRadius() - theMajorRadius) < TOLERANCE), "Major radius {} != {}".format(anEllipse.majorRadius(), theMajorRadius)
59     assert(math.fabs(anEllipse.minorRadius() - theMinorRadius) < TOLERANCE), "Minor radius {} != {}".format(anEllipse.minorRadius(), theMinorRadius)
60
61     center = GeomAPI.GeomAPI_Pnt((theFirstFocus.x() + theSecondFocus.x()) * 0.5, (theFirstFocus.y() + theSecondFocus.y()) * 0.5, (theFirstFocus.z() + theSecondFocus.z()) * 0.5)
62     assert(anEllipse.center().distance(center) < TOLERANCE), "({}, {}, {}) != expected ({}, {}, {})".format(anEllipse.center().x(), anEllipse.center().y(), anEllipse.center().z(), center.x(), center.y(), center.z())
63
64     if theNormal is not None:
65         assert(math.fabs(anEllipse.normal().dot(theNormal) - 1.) < TOLERANCE), "Normal ({}, {}, {}) != ({}, {}, {})".format(anEllipse.normal().x(), anEllipse.normal().y(), anEllipse.normal().z(), theNormal.x(), theNormal.y(), theNormal.z())
66
67 def checkEllipseEdge(theDocument, theEdgeName, theFirstFocus, theSecondFocus, theMajorRadius, theMinorRadius, theNormal):
68     anEdge = model.addEdge(theDocument, [model.selection("EDGE", theEdgeName)])
69     aShape = anEdge.result().resultSubShapePair()[0].shape()
70     assert(aShape.isEdge())
71     assertEllipse(aShape.edge(), theFirstFocus, theSecondFocus, theMajorRadius, theMinorRadius, theNormal)
72     theDocument.removeFeature(anEdge.feature())
73
74 def checkEllipseFace(theDocument, theFaceName, theFirstFocus, theSecondFocus, theMajorRadius, theMinorRadius):
75     aFaceFeature = model.addFace(theDocument, [model.selection("FACE", theFaceName)])
76     aShape = aFaceFeature.result().resultSubShapePair()[0].shape()
77     assert(aShape.isFace())
78     aFace = aShape.face();
79     aSubs = aFace.subShapes(GeomAPI.GeomAPI_Shape.EDGE)
80     assert(aSubs.size() == 1)
81     assertEllipse(aSubs[0].edge(), theFirstFocus, theSecondFocus, theMajorRadius, theMinorRadius)
82     theDocument.removeFeature(aFaceFeature.feature())
83
84 def assertCone(theCone, theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight):
85     assert(theCone is not None)
86     assert(theCone.isSemiInfinite() == False)
87     assert(theCone.isInfinite() == False)
88     anApex = theCone.apex()
89     anAxis = theCone.axis()
90     assert(anApex.distance(theApex) < TOLERANCE), "({}, {}, {}) != expected ({}, {}, {})".format(anApex.x(), anApex.y(), anApex.z(), theApex.x(), theApex.y(), theApex.z())
91     assert(anAxis.isParallel(theAxis, TOLERANCE)), "dir({}, {}, {}) is not parallel to dir({}, {}, {})".format(anAxis.x(), anAxis.y(), anAxis.z(), theAxis.x(), theAxis.y(), theAxis.z())
92     assert(math.fabs(theCone.semiAngle() - theSemiAngle) < TOLERANCE), "SemiAngle {} != {}".format(theCone.semiAngle(), theSemiAngle)
93     assert(math.fabs(theCone.radius1() - theRadius1) < TOLERANCE), "Radius1 {} != {}".format(theCone.radius1(), theRadius1)
94     assert(math.fabs(theCone.radius2() - theRadius2) < TOLERANCE), "Radius2 {} != {}".format(theCone.radius2(), theRadius2)
95     assert(math.fabs(theCone.height() - theHeight) < TOLERANCE), "Height {} != {}".format(theCone.height(), theHeight)
96
97 def checkConeFace(theDocument, theFaceName, theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight):
98     # check conical face
99     aFace = model.addFace(theDocument, [model.selection("FACE", theFaceName)])
100     aShape = aFace.result().resultSubShapePair()[0].shape()
101     assert(aShape.isFace())
102     assertCone(aShape.face().getCone(), theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight)
103     theDocument.removeFeature(aFace.feature())
104
105 def checkConeShell(theDocument, theFaceNames, theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight):
106     # check conical shell
107     aSelection = []
108     for name in theFaceNames:
109         aSelection.append(model.selection("FACE", name))
110     aShell = model.addShell(theDocument, aSelection)
111     aShape = aShell.result().resultSubShapePair()[0].shape()
112     assert(aShape.isShell())
113     assertCone(aShape.shell().getCone(), theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight)
114     theDocument.removeFeature(aShell.feature())
115
116 def checkConeSolid(theDocument, theFaceNames, theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight):
117     # check cone
118     aSelection = []
119     for name in theFaceNames:
120         aSelection.append(model.selection("FACE", name))
121     aSolid = model.addSolid(theDocument, aSelection)
122     aShape = aSolid.result().resultSubShapePair()[0].shape()
123     assert(aShape.isSolid())
124     assertCone(aShape.solid().getCone(), theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight)
125     theDocument.removeFeature(aSolid.feature())
126
127 def checkConeAll(theDocument, theFeature, theFaceName, theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight):
128     # check solid
129     aShape = theFeature.result().resultSubShapePair()[0].shape()
130     assert(aShape.isSolid())
131     assertCone(aShape.solid().getCone(), theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight)
132
133     checkConeShell(theDocument, [theFaceName], theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight)
134     checkConeFace(theDocument, theFaceName, theApex, theAxis, theSemiAngle, theRadius1, theRadius2, theHeight)
135
136 def checkNonCone(theFeature):
137     aShape = theFeature.result().resultSubShapePair()[0].shape()
138     assert(aShape.isSolid())
139     assert(aShape.solid().getCone() is None)
140
141 def checkNonConeShell(theFeature):
142     aShape = theFeature.result().resultSubShapePair()[0].shape()
143     assert(aShape.isShell())
144     assert(aShape.shell().getCone() is None)
145
146 def checkSegment(theDocument, theEdgeName, theStartPoint, theEndPoint):
147     anEdgeFeature = model.addEdge(theDocument, [model.selection("EDGE", theEdgeName)])
148     aShape = anEdgeFeature.result().resultSubShapePair()[0].shape()
149     assert(aShape.isEdge())
150     anEdge = aShape.edge()
151     assert(anEdge.isLine())
152     assert(anEdge.firstPoint().distance(theStartPoint) < TOLERANCE)
153     assert(anEdge.lastPoint().distance(theEndPoint) < TOLERANCE)
154     theDocument.removeFeature(anEdgeFeature.feature())
155
156 def checkVertex(theDocument, theVertexName, theCoordinates):
157     aVertex = model.addVertex(theDocument, [model.selection("VERTEX", theVertexName)])
158     aShape = aVertex.result().resultSubShapePair()[0].shape()
159     assert(aShape.isVertex())
160     assert(aShape.vertex().point().distance(theCoordinates) < TOLERANCE)
161     theDocument.removeFeature(aVertex.feature())
162
163 def semiAngle(theRadius1, theRadius2, theHeight):
164     return math.atan(math.fabs(theRadius1 - theRadius2) / theHeight)
165
166
167 model.begin()
168 partSet = model.moduleDocument()
169 Part_1 = model.addPart(partSet)
170 Part_1_doc = Part_1.document()
171 ParamR1 = model.addParameter(Part_1_doc, "R1", "50")
172 ParamR2 = model.addParameter(Part_1_doc, "R2", "5")
173 ParamH = model.addParameter(Part_1_doc, "H", "70")
174 ParamShift = model.addParameter(Part_1_doc, "Shift", "5")
175 ParamAngle = model.addParameter(Part_1_doc, "Angle", "60")
176 Cone_1 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), "R1", "R2", "H")
177 model.do()
178
179 # Test 1. Check cone
180 aSemiAngle = semiAngle(ParamR1.value(), ParamR2.value(), ParamH.value())
181 anApex = GeomAPI.GeomAPI_Pnt(0, 0, ParamR1.value() / math.tan(aSemiAngle))
182 anAxis = GeomAPI.GeomAPI_Dir(0, 0, 1)
183 checkConeAll(Part_1_doc, Cone_1, "Cone_1_1/Face_1", anApex, anAxis, aSemiAngle, ParamR2.value(), ParamR1.value(), ParamH.value())
184 checkCircleFace(Part_1_doc, "Cone_1_1/Face_2", GeomAPI.GeomAPI_Pnt(0, 0, ParamH.value()), ParamR2.value())
185 checkCircleEdge(Part_1_doc, "[Cone_1_1/Face_1][Cone_1_1/Face_2]", GeomAPI.GeomAPI_Pnt(0, 0, ParamH.value()), ParamR2.value())
186 checkCircleFace(Part_1_doc, "Cone_1_1/Face_3", GeomAPI.GeomAPI_Pnt(0, 0, 0), ParamR1.value())
187 checkCircleEdge(Part_1_doc, "[Cone_1_1/Face_1][Cone_1_1/Face_3]", GeomAPI.GeomAPI_Pnt(0, 0, 0), ParamR1.value())
188 checkSegment(Part_1_doc, "[Cone_1_1/Face_1][weak_name_3]", GeomAPI.GeomAPI_Pnt(ParamR1.value(), 0, 0), GeomAPI.GeomAPI_Pnt(ParamR2.value(), 0, ParamH.value()))
189
190 # Test 2. Update cone radii
191 ParamR1.setValue(0)
192 model.do()
193 aSemiAngle = semiAngle(ParamR1.value(), ParamR2.value(), ParamH.value())
194 anApex.setZ(0)
195 checkConeAll(Part_1_doc, Cone_1, "Cone_1_1/Face_1", anApex, anAxis, aSemiAngle, ParamR1.value(), ParamR2.value(), ParamH.value())
196 checkCircleFace(Part_1_doc, "Cone_1_1/Face_2", GeomAPI.GeomAPI_Pnt(0, 0, ParamH.value()), ParamR2.value())
197 checkCircleEdge(Part_1_doc, "[Cone_1_1/Face_1][Cone_1_1/Face_2]", GeomAPI.GeomAPI_Pnt(0, 0, ParamH.value()), ParamR2.value())
198 checkSegment(Part_1_doc, "[Cone_1_1/Face_1][weak_name_3]", GeomAPI.GeomAPI_Pnt(0, 0, 0), GeomAPI.GeomAPI_Pnt(ParamR2.value(), 0, ParamH.value()))
199 checkVertex(Part_1_doc, "Cone_1_1/Vertex_2", GeomAPI.GeomAPI_Pnt(0, 0, 0))
200
201 ParamR2.setValue(50)
202 ParamR1.setValue(10)
203 model.do()
204 aSemiAngle = semiAngle(ParamR1.value(), ParamR2.value(), ParamH.value())
205 anApex.setZ(-ParamR1.value() / math.tan(aSemiAngle))
206 checkConeAll(Part_1_doc, Cone_1, "Cone_1_1/Face_1", anApex, anAxis, aSemiAngle, ParamR1.value(), ParamR2.value(), ParamH.value())
207 checkCircleFace(Part_1_doc, "Cone_1_1/Face_2", GeomAPI.GeomAPI_Pnt(0, 0, ParamH.value()), ParamR2.value())
208 checkCircleEdge(Part_1_doc, "[Cone_1_1/Face_1][Cone_1_1/Face_2]", GeomAPI.GeomAPI_Pnt(0, 0, ParamH.value()), ParamR2.value())
209 checkCircleFace(Part_1_doc, "Cone_1_1/Face_3", GeomAPI.GeomAPI_Pnt(0, 0, 0), ParamR1.value())
210 checkCircleEdge(Part_1_doc, "[Cone_1_1/Face_1][Cone_1_1/Face_3]", GeomAPI.GeomAPI_Pnt(0, 0, 0), ParamR1.value())
211 checkSegment(Part_1_doc, "[Cone_1_1/Face_1][weak_name_3]", GeomAPI.GeomAPI_Pnt(ParamR1.value(), 0, 0), GeomAPI.GeomAPI_Pnt(ParamR2.value(), 0, ParamH.value()))
212
213 # Test 3. Translate cone
214 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cone_1_1")], model.selection("EDGE", "PartSet/OX"), "Shift")
215 anApex.setX(anApex.x() + ParamShift.value())
216 checkConeAll(Part_1_doc, Translation_1, "Translation_1_1/MF:Translated&Cone_1_1/Face_1", anApex, anAxis, aSemiAngle, ParamR1.value(), ParamR2.value(), ParamH.value())
217 checkCircleFace(Part_1_doc, "Translation_1_1/MF:Translated&Cone_1_1/Face_2", GeomAPI.GeomAPI_Pnt(ParamShift.value(), 0, ParamH.value()), ParamR2.value())
218 checkCircleEdge(Part_1_doc, "[Translation_1_1/MF:Translated&Cone_1_1/Face_1][Translation_1_1/MF:Translated&Cone_1_1/Face_2]", GeomAPI.GeomAPI_Pnt(ParamShift.value(), 0, ParamH.value()), ParamR2.value())
219 checkCircleFace(Part_1_doc, "Translation_1_1/MF:Translated&Cone_1_1/Face_3", GeomAPI.GeomAPI_Pnt(ParamShift.value(), 0, 0), ParamR1.value())
220 checkCircleEdge(Part_1_doc, "[Translation_1_1/MF:Translated&Cone_1_1/Face_1][Translation_1_1/MF:Translated&Cone_1_1/Face_3]", GeomAPI.GeomAPI_Pnt(ParamShift.value(), 0, 0), ParamR1.value())
221 checkSegment(Part_1_doc, "[Translation_1_1/MF:Translated&Cone_1_1/Face_1][weak_name_3]", GeomAPI.GeomAPI_Pnt(ParamR1.value() + ParamShift.value(), 0, 0), GeomAPI.GeomAPI_Pnt(ParamR2.value() + ParamShift.value(), 0, ParamH.value()))
222
223 # Test 4. Rotate cone
224 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], model.selection("EDGE", "PartSet/OY"), "Angle")
225 anAngle = ParamAngle.value() * math.pi / 180.0
226 anAxis = GeomAPI.GeomAPI_Dir(math.sin(anAngle), 0, math.cos(anAngle))
227 x, z = anApex.x(), anApex.z()
228 anApex.setX(x * math.cos(anAngle) + z * math.sin(anAngle))
229 anApex.setZ(-x * math.sin(anAngle) + z * math.cos(anAngle))
230 checkConeAll(Part_1_doc, Rotation_1, "Rotation_1_1/MF:Rotated&Cone_1_1/Face_1", anApex, anAxis, aSemiAngle, ParamR1.value(), ParamR2.value(), ParamH.value())
231 aCenter = GeomAPI.GeomAPI_Pnt(ParamShift.value() * math.cos(anAngle) + ParamH.value() * math.sin(anAngle), 0, -ParamShift.value() * math.sin(anAngle) + ParamH.value() * math.cos(anAngle))
232 checkCircleFace(Part_1_doc, "Rotation_1_1/MF:Rotated&Cone_1_1/Face_2", aCenter, ParamR2.value())
233 checkCircleEdge(Part_1_doc, "[Rotation_1_1/MF:Rotated&Cone_1_1/Face_1][Rotation_1_1/MF:Rotated&Cone_1_1/Face_2]", aCenter, ParamR2.value())
234 aCenter = GeomAPI.GeomAPI_Pnt(ParamShift.value() * math.cos(anAngle), 0, -ParamShift.value() * math.sin(anAngle))
235 checkCircleFace(Part_1_doc, "Rotation_1_1/MF:Rotated&Cone_1_1/Face_3", aCenter, ParamR1.value())
236 checkCircleEdge(Part_1_doc, "[Rotation_1_1/MF:Rotated&Cone_1_1/Face_1][Rotation_1_1/MF:Rotated&Cone_1_1/Face_3]", aCenter, ParamR1.value())
237
238 # Test 5. Split cone by plane and check conical shell and elliptic face
239 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/YOZ"), 20, False)
240 Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Rotation_1_1"), model.selection("FACE", "Plane_1")])
241 checkConeShell(Part_1_doc, ["Partition_1_1_1/Modified_Face&Cone_1_1/Face_1", "Partition_1_1_2/Modified_Face&Cone_1_1/Face_1"], anApex, anAxis, aSemiAngle, ParamR1.value(), ParamR2.value(), ParamH.value())
242
243 aFirstFocus = GeomAPI.GeomAPI_Pnt(20, 0, 31.062397266842858)
244 aSecondFocus = GeomAPI.GeomAPI_Pnt(20, 0, -1.0935246846933797)
245 aMajorRadius = 27.91915871311068
246 aMinorRadius = 22.824955511666207
247 aNormal = GeomAPI.GeomAPI_Dir(1, 0, 0)
248 checkEllipseFace(Part_1_doc, "_weak_name_1_Partition_1_1_2", aFirstFocus, aSecondFocus, aMajorRadius, aMinorRadius)
249 checkEllipseEdge(Part_1_doc, "Partition_1_1_1/Generated_Edge&Cone_1_1/Face_1", aFirstFocus, aSecondFocus, aMajorRadius, aMinorRadius, aNormal)
250
251 # Test 6. Compose a conical solid
252 Solid_1_objects = ["Rotation_1_1/MF:Rotated&Cone_1_1/Face_3",
253                    "Partition_1_1_1/Modified_Face&Cone_1_1/Face_1",
254                    "Partition_1_1_2/Modified_Face&Cone_1_1/Face_1",
255                    "Rotation_1_1/MF:Rotated&Cone_1_1/Face_2"]
256 checkConeSolid(Part_1_doc, Solid_1_objects, anApex, anAxis, aSemiAngle, ParamR1.value(), ParamR2.value(), ParamH.value())
257
258 # Test 7. Check non-cone
259 Cone_2 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 5, 10)
260 Cone_3 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10, 20)
261 Fuse_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Cone_2_1"), model.selection("SOLID", "Cone_3_1")], True)
262
263 model.do()
264 Solid_2_objects = [model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_2_1/Face_3&Cone_3_1/Face_3"),
265                    model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_2_1/Face_1"),
266                    model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_3_1/Face_1"),
267                    model.selection("FACE", "Cone_3_1/Face_2")]
268 Solid_2 = model.addSolid(Part_1_doc, Solid_2_objects)
269 checkNonCone(Solid_2)
270 model.end()
271
272 # in order to use study objects once again, undo Test7 actions
273 model.undo()
274
275 # Test 8. Check non-conical shell
276 model.begin()
277 Shell_1_objects = [model.selection("FACE", "Rotation_1_1/MF:Rotated&Cone_1_1/Face_3"),
278                    model.selection("FACE", "Partition_1_1_1/Modified_Face&Cone_1_1/Face_1"),
279                    model.selection("FACE", "Partition_1_1_2/Modified_Face&Cone_1_1/Face_1"),
280                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Cone_1_1/Face_2")]
281 Shell_1 = model.addShell(Part_1_doc, Shell_1_objects)
282 checkNonConeShell(Shell_1)
283
284 Shell_2 = model.addShell(Part_1_doc, [model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_2_1/Face_1"), model.selection("FACE", "Fuse_1_1/Modified_Face&Cone_3_1/Face_1")])
285 checkNonConeShell(Shell_2)
286 model.end()
287
288 # in order to use study objects once again, undo Test8 actions
289 model.undo()
290
291 # Test 9. Check error on conversion to wrong type of curve
292 model.begin()
293 anEdge = model.addEdge(Part_1_doc, [model.selection("EDGE", "[Partition_1_1_2/Modified_Face&Cone_1_1/Face_1][Rotation_1_1/MF:Rotated&Cone_1_1/Face_2]")])
294 aShape = anEdge.result().resultSubShapePair()[0].shape()
295 assert(aShape.isEdge())
296 assert(aShape.edge().ellipse() is None)
297 assert(aShape.edge().line() is None)
298 model.end()
299
300 model.undo()
301
302 model.begin()
303
304 anEdge = model.addEdge(Part_1_doc, [model.selection("EDGE", "[Partition_1_1_2/Modified_Face&Cone_1_1/Face_1][weak_name_2]")])
305 aShape = anEdge.result().resultSubShapePair()[0].shape()
306 assert(aShape.isEdge())
307 assert(aShape.edge().circle() is None)
308 assert(aShape.isSelfIntersected() == False)
309
310 # Test 10. Test cone constructors
311 apex = GeomAPI_Pnt(10, 0, 0)
312 dir = GeomAPI_Dir(1, 0, 0)
313 semiAngle = math.pi / 4
314 cone = GeomAPI_Cone(apex, dir, semiAngle)
315 assert(cone.location().distance(apex) < TOLERANCE)
316
317 radius = 5
318 cone = GeomAPI_Cone(apex, dir, semiAngle, radius)
319 assert(cone.location().distance(apex) < TOLERANCE)
320
321 model.end()