Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom.git into Dev_1.2.0
[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::typeId());
16         data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
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 aSketchCommonFeature = aDocument.addFeature("Sketch")
34 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
35 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
36 origin.setValue(0, 0, 0)
37 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
38 dirx.setValue(1, 0, 0)
39 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
40 norm.setValue(0, 0, 1)
41 aSession.finishOperation()
42 #=========================================================================
43 # Create a line and an arc
44 #=========================================================================
45 aSession.startOperation()
46 aSketchArc = aSketchFeature.addFeature("SketchArc")
47 anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
48 anArcStartPoint = geomDataAPI_Point2D(
49     aSketchArc.attribute("ArcStartPoint"))
50 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
51 anArcCentr.setValue(10., 10.)
52 anArcStartPoint.setValue(0., 50.)
53 anArcEndPoint.setValue(50., 0.)
54 aSketchLine = aSketchFeature.addFeature("SketchLine")
55 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
56 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
57 # Lets initialize line start at circle's end:
58 aLineStartPoint.setValue(50., 0.)
59 aLineEndPoint.setValue(100., 25.)
60 aSession.finishOperation()
61 #=========================================================================
62 # Link arc's end and line's start points with concidence constraint
63 #=========================================================================
64 aSession.startOperation()
65 aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
66 reflistA = aConstraint.refattr("ConstraintEntityA")
67 reflistB = aConstraint.refattr("ConstraintEntityB")
68 reflistA.setAttr(anArcEndPoint)
69 reflistB.setAttr(aLineStartPoint)
70 aConstraint.execute()
71 aSession.finishOperation()
72 #=========================================================================
73 # Check values and move one constrainted object
74 #=========================================================================
75 assert (anArcEndPoint.x() == 50)
76 assert (anArcEndPoint.y() == 0)
77 assert (aLineStartPoint.x() == 50)
78 assert (aLineStartPoint.y() == 0)
79 deltaX = deltaY = 40.
80 #  move line
81 aSession.startOperation()
82 anArcStartPoint.setValue(aLineStartPoint.x() + deltaX,
83                          aLineStartPoint.y() + deltaY)
84 anArcEndPoint.setValue(aLineEndPoint.x() + deltaX,
85                        aLineEndPoint.y() + deltaY)
86 aSession.finishOperation()
87 # check that arc's points are moved also
88 assert (anArcEndPoint.x() == aLineStartPoint.x())
89 assert (anArcEndPoint.y() == aLineStartPoint.y())
90 #=========================================================================
91 # TODO: improve test
92 # 1. remove constraint, move line to check that constraint are not applied
93 # 2. make a new constraint when the points are distanced from each other,
94 #    check that one from constrainted objects has moved
95 #=========================================================================
96 #=========================================================================
97 # End of test
98 #=========================================================================