]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/Test1673.py
Salome HOME
4caa894e70e0d405f94c3f3ad2a3904e1734c7f3
[modules/shaper.git] / src / SketchPlugin / Test / Test1673.py
1 # Copyright (C) 2014-2020  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 """
21     Test1673.py
22     Test case for issue #1673 "Drag and drop the extremity of an arc is too slow"
23 """
24
25 from salome.shaper import model
26 from timeit import default_timer as timer
27 import math
28
29 # convenient ratio of time moving point to time creating sketch
30 MOVE_BUILD_RATIO = 0.1
31 # tolerance for comparison of reals
32 TOLERANCE = 1.e-7
33
34 model.begin()
35 partSet = model.moduleDocument()
36 Part_1 = model.addPart(partSet)
37 Part_1_doc = Part_1.document()
38 model.addParameter(Part_1_doc, "ep_jupe", "0.188")
39 model.addParameter(Part_1_doc, "width_gallery", "1.5")
40 model.addParameter(Part_1_doc, "h_bas_dome", "9.025")
41 model.addParameter(Part_1_doc, "r_dome", "9.794")
42 model.addParameter(Part_1_doc, "demi_ep_dome", "0.082")
43
44 # time to build sketch
45 sketchTime = timer()
46
47 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
48 SketchLine_1 = Sketch_1.addLine(-6.538, -3.45, -7.782, -3.45)
49 SketchLine_1.setName("SketchLine_2")
50 SketchLine_1.result().setName("SketchLine_2")
51 SketchLine_2 = Sketch_1.addLine(-7.782, -3.45, -7.782, -6.45)
52 SketchLine_2.setName("SketchLine_3")
53 SketchLine_2.result().setName("SketchLine_3")
54 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
55 SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_2")
56 SketchLine_3 = Sketch_1.addLine(-7.782, -6.45, 0, -6.45)
57 SketchLine_3.setName("SketchLine_4")
58 SketchLine_3.result().setName("SketchLine_4")
59 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
60 SketchConstraintCoincidence_2.setName("SketchConstraintCoincidence_3")
61 SketchLine_4 = Sketch_1.addLine(0, -6.45, 0, -3.45)
62 SketchLine_4.setName("SketchLine_5")
63 SketchLine_4.result().setName("SketchLine_5")
64 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
65 SketchConstraintCoincidence_3.setName("SketchConstraintCoincidence_4")
66 SketchLine_5 = Sketch_1.addLine(0, -3.45, -6.188, -3.45)
67 SketchLine_5.setName("SketchLine_6")
68 SketchLine_5.result().setName("SketchLine_6")
69 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
70 SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_5")
71 SketchLine_6 = Sketch_1.addLine(-6.188, -3.45, -6.188, 9.025)
72 SketchLine_6.setName("SketchLine_7")
73 SketchLine_6.result().setName("SketchLine_7")
74 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
75 SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_6")
76 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_5.result())
77 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_1.result())
78 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_3.result())
79 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_6.result())
80 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_2.result())
81 SketchConstraintVertical_2.setName("SketchConstraintVertical_3")
82 SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_4.result())
83 SketchConstraintVertical_3.setName("SketchConstraintVertical_4")
84 SketchLine_7 = Sketch_1.addLine(-6.376, 9.025, -6.376, -2.25)
85 SketchLine_7.setName("SketchLine_8")
86 SketchLine_7.result().setName("SketchLine_8")
87 SketchLine_8 = Sketch_1.addLine(-6.376, -2.25, -6.538, -2.4)
88 SketchLine_8.setName("SketchLine_9")
89 SketchLine_8.result().setName("SketchLine_9")
90 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
91 SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_7")
92 SketchLine_9 = Sketch_1.addLine(-6.538, -2.4, -6.538, -3.45)
93 SketchLine_9.setName("SketchLine_10")
94 SketchLine_9.result().setName("SketchLine_10")
95 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint())
96 SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_8")
97 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_9.endPoint())
98 SketchConstraintCoincidence_8.setName("SketchConstraintCoincidence_9")
99 SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_7.result())
100 SketchConstraintVertical_4.setName("SketchConstraintVertical_5")
101 SketchConstraintVertical_5 = Sketch_1.setVertical(SketchLine_9.result())
102 SketchConstraintVertical_5.setName("SketchConstraintVertical_6")
103 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_4.result(), SketchLine_2.result())
104 SketchPoint_1 = Sketch_1.addPoint(model.selection("VERTEX", "PartSet/Origin"))
105 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchPoint_1.coordinates(), SketchLine_5.result(), 3.45)
106 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchPoint_1.coordinates(), SketchLine_6.result(), 6.188)
107 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchLine_6.startPoint(), SketchLine_9.result(), 0.35)
108 SketchConstraintDistance_3.setName("SketchConstraintDistance_4")
109 SketchConstraintDistance_4 = Sketch_1.setDistance(SketchLine_6.startPoint(), SketchLine_7.result(), "ep_jupe")
110 SketchConstraintDistance_4.setName("SketchConstraintDistance_5")
111 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_4.result(), 3)
112 SketchLine_10 = Sketch_1.addLine(-6.282, 0.5300728101808314, -6.282, -4.926040141145169)
113 SketchLine_10.setName("SketchLine_11")
114 SketchLine_10.result().setName("SketchLine_11")
115 SketchLine_10.setAuxiliary(True)
116 SketchConstraintVertical_6 = Sketch_1.setVertical(SketchLine_10.result())
117 SketchConstraintVertical_6.setName("SketchConstraintVertical_7")
118 SketchConstraintDistance_5 = Sketch_1.setDistance(SketchLine_6.startPoint(), SketchLine_10.result(), "ep_jupe/2")
119 SketchConstraintDistance_5.setName("SketchConstraintDistance_6")
120 SketchLine_11 = Sketch_1.addLine(-5.532, -4.05, -7.032, -4.05)
121 SketchLine_11.setName("SketchLine_12")
122 SketchLine_11.result().setName("SketchLine_12")
123 SketchLine_12 = Sketch_1.addLine(-7.032, -4.05, -7.032, -5.85)
124 SketchLine_12.setName("SketchLine_13")
125 SketchLine_12.result().setName("SketchLine_13")
126 SketchLine_13 = Sketch_1.addLine(-7.032, -5.85, -5.532, -5.85)
127 SketchLine_13.setName("SketchLine_14")
128 SketchLine_13.result().setName("SketchLine_14")
129 SketchLine_14 = Sketch_1.addLine(-5.532, -5.85, -5.532, -4.05)
130 SketchLine_14.setName("SketchLine_15")
131 SketchLine_14.result().setName("SketchLine_15")
132 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_14.endPoint(), SketchLine_11.startPoint())
133 SketchConstraintCoincidence_9.setName("SketchConstraintCoincidence_10")
134 SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_12.startPoint())
135 SketchConstraintCoincidence_10.setName("SketchConstraintCoincidence_11")
136 SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchLine_13.startPoint())
137 SketchConstraintCoincidence_11.setName("SketchConstraintCoincidence_12")
138 SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_13.endPoint(), SketchLine_14.startPoint())
139 SketchConstraintCoincidence_12.setName("SketchConstraintCoincidence_13")
140 SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_11.result())
141 SketchConstraintVertical_7 = Sketch_1.setVertical(SketchLine_12.result())
142 SketchConstraintVertical_7.setName("SketchConstraintVertical_8")
143 SketchConstraintHorizontal_5 = Sketch_1.setHorizontal(SketchLine_13.result())
144 SketchConstraintVertical_8 = Sketch_1.setVertical(SketchLine_14.result())
145 SketchConstraintVertical_8.setName("SketchConstraintVertical_9")
146 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_13.result(), "width_gallery")
147 SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_14.result(), 1.8)
148 SketchConstraintDistance_6 = Sketch_1.setDistance(SketchLine_11.startPoint(), SketchLine_10.result(), "width_gallery/2")
149 SketchConstraintDistance_6.setName("SketchConstraintDistance_7")
150 SketchConstraintDistance_7 = Sketch_1.setDistance(SketchLine_12.startPoint(), SketchLine_1.result(), 0.6)
151 SketchConstraintDistance_7.setName("SketchConstraintDistance_8")
152 SketchConstraintDistance_8 = Sketch_1.setDistance(SketchLine_2.startPoint(), SketchLine_10.result(), "width_gallery")
153 SketchConstraintDistance_8.setName("SketchConstraintDistance_9")
154 SketchLine_15 = Sketch_1.addLine(model.selection("VERTEX", "PartSet/OZ"))
155 SketchLine_15.setName("Axis_Z")
156 SketchLine_15.result().setName("Axis_Z")
157 SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchLine_5.startPoint(), SketchLine_15.result())
158 SketchConstraintCoincidence_13.setName("SketchConstraintCoincidence_14")
159 SketchLine_16 = Sketch_1.addLine(model.selection("VERTEX", "PartSet/OX"))
160 SketchLine_16.setName("Axis_X")
161 SketchLine_16.result().setName("Axis_X")
162 SketchConstraintDistance_9 = Sketch_1.setDistance(SketchLine_8.startPoint(), SketchLine_16.result(), 2.25)
163 SketchConstraintDistance_9.setName("SketchConstraintDistance_10")
164 SketchLine_17 = Sketch_1.addLine(-6.376, -2.25, -7.479754760955, -2.25)
165 SketchLine_17.setAuxiliary(True)
166 SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_17.startPoint())
167 SketchConstraintCoincidence_14.setName("SketchConstraintCoincidence_15")
168 SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchLine_8.startPoint(), SketchLine_17.startPoint())
169 SketchConstraintCoincidence_15.setName("SketchConstraintCoincidence_16")
170 SketchConstraintHorizontal_6 = Sketch_1.setHorizontal(SketchLine_17.result())
171 SketchConstraintDistance_10 = Sketch_1.setDistance(SketchLine_9.startPoint(), SketchLine_17.result(), 0.15)
172 SketchConstraintDistance_10.setName("SketchConstraintDistance_11")
173 SketchConstraintDistance_11 = Sketch_1.setDistance(SketchLine_6.endPoint(), SketchLine_16.result(), "h_bas_dome")
174 SketchConstraintDistance_11.setName("SketchConstraintDistance_12")
175 SketchConstraintDistance_12 = Sketch_1.setDistance(SketchLine_7.startPoint(), SketchLine_16.result(), "h_bas_dome")
176 SketchConstraintDistance_12.setName("SketchConstraintDistance_13")
177 SketchLine_18 = Sketch_1.addLine(-6.188, 9.025, -6.082, 9.532)
178 SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_18.startPoint())
179 SketchConstraintCoincidence_16.setName("SketchConstraintCoincidence_17")
180 SketchLine_19 = Sketch_1.addLine(-6.376, 9.025, -6.538, 9.187)
181 SketchConstraintCoincidence_17 = Sketch_1.setCoincident(SketchLine_7.startPoint(), SketchLine_19.startPoint())
182 SketchConstraintCoincidence_17.setName("SketchConstraintCoincidence_18")
183 SketchLine_20 = Sketch_1.addLine(-6.538, 9.187, -6.538, 10.256)
184 SketchConstraintCoincidence_18 = Sketch_1.setCoincident(SketchLine_19.endPoint(), SketchLine_20.startPoint())
185 SketchConstraintCoincidence_18.setName("SketchConstraintCoincidence_19")
186 SketchLine_21 = Sketch_1.addLine(-6.538, 10.256, -6.188, 10.256)
187 SketchConstraintCoincidence_19 = Sketch_1.setCoincident(SketchLine_20.endPoint(), SketchLine_21.startPoint())
188 SketchConstraintCoincidence_19.setName("SketchConstraintCoincidence_20")
189 SketchConstraintDistance_13 = Sketch_1.setDistance(SketchLine_19.endPoint(), SketchLine_16.result(), 9.187)
190 SketchConstraintDistance_13.setName("SketchConstraintDistance_14")
191 SketchConstraintDistance_14 = Sketch_1.setDistance(SketchLine_6.endPoint(), SketchLine_20.result(), 0.35)
192 SketchConstraintDistance_14.setName("SketchConstraintDistance_15")
193 SketchConstraintVertical_9 = Sketch_1.setVertical(SketchLine_20.result())
194 SketchConstraintVertical_9.setName("SketchConstraintVertical_10")
195 SketchConstraintVertical_10 = Sketch_1.setVertical(SketchLine_20.result())
196 SketchConstraintVertical_10.setName("SketchConstraintVertical_11")
197 SketchLine_22 = Sketch_1.addLine(-6.376, 9.025, -7.650292531, 9.025)
198 SketchLine_22.setAuxiliary(True)
199 SketchConstraintCoincidence_20 = Sketch_1.setCoincident(SketchLine_7.startPoint(), SketchLine_22.startPoint())
200 SketchConstraintCoincidence_20.setName("SketchConstraintCoincidence_21")
201 SketchConstraintCoincidence_21 = Sketch_1.setCoincident(SketchLine_19.startPoint(), SketchLine_22.startPoint())
202 SketchConstraintCoincidence_21.setName("SketchConstraintCoincidence_22")
203 SketchConstraintHorizontal_7 = Sketch_1.setHorizontal(SketchLine_22.result())
204 SketchConstraintHorizontal_8 = Sketch_1.setHorizontal(SketchLine_21.result())
205 SketchLine_23 = Sketch_1.addLine(-6.188, 10.256, -4.938, 10.97786688777511)
206 SketchConstraintCoincidence_22 = Sketch_1.setCoincident(SketchLine_21.endPoint(), SketchLine_23.startPoint())
207 SketchConstraintCoincidence_22.setName("SketchConstraintCoincidence_23")
208 SketchArc_1 = Sketch_1.addArc(0, 2.425, -4.938, 10.97786688777511, 0, 12.301, True)
209 SketchConstraintCoincidence_23 = Sketch_1.setCoincident(SketchArc_1.center(), SketchLine_15.result())
210 SketchConstraintCoincidence_23.setName("SketchConstraintCoincidence_24")
211 SketchConstraintCoincidence_24 = Sketch_1.setCoincident(SketchLine_23.endPoint(), SketchArc_1.startPoint())
212 SketchConstraintCoincidence_24.setName("SketchConstraintCoincidence_25")
213 SketchConstraintCoincidence_25 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_15.result())
214 SketchConstraintCoincidence_25.setName("SketchConstraintCoincidence_26")
215 SketchConstraintDistance_15 = Sketch_1.setDistance(SketchLine_16.result(), SketchArc_1.center(), 2.425)
216 SketchConstraintDistance_15.setName("SketchConstraintDistance_16")
217 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], "r_dome+demi_ep_dome")
218 SketchConstraintLength_4 = Sketch_1.setLength(SketchLine_21.result(), 0.35)
219 SketchLine_24 = Sketch_1.addLine(-4.938, 10.97786688777511, 0, 2.425)
220 SketchLine_24.setAuxiliary(True)
221 SketchConstraintCoincidence_26 = Sketch_1.setCoincident(SketchLine_23.endPoint(), SketchLine_24.startPoint())
222 SketchConstraintCoincidence_26.setName("SketchConstraintCoincidence_27")
223 SketchConstraintCoincidence_27 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_24.startPoint())
224 SketchConstraintCoincidence_27.setName("SketchConstraintCoincidence_28")
225 SketchConstraintCoincidence_28 = Sketch_1.setCoincident(SketchArc_1.center(), SketchLine_24.endPoint())
226 SketchConstraintCoincidence_28.setName("SketchConstraintCoincidence_29")
227 SketchConstraintAngle_1 = Sketch_1.setAngleBackward(SketchLine_24.result(), SketchLine_15.result(), 30)
228 SketchConstraintDistance_16 = Sketch_1.setDistance(SketchLine_20.endPoint(), SketchLine_16.result(), 10.256)
229 SketchConstraintDistance_16.setName("SketchConstraintDistance_17")
230 SketchConstraintDistance_17 = Sketch_1.setDistance(SketchLine_18.endPoint(), SketchLine_16.result(), 9.532)
231 SketchConstraintDistance_17.setName("SketchConstraintDistance_18")
232 SketchConstraintDistance_18 = Sketch_1.setDistance(SketchLine_18.endPoint(), SketchLine_6.result(), 0.106)
233 SketchConstraintDistance_18.setName("SketchConstraintDistance_19")
234 SketchArc_2 = Sketch_1.addArc(-4.79378612024245, 9.263, -6.082, 9.532, -6.022198038184096, 9.735080670922804, True)
235 SketchConstraintCoincidence_29 = Sketch_1.setCoincident(SketchLine_18.endPoint(), SketchArc_2.startPoint())
236 SketchConstraintCoincidence_29.setName("SketchConstraintCoincidence_30")
237 SketchConstraintDistance_19 = Sketch_1.setDistance(SketchArc_2.center(), SketchLine_16.result(), 9.263)
238 SketchConstraintDistance_19.setName("SketchConstraintDistance_20")
239 SketchConstraintRadius_2 = Sketch_1.setRadius(SketchArc_2.results()[1], 1.316)
240 SketchPoint_2 = Sketch_1.addPoint(0, 0)
241 SketchLine_25 = Sketch_1.addLine(-4.79378612024245, 9.263, -4.793786120242411, 9.813514482867)
242 SketchLine_25.setAuxiliary(True)
243 SketchConstraintCoincidence_30 = Sketch_1.setCoincident(SketchArc_2.center(), SketchLine_25.startPoint())
244 SketchConstraintCoincidence_30.setName("SketchConstraintCoincidence_31")
245 SketchConstraintVertical_11 = Sketch_1.setVertical(SketchLine_25.result())
246 SketchConstraintVertical_11.setName("SketchConstraintVertical_12")
247 model.do()
248
249 sketchTime = timer() - sketchTime
250 print("Sketch creation time: {0}".format(sketchTime))
251 expectedTime = MOVE_BUILD_RATIO * sketchTime
252 averageTime = 0
253 nbMoves = 0
254
255 # Two vertical constraints: due to #1889 the sketch is invalid now, not overconstrained
256 from ModelAPI import *
257 aFactory = ModelAPI_Session.get().validators()
258 assert(not aFactory.validate(SketchConstraintVertical_10.feature()))
259 #assert Sketch_1.solverError().value() != "", "FAILED: Sketch should report over-constrained situation"
260
261 # Remove duplicated Vertical constraints
262 Part_1_doc.removeFeature(SketchConstraintVertical_10.feature())
263 model.do()
264 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
265
266 #=========================================================================
267 # Move end point of SketchArc_2
268 #=========================================================================
269 aCenter = SketchArc_2.center()
270 aEndPoint = SketchArc_2.endPoint()
271 aDeltaX = aEndPoint.x() - aCenter.x()
272 aDeltaY = aEndPoint.y() - aCenter.y()
273
274 anAngle = math.pi / 100.
275 aCos = math.cos(anAngle)
276 aSin = math.sin(anAngle)
277
278 for ang in range(0, 50):
279     movementTime = timer()
280     X = aCenter.x() + aDeltaX * aCos + aDeltaY * aSin
281     Y = aCenter.y() - aDeltaX * aSin + aDeltaY * aCos
282     aEndPoint.setValue(X, Y)
283     model.do()
284     movementTime = timer() - movementTime
285     assert movementTime < expectedTime, "Time to move point {0} is greater than expected {1}".format(movementTime, expectedTime)
286     assert math.fabs(aEndPoint.x() - X) < TOLERANCE and math.fabs(aEndPoint.y() - Y) < TOLERANCE, "({0}, {1}) != ({2}, {3})".format(aEndPoint.x(), aEndPoint.y(), X, Y)
287     averageTime += movementTime
288     nbMoves += 1
289     aDeltaX = aEndPoint.x() - aCenter.x()
290     aDeltaY = aEndPoint.y() - aCenter.y()
291 print("Movement average time: {0}".format(averageTime / nbMoves))
292
293 model.end()
294
295
296 assert(model.checkPythonDump())