2 TestFilletInteracting.py
3 Unit test of SketchPlugin_Fillet feature.
4 In scope of interaction with another constraints applied to filleted features.
8 from GeomDataAPI import *
12 from salome.shaper import model
14 __updated__ = "2017-03-06"
16 def isArcLineSmooth(theArc, theLine, theTolerance):
17 aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
18 aDistance = model.distancePointLine(aCenter, theLine)
19 aRadius = arcRadius(theArc)
20 return math.fabs(aRadius - aDistance) < theTolerance
22 def isArcArcSmooth(theArc1, theArc2, theTolerance):
23 aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point"))
24 aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point"))
25 aDistance = model.distancePointPoint(aCenter1, aCenter2)
26 aRadius1 = arcRadius(theArc1)
27 aRadius2 = arcRadius(theArc2)
28 aRadSum = aRadius1 + aRadius2
29 aRadDiff = math.fabs(aRadius1 - aRadius2)
30 return math.fabs(aDistance - aRadSum) < theTolerance or math.fabs(aDistance - aRadDiff) < theTolerance
32 def arcRadius(theArc):
33 aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
34 aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
35 return model.distancePointPoint(aCenter, aStart)
39 class TestFilletInteracting(unittest.TestCase):
42 self.myDocument = model.moduleDocument()
43 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
44 self.myTolerance = 1.e-6
49 self.assertTrue(model.checkPythonDump())
54 self.assertEqual(model.dof(self.mySketch), self.myDOF)
56 def collectFeatures(self):
58 for aSubObj in self.mySketch.features().list():
59 aFeature = ModelAPI.ModelAPI_Feature.feature(aSubObj)
60 if aFeature is not None:
61 if self.myFeatures.get(aFeature.getKind()) == None:
62 self.myFeatures[aFeature.getKind()] = 1
64 self.myFeatures[aFeature.getKind()] += 1
66 def checkNbFeatures(self, theFeatureKind, theFeatureCount):
67 if theFeatureCount == 0:
68 self.assertIsNone(self.myFeatures.get(theFeatureKind))
70 self.assertIsNotNone(self.myFeatures.get(theFeatureKind), "No features of kind {0} but expected {1}".format(theFeatureKind, theFeatureCount))
71 self.assertEqual(self.myFeatures[theFeatureKind], theFeatureCount, "Observed number of {0} is {1} but expected {2}".format(theFeatureKind, self.myFeatures[theFeatureKind], theFeatureCount))
73 def checkFillet(self):
74 aPtPtCoincidences = self.getCoincidences()
75 for coinc in aPtPtCoincidences:
76 aConnectedFeatures = self.connectedFeatures(coinc)
77 self.assertEqual(len(aConnectedFeatures), 2)
78 if aConnectedFeatures[0].getKind() == "SketchArc":
79 if aConnectedFeatures[1].getKind() == "SketchArc":
80 self.assertTrue(isArcArcSmooth(aConnectedFeatures[0], aConnectedFeatures[1], self.myTolerance))
81 elif aConnectedFeatures[1].getKind() == "SketchLine":
82 self.assertTrue(isArcLineSmooth(aConnectedFeatures[0], aConnectedFeatures[1], self.myTolerance))
83 elif aConnectedFeatures[0].getKind() == "SketchLine" and aConnectedFeatures[1].getKind() == "SketchArc":
84 self.assertTrue(isArcLineSmooth(aConnectedFeatures[1], aConnectedFeatures[0], self.myTolerance))
86 def getCoincidences(self):
88 for aSubObj in self.mySketch.features().list():
89 aSubFeature = ModelAPI.ModelAPI_Feature.feature(aSubObj)
90 if aSubFeature is not None and aSubFeature.getKind() == "SketchConstraintCoincidence":
91 anEntityA = aSubFeature.refattr("ConstraintEntityA")
92 anEntityB = aSubFeature.refattr("ConstraintEntityB")
93 if not anEntityA.isObject() and not anEntityB.isObject():
94 aCoincidences.append(aSubFeature)
97 def connectedFeatures(self, theCoincidence):
98 anEntityA = theCoincidence.refattr("ConstraintEntityA")
99 anEntityB = theCoincidence.refattr("ConstraintEntityB")
100 aFeatureA = ModelAPI.ModelAPI_Feature.feature(anEntityA.attr().owner())
101 aFeatureB = ModelAPI.ModelAPI_Feature.feature(anEntityB.attr().owner())
102 return [aFeatureA, aFeatureB]
105 def test_fillet_two_lines(self):
106 """ Test 1. Fillet on two connected lines
108 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
109 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
112 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
116 self.mySketch.setFillet(aSketchLineA.startPoint())
122 self.collectFeatures()
123 self.checkNbFeatures("SketchLine", 2)
124 self.checkNbFeatures("SketchArc", 1)
125 self.checkNbFeatures("SketchConstraintCoincidence", 2)
126 self.checkNbFeatures("SketchConstraintTangent", 2)
127 self.checkNbFeatures("SketchFillet", 0)
129 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
130 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
131 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
133 def test_wrong_fillet_two_lines(self):
134 """ Test 2. Check the fillet is wrong on two connected lines when selecting incorrect point
136 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
137 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
140 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
144 aFillet = self.mySketch.setFillet(aSketchLineA.endPoint())
148 self.collectFeatures()
149 self.checkNbFeatures("SketchLine", 2)
150 self.checkNbFeatures("SketchArc", 0) # no arcs should be created
151 self.checkNbFeatures("SketchConstraintCoincidence", 1) # number of coincidences should not change
152 self.checkNbFeatures("SketchConstraintTangent", 0) # no tangencies should not be created
153 self.checkNbFeatures("SketchFillet", 1) # fillet feature should still exist. it should be wrong
155 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
156 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [2])
157 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [4])
159 # remove fillet for correct python dump
160 self.myDocument.removeFeature(aFillet.feature())
162 def test_fillet_arc_line(self):
163 """ Test 3. Fillet on connected arc and line
165 aSketchLine = self.mySketch.addLine(10., 10., 20., 10.)
166 aSketchArc = self.mySketch.addArc(20., 10., 20., 20., 10., 10., False)
169 self.mySketch.setCoincident(aSketchLine.startPoint(), aSketchArc.endPoint())
173 self.mySketch.setFillet(aSketchLine.startPoint())
179 self.collectFeatures()
180 self.checkNbFeatures("SketchLine", 1)
181 self.checkNbFeatures("SketchArc", 2)
182 self.checkNbFeatures("SketchConstraintCoincidence", 2)
183 self.checkNbFeatures("SketchConstraintTangent", 2)
184 self.checkNbFeatures("SketchFillet", 0)
186 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
187 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
188 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
190 def test_fillet_two_arcs(self):
191 """ Test 4. Fillet on two connected arcs
193 aSketchArc1 = self.mySketch.addArc(20., 0., 20., 20., 10., 17.32050807568877293, False)
194 aSketchArc2 = self.mySketch.addArc(20., 34.64101615137754586, 20., 14.64101615137754586, 10., 17.32050807568877293, True)
197 self.mySketch.setCoincident(aSketchArc1.endPoint(), aSketchArc2.endPoint())
201 self.mySketch.setFillet(aSketchArc1.endPoint())
207 self.collectFeatures()
208 self.checkNbFeatures("SketchLine", 0)
209 self.checkNbFeatures("SketchArc", 3)
210 self.checkNbFeatures("SketchConstraintCoincidence", 2)
211 self.checkNbFeatures("SketchConstraintTangent", 2)
212 self.checkNbFeatures("SketchFillet", 0)
214 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
215 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
216 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
218 def test_fillet_with_horizontal_vertical(self):
219 """ Test 5. Fillet on two connected lines in case of Horizontal or Vertical constraints applied
221 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
222 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
225 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
229 self.mySketch.setHorizontal(aSketchLineA.result())
230 self.mySketch.setVertical(aSketchLineB.result())
234 self.mySketch.setFillet(aSketchLineA.startPoint())
240 self.collectFeatures()
241 self.checkNbFeatures("SketchLine", 2)
242 self.checkNbFeatures("SketchArc", 1)
243 self.checkNbFeatures("SketchConstraintCoincidence", 2)
244 self.checkNbFeatures("SketchConstraintTangent", 2)
245 self.checkNbFeatures("SketchConstraintHorizontal", 1)
246 self.checkNbFeatures("SketchConstraintVertical", 1)
247 self.checkNbFeatures("SketchFillet", 0)
249 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
250 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
251 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
253 def test_fillet_with_orthogonal(self):
254 """ Test 6. Fillet on two connected lines in case of Perpendicular constraint applied
256 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
257 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
260 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
264 self.mySketch.setPerpendicular(aSketchLineA.result(), aSketchLineB.result())
268 self.mySketch.setFillet(aSketchLineA.startPoint())
274 self.collectFeatures()
275 self.checkNbFeatures("SketchLine", 2)
276 self.checkNbFeatures("SketchArc", 1)
277 self.checkNbFeatures("SketchConstraintCoincidence", 2)
278 self.checkNbFeatures("SketchConstraintTangent", 2)
279 self.checkNbFeatures("SketchConstraintPerpendicular", 1)
280 self.checkNbFeatures("SketchFillet", 0)
282 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
283 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
284 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
286 def test_fillet_with_parallel(self):
287 """ Test 7. Fillet on two connected lines in case of Parallel constraint applied
289 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
290 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
293 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
297 # third line to apply parallel constraint
298 aSketchLineC = self.mySketch.addLine(10., 0., 20., 5.)
300 self.mySketch.setParallel(aSketchLineB.result(), aSketchLineC.result())
304 self.mySketch.setFillet(aSketchLineA.startPoint())
310 self.collectFeatures()
311 self.checkNbFeatures("SketchLine", 3)
312 self.checkNbFeatures("SketchArc", 1)
313 self.checkNbFeatures("SketchConstraintCoincidence", 2)
314 self.checkNbFeatures("SketchConstraintTangent", 2)
315 self.checkNbFeatures("SketchConstraintParallel", 1)
316 self.checkNbFeatures("SketchFillet", 0)
318 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
319 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [4])
320 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [8])
322 def test_fillet_with_equal_lines(self):
323 """ Test 8. Fillet on two connected lines in case of Equal constraint applied
325 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
326 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
329 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
333 self.mySketch.setEqual(aSketchLineA.result(), aSketchLineB.result())
337 self.mySketch.setFillet(aSketchLineA.startPoint())
338 self.myDOF += 2 # Equal has been removed
343 self.collectFeatures()
344 self.checkNbFeatures("SketchLine", 2)
345 self.checkNbFeatures("SketchArc", 1)
346 self.checkNbFeatures("SketchConstraintCoincidence", 2)
347 self.checkNbFeatures("SketchConstraintTangent", 2)
348 self.checkNbFeatures("SketchConstraintEqual", 0) # Equal constraint expected to be removed
349 self.checkNbFeatures("SketchFillet", 0)
351 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
352 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
353 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
355 def test_fillet_with_equal_arcs(self):
356 """ Test 9. Fillet on two connected arcs in case of Equal constraint applied
358 aSketchArc1 = self.mySketch.addArc(20., 0., 20., 20., 10., 17.32050807568877293, False)
359 aSketchArc2 = self.mySketch.addArc(20., 34.64101615137754586, 20., 14.64101615137754586, 10., 17.32050807568877293, True)
362 self.mySketch.setCoincident(aSketchArc1.endPoint(), aSketchArc2.endPoint())
366 self.mySketch.setEqual(aSketchArc1.results()[1], aSketchArc2.results()[1])
370 self.mySketch.setFillet(aSketchArc1.endPoint())
371 self.myDOF += 2 # Equal has been removed
376 self.collectFeatures()
377 self.checkNbFeatures("SketchLine", 0)
378 self.checkNbFeatures("SketchArc", 3)
379 self.checkNbFeatures("SketchConstraintCoincidence", 2)
380 self.checkNbFeatures("SketchConstraintTangent", 2)
381 self.checkNbFeatures("SketchConstraintEqual", 0) # Equal constraint expected to be removed
382 self.checkNbFeatures("SketchFillet", 0)
384 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
385 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
386 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
388 def test_fillet_with_length(self):
389 """ Test 10. Fillet on two connected lines in case of Length constraint applied
391 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
392 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
395 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
399 self.mySketch.setLength(aSketchLineA.result(), 15.)
403 self.mySketch.setFillet(aSketchLineA.startPoint())
409 self.collectFeatures()
410 self.checkNbFeatures("SketchLine", 2)
411 self.checkNbFeatures("SketchArc", 1)
412 self.checkNbFeatures("SketchConstraintCoincidence", 2)
413 self.checkNbFeatures("SketchConstraintTangent", 2)
414 self.checkNbFeatures("SketchConstraintLength", 0) # Length constraint expected to be removed
415 self.checkNbFeatures("SketchFillet", 0)
417 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
418 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
419 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
421 def test_fillet_with_radius(self):
422 """ Test 11. Fillet on connected arc and line in case of Radius constraint is applied to arc
424 aSketchLine = self.mySketch.addLine(10., 10., 20., 10.)
425 aSketchArc = self.mySketch.addArc(0., 10., 0., 20., 10., 10., True)
428 self.mySketch.setCoincident(aSketchLine.startPoint(), aSketchArc.endPoint())
432 self.mySketch.setRadius(aSketchArc.results()[1], 12.)
436 self.mySketch.setFillet(aSketchLine.startPoint())
442 self.collectFeatures()
443 self.checkNbFeatures("SketchLine", 1)
444 self.checkNbFeatures("SketchArc", 2)
445 self.checkNbFeatures("SketchConstraintCoincidence", 2)
446 self.checkNbFeatures("SketchConstraintTangent", 2)
447 self.checkNbFeatures("SketchConstraintRadius", 1)
448 self.checkNbFeatures("SketchFillet", 0)
450 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
451 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
452 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
454 def test_fillet_with_distance(self):
455 """ Test 12. Fillet on two connected lines in case of Distance constraint applied
457 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
458 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
461 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
465 # third line to apply Distance constraints
466 aSketchLineC = self.mySketch.addLine(10., 0., 20., 5.)
468 self.mySketch.setDistance(aSketchLineB.startPoint(), aSketchLineC.result(), 10.)
469 self.mySketch.setDistance(aSketchLineB.endPoint(), aSketchLineC.result(), 5.)
473 self.mySketch.setFillet(aSketchLineA.startPoint())
474 self.myDOF += 2 # Distance has been removed
479 self.collectFeatures()
480 self.checkNbFeatures("SketchLine", 3)
481 self.checkNbFeatures("SketchArc", 1)
482 self.checkNbFeatures("SketchConstraintCoincidence", 2)
483 self.checkNbFeatures("SketchConstraintTangent", 2)
484 self.checkNbFeatures("SketchConstraintDistance", 1) # only one Distance should be left
485 self.checkNbFeatures("SketchFillet", 0)
487 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
488 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [4])
489 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [8])
491 def test_fillet_with_fixed_point(self):
492 """ Test 13. Fillet on two connected lines in case of Fixed constraint applied to the fillet point
494 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
495 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
498 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
502 self.mySketch.setFixed(aSketchLineA.startPoint())
506 self.mySketch.setFillet(aSketchLineA.startPoint())
507 self.myDOF += 3 # Fixed constraint has been removed
512 self.collectFeatures()
513 self.checkNbFeatures("SketchLine", 2)
514 self.checkNbFeatures("SketchArc", 1)
515 self.checkNbFeatures("SketchConstraintCoincidence", 2)
516 self.checkNbFeatures("SketchConstraintTangent", 2)
517 self.checkNbFeatures("SketchConstraintFixed", 0) # Fixed constraint expected to be removed
518 self.checkNbFeatures("SketchFillet", 0)
520 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
521 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
522 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
524 def test_fillet_with_fixed_line(self):
525 """ Test 14. Fillet on two connected lines in case of Fixed constraint applied to one of lines
527 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
528 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
531 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
535 self.mySketch.setFixed(aSketchLineA.result())
539 self.mySketch.setFillet(aSketchLineA.startPoint())
545 self.collectFeatures()
546 self.checkNbFeatures("SketchLine", 2)
547 self.checkNbFeatures("SketchArc", 1)
548 self.checkNbFeatures("SketchConstraintCoincidence", 2)
549 self.checkNbFeatures("SketchConstraintTangent", 2)
550 self.checkNbFeatures("SketchConstraintLength", 0) # Fixed constraint expected to be kept
551 self.checkNbFeatures("SketchFillet", 0)
553 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
554 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
555 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
557 def test_fillet_with_angle(self):
558 """ Test 15. Fillet on two connected lines in case of Perpendicular constraint applied
560 aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
561 aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
564 self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
568 self.mySketch.setAngle(aSketchLineA.result(), aSketchLineB.result(), 60.)
572 self.mySketch.setFillet(aSketchLineA.startPoint())
578 self.collectFeatures()
579 self.checkNbFeatures("SketchLine", 2)
580 self.checkNbFeatures("SketchArc", 1)
581 self.checkNbFeatures("SketchConstraintCoincidence", 2)
582 self.checkNbFeatures("SketchConstraintTangent", 2)
583 self.checkNbFeatures("SketchConstraintAngle", 1)
584 self.checkNbFeatures("SketchFillet", 0)
586 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
587 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
588 model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
591 if __name__ == '__main__':