Salome HOME
Merge branch 'master' of newgeom:newgeom
[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-10-28"
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 = modelAPI_CompositeFeature(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 diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
42 diry.setValue(0, 1, 0)
43 norm = geomDataAPI_Dir(aSketchFeature.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 aSketchArc = aSketchFeature.addFeature("SketchArc")
51 anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
52 anArcCentr.setValue(10., 10.)
53 anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
54 anArcStartPoint.setValue(0., 50.)
55 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
56 anArcEndPoint.setValue(50., 0.)
57 aSession.finishOperation()
58 # Circle
59 aSession.startOperation()
60 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
61 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
62 aCircleRadius = aSketchCircle.real("CircleRadius")
63 anCircleCentr.setValue(-25., -25)
64 aCircleRadius.setValue(25.)
65 aSession.finishOperation()
66 #=========================================================================
67 # Make a constraint to keep the radius of the arc
68 #=========================================================================
69 aSession.startOperation()
70 aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
71 aRadius = aConstraint.real("ConstraintValue")
72 aRefObject = aConstraint.refattr("ConstraintEntityA")
73 aResult = aSketchArc.firstResult()
74 assert (aResult is not None)
75 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
76 aConstraint.execute()
77 aSession.finishOperation()
78 assert (aRadius.isInitialized())
79 assert (aRefObject.isInitialized())
80 #=========================================================================
81 # Make a constraint to keep the radius of the circle
82 #=========================================================================
83 aSession.startOperation()
84 aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
85 aRadius = aConstraint.real("ConstraintValue")
86 aRefObject = aConstraint.refattr("ConstraintEntityA")
87 aResult = aSketchCircle.firstResult()
88 assert (aResult is not None)
89 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
90 aConstraint.execute()
91 aSession.finishOperation()
92 assert (aRadius.isInitialized())
93 assert (aRefObject.isInitialized())
94 #=========================================================================
95 # Perform some actions and checks:
96 # 1. Check that constraints does not changes values
97 # 2. Move one point of the arc
98 # 3. Check that second point is moved also
99 #=========================================================================
100 assert (anArcCentr.x() == 10.)
101 assert (anArcCentr.y() == 10.)
102 assert (anArcStartPoint.x() == 0.)
103 assert (anArcStartPoint.y() == 50.)
104 anArcPrevEndPointX = anArcEndPoint.x()
105 anArcPrevEndPointY = anArcEndPoint.y()
106 assert (anArcPrevEndPointX == 50.)
107 assert (anArcPrevEndPointY == 0.)
108 # Move one point of the arc
109 aSession.startOperation()
110 anArcStartPoint.setValue(0., 60)
111 aSession.finishOperation()
112 assert (anArcCentr.x() == 10.)
113 assert (anArcCentr.y() == 10.)
114 assert (anArcEndPoint.x() != anArcPrevEndPointX)
115 assert (anArcEndPoint.y() != anArcPrevEndPointY)
116 #=========================================================================
117 # 4. Move the centr or the point of the arc
118 # 5. Check radius is the same
119 #=========================================================================
120 assert (anCircleCentr.x() == -25)
121 assert (anCircleCentr.y() == -25)
122 assert (aCircleRadius.value() == 25)
123 aSession.startOperation()
124 anCircleCentr.setValue(100., 100.)
125 aSession.finishOperation()
126 assert (anCircleCentr.x() == 100)
127 assert (anCircleCentr.y() == 100)
128 assert (aCircleRadius.value() == 25)
129 #=========================================================================
130 # End of test
131 #=========================================================================