Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimCircle05.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 SketchPointId = 'SketchPoint'
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 SketchPoint_1 = Sketch.addPoint(70, 50)
26 SketchPoint_2 = Sketch.addPoint(30, 50)
27 SketchPoint_3 = Sketch.addPoint(50, 70)
28 SketchPoint_4 = Sketch.addPoint(50, 30)
29
30 #coincidence point to circle
31 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchPoint_1.results()[0], SketchCircle.results()[1])
32 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchPoint_2.results()[0], SketchCircle.results()[1])
33
34 #coincidence circle to point
35 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchCircle.results()[1], SketchPoint_3.results()[0])
36 SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchCircle.results()[1], SketchPoint_4.results()[0])
37
38 Sketch_features = featureToCompositeFeature(Sketch.feature())
39 assert (Sketch_features.numberOfSubs() == 9)
40 #intersection points on circle to prepare a trim selection point
41 SketchLine_intersecting = Sketch.addLine(10, 60, 90, 60)
42 Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()]))
43 assert(len(Circle_Points) == 2)
44 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
45 Sketch_features = featureToCompositeFeature(Sketch.feature())
46 assert (Sketch_features.numberOfSubs() == 9)
47
48 assert (len(Circle_Points) == 2)
49 if Circle_Points[0].x() < Circle_Points[1].x():
50   GeomPoint = Circle_Points[0]
51 else:
52   GeomPoint = Circle_Points[1]
53
54 #check number of features before trim
55 Sketch_feature = featureToCompositeFeature(Sketch.feature())
56 idList_before = []
57 for index in range(Sketch_feature.numberOfSubs()):
58   idList_before.append(Sketch_feature.subFeature(index).getKind())
59
60 assert(idList_before.count(SketchCircleId) == 1)
61 assert(idList_before.count(SketchArcId) == 0)
62 assert(idList_before.count(SketchPointId) == 4)
63 assert(idList_before.count(SketchConstraintCoincidenceId) == 4)
64
65 #perform trim
66 SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint))
67 SketchTrim.execute()
68 model.do()
69
70 #check number of features after trim
71 SketchFeatures = featureToCompositeFeature(Sketch.feature())
72 idList_after = []
73 for SubIndex in range(SketchFeatures.numberOfSubs()):
74     SubFeature = SketchFeatures.subFeature(SubIndex)
75     idList_after.append(SubFeature.getKind())
76     if SubFeature.getKind() == SketchArcId:
77       SketchArc = SubFeature
78
79 assert(idList_after.count(SketchCircleId) == 0)
80 assert(idList_after.count(SketchArcId) == 1)
81 assert(idList_after.count(SketchPointId) == 4)
82 assert(idList_after.count(SketchConstraintCoincidenceId) == 4)
83
84
85 #check arc position intersections of created arc to an additional line
86 SketchLine_intersecting_1 = Sketch.addLine(0, 0, 100, 100)
87 SketchLine_intersecting_2 = Sketch.addLine(0, 100, 100, 0)
88
89 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()]))
90 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()]))
91
92 assert(len(Intersection_Points_1) == 2)
93 assert(len(Intersection_Points_2) == 1)
94
95 #add point for check
96 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
97 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
98 assert(len(Intersection_Points_3) == 0)
99
100 model.end()
101
102 assert(model.checkPythonDump())