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 aCoincidenceConstraint = aDocument.addFeature("SketchConstraintCoincidence")
74 aConstraintData = aCoincidenceConstraint.data()
75 reflistA = aConstraintData.refattr("ConstraintEntityA")
76 reflistB = aConstraintData.refattr("ConstraintEntityB")
77 reflistA.setAttr(anArcEndPoint)
78 reflistB.setAttr(aLineStartPoint)
79 aDocument.finishOperation()
80 #=========================================================================
81 # Check values and move one constrainted object
82 #=========================================================================
83 assert (anArcEndPoint.x() == 50)
84 assert (anArcEndPoint.y() == 0)
85 assert (aLineStartPoint.x() == 50)
86 assert (aLineStartPoint.y() == 0)
89 aDocument.startOperation()
90 aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
91 aLineStartPoint.y() + deltaY)
92 aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
93 aLineEndPoint.y() + deltaY)
94 aDocument.finishOperation()
95 # check that arc's points are moved also
96 print ("assert anArcEndPoint.x() == %d" % anArcEndPoint.x())
97 print ("assert anArcEndPoint.y() == %d" % anArcEndPoint.y())
98 print ("assert aLineStartPoint.x() == %d" % aLineStartPoint.x())
99 print ("assert aLineStartPoint.y() == %d" % aLineStartPoint.y())
100 #=========================================================================
102 # 1. remove constraint, move line to check that constraint are not applied
103 # 2. make a new constraint when the points are distanced from each other,
104 # check that one from constrainted objects has moved
105 #=========================================================================
106 #=========================================================================
108 #=========================================================================