2 TestConstraintParallel.py
3 Unit test of SketchPlugin_ConstraintParallel class
5 SketchPlugin_ConstraintParallel
6 static const std::string MY_CONSTRAINT_PARALLEL_ID("SketchConstraintParallel");
7 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
8 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
9 data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
12 from GeomDataAPI import *
13 from ModelAPI import *
14 #=========================================================================
15 # Initialization of the test
16 #=========================================================================
18 __updated__ = "2014-07-29"
20 aPluginManager = ModelAPI_PluginManager.get()
21 aDocument = aPluginManager.rootDocument()
22 #=========================================================================
23 # Creation of a sketch
24 #=========================================================================
25 aDocument.startOperation()
26 aSketchFeature = aDocument.addFeature("Sketch")
27 aSketchFeatureData = aSketchFeature.data()
28 origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
29 origin.setValue(0, 0, 0)
30 dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
31 dirx.setValue(1, 0, 0)
32 diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
33 diry.setValue(0, 1, 0)
34 norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
35 norm.setValue(0, 0, 1)
36 aDocument.finishOperation()
37 #=========================================================================
38 # Create two lines which are not parallel
39 #=========================================================================
40 aDocument.startOperation()
41 aSketchReflist = aSketchFeatureData.reflist("Features")
43 aSketchLineA = aDocument.addFeature("SketchLine")
44 aSketchReflist.append(aSketchLineA)
45 aLineAStartPoint = geomDataAPI_Point2D(
46 aSketchLineA.data().attribute("StartPoint"))
47 aLineAEndPoint = geomDataAPI_Point2D(
48 aSketchLineA.data().attribute("EndPoint"))
49 aSketchLineB = aDocument.addFeature("SketchLine")
50 aLineAStartPoint.setValue(0., 25)
51 aLineAEndPoint.setValue(85., 25)
53 aSketchReflist.append(aSketchLineB)
54 aLineBStartPoint = geomDataAPI_Point2D(
55 aSketchLineB.data().attribute("StartPoint"))
56 aLineBEndPoint = geomDataAPI_Point2D(
57 aSketchLineB.data().attribute("EndPoint"))
58 aLineBStartPoint.setValue(0., 50)
59 aLineBEndPoint.setValue(80., 75)
60 aDocument.finishOperation()
61 #=========================================================================
62 # Make a constraint to keep the length of the line constant
63 # to parallel perpendicular constraint collapsing line to point
64 #=========================================================================
65 aDocument.startOperation()
66 aLengthConstraint = aDocument.addFeature("SketchConstraintLength")
67 aSketchReflist.append(aLengthConstraint)
68 aLengthConstraintData = aLengthConstraint.data()
69 refattrA = aLengthConstraintData.refattr("ConstraintEntityA")
70 aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult())
71 assert (aResultA is not None)
72 refattrA.setObject(aResultA)
73 aDocument.finishOperation()
74 # Coordinates of lines should not be changed after this constraint
75 assert (aLineAStartPoint.x() == 0)
76 assert (aLineAStartPoint.y() == 25)
77 assert (aLineAEndPoint.x() == 85)
78 assert (aLineAEndPoint.y() == 25)
79 assert (aLineBStartPoint.x() == 0)
80 assert (aLineBStartPoint.y() == 50)
81 assert (aLineBEndPoint.x() == 80)
82 assert (aLineBEndPoint.y() == 75)
83 #=========================================================================
84 # Link lines with parallel constraint
85 #=========================================================================
86 aDocument.startOperation()
87 aParallelConstraint = aDocument.addFeature("SketchConstraintParallel")
88 aSketchReflist.append(aParallelConstraint)
89 aConstraintData = aParallelConstraint.data()
90 refattrA = aConstraintData.refattr("ConstraintEntityA")
91 refattrB = aConstraintData.refattr("ConstraintEntityB")
92 # aResultA is already defined for the length constraint
93 aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult())
94 assert (aResultB is not None)
95 refattrA.setObject(aResultA)
96 refattrB.setObject(aResultB)
97 aDocument.finishOperation()
98 # print "Link lines with parallel constraint"
99 # print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x()
100 # print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y()
101 # print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x()
102 # print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y()
103 # print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x()
104 # print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y()
105 # print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x()
106 # print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y()
107 #=========================================================================
108 # Check values and move one constrainted object
109 #=========================================================================
110 deltaX = deltaY = 10.
111 # rotate line, check that reference's line points are moved also
112 aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX,
113 aLineAStartPoint.y() + deltaY)
114 aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX,
115 aLineAEndPoint.y() - deltaY)
116 # print "Rotate line, check that reference's line points are moved also"
117 # print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x()
118 # print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y()
119 # print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x()
120 # print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y()
121 # print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x()
122 # print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y()
123 # print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x()
124 # print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y()
125 #=========================================================================
127 #=========================================================================