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