Salome HOME
Issue #2027: Sketcher Trim Feature unit tests for Circle/Arc
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimCircle03.py
1 from salome.shaper import model
2
3 from ModelAPI import *
4 from GeomDataAPI import *
5 from ModelGeomAlgo import ModelGeomAlgo_Point2D
6 from salome.shaper import geom
7 import math
8
9 TOLERANCE = 1.e-7
10
11 SketchLineId = 'SketchLine'
12 SketchArcId = 'SketchArc'
13 SketchCircleId = 'SketchCircle'
14 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
15
16 aSession = ModelAPI_Session.get()
17 model.begin()
18 partSet = model.moduleDocument()
19 Part = model.addPart(partSet)
20 Part_doc = Part.document()
21
22 # Test1:begin split on circle with coincident point and intersection line : smaller part
23 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY"))
24 SketchCircle = Sketch.addCircle(50, 50, 20)
25 SketchLine_1 = Sketch.addLine(70, 50, 80, 80)
26 SketchLine_2 = Sketch.addLine(80, 80, 50, 70)
27
28 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
29 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchCircle.results()[1])
30 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchCircle.results()[1])
31
32
33 Sketch_features = featureToCompositeFeature(Sketch.feature())
34 assert (Sketch_features.numberOfSubs() == 6)
35 #intersection points on circle to prepare a trim selection point
36 SketchLine_intersecting = Sketch.addLine(10, 60, 90, 60)
37 Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()]))
38 assert(len(Circle_Points) == 2)
39 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
40 Sketch_features = featureToCompositeFeature(Sketch.feature())
41 assert (Sketch_features.numberOfSubs() == 6)
42
43 assert (len(Circle_Points) == 2)
44 if Circle_Points[0].x() < Circle_Points[1].x():
45   GeomPoint = Circle_Points[0]
46 else:
47   GeomPoint = Circle_Points[1]
48
49 #check number of features before trim
50 Sketch_feature = featureToCompositeFeature(Sketch.feature())
51 idList_before = []
52 for index in range(Sketch_feature.numberOfSubs()):
53   idList_before.append(Sketch_feature.subFeature(index).getKind())
54
55 assert(idList_before.count(SketchCircleId) == 1)
56 assert(idList_before.count(SketchArcId) == 0)
57 assert(idList_before.count(SketchLineId) == 2)
58 assert(idList_before.count(SketchConstraintCoincidenceId) == 3)
59
60 #perform trim
61 SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint))
62 SketchTrim.execute()
63 model.do()
64
65 #check number of features after trim
66 SketchFeatures = featureToCompositeFeature(Sketch.feature())
67 idList_after = []
68 for SubIndex in range(SketchFeatures.numberOfSubs()):
69     SubFeature = SketchFeatures.subFeature(SubIndex)
70     idList_after.append(SubFeature.getKind())
71     if SubFeature.getKind() == SketchArcId:
72       SketchArc = SubFeature
73
74 assert(idList_after.count(SketchCircleId) == 0)
75 assert(idList_after.count(SketchArcId) == 1)
76 assert(idList_after.count(SketchLineId) == 2)
77 assert(idList_after.count(SketchConstraintCoincidenceId) == 3)
78
79
80 #check arc position intersections of created arc to an additional line
81 SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50)
82 SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100)
83
84 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()]))
85 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()]))
86
87 assert(len(Intersection_Points_1) == 0)
88 assert(len(Intersection_Points_2) == 1)
89
90 #add point for check
91 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
92 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
93 assert(len(Intersection_Points_3) == 0)
94
95 model.end()
96
97 #assert(model.checkPythonDump())