Salome HOME
106297adc1c0bd0e71393e00bc76f6703d83a270
[modules/shaper.git] / src / SketchPlugin / Test / TestCreateCircleByThreePoints.py
1 # Copyright (C) 2014-2023  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     TestCreateCircleByThreePoints.py
22
23     Test creation methods of a circle built by three points
24 """
25
26 #=========================================================================
27 # Initialization of the test
28 #=========================================================================
29 from GeomDataAPI import *
30 from GeomAPI import *
31 from ModelAPI import *
32 from SketchAPI import SketchAPI_Sketch
33 from salome.shaper import model
34 import math
35
36 __updated__ = "2017-03-22"
37
38
39 #=========================================================================
40 # Auxiliary functions
41 #=========================================================================
42 TOLERANCE = 1.e-7
43
44 def verifyLastCircle(theSketch, theX, theY, theR):
45     """
46     subroutine to verify position of last circle in the sketch
47     """
48     aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
49     model.assertCircle(aLastCircle, [theX, theY], theR)
50
51 def verifyPointOnCircle(thePoint, theCircle):
52     aCircleCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
53     aDistCP = model.distancePointPoint(aCircleCenter, thePoint)
54     aCircleRadius = theCircle.real("circle_radius").value()
55     assert math.fabs(aDistCP - aCircleRadius) < TOLERANCE, "Point is not on circle, distance: {0}, radius of circle: {1}".format(aDistCP, aCircleRadius)
56
57 def verifyTangentCircles(theCircle1, theCircle2):
58     aCenter1 = geomDataAPI_Point2D(theCircle1.attribute("circle_center"))
59     aCenter2 = geomDataAPI_Point2D(theCircle2.attribute("circle_center"))
60     aDistCC = model.distancePointPoint(aCenter1, aCenter2)
61     aRadius1 = theCircle1.real("circle_radius").value()
62     aRadius2 = theCircle2.real("circle_radius").value()
63     verifyTangentCircular(aDistCC, aRadius1, aRadius2)
64
65 def verifyTangentCircleArc(theCircle, theArc):
66     aCircleCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
67     anArcCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
68     anArcStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
69     aDistCC = model.distancePointPoint(aCircleCenter, anArcCenter)
70     aCircleRadius = theCircle.real("circle_radius").value()
71     anArcRadius = model.distancePointPoint(anArcCenter, anArcStart)
72     verifyTangentCircular(aDistCC, aCircleRadius, anArcRadius)
73
74 def verifyTangentCircular(theDistBetweenCenters, theRadius1, theRadius2):
75     aRSum = theRadius1 + theRadius2
76     aRDiff = math.fabs(theRadius1 - theRadius2)
77     assert math.fabs(aRSum - theDistBetweenCenters) < TOLERANCE or math.fabs(aRDiff - theDistBetweenCenters) < TOLERANCE, "Two circulars are not tangent"
78
79 def verifyTangentCircleLine(theCircle, theLine):
80     aCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
81     aRadius = theCircle.real("circle_radius").value()
82     aDistCL = model.distancePointLine(aCenter, theLine)
83     assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent"
84
85
86 #=========================================================================
87 # Start of test
88 #=========================================================================
89
90 aSession = ModelAPI_Session.get()
91 aDocument = aSession.moduleDocument()
92 #=========================================================================
93 # Creation of a sketch
94 #=========================================================================
95 aSession.startOperation()
96 aSketchCommonFeature = aDocument.addFeature("Sketch")
97 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
98 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
99 origin.setValue(0, 0, 0)
100 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
101 dirx.setValue(1, 0, 0)
102 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
103 norm.setValue(0, 0, 1)
104 aSession.finishOperation()
105 aSketch = SketchAPI_Sketch(aSketchFeature)
106
107 #=========================================================================
108 # Test 1. Create a circle by three points
109 #=========================================================================
110 expectedCenter = [0., 0.]
111 expectedRadius = 10.
112 aSession.startOperation()
113 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
114 assert (aCircle.getKind() == "SketchMacroCircle")
115 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
116 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
117 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
118 assert (not aCirclePnt1.isInitialized())
119 assert (not aCirclePnt2.isInitialized())
120 assert (not aCirclePnt3.isInitialized())
121 aCircleType = aCircle.string("circle_type")
122 assert (not aCircleType.isInitialized())
123 aCircleType.setValue("circle_type_by_three_points")
124 aCirclePnt1.setValue(expectedCenter[0] - expectedRadius, expectedCenter[1])
125 aCirclePnt2.setValue(expectedCenter[0] + expectedRadius, expectedCenter[1])
126 aCirclePnt3.setValue(expectedCenter[0], expectedCenter[1] + expectedRadius)
127 aSession.finishOperation()
128 assert (aSketchFeature.numberOfSubs() == 1)
129 verifyLastCircle(aSketchFeature, expectedCenter[0], expectedCenter[1], expectedRadius)
130
131 #=========================================================================
132 # Test 2. Create a circle by three points coincident to other points
133 #=========================================================================
134 # get previous circle
135 aPrevCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
136 aPrevCenter = geomDataAPI_Point2D(aPrevCircle.attribute("circle_center"))
137 aPrevCenterXY = [aPrevCenter.x(), aPrevCenter.y()]
138 aPrevCircleRadius = aPrevCircle.real("circle_radius").value()
139 # create additional point and line
140 aPointCoordinates = [5., 20.]
141 aLineStart = [10., 0.]
142 aLineEnd = [10., 50.]
143 aSession.startOperation()
144 aPoint = aSketchFeature.addFeature("SketchPoint")
145 aPointCoord = geomDataAPI_Point2D(aPoint.attribute("PointCoordinates"))
146 aPointCoord.setValue(aPointCoordinates[0], aPointCoordinates[1])
147 aLine = aSketchFeature.addFeature("SketchLine")
148 aStartPnt = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
149 aStartPnt.setValue(aLineStart[0], aLineStart[1])
150 aEndPnt = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
151 aEndPnt.setValue(aLineEnd[0], aLineEnd[1])
152 aSession.finishOperation()
153 # create new circle
154 aSession.startOperation()
155 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
156 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
157 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
158 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
159 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
160 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
161 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
162 aCircleType = aCircle.string("circle_type")
163 # initialize attributes
164 aCircleType.setValue("circle_type_by_three_points")
165 aCirclePnt1Ref.setAttr(aPrevCenter)
166 aCirclePnt1.setValue(aPrevCenter.pnt())
167 aCirclePnt2Ref.setObject(aPoint.lastResult())
168 aCirclePnt2.setValue(aPointCoord.pnt())
169 aCirclePnt3Ref.setAttr(aStartPnt)
170 aCirclePnt3.setValue(aLineStart[0], aLineStart[1])
171 aSession.finishOperation()
172 assert (aSketchFeature.numberOfSubs() == 7)
173 # check the points do not change their positions
174 model.assertPoint(aPrevCenter, aPrevCenterXY)
175 model.assertPoint(aPointCoord, aPointCoordinates)
176 model.assertPoint(aStartPnt, aLineStart)
177 # check newly created circle passes through the points
178 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
179 verifyPointOnCircle(aPrevCenter, aCircle)
180 verifyPointOnCircle(aPointCoord, aCircle)
181 verifyPointOnCircle(aStartPnt, aCircle)
182 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
183 model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0)
184
185 #=========================================================================
186 # Test 3. Create a circle by three points and tangent to line, circle and arc
187 #=========================================================================
188 # create additional arc
189 anArcRadius = 5.
190 anArcCenter = [-10., 10.]
191 anArcStart = [anArcCenter[0], anArcCenter[1] - anArcRadius]
192 anArcEnd = [anArcCenter[0], anArcCenter[1] + anArcRadius]
193 aSession.startOperation()
194 anArc = aSketchFeature.addFeature("SketchArc")
195 anArcCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
196 anArcCenterPnt.setValue(anArcCenter[0], anArcCenter[1])
197 anArcStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
198 anArcStartPnt.setValue(anArcStart[0], anArcStart[1])
199 anArcEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
200 anArcEndPnt.setValue(anArcEnd[0], anArcEnd[1])
201 aSession.finishOperation()
202 # create new circle
203 aSession.startOperation()
204 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
205 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
206 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
207 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
208 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
209 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
210 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
211 aCircleType = aCircle.string("circle_type")
212 # initialize attributes
213 aCircleType.setValue("circle_type_by_three_points")
214 aCirclePnt1Ref.setObject(aPrevCircle.lastResult())
215 aCirclePnt1.setValue(aPrevCenter.x(), aPrevCenter.y() + aPrevCircleRadius)
216 aCirclePnt2Ref.setObject(aLine.lastResult())
217 aCirclePnt2.setValue(aLineEnd[0], aLineEnd[1])
218 aCirclePnt3Ref.setObject(anArc.lastResult())
219 aCirclePnt3.setValue(anArcCenter[0] + anArcRadius, anArcCenter[1])
220 aSession.finishOperation()
221 assert (aSketchFeature.numberOfSubs() == 12)
222 # check the tangent entities do not change their positions
223 model.assertPoint(aPrevCenter, aPrevCenterXY)
224 assert (aPrevCircle.real("circle_radius").value() == aPrevCircleRadius)
225 model.assertLine(aLine, aLineStart, aLineEnd)
226 model.assertArc(anArc, anArcCenter, anArcStart, anArcEnd)
227 # check newly created circle passes through the points
228 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
229 verifyTangentCircles(aCircle, aPrevCircle)
230 verifyTangentCircleArc(aCircle, anArc)
231 verifyTangentCircleLine(aCircle, aLine)
232 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
233 model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 3)
234
235 #=========================================================================
236 # Test 4. Create a circle by three points:
237 #         a. first two points are coincident to extremities of the line
238 #         b. check that this line is not selectable by third point
239 #=========================================================================
240 aSession.startOperation()
241 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
242 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
243 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
244 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
245 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
246 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
247 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
248 aCircleType = aCircle.string("circle_type")
249 # initialize attributes
250 aCircleType.setValue("circle_type_by_three_points")
251 aCirclePnt1Ref.setAttr(aStartPnt)
252 aCirclePnt1.setValue(aStartPnt.pnt())
253 aCirclePnt2Ref.setAttr(aEndPnt)
254 aCirclePnt2.setValue(aEndPnt.pnt())
255 aCirclePnt3Ref.setObject(aLine.lastResult())
256 aCirclePnt3.setValue(aLineEnd[0], aLineEnd[1])
257 aSession.finishOperation()
258 aLastFeature = aSketchFeature.subFeature(aSketchFeature.numberOfSubs() - 1)
259 assert aLastFeature.getKind() == "SketchMacroCircle", "ERROR: SketchMacroCircle has NOT expected to be valid"
260 aSession.startOperation()
261 aDocument.removeFeature(aCircle)
262 aSession.finishOperation()
263 assert (aSketchFeature.numberOfSubs() == 12)
264
265 #=========================================================================
266 # Test 5. Create a circle by three points:
267 #         a. first two points are placed on both sides from line
268 #         b. check that this line is not selectable by third point
269 #=========================================================================
270 aDistanceFromLine = 20.
271 aSession.startOperation()
272 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
273 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
274 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
275 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
276 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
277 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
278 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
279 aCircleType = aCircle.string("circle_type")
280 # initialize attributes
281 aCircleType.setValue("circle_type_by_three_points")
282 aCirclePnt1.setValue(aLineStart[0] + aDistanceFromLine, aLineStart[1])
283 aCirclePnt2.setValue(aLineStart[0] - aDistanceFromLine, aLineStart[1])
284 aCirclePnt3Ref.setObject(aLine.lastResult())
285 aCirclePnt3.setValue(aLineEnd[0], aLineEnd[1])
286 aSession.finishOperation()
287 aLastFeature = aSketchFeature.subFeature(aSketchFeature.numberOfSubs() - 1)
288 assert aLastFeature.getKind() == "SketchMacroCircle", "ERROR: SketchMacroCircle has NOT expected to be valid"
289 aSession.startOperation()
290 aDocument.removeFeature(aCircle)
291 aSession.finishOperation()
292 assert (aSketchFeature.numberOfSubs() == 12)
293
294
295 #=========================================================================
296 # Auxiliary objects for the following tests
297 #=========================================================================
298 from salome.shaper import model
299
300 model.begin()
301 Sketch_1 = model.addSketch(aDocument, model.defaultPlane("XOY"))
302 SketchLine_1 = Sketch_1.addLine(20, -10, 20, 10)
303 SketchLine_2 = Sketch_1.addLine(20, 10, 40, 10)
304 SketchLine_3 = Sketch_1.addLine(40, 10, 40, -10)
305 SketchCircle_1 = Sketch_1.addCircle(-10, 0, 20)
306 SketchCircle_2 = Sketch_1.addCircle(30, 25, 5)
307 SketchCircle_3 = Sketch_1.addCircle(50, 0, 10)
308 model.do()
309 model.end()
310 aSketchFeature = featureToCompositeFeature(Sketch_1.feature())
311
312 #=========================================================================
313 # Test 6. Create a circle passing through a point and tangent to 2 lines
314 #=========================================================================
315 # create new circle
316 aSession.startOperation()
317 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
318 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
319 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
320 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
321 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
322 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
323 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
324 aCircleType = aCircle.string("circle_type")
325 # initialize attributes
326 aCircleType.setValue("circle_type_by_three_points")
327 aCirclePnt1.setValue(0, 0)
328 aCirclePnt2Ref.setObject(SketchLine_1.feature().lastResult())
329 aCirclePnt2.setValue(SketchLine_1.startPoint().x(), SketchLine_1.startPoint().y())
330 aCirclePnt3Ref.setObject(SketchLine_2.feature().lastResult())
331 aCirclePnt3.setValue(SketchLine_2.startPoint().x(), SketchLine_2.startPoint().y())
332 aSession.finishOperation()
333 assert (aSketchFeature.numberOfSubs() == 9)
334 # check newly created circle tangent to objects
335 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
336 verifyTangentCircleLine(aCircle, SketchLine_1.feature())
337 verifyTangentCircleLine(aCircle, SketchLine_2.feature())
338 model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 0)
339 model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 2)
340
341 #=========================================================================
342 # Test 7. Create a circle passing through a point and tangent to 2 circles
343 #=========================================================================
344 # create new circle
345 aSession.startOperation()
346 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
347 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
348 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
349 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
350 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
351 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
352 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
353 aCircleType = aCircle.string("circle_type")
354 # initialize attributes
355 aCircleType.setValue("circle_type_by_three_points")
356 aCirclePnt1.setValue(0, 0)
357 aCirclePnt2Ref.setObject(SketchCircle_3.feature().lastResult())
358 aCirclePnt2.setValue(40, 0)
359 aCirclePnt3Ref.setObject(SketchCircle_2.feature().lastResult())
360 aCirclePnt3.setValue(30, 20)
361 aSession.finishOperation()
362 assert (aSketchFeature.numberOfSubs() == 12)
363 # check newly created circle tangent to objects
364 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
365 verifyTangentCircles(aCircle, SketchCircle_3.feature())
366 verifyTangentCircles(aCircle, SketchCircle_2.feature())
367 model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 0)
368 model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 4)
369
370 #=========================================================================
371 # Test 8. Create a circle passing through a point and tangent to line and circle
372 #=========================================================================
373 # create new circle
374 aSession.startOperation()
375 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
376 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
377 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
378 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
379 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
380 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
381 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
382 aCircleType = aCircle.string("circle_type")
383 # initialize attributes
384 aCircleType.setValue("circle_type_by_three_points")
385 aCirclePnt1.setValue(0, 0)
386 aCirclePnt2Ref.setObject(SketchLine_3.feature().lastResult())
387 aCirclePnt2.setValue(30, 0)
388 aCirclePnt3Ref.setObject(SketchCircle_2.feature().lastResult())
389 aCirclePnt3.setValue(30, 20)
390 aSession.finishOperation()
391 assert (aSketchFeature.numberOfSubs() == 15)
392 # check newly created circle tangent to objects
393 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
394 verifyTangentCircles(aCircle, SketchCircle_2.feature())
395 verifyTangentCircleLine(aCircle, SketchLine_3.feature())
396 model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 0)
397 model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 6)
398
399 #=========================================================================
400 # Test 9. Create a circle tangent to 3 lines
401 #=========================================================================
402 # create new circle
403 aSession.startOperation()
404 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
405 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
406 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
407 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
408 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
409 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
410 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
411 aCircleType = aCircle.string("circle_type")
412 # initialize attributes
413 aCircleType.setValue("circle_type_by_three_points")
414 aCirclePnt1Ref.setObject(SketchLine_1.feature().lastResult())
415 aCirclePnt1.setValue(20, 0)
416 aCirclePnt2Ref.setObject(SketchLine_2.feature().lastResult())
417 aCirclePnt2.setValue(30, 10)
418 aCirclePnt3Ref.setObject(SketchLine_3.feature().lastResult())
419 aCirclePnt3.setValue(40, 0)
420 aSession.finishOperation()
421 assert (aSketchFeature.numberOfSubs() == 19)
422 # check newly created circle tangent to objects
423 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
424 verifyTangentCircleLine(aCircle, SketchLine_1.feature())
425 verifyTangentCircleLine(aCircle, SketchLine_2.feature())
426 verifyTangentCircleLine(aCircle, SketchLine_3.feature())
427 model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 0)
428 model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 9)
429
430 #=========================================================================
431 # Test 10. Create a circle tangent to a circle and 2 lines
432 #=========================================================================
433 # create new circle
434 aSession.startOperation()
435 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
436 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
437 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
438 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
439 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
440 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
441 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
442 aCircleType = aCircle.string("circle_type")
443 # initialize attributes
444 aCircleType.setValue("circle_type_by_three_points")
445 aCirclePnt1Ref.setObject(SketchLine_1.feature().lastResult())
446 aCirclePnt1.setValue(20, 0)
447 aCirclePnt2Ref.setObject(SketchLine_2.feature().lastResult())
448 aCirclePnt2.setValue(30, 10)
449 aCirclePnt3Ref.setObject(SketchCircle_3.feature().lastResult())
450 aCirclePnt3.setValue(40, 0)
451 aSession.finishOperation()
452 assert (aSketchFeature.numberOfSubs() == 23)
453 # check newly created circle tangent to objects
454 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
455 verifyTangentCircleLine(aCircle, SketchLine_1.feature())
456 verifyTangentCircleLine(aCircle, SketchLine_2.feature())
457 verifyTangentCircles(aCircle, SketchCircle_3.feature())
458 model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 0)
459 model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 12)
460
461 #=========================================================================
462 # Test 11. Create a circle tangent to 3 circles
463 #=========================================================================
464 # create new circle
465 aSession.startOperation()
466 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
467 aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
468 aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
469 aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
470 aCirclePnt1Ref = aCircle.refattr("first_point_ref")
471 aCirclePnt2Ref = aCircle.refattr("second_point_ref")
472 aCirclePnt3Ref = aCircle.refattr("third_point_ref")
473 aCircleType = aCircle.string("circle_type")
474 # initialize attributes
475 aCircleType.setValue("circle_type_by_three_points")
476 aCirclePnt1Ref.setObject(SketchCircle_1.feature().lastResult())
477 aCirclePnt1.setValue(10, 0)
478 aCirclePnt2Ref.setObject(SketchCircle_2.feature().lastResult())
479 aCirclePnt2.setValue(30, 20)
480 aCirclePnt3Ref.setObject(SketchCircle_3.feature().lastResult())
481 aCirclePnt3.setValue(40, 0)
482 aSession.finishOperation()
483 assert (aSketchFeature.numberOfSubs() == 27)
484 # check newly created circle tangent to objects
485 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
486 verifyTangentCircles(aCircle, SketchCircle_1.feature())
487 verifyTangentCircles(aCircle, SketchCircle_2.feature())
488 verifyTangentCircles(aCircle, SketchCircle_3.feature())
489 model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 0)
490 model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 15)
491
492 #=========================================================================
493 # End of test
494 #=========================================================================
495
496 assert(model.checkPythonDump())