Salome HOME
Issue #2130: arc is done not as desired
[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::typeId());
8         data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
9         data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
10
11 """
12 from GeomDataAPI import *
13 from ModelAPI import *
14 from salome.shaper import model
15
16 #=========================================================================
17 # Initialization of the test
18 #=========================================================================
19
20 __updated__ = "2014-10-28"
21
22 aSession = ModelAPI_Session.get()
23 aDocument = aSession.moduleDocument()
24 #=========================================================================
25 # Creation of a sketch
26 #=========================================================================
27 aSession.startOperation()
28 aSketchCommonFeature = aDocument.addFeature("Sketch")
29 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
30 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
31 origin.setValue(0, 0, 0)
32 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
33 dirx.setValue(1, 0, 0)
34 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
35 norm.setValue(0, 0, 1)
36 aSession.finishOperation()
37 #=========================================================================
38 # Create two lines which are not parallel
39 #=========================================================================
40 aSession.startOperation()
41 # line A
42 aSketchLineA = aSketchFeature.addFeature("SketchLine")
43 aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
44 aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
45 aSketchLineB = aSketchFeature.addFeature("SketchLine")
46 aLineAStartPoint.setValue(0., 25)
47 aLineAEndPoint.setValue(85., 25)
48 # line B
49 aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
50 aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
51 aLineBStartPoint.setValue(0., 50)
52 aLineBEndPoint.setValue(80., 75)
53 aSession.finishOperation()
54 assert (model.dof(aSketchFeature) == 8)
55 #=========================================================================
56 # Make a constraint to keep the length of the line constant
57 # to parallel perpendicular constraint collapsing line to point
58 #=========================================================================
59 aSession.startOperation()
60 for eachFeature in [aSketchLineA, aSketchLineB]:
61     aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
62     refattrA = aLengthConstraint.refattr("ConstraintEntityA")
63     aResultA = modelAPI_ResultConstruction(eachFeature.firstResult())
64     assert (aResultA is not None)
65     refattrA.setObject(aResultA)
66     aLengthConstraint.execute()
67 aSession.finishOperation()
68 # Coordinates of lines should not be changed after this constraint
69 assert (aLineAStartPoint.x() == 0)
70 assert (aLineAStartPoint.y() == 25)
71 assert (aLineAEndPoint.x() == 85)
72 assert (aLineAEndPoint.y() == 25)
73 assert (aLineBStartPoint.x() == 0)
74 assert (aLineBStartPoint.y() == 50)
75 assert (aLineBEndPoint.x() == 80)
76 assert (aLineBEndPoint.y() == 75)
77 assert (model.dof(aSketchFeature) == 6)
78 #=========================================================================
79 # Link lines with parallel constraint
80 #=========================================================================
81 aSession.startOperation()
82 aParallelConstraint = aSketchFeature.addFeature("SketchConstraintParallel")
83 refattrA = aParallelConstraint.refattr("ConstraintEntityA")
84 refattrB = aParallelConstraint.refattr("ConstraintEntityB")
85 # aResultA is already defined for the length constraint
86 aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult())
87 aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult())
88 assert (aResultA is not None)
89 assert (aResultB is not None)
90 refattrA.setObject(aResultA)
91 refattrB.setObject(aResultB)
92 aParallelConstraint.execute()
93 aSession.finishOperation()
94 assert (model.dof(aSketchFeature) == 5)
95 #=========================================================================
96 # Check values and move one constrainted object
97 #=========================================================================
98 deltaX = deltaY = 10.
99 # rotate line, check that reference's line points are moved also
100 aLineBStartPointPrev = (aLineBStartPoint.x(), aLineBStartPoint.y())
101 aLineBEndPointPrev = (aLineBEndPoint.x(), aLineBEndPoint.y())
102 aSession.startOperation()
103 aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX,
104                           aLineAStartPoint.y() + deltaY)
105 aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX,
106                         aLineAEndPoint.y() - deltaY)
107 aSession.finishOperation()
108 aLineBStartPointNew = (aLineBStartPoint.x(), aLineBStartPoint.y())
109 aLineBEndPointNew = (aLineBEndPoint.x(), aLineBEndPoint.y())
110
111 assert (aLineBStartPointPrev != aLineBStartPointNew)
112 assert (aLineBEndPointPrev != aLineBEndPointNew)
113 assert (model.dof(aSketchFeature) == 5)
114 #=========================================================================
115 # End of test
116 #=========================================================================
117
118 assert(model.checkPythonDump())