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