Salome HOME
Added MultiRotation feature (parametric API).
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimCircle04.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 GeomPoint = Circle_Points[1]
45 if Circle_Points[0].x() < Circle_Points[1].x():
46   GeomPoint = Circle_Points[1]
47 else:
48   GeomPoint = Circle_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(SketchCircleId) == 1)
57 assert(idList_before.count(SketchArcId) == 0)
58 assert(idList_before.count(SketchLineId) == 2)
59 assert(idList_before.count(SketchConstraintCoincidenceId) == 3)
60
61 #perform trim
62 SketchTrim = Sketch.addTrim(SketchCircle, 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 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
75 assert(idList_after.count(SketchCircleId) == 0)
76 assert(idList_after.count(SketchArcId) == 1)
77 assert(idList_after.count(SketchLineId) == 2)
78 assert(idList_after.count(SketchConstraintCoincidenceId) == 3)
79
80
81 #check arc position intersections of created arc to an additional line
82 SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50)
83 SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100)
84
85 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()]))
86 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()]))
87
88 assert(len(Intersection_Points_1) == 1)
89 assert(len(Intersection_Points_2) == 0)
90
91 #add point for check
92 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
93 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
94 assert(len(Intersection_Points_3) == 0)
95
96 model.end()
97
98 #assert(model.checkPythonDump())