Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintConcidence.py
1 """
2     TestConstraintCoincidence.py
3     Unit test of SketchPlugin_ConstraintCoincidence 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_ConstraintCoincidence
14         static const std::string MY_CONSTRAINT_COINCIDENCE_ID("SketchConstraintCoincidence");
15         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
16         data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
17
18 """
19 from GeomDataAPI import *
20 from ModelAPI import *
21 #=========================================================================
22 # Initialization of the test
23 #=========================================================================
24
25 __updated__ = "2014-10-28"
26
27 aSession = ModelAPI_Session.get()
28 aDocument = aSession.moduleDocument()
29 #=========================================================================
30 # Creation of a sketch
31 #=========================================================================
32 aSession.startOperation()
33 aSketchFeature = aDocument.addFeature("Sketch")
34 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
35 origin.setValue(0, 0, 0)
36 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
37 dirx.setValue(1, 0, 0)
38 diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
39 diry.setValue(0, 1, 0)
40 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
41 norm.setValue(0, 0, 1)
42 aSession.finishOperation()
43 #=========================================================================
44 # Create a line and an arc
45 #=========================================================================
46 aSession.startOperation()
47 aSketchReflist = aSketchFeature.reflist("Features")
48 aSketchArc = aDocument.addFeature("SketchArc")
49 aSketchReflist.append(aSketchArc)
50 anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
51 anArcStartPoint = geomDataAPI_Point2D(
52     aSketchArc.attribute("ArcStartPoint"))
53 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
54 aSketchFeature = aDocument.addFeature("SketchConstraintCoincidence")
55 anArcCentr.setValue(10., 10.)
56 anArcStartPoint.setValue(0., 50.)
57 anArcEndPoint.setValue(50., 0.)
58 aSketchLine = aDocument.addFeature("SketchLine")
59 aSketchReflist.append(aSketchLine)
60 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
61 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
62 # Lets initialize line start at circle's end:
63 aLineStartPoint.setValue(50., 0.)
64 aLineEndPoint.setValue(100., 25.)
65 aSession.finishOperation()
66 #=========================================================================
67 # Link arc's end and line's start points with concidence constraint
68 #=========================================================================
69 aSession.startOperation()
70 aConstraint = aDocument.addFeature("SketchConstraintCoincidence")
71 aSketchReflist.append(aConstraint)
72 reflistA = aConstraint.refattr("ConstraintEntityA")
73 reflistB = aConstraint.refattr("ConstraintEntityB")
74 reflistA.setAttr(anArcEndPoint)
75 reflistB.setAttr(aLineStartPoint)
76 aSession.finishOperation()
77 #=========================================================================
78 # Check values and move one constrainted object
79 #=========================================================================
80 assert (anArcEndPoint.x() == 50)
81 assert (anArcEndPoint.y() == 0)
82 assert (aLineStartPoint.x() == 50)
83 assert (aLineStartPoint.y() == 0)
84 deltaX = deltaY = 40.
85 #  move line
86 aSession.startOperation()
87 aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
88                          aLineStartPoint.y() + deltaY)
89 aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
90                        aLineEndPoint.y() + deltaY)
91 aSession.finishOperation()
92 # check that arc's points are moved also
93 assert (anArcEndPoint.x() == aLineStartPoint.x())
94 assert (anArcEndPoint.y() == aLineStartPoint.y())
95 #=========================================================================
96 # TODO: improve test
97 # 1. remove constraint, move line to check that constraint are not applied
98 # 2. make a new constraint when the points are distanced from each other,
99 #    check that one from constrainted objects has moved
100 #=========================================================================
101 #=========================================================================
102 # End of test
103 #=========================================================================