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