Salome HOME
c8fd1044a25803ce5780008c5eb1862459f138bc
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimArc05.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 # Test of inverted Arc
25 SketchArc = Sketch.addArc(50, 50, 50, 70, 30, 50, True)
26 SketchLine_1 = Sketch.addLine(50, 20, 100, 20)
27 SketchLine_2 = Sketch.addLine(100, 20, 70, 50)
28 SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40)
29
30 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchArc.results()[1])
31 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchArc.results()[1])
32 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
33
34 Sketch_features = featureToCompositeFeature(Sketch.feature())
35 assert (Sketch_features.numberOfSubs() == 7)
36
37 Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()]))
38 assert(len(Arc_Points) == 2)
39
40 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
41
42 Sketch_features = featureToCompositeFeature(Sketch.feature())
43 assert (Sketch_features.numberOfSubs() == 6)
44
45 assert (len(Arc_Points) == 2)
46 if Arc_Points[0].x() < Arc_Points[1].x():
47   GeomPoint = Arc_Points[0]
48 else:
49   GeomPoint = Arc_Points[1]
50
51 #check number of features before trim
52 Sketch_feature = featureToCompositeFeature(Sketch.feature())
53 idList_before = []
54 for index in range(Sketch_feature.numberOfSubs()):
55   idList_before.append(Sketch_feature.subFeature(index).getKind())
56
57 assert(idList_before.count(SketchArcId) == 1)
58 assert(idList_before.count(SketchLineId) == 2)
59 assert(idList_before.count(SketchConstraintCoincidenceId) == 3)
60
61 #perform trim
62 SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint))
63 SketchTrim.execute()
64 model.do()
65
66 #check number of features after trim
67 SketchFeatures = featureToCompositeFeature(Sketch.feature())
68 idList_after = []
69 anArcList = FeatureList()
70 for SubIndex in range(SketchFeatures.numberOfSubs()):
71     SubFeature = SketchFeatures.subFeature(SubIndex)
72     idList_after.append(SubFeature.getKind())
73     if SubFeature.getKind() == SketchArcId:
74       SketchArc = SubFeature
75       anArcList.append(SubFeature)
76
77 assert(len(anArcList) == 1)
78 assert(idList_after.count(SketchArcId) == 1)
79 assert(idList_after.count(SketchLineId) == 2)
80 assert(idList_after.count(SketchConstraintCoincidenceId) == 3)
81
82 #check arc position intersections of created arc to an additional line
83 SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25)
84 SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25)
85 SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75)
86 SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75)
87
88 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_1.feature(), anArcList)
89 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_2.feature(), anArcList)
90 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_3.feature(), anArcList)
91 Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_4.feature(), anArcList)
92
93 assert(len(Intersection_Points_1) == 0)
94 assert(len(Intersection_Points_2) == 1)
95 assert(len(Intersection_Points_3) == 1)
96 assert(len(Intersection_Points_4) == 0)
97
98 #add point for check
99 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
100 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
101 Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList)
102 assert(len(Intersection_Points_5) == 0)
103
104 model.end()
105
106 assert(model.checkPythonDump())