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