Salome HOME
Issue #2431 - remove application exit from unit tests
[modules/shaper.git] / src / SketchPlugin / Test / TestFilletInteracting.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     TestFilletInteracting.py
23     Unit test of SketchPlugin_Fillet feature.
24     In scope of interaction with another constraints applied to filleted features.
25 """
26
27 from GeomAPI import *
28 from GeomDataAPI import *
29 from ModelAPI import *
30 from SketchAPI import *
31 import math
32 import unittest
33 from salome.shaper import model
34
35 __updated__ = "2017-03-06"
36
37 def isArcLineSmooth(theArc, theLine, theTolerance):
38   aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
39   aDistance = model.distancePointLine(aCenter, theLine)
40   aRadius = arcRadius(theArc)
41   return math.fabs(aRadius - aDistance) < theTolerance
42
43 def isArcArcSmooth(theArc1, theArc2, theTolerance):
44   aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point"))
45   aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point"))
46   aDistance = model.distancePointPoint(aCenter1, aCenter2)
47   aRadius1 = arcRadius(theArc1)
48   aRadius2 = arcRadius(theArc2)
49   aRadSum = aRadius1 + aRadius2
50   aRadDiff = math.fabs(aRadius1 - aRadius2)
51   return math.fabs(aDistance - aRadSum) < theTolerance or math.fabs(aDistance - aRadDiff) < theTolerance
52
53 def arcRadius(theArc):
54   aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
55   aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
56   return model.distancePointPoint(aCenter, aStart)
57
58
59
60 class TestFilletInteracting(unittest.TestCase):
61   def setUp(self):
62     model.begin()
63     self.myDocument = model.moduleDocument()
64     self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
65     self.myTolerance = 1.e-6
66     self.myDOF = 0
67
68   def tearDown(self):
69     model.end()
70     self.assertTrue(model.checkPythonDump())
71     model.reset()
72
73
74   def checkDOF(self):
75     self.assertEqual(model.dof(self.mySketch), self.myDOF)
76
77   def collectFeatures(self):
78     self.myFeatures = {}
79     for aSubObj in self.mySketch.features().list():
80       aFeature = ModelAPI.ModelAPI_Feature.feature(aSubObj)
81       if aFeature is not None:
82         if self.myFeatures.get(aFeature.getKind()) == None:
83           self.myFeatures[aFeature.getKind()] = 1
84         else:
85           self.myFeatures[aFeature.getKind()] += 1
86
87   def checkNbFeatures(self, theFeatureKind, theFeatureCount):
88     if theFeatureCount == 0:
89       self.assertIsNone(self.myFeatures.get(theFeatureKind))
90     else:
91       self.assertIsNotNone(self.myFeatures.get(theFeatureKind), "No features of kind {0} but expected {1}".format(theFeatureKind, theFeatureCount))
92       self.assertEqual(self.myFeatures[theFeatureKind], theFeatureCount, "Observed number of {0} is {1} but expected {2}".format(theFeatureKind, self.myFeatures[theFeatureKind], theFeatureCount))
93
94   def checkFillet(self):
95     aPtPtCoincidences = self.getCoincidences()
96     for coinc in aPtPtCoincidences:
97       aConnectedFeatures = self.connectedFeatures(coinc)
98       self.assertEqual(len(aConnectedFeatures), 2)
99       if aConnectedFeatures[0].getKind() == "SketchArc":
100         if aConnectedFeatures[1].getKind() == "SketchArc":
101           self.assertTrue(isArcArcSmooth(aConnectedFeatures[0], aConnectedFeatures[1], self.myTolerance))
102         elif aConnectedFeatures[1].getKind() == "SketchLine":
103           self.assertTrue(isArcLineSmooth(aConnectedFeatures[0], aConnectedFeatures[1], self.myTolerance))
104       elif aConnectedFeatures[0].getKind() == "SketchLine" and aConnectedFeatures[1].getKind() == "SketchArc":
105         self.assertTrue(isArcLineSmooth(aConnectedFeatures[1], aConnectedFeatures[0], self.myTolerance))
106
107   def getCoincidences(self):
108     aCoincidences = []
109     for aSubObj in self.mySketch.features().list():
110       aSubFeature = ModelAPI.ModelAPI_Feature.feature(aSubObj)
111       if aSubFeature is not None and aSubFeature.getKind() == "SketchConstraintCoincidence":
112         anEntityA = aSubFeature.refattr("ConstraintEntityA")
113         anEntityB = aSubFeature.refattr("ConstraintEntityB")
114         if not anEntityA.isObject() and not anEntityB.isObject():
115           aCoincidences.append(aSubFeature)
116     return aCoincidences
117
118   def connectedFeatures(self, theCoincidence):
119     anEntityA = theCoincidence.refattr("ConstraintEntityA")
120     anEntityB = theCoincidence.refattr("ConstraintEntityB")
121     aFeatureA = ModelAPI.ModelAPI_Feature.feature(anEntityA.attr().owner())
122     aFeatureB = ModelAPI.ModelAPI_Feature.feature(anEntityB.attr().owner())
123     return [aFeatureA, aFeatureB]
124
125
126   def test_fillet_two_lines(self):
127     """ Test 1. Fillet on two connected lines
128     """
129     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
130     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
131     self.myDOF += 8
132     self.checkDOF()
133     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
134     self.myDOF -= 2
135     model.do()
136     self.checkDOF()
137     self.mySketch.setFillet(aSketchLineA.startPoint())
138     self.myDOF += 1
139     model.do()
140     self.checkFillet()
141     self.checkDOF()
142
143     self.collectFeatures()
144     self.checkNbFeatures("SketchLine", 2)
145     self.checkNbFeatures("SketchArc", 1)
146     self.checkNbFeatures("SketchConstraintCoincidence", 2)
147     self.checkNbFeatures("SketchConstraintTangent", 2)
148     self.checkNbFeatures("SketchFillet", 0)
149
150     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
151     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
152     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
153
154   def test_wrong_fillet_two_lines(self):
155     """ Test 2. Check the fillet is wrong on two connected lines when selecting incorrect point
156     """
157     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
158     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
159     self.myDOF += 8
160     self.checkDOF()
161     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
162     self.myDOF -= 2
163     model.do()
164     self.checkDOF()
165     aFillet = self.mySketch.setFillet(aSketchLineA.endPoint())
166     model.do()
167     self.checkDOF()
168
169     self.collectFeatures()
170     self.checkNbFeatures("SketchLine", 2)
171     self.checkNbFeatures("SketchArc", 0) # no arcs should be created
172     self.checkNbFeatures("SketchConstraintCoincidence", 1) # number of coincidences should not change
173     self.checkNbFeatures("SketchConstraintTangent", 0) # no tangencies should not be created
174     self.checkNbFeatures("SketchFillet", 1) # fillet feature should still exist. it should be wrong
175
176     # sketch is invalid, so, no results at all
177     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [])
178     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [])
179     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [])
180
181     # remove fillet for correct python dump
182     self.myDocument.removeFeature(aFillet.feature())
183
184   def test_fillet_arc_line(self):
185     """ Test 3. Fillet on connected arc and line
186     """
187     aSketchLine = self.mySketch.addLine(10., 10., 20., 10.)
188     aSketchArc = self.mySketch.addArc(20., 10., 20., 20., 10., 10., False)
189     self.myDOF += 9
190     self.checkDOF()
191     self.mySketch.setCoincident(aSketchLine.startPoint(), aSketchArc.endPoint())
192     self.myDOF -= 2
193     model.do()
194     self.checkDOF()
195     self.mySketch.setFillet(aSketchLine.startPoint())
196     self.myDOF += 1
197     model.do()
198     self.checkFillet()
199     self.checkDOF()
200
201     self.collectFeatures()
202     self.checkNbFeatures("SketchLine", 1)
203     self.checkNbFeatures("SketchArc", 2)
204     self.checkNbFeatures("SketchConstraintCoincidence", 2)
205     self.checkNbFeatures("SketchConstraintTangent", 2)
206     self.checkNbFeatures("SketchFillet", 0)
207
208     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
209     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
210     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
211
212   def test_fillet_two_arcs(self):
213     """ Test 4. Fillet on two connected arcs
214     """
215     aSketchArc1 = self.mySketch.addArc(20., 0., 20., 20., 10., 17.32050807568877293, False)
216     aSketchArc2 = self.mySketch.addArc(20., 34.64101615137754586, 20., 14.64101615137754586, 10., 17.32050807568877293, True)
217     self.myDOF += 10
218     self.checkDOF()
219     self.mySketch.setCoincident(aSketchArc1.endPoint(), aSketchArc2.endPoint())
220     self.myDOF -= 2
221     model.do()
222     self.checkDOF()
223     self.mySketch.setFillet(aSketchArc1.endPoint())
224     self.myDOF += 1
225     model.do()
226     self.checkFillet()
227     self.checkDOF()
228
229     self.collectFeatures()
230     self.checkNbFeatures("SketchLine", 0)
231     self.checkNbFeatures("SketchArc", 3)
232     self.checkNbFeatures("SketchConstraintCoincidence", 2)
233     self.checkNbFeatures("SketchConstraintTangent", 2)
234     self.checkNbFeatures("SketchFillet", 0)
235
236     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
237     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
238     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
239
240   def test_fillet_with_horizontal_vertical(self):
241     """ Test 5. Fillet on two connected lines in case of Horizontal or Vertical constraints applied
242     """
243     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
244     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
245     self.myDOF += 8
246     self.checkDOF()
247     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
248     self.myDOF -= 2
249     model.do()
250     self.checkDOF()
251     self.mySketch.setHorizontal(aSketchLineA.result())
252     self.mySketch.setVertical(aSketchLineB.result())
253     self.myDOF -= 2
254     model.do()
255     self.checkDOF()
256     self.mySketch.setFillet(aSketchLineA.startPoint())
257     self.myDOF += 1
258     model.do()
259     self.checkFillet()
260     self.checkDOF()
261
262     self.collectFeatures()
263     self.checkNbFeatures("SketchLine", 2)
264     self.checkNbFeatures("SketchArc", 1)
265     self.checkNbFeatures("SketchConstraintCoincidence", 2)
266     self.checkNbFeatures("SketchConstraintTangent", 2)
267     self.checkNbFeatures("SketchConstraintHorizontal", 1)
268     self.checkNbFeatures("SketchConstraintVertical", 1)
269     self.checkNbFeatures("SketchFillet", 0)
270
271     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
272     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
273     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
274
275   def test_fillet_with_orthogonal(self):
276     """ Test 6. Fillet on two connected lines in case of Perpendicular constraint applied
277     """
278     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
279     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
280     self.myDOF += 8
281     self.checkDOF()
282     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
283     self.myDOF -= 2
284     model.do()
285     self.checkDOF()
286     self.mySketch.setPerpendicular(aSketchLineA.result(), aSketchLineB.result())
287     self.myDOF -= 1
288     model.do()
289     self.checkDOF()
290     self.mySketch.setFillet(aSketchLineA.startPoint())
291     self.myDOF += 1
292     model.do()
293     self.checkFillet()
294     self.checkDOF()
295
296     self.collectFeatures()
297     self.checkNbFeatures("SketchLine", 2)
298     self.checkNbFeatures("SketchArc", 1)
299     self.checkNbFeatures("SketchConstraintCoincidence", 2)
300     self.checkNbFeatures("SketchConstraintTangent", 2)
301     self.checkNbFeatures("SketchConstraintPerpendicular", 1)
302     self.checkNbFeatures("SketchFillet", 0)
303
304     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
305     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
306     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
307
308   def test_fillet_with_parallel(self):
309     """ Test 7. Fillet on two connected lines in case of Parallel constraint applied
310     """
311     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
312     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
313     self.myDOF += 8
314     self.checkDOF()
315     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
316     self.myDOF -= 2
317     model.do()
318     self.checkDOF()
319     # third line to apply parallel constraint
320     aSketchLineC = self.mySketch.addLine(10., 0., 20., 5.)
321     self.myDOF += 4
322     self.mySketch.setParallel(aSketchLineB.result(), aSketchLineC.result())
323     self.myDOF -= 1
324     model.do()
325     self.checkDOF()
326     self.mySketch.setFillet(aSketchLineA.startPoint())
327     self.myDOF += 1
328     model.do()
329     self.checkFillet()
330     self.checkDOF()
331
332     self.collectFeatures()
333     self.checkNbFeatures("SketchLine", 3)
334     self.checkNbFeatures("SketchArc", 1)
335     self.checkNbFeatures("SketchConstraintCoincidence", 2)
336     self.checkNbFeatures("SketchConstraintTangent", 2)
337     self.checkNbFeatures("SketchConstraintParallel", 1)
338     self.checkNbFeatures("SketchFillet", 0)
339
340     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
341     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [4])
342     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [8])
343
344   def test_fillet_with_equal_lines(self):
345     """ Test 8. Fillet on two connected lines in case of Equal constraint applied
346     """
347     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
348     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
349     self.myDOF += 8
350     self.checkDOF()
351     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
352     self.myDOF -= 2
353     model.do()
354     self.checkDOF()
355     self.mySketch.setEqual(aSketchLineA.result(), aSketchLineB.result())
356     self.myDOF -= 1
357     model.do()
358     self.checkDOF()
359     self.mySketch.setFillet(aSketchLineA.startPoint())
360     self.myDOF += 2 # Equal has been removed
361     model.do()
362     self.checkFillet()
363     self.checkDOF()
364
365     self.collectFeatures()
366     self.checkNbFeatures("SketchLine", 2)
367     self.checkNbFeatures("SketchArc", 1)
368     self.checkNbFeatures("SketchConstraintCoincidence", 2)
369     self.checkNbFeatures("SketchConstraintTangent", 2)
370     self.checkNbFeatures("SketchConstraintEqual", 0) # Equal constraint expected to be removed
371     self.checkNbFeatures("SketchFillet", 0)
372
373     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
374     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
375     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
376
377   def test_fillet_with_equal_arcs(self):
378     """ Test 9. Fillet on two connected arcs in case of Equal constraint applied
379     """
380     aSketchArc1 = self.mySketch.addArc(20., 0., 20., 20., 10., 17.32050807568877293, False)
381     aSketchArc2 = self.mySketch.addArc(20., 34.64101615137754586, 20., 14.64101615137754586, 10., 17.32050807568877293, True)
382     self.myDOF += 10
383     self.checkDOF()
384     self.mySketch.setCoincident(aSketchArc1.endPoint(), aSketchArc2.endPoint())
385     self.myDOF -= 2
386     model.do()
387     self.checkDOF()
388     self.mySketch.setEqual(aSketchArc1.results()[1], aSketchArc2.results()[1])
389     self.myDOF -= 1
390     model.do()
391     self.checkDOF()
392     self.mySketch.setFillet(aSketchArc1.endPoint())
393     self.myDOF += 2 # Equal has been removed
394     model.do()
395     self.checkFillet()
396     self.checkDOF()
397
398     self.collectFeatures()
399     self.checkNbFeatures("SketchLine", 0)
400     self.checkNbFeatures("SketchArc", 3)
401     self.checkNbFeatures("SketchConstraintCoincidence", 2)
402     self.checkNbFeatures("SketchConstraintTangent", 2)
403     self.checkNbFeatures("SketchConstraintEqual", 0) # Equal constraint expected to be removed
404     self.checkNbFeatures("SketchFillet", 0)
405
406     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
407     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
408     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
409
410   def test_fillet_with_length(self):
411     """ Test 10. Fillet on two connected lines in case of Length constraint applied
412     """
413     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
414     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
415     self.myDOF += 8
416     self.checkDOF()
417     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
418     self.myDOF -= 2
419     model.do()
420     self.checkDOF()
421     self.mySketch.setLength(aSketchLineA.result(), 15.)
422     self.myDOF -= 1
423     model.do()
424     self.checkDOF()
425     self.mySketch.setFillet(aSketchLineA.startPoint())
426     self.myDOF += 1
427     model.do()
428     self.checkFillet()
429     self.checkDOF()
430
431     self.collectFeatures()
432     self.checkNbFeatures("SketchLine", 2)
433     self.checkNbFeatures("SketchArc", 1)
434     self.checkNbFeatures("SketchConstraintCoincidence", 4) # Additionally 2 coincidences for apex with fillet objects
435     self.checkNbFeatures("SketchConstraintTangent", 2)
436     self.checkNbFeatures("SketchConstraintLength", 0) # Length constraint expected to be removed
437     self.checkNbFeatures("SketchConstraintDistance", 1) # Distance constraint should appear instead of Length
438     self.checkNbFeatures("SketchFillet", 0)
439
440     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
441     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
442     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
443
444   def test_fillet_with_radius(self):
445     """ Test 11. Fillet on connected arc and line in case of Radius constraint is applied to arc
446     """
447     aSketchLine = self.mySketch.addLine(10., 10., 20., 10.)
448     aSketchArc = self.mySketch.addArc(0., 10., 0., 20., 10., 10., True)
449     self.myDOF += 9
450     self.checkDOF()
451     self.mySketch.setCoincident(aSketchLine.startPoint(), aSketchArc.endPoint())
452     self.myDOF -= 2
453     model.do()
454     self.checkDOF()
455     self.mySketch.setRadius(aSketchArc.results()[1], 12.)
456     self.myDOF -= 1
457     model.do()
458     self.checkDOF()
459     self.mySketch.setFillet(aSketchLine.startPoint())
460     self.myDOF += 1
461     model.do()
462     self.checkFillet()
463     self.checkDOF()
464
465     self.collectFeatures()
466     self.checkNbFeatures("SketchLine", 1)
467     self.checkNbFeatures("SketchArc", 2)
468     self.checkNbFeatures("SketchConstraintCoincidence", 2)
469     self.checkNbFeatures("SketchConstraintTangent", 2)
470     self.checkNbFeatures("SketchConstraintRadius", 1)
471     self.checkNbFeatures("SketchFillet", 0)
472
473     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
474     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
475     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
476
477   def test_fillet_with_distance(self):
478     """ Test 12. Fillet on two connected lines in case of Distance constraint applied
479     """
480     aSketchLineA = self.mySketch.addLine(20, 20, 70, 20)
481     aSketchLineB = self.mySketch.addLine(70, 20, 70, 53.16624790355412)
482     aSketchLineC = self.mySketch.addLine(70, 53.16624790355412, 20, 20)
483     self.myDOF += 12
484     model.do()
485     self.checkDOF()
486     # coincidences
487     self.mySketch.setCoincident(aSketchLineA.endPoint(), aSketchLineB.startPoint())
488     self.mySketch.setCoincident(aSketchLineB.endPoint(), aSketchLineC.startPoint())
489     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineC.endPoint())
490     self.myDOF -= 6
491     model.do()
492     self.checkDOF()
493     # other constraints
494     self.mySketch.setHorizontal(aSketchLineA.result())
495     self.mySketch.setVertical(aSketchLineB.result())
496     self.myDOF -= 2
497     model.do()
498     self.checkDOF()
499     # construction point
500     aProjection = self.mySketch.addProjection(model.selection("VERTEX", "Origin"), False)
501     aSketchPoint = SketchAPI_Point(aProjection.createdFeature())
502     model.do()
503     # distances
504     self.mySketch.setLength(aSketchLineA.result(), 50)
505     self.mySketch.setDistance(aSketchLineA.startPoint(), aSketchLineC.startPoint(), 60, True)
506     self.mySketch.setHorizontalDistance(aSketchPoint.coordinates(), aSketchLineA.startPoint(), 20)
507     self.mySketch.setVerticalDistance(aSketchPoint.coordinates(), aSketchLineC.endPoint(), 20)
508     self.myDOF -= 4
509     model.do()
510     self.checkDOF()
511
512     self.mySketch.setFillet(aSketchLineA.startPoint())
513     self.myDOF += 1
514     model.do()
515     self.checkFillet()
516     self.checkDOF()
517
518     self.collectFeatures()
519     self.checkNbFeatures("SketchLine", 3)
520     self.checkNbFeatures("SketchArc", 1)
521     self.checkNbFeatures("SketchConstraintCoincidence", 6) # Additionally 2 coincidences for apex with fillet objects
522     self.checkNbFeatures("SketchConstraintHorizontal", 1)
523     self.checkNbFeatures("SketchConstraintVertical", 1)
524     self.checkNbFeatures("SketchConstraintTangent", 2)
525     self.checkNbFeatures("SketchConstraintLength", 0) # Length translated to Distance
526     self.checkNbFeatures("SketchConstraintDistance", 2) # Length translated to Distance
527     self.checkNbFeatures("SketchConstraintDistanceHorizontal", 1)
528     self.checkNbFeatures("SketchConstraintDistanceVertical", 1)
529     self.checkNbFeatures("SketchFillet", 0)
530
531     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
532     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [4])
533     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [8])
534
535   def test_fillet_with_fixed_point(self):
536     """ Test 13. Fillet on two connected lines in case of Fixed constraint applied to the fillet point
537     """
538     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
539     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
540     self.myDOF += 8
541     self.checkDOF()
542     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
543     self.myDOF -= 2
544     model.do()
545     self.checkDOF()
546     self.mySketch.setFixed(aSketchLineA.startPoint())
547     self.myDOF -= 2
548     model.do()
549     self.checkDOF()
550     self.mySketch.setFillet(aSketchLineA.startPoint())
551     self.myDOF += 3 # Fixed constraint has been removed
552     model.do()
553     self.checkFillet()
554     self.checkDOF()
555
556     self.collectFeatures()
557     self.checkNbFeatures("SketchLine", 2)
558     self.checkNbFeatures("SketchArc", 1)
559     self.checkNbFeatures("SketchConstraintCoincidence", 2)
560     self.checkNbFeatures("SketchConstraintTangent", 2)
561     self.checkNbFeatures("SketchConstraintFixed", 0) # Fixed constraint expected to be removed
562     self.checkNbFeatures("SketchFillet", 0)
563
564     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
565     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
566     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
567
568   def test_fillet_with_fixed_line(self):
569     """ Test 14. Fillet on two connected lines in case of Fixed constraint applied to one of lines
570     """
571     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
572     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
573     self.myDOF += 8
574     self.checkDOF()
575     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
576     self.myDOF -= 2
577     model.do()
578     self.checkDOF()
579     self.mySketch.setFixed(aSketchLineA.result())
580     self.myDOF -= 4
581     model.do()
582     self.checkDOF()
583     self.mySketch.setFillet(aSketchLineA.startPoint())
584     self.myDOF += 1
585     model.do()
586     self.checkFillet()
587     self.checkDOF()
588
589     self.collectFeatures()
590     self.checkNbFeatures("SketchLine", 2)
591     self.checkNbFeatures("SketchArc", 1)
592     self.checkNbFeatures("SketchConstraintCoincidence", 2)
593     self.checkNbFeatures("SketchConstraintTangent", 2)
594     self.checkNbFeatures("SketchConstraintLength", 0) # Fixed constraint expected to be kept
595     self.checkNbFeatures("SketchFillet", 0)
596
597     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
598     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
599     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
600
601   def test_fillet_with_angle(self):
602     """ Test 15. Fillet on two connected lines in case of Perpendicular constraint applied
603     """
604     aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
605     aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
606     self.myDOF += 8
607     self.checkDOF()
608     self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
609     self.myDOF -= 2
610     model.do()
611     self.checkDOF()
612     self.mySketch.setAngle(aSketchLineA.result(), aSketchLineB.result(), 60.)
613     self.myDOF -= 1
614     model.do()
615     self.checkDOF()
616     self.mySketch.setFillet(aSketchLineA.startPoint())
617     self.myDOF += 1
618     model.do()
619     self.checkFillet()
620     self.checkDOF()
621
622     self.collectFeatures()
623     self.checkNbFeatures("SketchLine", 2)
624     self.checkNbFeatures("SketchArc", 1)
625     self.checkNbFeatures("SketchConstraintCoincidence", 2)
626     self.checkNbFeatures("SketchConstraintTangent", 2)
627     self.checkNbFeatures("SketchConstraintAngle", 1)
628     self.checkNbFeatures("SketchFillet", 0)
629
630     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
631     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
632     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
633
634
635 if __name__ == '__main__':
636   unittest.main(exit=False)