]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestConstraintParallel.py
Salome HOME
Bring batch tests to valid state
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintParallel.py
1 """
2     TestConstraintParallel.py
3     Unit test of SketchPlugin_ConstraintParallel class
4         
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());
10
11 """
12 from GeomDataAPI import *
13 from ModelAPI import *
14 #=========================================================================
15 # Initialization of the test
16 #=========================================================================
17
18 __updated__ = "2014-10-28"
19
20 aSession = ModelAPI_Session.get()
21 aDocument = aSession.moduleDocument()
22 #=========================================================================
23 # Creation of a sketch
24 #=========================================================================
25 aSession.startOperation()
26 aSketchCommonFeature = aDocument.addFeature("Sketch")
27 aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
28 aSketchFeatureData = aSketchFeature.data()
29 origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
30 origin.setValue(0, 0, 0)
31 dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
32 dirx.setValue(1, 0, 0)
33 diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
34 diry.setValue(0, 1, 0)
35 norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
36 norm.setValue(0, 0, 1)
37 aSession.finishOperation()
38 #=========================================================================
39 # Create two lines which are not parallel
40 #=========================================================================
41 aSession.startOperation()
42 # line A
43 aSketchLineA = aSketchFeature.addFeature("SketchLine")
44 aLineAStartPoint = geomDataAPI_Point2D(
45     aSketchLineA.data().attribute("StartPoint"))
46 aLineAEndPoint = geomDataAPI_Point2D(
47     aSketchLineA.data().attribute("EndPoint"))
48 aSketchLineB = aSketchFeature.addFeature("SketchLine")
49 aLineAStartPoint.setValue(0., 25)
50 aLineAEndPoint.setValue(85., 25)
51 # line B
52 aLineBStartPoint = geomDataAPI_Point2D(
53     aSketchLineB.data().attribute("StartPoint"))
54 aLineBEndPoint = geomDataAPI_Point2D(
55     aSketchLineB.data().attribute("EndPoint"))
56 aLineBStartPoint.setValue(0., 50)
57 aLineBEndPoint.setValue(80., 75)
58 aSession.finishOperation()
59 #=========================================================================
60 # Make a constraint to keep the length of the line constant
61 # to parallel perpendicular constraint collapsing line to point
62 #=========================================================================
63 for eachFeature in [aSketchLineA, aSketchLineB]:
64     aSession.startOperation()
65     aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
66     aLengthConstraintData = aLengthConstraint.data()
67     refattrA = aLengthConstraintData.refattr("ConstraintEntityA")
68     aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
69     assert (aResultA is not None)
70     refattrA.setObject(aResultA)
71     aLengthConstraint.execute()
72     aSession.finishOperation()
73 # Coordinates of lines should not be changed after this constraint
74 assert (aLineAStartPoint.x() == 0)
75 assert (aLineAStartPoint.y() == 25)
76 assert (aLineAEndPoint.x() == 85)
77 assert (aLineAEndPoint.y() == 25)
78 assert (aLineBStartPoint.x() == 0)
79 assert (aLineBStartPoint.y() == 50)
80 assert (aLineBEndPoint.x() == 80)
81 assert (aLineBEndPoint.y() == 75)
82 #=========================================================================
83 # Link lines with parallel constraint
84 #=========================================================================
85 aSession.startOperation()
86 aParallelConstraint = aSketchFeature.addFeature("SketchConstraintParallel")
87 aConstraintData = aParallelConstraint.data()
88 refattrA = aConstraintData.refattr("ConstraintEntityA")
89 refattrB = aConstraintData.refattr("ConstraintEntityB")
90 # aResultA is already defined for the length constraint
91 aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
92 aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult())
93 assert (aResultB is not None)
94 refattrA.setObject(aResultA)
95 refattrB.setObject(aResultB)
96 aParallelConstraint.execute()
97 aSession.finishOperation()
98 #=========================================================================
99 # Check values and move one constrainted object
100 #=========================================================================
101 deltaX = deltaY = 10.
102 # rotate line, check that reference's line points are moved also
103 # print "Rotate line, check that reference's line points are moved also"
104 # print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x()
105 # print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y()
106 # print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x()
107 # print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y()
108 # print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x()
109 # print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y()
110 # print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x()
111 # print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y()
112 aLineBStartPointXPrev = aLineBStartPoint.x()
113 aLineBStartPointYPrev = aLineBStartPoint.y()
114 aLineBEndPointXPrev = aLineBEndPoint.x()
115 aLineBEndPointYPrev = aLineBEndPoint.y()
116 aSession.startOperation()
117 aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX,
118                           aLineAStartPoint.y() + deltaY)
119 aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX,
120                         aLineAEndPoint.y() - deltaY)
121 aSession.finishOperation()
122 # print "After transformation:"
123 # print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x()
124 # print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y()
125 # print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x()
126 # print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y()
127 # print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x()
128 # print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y()
129 # print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x()
130 # print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y()
131 #=========================================================================
132 # End of test
133 #=========================================================================