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