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