Salome HOME
4aea784887edccc81d1190ad572d846972c59ece
[modules/shaper.git] / src / SketchPlugin / Test / TestSplit.py
1 # Copyright (C) 2014-2021  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 ModelGeomAlgo import ModelGeomAlgo_Point2D
24 from salome.shaper import geom
25
26 SketchPointId = 'SketchPoint'
27 SketchLineId = 'SketchLine'
28 SketchArcId = 'SketchArc'
29 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
30 SketchConstraintParallelId = 'SketchConstraintParallel'
31 SketchConstraintTangentId = 'SketchConstraintTangent'
32 SketchConstraintEqualId = 'SketchConstraintEqual'
33
34 # Test split on line with one point
35 model.begin()
36 partSet = model.moduleDocument()
37 Part_1 = model.addPart(partSet)
38 Part_1_doc = Part_1.document()
39 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
40 SketchLine_1 = Sketch_1.addLine(0, 50, 100, 50)
41 SketchPoint_1 = Sketch_1.addPoint(50, 50)
42 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchLine_1.result())
43 GeomPoint = geom.Pnt2d(20, 50)
44 Sketch_1.addSplit(SketchLine_1, GeomPoint)
45 model.do()
46
47 Sketch_1_feature = featureToCompositeFeature(Sketch_1.feature())
48 idList = []
49 for index in range(Sketch_1_feature.numberOfSubs()):
50   idList.append(Sketch_1_feature.subFeature(index).getKind())
51
52 assert(idList.count(SketchLineId) == 2)
53 assert(idList.count(SketchPointId) == 1)
54 assert(idList.count(SketchConstraintCoincidenceId) == 3)
55 assert(idList.count(SketchConstraintParallelId) == 0)
56 # Test end
57
58 # Test split on line with two points
59 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
60 SketchLine_2_1 = Sketch_2.addLine(0, 50, 100, 50)
61 SketchPoint_2_1 = Sketch_2.addPoint(25, 50)
62 SketchPoint_2_2 = Sketch_2.addPoint(75, 50)
63 SketchConstraintCoincidence_2_1 = Sketch_2.setCoincident(SketchPoint_2_1.coordinates(), SketchLine_2_1.result())
64 SketchConstraintCoincidence_2_2 = Sketch_2.setCoincident(SketchPoint_2_2.coordinates(), SketchLine_2_1.result())
65 GeomPoint = geom.Pnt2d(40, 50)
66 Sketch_2.addSplit(SketchLine_2_1, GeomPoint)
67 model.do()
68
69 Sketch_2_feature = featureToCompositeFeature(Sketch_2.feature())
70 idList = []
71 for index in range(Sketch_2_feature.numberOfSubs()):
72   idList.append(Sketch_2_feature.subFeature(index).getKind())
73
74 assert(idList.count(SketchLineId) == 3)
75 assert(idList.count(SketchPointId) == 2)
76 assert(idList.count(SketchConstraintCoincidenceId) == 6)
77 assert(idList.count(SketchConstraintParallelId) == 0)
78 # Test end
79
80 # Test split on circle with two points
81 Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
82 SketchCircle_3_1 = Sketch_3.addCircle(50, 50, 50)
83 SketchPoint_3_1 = Sketch_3.addPoint(50, 0)
84 SketchPoint_3_2 = Sketch_3.addPoint(50, 100)
85 SketchConstraintCoincidence_3_1 = Sketch_3.setCoincident(SketchPoint_3_1.coordinates(), SketchCircle_3_1.results()[1])
86 SketchConstraintCoincidence_3_2 = Sketch_3.setCoincident(SketchPoint_3_2.coordinates(), SketchCircle_3_1.results()[1])
87 GeomPoint = geom.Pnt2d(0, 50)
88 Sketch_3.addSplit(SketchCircle_3_1, GeomPoint)
89 model.do()
90
91 Sketch_3_feature = featureToCompositeFeature(Sketch_3.feature())
92 idList = []
93 for index in range(Sketch_3_feature.numberOfSubs()):
94   idList.append(Sketch_3_feature.subFeature(index).getKind())
95
96 assert(idList.count(SketchArcId) == 2)
97 assert(idList.count(SketchPointId) == 2)
98 assert(idList.count(SketchConstraintCoincidenceId) == 6)
99 assert(idList.count(SketchConstraintTangentId) == 0)
100 # Test end
101
102 # Test split on arc with one point
103 Sketch_4 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
104 SketchArc_4_1 = Sketch_4.addArc(50, 50, 50, 0, 0, 50, False)
105 Sketch_4.setFixed(SketchArc_4_1.startPoint())
106 Sketch_4.setFixed(SketchArc_4_1.endPoint())
107 Sketch_4.setRadius(SketchArc_4_1, 50)
108 SketchPoint_4_1 = Sketch_4.addPoint(50, 100)
109 SketchConstraintCoincidence_4_1 = Sketch_4.setCoincident(SketchPoint_4_1.coordinates(), SketchArc_4_1.results()[1])
110 # prepare point on circle
111 SketchLine_intersecting = Sketch_4.addLine(0, 100, 50, 50)
112 Intersection_Point = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc_4_1.feature(), FeatureList([SketchLine_intersecting.feature()]))
113 removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
114 Intersection_GeomPoint = Intersection_Point[0]
115 Sketch_4.addSplit(SketchArc_4_1, Sketch_1.to2D(Intersection_GeomPoint))
116 model.do()
117
118 Sketch_4_feature = featureToCompositeFeature(Sketch_4.feature())
119 idList = []
120 for index in range(Sketch_4_feature.numberOfSubs()):
121   idList.append(Sketch_4_feature.subFeature(index).getKind())
122
123 assert(idList.count(SketchArcId) == 2)
124 assert(idList.count(SketchPointId) == 1)
125 assert(idList.count(SketchConstraintCoincidenceId) == 3)
126 assert(idList.count(SketchConstraintEqualId) == 0)
127 assert(idList.count(SketchConstraintTangentId) == 0)
128 # Test end
129
130 # Test split on arc with two points
131 Sketch_5 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
132 SketchArc_5_1 = Sketch_5.addArc(50, 50, 93.30127018922, 75, 0, 50, False)
133 Sketch_5.setFixed(SketchArc_5_1.startPoint())
134 Sketch_5.setFixed(SketchArc_5_1.endPoint())
135 Sketch_5.setRadius(SketchArc_5_1, 50)
136 SketchLine_5_1 = Sketch_5.addLine(25, 93.301270189222, 75, 93.301270189222)
137 SketchConstraintCoincidence_5_1 = Sketch_5.setCoincident(SketchLine_5_1.startPoint(), SketchArc_5_1.results()[1])
138 SketchConstraintCoincidence_5_2 = Sketch_5.setCoincident(SketchLine_5_1.endPoint(), SketchArc_5_1.results()[1])
139 SketchConstraintHorizontal_5_1 = Sketch_5.setHorizontal(SketchLine_5_1.result())
140 SketchConstraintLength_5_1 = Sketch_5.setLength(SketchLine_5_1.result(), 50)
141 GeomPoint = geom.Pnt2d(50, 100)
142 Sketch_5.addSplit(SketchArc_5_1, GeomPoint)
143 model.do()
144
145 Sketch_5_feature = featureToCompositeFeature(Sketch_5.feature())
146 idList = []
147 for index in range(Sketch_5_feature.numberOfSubs()):
148   idList.append(Sketch_5_feature.subFeature(index).getKind())
149
150 assert(idList.count(SketchArcId) == 3)
151 assert(idList.count(SketchPointId) == 0)
152 assert(idList.count(SketchConstraintCoincidenceId) == 6)
153 assert(idList.count(SketchConstraintEqualId) == 0)
154 assert(idList.count(SketchConstraintTangentId) == 0)
155 # Test end
156
157 model.end()
158
159 assert(model.checkPythonDump())