]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestConstraintFixed.py
Salome HOME
Task 2.4. Ability to modify the radius of circles and arcs of circle with the mouse
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintFixed.py
1 """
2     TestConstraintRigid.py
3     Unit test of SketchPlugin_ConstraintRigid class
4
5     SketchPlugin_Constraint
6         static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
7         static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
8         static const std::string MY_ENTITY_A("ConstraintEntityA");
9         static const std::string MY_ENTITY_B("ConstraintEntityB");
10         static const std::string MY_ENTITY_C("ConstraintEntityC");
11         static const std::string MY_ENTITY_D("ConstraintEntityD");
12
13     SketchPlugin_ConstraintRigid
14         static const std::string MY_CONSTRAINT_RIGID_ID("SketchConstraintRigid");
15         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
16
17 """
18 from GeomDataAPI import *
19 from ModelAPI import *
20 from GeomAPI import *
21 from salome.shaper import model
22
23 #=========================================================================
24 # Initialization of the test
25 #=========================================================================
26
27 __updated__ = "2014-11-21"
28
29 aSession = ModelAPI_Session.get()
30 aDocument = aSession.moduleDocument()
31 #=========================================================================
32 # Creation of a sketch
33 #=========================================================================
34 aSession.startOperation()
35 aSketchCommonFeature = aDocument.addFeature("Sketch")
36 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
37 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
38 origin.setValue(0, 0, 0)
39 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
40 dirx.setValue(1, 0, 0)
41 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
42 norm.setValue(0, 0, 1)
43 aSession.finishOperation()
44 #=========================================================================
45 # Create a triangle ABC
46 #=========================================================================
47 aSession.startOperation()
48 aSketchLineA = aSketchFeature.addFeature("SketchLine")
49 aSketchLineB = aSketchFeature.addFeature("SketchLine")
50 aSketchLineC = aSketchFeature.addFeature("SketchLine")
51 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
52 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
53 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
54 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
55 aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
56 aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
57 aLineAStartPoint.setValue(25., 25.)
58 aLineAEndPoint.setValue(100., 25.)
59 aLineBStartPoint.setValue(100., 25.)
60 aLineBEndPoint.setValue(60., 75.)
61 aLineCStartPoint.setValue(60., 75.)
62 aLineCEndPoint.setValue(25., 25.)
63 aSession.finishOperation()
64 assert (model.dof(aSketchFeature) == 12)
65 # Store initial values of lines
66 kLineAStart = (aLineAStartPoint.x(), aLineAStartPoint.y())
67 kLineAEnd = (aLineAEndPoint.x(),   aLineAEndPoint.y())
68 kLineBStart = (aLineBStartPoint.x(), aLineBStartPoint.y())
69 kLineBEnd = (aLineBEndPoint.x(),   aLineBEndPoint.y())
70 kLineCStart = (aLineCStartPoint.x(), aLineCStartPoint.y())
71 kLineCEnd = (aLineCEndPoint.x(),   aLineCEndPoint.y())
72 #=========================================================================
73 # Link triange lines with concidence
74 #=========================================================================
75 concidenceLinks = zip([aLineBStartPoint, aLineCStartPoint, aLineAStartPoint],
76                       [aLineAEndPoint, aLineBEndPoint, aLineCEndPoint])
77 aSession.startOperation()
78 for eachLink in concidenceLinks:
79     aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
80     reflistA = aConstraint.refattr("ConstraintEntityA")
81     reflistB = aConstraint.refattr("ConstraintEntityB")
82     reflistA.setAttr(eachLink[0])
83     reflistB.setAttr(eachLink[1])
84     aConstraint.execute()
85 aSession.finishOperation()
86 assert (model.dof(aSketchFeature) == 6)
87
88 # Check that constarints doesn't affected lines' values
89 assert (kLineAStart == (aLineAStartPoint.x(), aLineAStartPoint.y()))
90 assert (kLineAEnd == (aLineAEndPoint.x(),   aLineAEndPoint.y()))
91 assert (kLineBStart == (aLineBStartPoint.x(), aLineBStartPoint.y()))
92 assert (kLineBEnd == (aLineBEndPoint.x(),   aLineBEndPoint.y()))
93 assert (kLineCStart == (aLineCStartPoint.x(), aLineCStartPoint.y()))
94 assert (kLineCEnd == (aLineCEndPoint.x(),   aLineCEndPoint.y()))
95 #=========================================================================
96 # Make line A rigid
97 #=========================================================================
98 aSession.startOperation()
99 aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid")
100 eachRefattr = aRigidConstraint.refattr("ConstraintEntityA")
101 lineResults = aSketchLineA.results()
102 for eachResult in lineResults:
103     if eachResult.shape().isEdge():
104         break
105 aResult = modelAPI_ResultConstruction(eachResult)
106 assert (aResult is not None)
107 eachRefattr.setObject(aResult)
108 # aRigidConstraint.execute()
109 aSession.finishOperation()
110
111 # Check that constarints doesn't affected lines' values
112 assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLineCEndPoint.y()))
113 assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y()))
114 assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y()))
115 assert (model.dof(aSketchFeature) == 2)
116
117 #=========================================================================
118 # Check that moving line A does not affect lines
119 #=========================================================================
120 aSession.startOperation()
121 aLineAEndPoint.setValue(90., 0.)
122 aSession.finishOperation()
123 # Check that constarint keep features' values
124 assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLineCEndPoint.y()))
125 assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y()))
126 assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y()))
127 assert (model.dof(aSketchFeature) == 2)
128
129 #=========================================================================
130 # Check that moving line B does not affect lines
131 #=========================================================================
132 aSession.startOperation()
133 aLineBEndPoint.setValue(90., 150.)
134 aSession.finishOperation()
135 # Check that constarint keep features' values
136 assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLineCEndPoint.y()))
137 assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y()))
138 assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y()))
139 assert (model.dof(aSketchFeature) == 2)
140
141 #=========================================================================
142 # Remove constraint, move line to check that it is not fixed
143 #=========================================================================
144 aSession.startOperation()
145 aDocument.removeFeature(aRigidConstraint)
146 aLineBEndPoint.setValue(90., 150.)
147 aSession.finishOperation()
148 assert ((aLineAStartPoint.x(), aLineAStartPoint.y()) == (aLineCEndPoint.x(), aLineCEndPoint.y()))
149 assert ((aLineBStartPoint.x(), aLineBStartPoint.y()) == (aLineAEndPoint.x(), aLineAEndPoint.y()))
150 assert ((aLineCStartPoint.x(), aLineCStartPoint.y()) == (aLineBEndPoint.x(), aLineBEndPoint.y()))
151 assert (model.dof(aSketchFeature) == 6)
152
153 #=========================================================================
154 # Create circle, fix it and check the circle is not moved
155 #=========================================================================
156 aCenter = [10., 10.]
157 aRadius = 5.
158 aSession.startOperation()
159 aCircle = aSketchFeature.addFeature("SketchCircle")
160 aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
161 aCircleRadius = aCircle.real("circle_radius")
162 aCircleCenter.setValue(aCenter[0], aCenter[1])
163 aCircleRadius.setValue(aRadius)
164 aSession.finishOperation()
165 assert (model.dof(aSketchFeature) == 9)
166 # fixed constraints
167 aSession.startOperation()
168 aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid")
169 aRigidConstraint.refattr("ConstraintEntityA").setObject(aCircle.lastResult())
170 aSession.finishOperation()
171 assert (model.dof(aSketchFeature) == 6)
172 # move center of circle
173 aSession.startOperation()
174 aCircleCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.)
175 aSession.finishOperation()
176 assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1])
177 assert (aCircleRadius.value() == aRadius)
178 assert (model.dof(aSketchFeature) == 6)
179 # change radius of circle
180 aSession.startOperation()
181 aCircleRadius.setValue(aRadius + 3.)
182 aSession.finishOperation()
183 assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1])
184 assert (aCircleRadius.value() == aRadius)
185 assert (model.dof(aSketchFeature) == 6)
186
187 #=========================================================================
188 # Remove Fixed constraint and check the circle can be moved
189 #=========================================================================
190 aSession.startOperation()
191 aDocument.removeFeature(aRigidConstraint)
192 aSession.finishOperation()
193 assert (model.dof(aSketchFeature) == 9)
194 # move center of circle
195 aCenter = [aCenter[0] + 1., aCenter[1] - 1.]
196 aSession.startOperation()
197 aCircleCenter.setValue(aCenter[0], aCenter[1])
198 aSession.finishOperation()
199 assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1])
200 assert (aCircleRadius.value() == aRadius)
201 assert (model.dof(aSketchFeature) == 9)
202 # change radius of circle
203 aRadius = aRadius + 3.
204 aSession.startOperation()
205 aCircleRadius.setValue(aRadius)
206 aSession.finishOperation()
207 assert (aCircleCenter.x() == aCenter[0] and aCircleCenter.y() == aCenter[1])
208 assert (aCircleRadius.value() == aRadius)
209 assert (model.dof(aSketchFeature) == 9)
210
211 #=========================================================================
212 # Create arc, fix it and check it is not moved
213 #=========================================================================
214 aCenter = [10., 10.]
215 aStart = [5., 10.]
216 aEnd = [10., 15.]
217 aSession.startOperation()
218 anArc = aSketchFeature.addFeature("SketchArc")
219 anArcCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
220 anArcStart = geomDataAPI_Point2D(anArc.attribute("start_point"))
221 anArcEnd = geomDataAPI_Point2D(anArc.attribute("end_point"))
222 anArcCenter.setValue(aCenter[0], aCenter[1])
223 anArcStart.setValue(aStart[0], aStart[1])
224 anArcEnd.setValue(aEnd[0], aEnd[1])
225 aSession.finishOperation()
226 assert (model.dof(aSketchFeature) == 14)
227 # fixed constraints
228 aSession.startOperation()
229 aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid")
230 aRigidConstraint.refattr("ConstraintEntityA").setObject(anArc.lastResult())
231 aSession.finishOperation()
232 assert (model.dof(aSketchFeature) == 9)
233 # move center of arc
234 aSession.startOperation()
235 anArcCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.)
236 aSession.finishOperation()
237 assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1])
238 assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1])
239 assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1])
240 assert (model.dof(aSketchFeature) == 9)
241 # move start point of arc
242 aSession.startOperation()
243 anArcStart.setValue(aStart[0] + 1., aStart[1] - 1.)
244 aSession.finishOperation()
245 assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1])
246 assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1])
247 assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1])
248 assert (model.dof(aSketchFeature) == 9)
249 # move end point of arc
250 aSession.startOperation()
251 anArcEnd.setValue(aEnd[0] + 1., aEnd[1] - 1.)
252 aSession.finishOperation()
253 assert (anArcCenter.x() == aCenter[0] and anArcCenter.y() == aCenter[1])
254 assert (anArcStart.x() == aStart[0] and anArcStart.y() == aStart[1])
255 assert (anArcEnd.x() == aEnd[0] and anArcEnd.y() == aEnd[1])
256 assert (model.dof(aSketchFeature) == 9)
257
258 #=========================================================================
259 # Remove Fixed constraint and check the arc can be moved
260 #=========================================================================
261 aSession.startOperation()
262 aDocument.removeFeature(aRigidConstraint)
263 aSession.finishOperation()
264 assert (model.dof(aSketchFeature) == 14)
265 # move center of arc
266 aCenter = [anArcCenter.x(), anArcCenter.y()]
267 aSession.startOperation()
268 anArcCenter.setValue(aCenter[0] + 1., aCenter[1] - 1.)
269 aSession.finishOperation()
270 assert (anArcCenter.x() != aCenter[0] or anArcCenter.y() != aCenter[1])
271 assert (model.dof(aSketchFeature) == 14)
272 # move start point of arc
273 aStart = [anArcStart.x(), anArcStart.y()]
274 aSession.startOperation()
275 anArcStart.setValue(aStart[0] + 1., aStart[1] - 1.)
276 aSession.finishOperation()
277 assert (anArcStart.x() != aStart[0] or anArcStart.y() != aStart[1])
278 assert (model.dof(aSketchFeature) == 14)
279 # move end point of arc
280 aEnd = [anArcEnd.x(), anArcEnd.y()]
281 aSession.startOperation()
282 anArcEnd.setValue(aEnd[0] + 1., aEnd[1] - 1.)
283 aSession.finishOperation()
284 assert (anArcEnd.x() != aEnd[0] or anArcEnd.y() != aEnd[1])
285 assert (model.dof(aSketchFeature) == 14)
286
287 #=========================================================================
288 # End of test
289 #=========================================================================
290
291 assert(model.checkPythonDump())