Salome HOME
Merge branch 'V9_9_BR'
[modules/shaper.git] / src / SketchPlugin / Test / TestArcBehavior.py
1 # Copyright (C) 2014-2022  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     TestArcBehavior.py
22
23     It tests behavior of the arc during the changing of parameters to avoid
24     regressions in this complicated part.
25
26 """
27
28 #=========================================================================
29 # of the test
30 #=========================================================================
31 from GeomAPI import *
32 from GeomDataAPI import *
33 from ModelAPI import *
34 import math
35 from salome.shaper import model
36
37 aSession = ModelAPI_Session.get()
38 aDocument = aSession.moduleDocument()
39 #=========================================================================
40 # Creation of a sketch
41 #=========================================================================
42 aSession.startOperation()
43 #aSketchFeature = aDocument.addFeature("Sketch")
44 aSketchCommonFeature = aDocument.addFeature("Sketch")
45 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
46 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
47 origin.setValue(0, 0, 0)
48 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
49 dirx.setValue(1, 0, 0)
50 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
51 norm.setValue(0, 0, 1)
52 aSession.finishOperation()
53 #=========================================================================
54 # Test creation of arc and movements (of mouse coursor) of end point near to the start point:
55 # edge must be the minimal length.
56 #=========================================================================
57 aSession.startOperation()
58 aSketchArc = aSketchFeature.addFeature("SketchArc")
59 anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
60 anArcCentr.setValue(0., 0.)
61 anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
62 anArcStartPoint.setValue(0., 10.)
63 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
64 anArcEndPoint.setValue(1., 10.)
65 aSession.finishOperation()
66 # the arc must be small, not near to the whole circle
67 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 2.
68 # move to the half-circle
69 aSession.startOperation()
70 anArcEndPoint.setValue(10., 0.)
71 aSession.finishOperation()
72 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 16.
73 aSession.startOperation()
74 anArcEndPoint.setValue(0., -10.)
75 aSession.finishOperation()
76 assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 31.
77 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 32.
78 aSession.startOperation()
79 anArcEndPoint.setValue(-10., 0.)
80 aSession.finishOperation()
81 assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 47.
82 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 48.
83 aSession.startOperation()
84 anArcEndPoint.setValue(-1., 10.)
85 aSession.finishOperation()
86 assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 60.
87 # move to the initial point at the right side: the edge must reset to the initial one
88 aSession.startOperation()
89 anArcEndPoint.setValue(1., 10.)
90 aSession.finishOperation()
91 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 2.
92 # move to the counterclockwise direction
93 aSession.startOperation()
94 anArcEndPoint.setValue(-1., 10.)
95 aSession.finishOperation()
96 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 2.
97 aSession.startOperation()
98 anArcEndPoint.setValue(-10., 0.)
99 aSession.finishOperation()
100 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 16.
101 aSession.startOperation()
102 anArcEndPoint.setValue(0., -10.)
103 aSession.finishOperation()
104 assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 31.
105 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 32.
106 aSession.startOperation()
107 anArcEndPoint.setValue(10., 0.)
108 aSession.finishOperation()
109 assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 46.5
110 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 47.5
111 aSession.startOperation()
112 anArcEndPoint.setValue(1., 10.)
113 aSession.finishOperation()
114 assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 60.
115 # check from the scratch that from initial state to counterclockwise position also works
116 aSession.startOperation()
117 aSketchArc = aSketchFeature.addFeature("SketchArc")
118 anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
119 anArcCentr.setValue(0., 0.)
120 anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
121 anArcStartPoint.setValue(0., 10.)
122 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
123 anArcEndPoint.setValue(-1., 10.)
124 aSession.finishOperation()
125 # the arc must be small, not near to the whole circle
126 assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 2.
127 #=========================================================================
128 # Test that movement of the center of arc does not change the orientation of the arc
129 #=========================================================================
130 aSession.startOperation()
131 aSketchArc = aSketchFeature.addFeature("SketchArc")
132 anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
133 anArcCentr.setValue(0., 0.)
134 anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
135 anArcStartPoint.setValue(0., 10.)
136 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
137 anArcEndPoint.setValue(10, 0.)
138 aSession.finishOperation()
139 anInversed = aSketchArc.boolean("reversed").value()
140 for aCenterCoords in range(1, 20):
141   aSession.startOperation()
142   anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
143   aSession.finishOperation()
144   assert aSketchArc.boolean("reversed").value() == anInversed
145 for aCenterCoords in range(20, -20, -1):
146   aSession.startOperation()
147   anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
148   aSession.finishOperation()
149   assert aSketchArc.boolean("reversed").value() == anInversed
150 for aCenterCoords in range(-20, 20):
151   aSession.startOperation()
152   anArcCentr.setValue(aCenterCoords, aCenterCoords/2) # move center
153   aSession.finishOperation()
154   assert aSketchArc.boolean("reversed").value() == anInversed
155 #=========================================================================
156 # Test that movement of start point of arc does not break the arc
157 #=========================================================================
158 x = anArcCentr.x()
159 y = anArcCentr.y()
160 sx = anArcStartPoint.x()
161 sy = anArcStartPoint.y()
162 for aDelta in range(0, 20):
163   aSession.startOperation()
164   anArcStartPoint.setValue(sx, sy+aDelta) # move start point
165   aSession.finishOperation()
166   model.assertArcValidity(aSketchArc)
167 for aDelta in range(20, -1, -1):
168   aSession.startOperation()
169   anArcStartPoint.setValue(sx, sy+aDelta) # move start point
170   aSession.finishOperation()
171   model.assertArcValidity(aSketchArc)
172 #=========================================================================
173 # Test that movement of end point of arc does not break the arc
174 #=========================================================================
175 x = anArcCentr.x()
176 y = anArcCentr.y()
177 sx = anArcEndPoint.x()
178 sy = anArcEndPoint.y()
179 for aDelta in range(0, 20):
180   aSession.startOperation()
181   anArcEndPoint.setValue(sx+aDelta, sy) # move end point
182   aSession.finishOperation()
183   model.assertArcValidity(aSketchArc)
184 for aDelta in range(20, -1, -1):
185   aSession.startOperation()
186   anArcEndPoint.setValue(sx+aDelta, sy) # move end point
187   aSession.finishOperation()
188   model.assertArcValidity(aSketchArc)