2 TestConstraintCoincidence.py
3 Unit test of SketchPlugin_ConstraintCoincidence class
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");
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());
19 from GeomDataAPI import *
20 from ModelAPI import *
21 #=========================================================================
22 # Initialization of the test
23 #=========================================================================
25 __updated__ = "2014-07-28"
27 aPluginManager = ModelAPI_PluginManager.get()
28 aDocument = aPluginManager.rootDocument()
29 #=========================================================================
30 # Creation of a sketch
31 #=========================================================================
32 aDocument.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 aDocument.finishOperation()
44 #=========================================================================
45 # Create a line and an arc
46 #=========================================================================
47 aDocument.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 aDocument.finishOperation()
69 #=========================================================================
70 # Link arc's end and line's start points with concidence constraint
71 #=========================================================================
72 aDocument.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 aDocument.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)
90 aDocument.startOperation()
91 aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
92 aLineStartPoint.y() + deltaY)
93 aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
94 aLineEndPoint.y() + deltaY)
95 aDocument.finishOperation()
96 # check that arc's points are moved also
97 assert (anArcEndPoint.x() == aLineStartPoint.x())
98 assert (anArcEndPoint.y() == aLineStartPoint.y())
99 #=========================================================================
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 #=========================================================================
107 #=========================================================================