Salome HOME
4bd2df34e3ffe0e9e8da0d6d970933af286e5263
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimCircleAndArc01.py
1 # Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from salome.shaper import model
21
22 from ModelAPI import *
23 from GeomDataAPI import *
24 from ModelGeomAlgo import ModelGeomAlgo_Point2D
25 from salome.shaper import geom
26 import math
27
28 TOLERANCE = 1.e-7
29
30 SketchLineId = 'SketchLine'
31 SketchArcId = 'SketchArc'
32 SketchCircleId = 'SketchCircle'
33 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
34
35 aSession = ModelAPI_Session.get()
36 model.begin()
37 partSet = model.moduleDocument()
38 Part = model.addPart(partSet)
39 Part_doc = Part.document()
40
41 # Test1:begin split on circle with coincident point and intersection line : smaller part
42 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY"))
43 SketchCircle = Sketch.addCircle(50, 50, 20)
44 SketchLine_1 = Sketch.addLine(45, 68, 45, 73)
45 SketchLine_2 = Sketch.addLine(45, 73, 55, 73)
46 SketchLine_3 = Sketch.addLine(55, 73, 55, 68)
47
48 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
49 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
50 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchCircle.results()[1])
51 SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchLine_3.endPoint(), SketchCircle.results()[1])
52
53 SketchLine_4 = Sketch.addLine(68, 45, 73, 45)
54 SketchLine_5 = Sketch.addLine(73, 45, 73, 55)
55 SketchLine_6 = Sketch.addLine(73, 55, 68, 55)
56
57 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
58 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
59 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_4.startPoint(), SketchCircle.results()[1])
60 SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchLine_6.endPoint(), SketchCircle.results()[1])
61
62
63 Sketch_features = featureToCompositeFeature(Sketch.feature())
64 assert (Sketch_features.numberOfSubs() == 15)
65 #intersection points on circle to prepare a trim selection point
66 #first intersection point - vertical
67 SketchLine_intersecting = Sketch.addLine(48, 10, 48, 90)
68 Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()]))
69 assert(len(Circle_Points) == 2)
70 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
71 Sketch_features = featureToCompositeFeature(Sketch.feature())
72 assert (Sketch_features.numberOfSubs() == 15)
73
74 assert (len(Circle_Points) == 2)
75 GeomPoint = Circle_Points[1]
76 if Circle_Points[0].y() < Circle_Points[1].y():
77   GeomPoint = Circle_Points[1]
78 else:
79   GeomPoint = Circle_Points[0]
80
81 #check number of features before trim
82 Sketch_feature = featureToCompositeFeature(Sketch.feature())
83 idList_before = []
84 for index in range(Sketch_feature.numberOfSubs()):
85   idList_before.append(Sketch_feature.subFeature(index).getKind())
86
87 assert(idList_before.count(SketchCircleId) == 1)
88 assert(idList_before.count(SketchArcId) == 0)
89 assert(idList_before.count(SketchLineId) == 6)
90 assert(idList_before.count(SketchConstraintCoincidenceId) == 8)
91
92 #perform trim: vertical
93 SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint))
94 SketchTrim.execute()
95 model.do()
96
97 #check number of features after trim
98 SketchFeatures = featureToCompositeFeature(Sketch.feature())
99 idList_after = []
100 for SubIndex in range(SketchFeatures.numberOfSubs()):
101     SubFeature = SketchFeatures.subFeature(SubIndex)
102     idList_after.append(SubFeature.getKind())
103     if SubFeature.getKind() == SketchArcId:
104       SketchArc = SubFeature
105
106 assert(idList_after.count(SketchCircleId) == 0)
107 assert(idList_after.count(SketchArcId) == 1)
108 assert(idList_after.count(SketchLineId) == 6)
109 assert(idList_after.count(SketchConstraintCoincidenceId) == 8)
110
111
112 #add point for check
113 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
114 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
115 assert(len(Intersection_Points_3) == 0)
116
117 #perform trim: horizontal
118 #second intersection point - horizontal
119 SketchLine_intersecting_h = Sketch.addLine(10, 48, 72, 48)
120 Circle_Points_h = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_h.feature()]))
121 assert(len(Circle_Points_h) == 2)
122 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting_h.feature()]))
123 Sketch_features = featureToCompositeFeature(Sketch.feature())
124 assert (Sketch_features.numberOfSubs() == 16)
125
126 assert (len(Circle_Points_h) == 2)
127 GeomPoint = Circle_Points_h[1]
128 if Circle_Points_h[0].x() < Circle_Points_h[1].x():
129   GeomPoint_h = Circle_Points_h[1]
130 else:
131   GeomPoint_h = Circle_Points_h[0]
132
133
134 SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint_h))
135 SketchTrim.execute()
136 model.do()
137
138 #check number of features after trim
139 SketchFeatures = featureToCompositeFeature(Sketch.feature())
140 idList_after = []
141 anArcList = FeatureList()
142 for SubIndex in range(SketchFeatures.numberOfSubs()):
143     SubFeature = SketchFeatures.subFeature(SubIndex)
144     idList_after.append(SubFeature.getKind())
145     if SubFeature.getKind() == SketchArcId:
146       anArcList.append(SubFeature)
147
148 assert(len(anArcList) == 2)
149
150 assert(idList_after.count(SketchCircleId) == 0)
151 assert(idList_after.count(SketchArcId) == 2)
152 assert(idList_after.count(SketchLineId) == 6)
153 assert(idList_after.count(SketchConstraintCoincidenceId) == 9)
154
155
156 #add point for check
157 SketchPoint = Sketch.addPoint(GeomPoint_h.x(), GeomPoint_h.y())
158 Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList)
159 assert(len(Intersection_Points_5) == 0)
160
161
162 model.end()
163
164 assert(model.checkPythonDump())