Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimCircleAndArc01.py
1 ## Copyright (C) 2014-2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 from salome.shaper import model
22
23 from ModelAPI import *
24 from GeomDataAPI import *
25 from ModelGeomAlgo import ModelGeomAlgo_Point2D
26 from salome.shaper import geom
27 import math
28
29 TOLERANCE = 1.e-7
30
31 SketchLineId = 'SketchLine'
32 SketchArcId = 'SketchArc'
33 SketchCircleId = 'SketchCircle'
34 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
35
36 aSession = ModelAPI_Session.get()
37 model.begin()
38 partSet = model.moduleDocument()
39 Part = model.addPart(partSet)
40 Part_doc = Part.document()
41
42 # Test1:begin split on circle with coincident point and intersection line : smaller part
43 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY"))
44 SketchCircle = Sketch.addCircle(50, 50, 20)
45 SketchLine_1 = Sketch.addLine(45, 68, 45, 73)
46 SketchLine_2 = Sketch.addLine(45, 73, 55, 73)
47 SketchLine_3 = Sketch.addLine(55, 73, 55, 68)
48
49 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
50 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
51 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchCircle.results()[1])
52 SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchLine_3.endPoint(), SketchCircle.results()[1])
53
54 SketchLine_4 = Sketch.addLine(68, 45, 73, 45)
55 SketchLine_5 = Sketch.addLine(73, 45, 73, 55)
56 SketchLine_6 = Sketch.addLine(73, 55, 68, 55)
57
58 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
59 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
60 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_4.startPoint(), SketchCircle.results()[1])
61 SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchLine_6.endPoint(), SketchCircle.results()[1])
62
63
64 Sketch_features = featureToCompositeFeature(Sketch.feature())
65 assert (Sketch_features.numberOfSubs() == 15)
66 #intersection points on circle to prepare a trim selection point
67 #first intersection point - vertical
68 SketchLine_intersecting = Sketch.addLine(48, 10, 48, 90)
69 Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()]))
70 assert(len(Circle_Points) == 2)
71 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
72 Sketch_features = featureToCompositeFeature(Sketch.feature())
73 assert (Sketch_features.numberOfSubs() == 15)
74
75 assert (len(Circle_Points) == 2)
76 GeomPoint = Circle_Points[1]
77 if Circle_Points[0].y() < Circle_Points[1].y():
78   GeomPoint = Circle_Points[1]
79 else:
80   GeomPoint = Circle_Points[0]
81
82 #check number of features before trim
83 Sketch_feature = featureToCompositeFeature(Sketch.feature())
84 idList_before = []
85 for index in range(Sketch_feature.numberOfSubs()):
86   idList_before.append(Sketch_feature.subFeature(index).getKind())
87
88 assert(idList_before.count(SketchCircleId) == 1)
89 assert(idList_before.count(SketchArcId) == 0)
90 assert(idList_before.count(SketchLineId) == 6)
91 assert(idList_before.count(SketchConstraintCoincidenceId) == 8)
92
93 #perform trim: vertical
94 SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint))
95 SketchTrim.execute()
96 model.do()
97
98 #check number of features after trim
99 SketchFeatures = featureToCompositeFeature(Sketch.feature())
100 idList_after = []
101 for SubIndex in range(SketchFeatures.numberOfSubs()):
102     SubFeature = SketchFeatures.subFeature(SubIndex)
103     idList_after.append(SubFeature.getKind())
104     if SubFeature.getKind() == SketchArcId:
105       SketchArc = SubFeature
106
107 assert(idList_after.count(SketchCircleId) == 0)
108 assert(idList_after.count(SketchArcId) == 1)
109 assert(idList_after.count(SketchLineId) == 6)
110 assert(idList_after.count(SketchConstraintCoincidenceId) == 8)
111
112
113 #add point for check
114 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
115 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
116 assert(len(Intersection_Points_3) == 0)
117
118 #perform trim: horizontal
119 #second intersection point - horizontal
120 SketchLine_intersecting_h = Sketch.addLine(10, 48, 72, 48)
121 Circle_Points_h = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_h.feature()]))
122 assert(len(Circle_Points_h) == 2)
123 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting_h.feature()]))
124 Sketch_features = featureToCompositeFeature(Sketch.feature())
125 assert (Sketch_features.numberOfSubs() == 16)
126
127 assert (len(Circle_Points_h) == 2)
128 GeomPoint = Circle_Points_h[1]
129 if Circle_Points_h[0].x() < Circle_Points_h[1].x():
130   GeomPoint_h = Circle_Points_h[1]
131 else:
132   GeomPoint_h = Circle_Points_h[0]
133
134
135 SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint_h))
136 SketchTrim.execute()
137 model.do()
138
139 #check number of features after trim
140 SketchFeatures = featureToCompositeFeature(Sketch.feature())
141 idList_after = []
142 anArcList = FeatureList()
143 for SubIndex in range(SketchFeatures.numberOfSubs()):
144     SubFeature = SketchFeatures.subFeature(SubIndex)
145     idList_after.append(SubFeature.getKind())
146     if SubFeature.getKind() == SketchArcId:
147       anArcList.append(SubFeature)
148
149 assert(len(anArcList) == 2)
150
151 assert(idList_after.count(SketchCircleId) == 0)
152 assert(idList_after.count(SketchArcId) == 2)
153 assert(idList_after.count(SketchLineId) == 6)
154 assert(idList_after.count(SketchConstraintCoincidenceId) == 9)
155
156
157 #add point for check
158 SketchPoint = Sketch.addPoint(GeomPoint_h.x(), GeomPoint_h.y())
159 Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList)
160 assert(len(Intersection_Points_5) == 0)
161
162
163 model.end()
164
165 assert(model.checkPythonDump())