Salome HOME
Test corrected according to changes in the API
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintRadius.py
1 """
2     TestConstraintRadius.py
3     Unit test of SketchPlugin_ConstraintRadius 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_ConstraintRadius
14         static const std::string MY_CONSTRAINT_RADIUS_ID("SketchConstraintRadius");
15         data()->addAttribute(SketchPlugin_Constraint::VALUE(),    ModelAPI_AttributeDouble::type());
16         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
17         data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
18
19 """
20 from GeomDataAPI import *
21 from ModelAPI import *
22 import math
23 #=========================================================================
24 # Initialization of the test
25 #=========================================================================
26
27 __updated__ = "2014-09-26"
28
29 aSession = ModelAPI_Session.get()
30 aDocument = aSession.moduleDocument()
31 #=========================================================================
32 # Creation of a sketch
33 #=========================================================================
34 aSession.startOperation()
35 aSketchFeature = aDocument.addFeature("Sketch")
36 aSketchFeatureData = aSketchFeature.data()
37 origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
38 origin.setValue(0, 0, 0)
39 dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
40 dirx.setValue(1, 0, 0)
41 diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
42 diry.setValue(0, 1, 0)
43 norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
44 norm.setValue(0, 0, 1)
45 aSession.finishOperation()
46 #=========================================================================
47 # Creation of an arc and a circle
48 #=========================================================================
49 aSession.startOperation()
50 aSketchReflist = aSketchFeatureData.reflist("Features")
51 aSketchArc = aDocument.addFeature("SketchArc")
52 aSketchReflist.append(aSketchArc)
53 aSketchArcData = aSketchArc.data()
54 anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
55 anArcCentr.setValue(10., 10.)
56 anArcStartPoint = geomDataAPI_Point2D(
57     aSketchArcData.attribute("ArcStartPoint"))
58 anArcStartPoint.setValue(0., 50.)
59 anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
60 anArcEndPoint.setValue(50., 0.)
61 aSession.finishOperation()
62 # Circle
63 aSession.startOperation()
64 aSketchCircle = aDocument.addFeature("SketchCircle")
65 aSketchReflist.append(aSketchCircle)
66 aSketchCircleData = aSketchCircle.data()
67 anCircleCentr = geomDataAPI_Point2D(
68     aSketchCircleData.attribute("CircleCenter"))
69 aCircleRadius = aSketchCircleData.real("CircleRadius")
70 anCircleCentr.setValue(-25., -25)
71 aCircleRadius.setValue(25.)
72 aSession.finishOperation()
73 #=========================================================================
74 # Make a constraint to keep the radius of the arc
75 #=========================================================================
76 aSession.startOperation()
77 aConstraint = aDocument.addFeature("SketchConstraintRadius")
78 aSketchReflist.append(aConstraint)
79 aConstraintData = aConstraint.data()
80 aRadius = aConstraintData.real("ConstraintValue")
81 aRefObject = aConstraintData.refattr("ConstraintEntityA")
82 aResult = aSketchArc.firstResult()
83 assert (aResult is not None)
84 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
85 aConstraint.execute()
86 aSession.finishOperation()
87 assert (aRadius.isInitialized())
88 assert (aRefObject.isInitialized())
89 #=========================================================================
90 # Make a constraint to keep the radius of the circle
91 #=========================================================================
92 aSession.startOperation()
93 aConstraint = aDocument.addFeature("SketchConstraintRadius")
94 aSketchReflist.append(aConstraint)
95 aConstraintData = aConstraint.data()
96 aRadius = aConstraintData.real("ConstraintValue")
97 aRefObject = aConstraintData.refattr("ConstraintEntityA")
98 aResult = aSketchCircle.firstResult()
99 assert (aResult is not None)
100 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
101 aConstraint.execute()
102 aSession.finishOperation()
103 assert (aRadius.isInitialized())
104 assert (aRefObject.isInitialized())
105 #=========================================================================
106 # Perform some actions and checks:
107 # 1. Check that constraints does not changes values
108 # 2. Move one point of the arc
109 # 3. Check that second point is moved also
110 #=========================================================================
111 assert (anArcCentr.x() == 10.)
112 assert (anArcCentr.y() == 10.)
113 assert (anArcStartPoint.x() == 0.)
114 assert (anArcStartPoint.y() == 50.)
115 anArcPrevEndPointX = anArcEndPoint.x()
116 anArcPrevEndPointY = anArcEndPoint.y()
117 assert (anArcPrevEndPointX == 50.)
118 assert (anArcPrevEndPointY == 0.)
119 # Move one point of the arc
120 aSession.startOperation()
121 anArcStartPoint.setValue(0., 60)
122 aSession.finishOperation()
123 assert (anArcCentr.x() == 10.)
124 assert (anArcCentr.y() == 10.)
125 assert (anArcEndPoint.x() != anArcPrevEndPointX)
126 assert (anArcEndPoint.y() != anArcPrevEndPointY)
127 #=========================================================================
128 # 4. Move the centr or the point of the arc
129 # 5. Check radius is the same
130 #=========================================================================
131 assert (anCircleCentr.x() == -25)
132 assert (anCircleCentr.y() == -25)
133 assert (aCircleRadius.value() == 25)
134 aSession.startOperation()
135 anCircleCentr.setValue(100., 100.)
136 aSession.finishOperation()
137 assert (anCircleCentr.x() == 100)
138 assert (anCircleCentr.y() == 100)
139 assert (aCircleRadius.value() == 25)
140 #=========================================================================
141 # End of test
142 #=========================================================================