]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestConstraintConcidence.py
Salome HOME
Resolve batch runtime errors on debian squeeze
[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 = modelAPI_CompositeFeature(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 diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
40 diry.setValue(0, 1, 0)
41 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
42 norm.setValue(0, 0, 1)
43 aSession.finishOperation()
44 #=========================================================================
45 # Create a line and an arc
46 #=========================================================================
47 aSession.startOperation()
48 aSketchArc = aSketchFeature.addFeature("SketchArc")
49 anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
50 anArcStartPoint = geomDataAPI_Point2D(
51     aSketchArc.attribute("ArcStartPoint"))
52 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
53 anArcCentr.setValue(10., 10.)
54 anArcStartPoint.setValue(0., 50.)
55 anArcEndPoint.setValue(50., 0.)
56 aSketchLine = aSketchFeature.addFeature("SketchLine")
57 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
58 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
59 # Lets initialize line start at circle's end:
60 aLineStartPoint.setValue(50., 0.)
61 aLineEndPoint.setValue(100., 25.)
62 aSession.finishOperation()
63 #=========================================================================
64 # Link arc's end and line's start points with concidence constraint
65 #=========================================================================
66 aSession.startOperation()
67 aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
68 reflistA = aConstraint.refattr("ConstraintEntityA")
69 reflistB = aConstraint.refattr("ConstraintEntityB")
70 reflistA.setAttr(anArcEndPoint)
71 reflistB.setAttr(aLineStartPoint)
72 aConstraint.execute()
73 aSession.finishOperation()
74 #=========================================================================
75 # Check values and move one constrainted object
76 #=========================================================================
77 assert (anArcEndPoint.x() == 50)
78 assert (anArcEndPoint.y() == 0)
79 assert (aLineStartPoint.x() == 50)
80 assert (aLineStartPoint.y() == 0)
81 deltaX = deltaY = 40.
82 #  move line
83 aSession.startOperation()
84 anArcStartPoint.setValue(aLineStartPoint.x() + deltaX,
85                          aLineStartPoint.y() + deltaY)
86 anArcEndPoint.setValue(aLineEndPoint.x() + deltaX,
87                        aLineEndPoint.y() + deltaY)
88 aSession.finishOperation()
89 # check that arc's points are moved also
90 assert (anArcEndPoint.x() == aLineStartPoint.x())
91 assert (anArcEndPoint.y() == aLineStartPoint.y())
92 #=========================================================================
93 # TODO: improve test
94 # 1. remove constraint, move line to check that constraint are not applied
95 # 2. make a new constraint when the points are distanced from each other,
96 #    check that one from constrainted objects has moved
97 #=========================================================================
98 #=========================================================================
99 # End of test
100 #=========================================================================