Salome HOME
Adjust test cases for the Trim feature
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimArc04.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 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
14 SketchConstraintEqualId = 'SketchConstraintEqual'
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 arc with coincident point and intersection line : smaller part
23 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY"))
24 SketchArc = Sketch.addArc(50, 50, 30, 50, 50, 70, False)
25 SketchLine_1 = Sketch.addLine(50, 20, 100, 20)
26 SketchLine_2 = Sketch.addLine(100, 20, 70, 50)
27 SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40)
28
29 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchArc.results()[1])
30 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchArc.results()[1])
31 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
32
33 Sketch_features = featureToCompositeFeature(Sketch.feature())
34 assert (Sketch_features.numberOfSubs() == 7)
35
36 Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()]))
37 assert(len(Arc_Points) == 2)
38
39 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
40
41 Sketch_features = featureToCompositeFeature(Sketch.feature())
42 assert (Sketch_features.numberOfSubs() == 6)
43
44 assert (len(Arc_Points) == 2)
45 if Arc_Points[0].x() < Arc_Points[1].x():
46   GeomPoint = Arc_Points[1]
47 else:
48   GeomPoint = Arc_Points[0]
49
50 #check number of features before trim
51 Sketch_feature = featureToCompositeFeature(Sketch.feature())
52 idList_before = []
53 for index in range(Sketch_feature.numberOfSubs()):
54   idList_before.append(Sketch_feature.subFeature(index).getKind())
55
56 assert(idList_before.count(SketchArcId) == 1)
57 assert(idList_before.count(SketchLineId) == 2)
58 assert(idList_before.count(SketchConstraintCoincidenceId) == 3)
59
60 #perform trim
61 SketchTrim = Sketch.addTrim(SketchArc, 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 anArcList = FeatureList()
69 for SubIndex in range(SketchFeatures.numberOfSubs()):
70     SubFeature = SketchFeatures.subFeature(SubIndex)
71     idList_after.append(SubFeature.getKind())
72     if SubFeature.getKind() == SketchArcId:
73       SketchArc = SubFeature
74       anArcList.append(SubFeature)
75
76 assert(len(anArcList) == 2)
77 assert(idList_after.count(SketchArcId) == 2)
78 assert(idList_after.count(SketchLineId) == 2)
79 # TODO: Verify number of coincidence constraints (should be 4).
80 #       It should be one point-point constraint between arc and line extremities
81 #       but not a pair of point-on-entity constraints
82 assert(idList_after.count(SketchConstraintCoincidenceId) == 5)
83
84 #check arc position intersections of created arc to an additional line
85 SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25)
86 SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25)
87 SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75)
88 SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75)
89
90 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_1.feature(), anArcList)
91 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_2.feature(), anArcList)
92 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_3.feature(), anArcList)
93 Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_4.feature(), anArcList)
94
95 assert(len(Intersection_Points_1) == 1)
96 assert(len(Intersection_Points_2) == 0)
97 assert(len(Intersection_Points_3) == 1)
98 assert(len(Intersection_Points_4) == 0)
99
100 #add point for check
101 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
102 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
103 Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList)
104 assert(len(Intersection_Points_5) == 0)
105
106 model.end()
107
108 assert(model.checkPythonDump())