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