Salome HOME
Union of validator and filter functionalities.
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintVertical.py
1 """
2     TestConstraintVertical.py
3     Unit test of SketchPlugin_ConstraintVertical class
4         
5     SketchPlugin_ConstraintVertical
6         static const std::string MY_CONSTRAINT_VERTICAL_ID("SketchConstraintVertical");
7         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
8
9 """
10 from GeomDataAPI import *
11 from ModelAPI import *
12 #=========================================================================
13 # Initialization of the test
14 #=========================================================================
15
16 __updated__ = "2015-03-16"
17
18 aSession = ModelAPI_Session.get()
19 aDocument = aSession.moduleDocument()
20 #=========================================================================
21 # Creation of a sketch
22 #=========================================================================
23 aSession.startOperation()
24 aSketchCommonFeature = aDocument.addFeature("Sketch")
25 aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
26 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
27 origin.setValue(0, 0, 0)
28 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
29 dirx.setValue(1, 0, 0)
30 diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
31 diry.setValue(0, 1, 0)
32 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
33 norm.setValue(0, 0, 1)
34 aSession.finishOperation()
35 #=========================================================================
36 # Create non-vertical line
37 #=========================================================================
38 aSession.startOperation()
39 aSketchLine = aSketchFeature.addFeature("SketchLine")
40 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
41 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
42 aLineStartPoint.setValue(0., 15.)
43 aLineEndPoint.setValue(20., 25.)
44 aSession.finishOperation()
45 #=========================================================================
46 # Assign vertical constraint for a line
47 #=========================================================================
48 aSession.startOperation()
49 aVerticalConstraint = aSketchFeature.addFeature("SketchConstraintVertical")
50 refattrA = aVerticalConstraint.refattr("ConstraintEntityA")
51 aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
52 assert (aResult is not None)
53 refattrA.setObject(aResult)
54 aVerticalConstraint.execute()
55 aSession.finishOperation()
56 assert(aLineStartPoint.x() == aLineEndPoint.x())
57 #=========================================================================
58 # Move one of boundary points of a line
59 #=========================================================================
60 deltaX = deltaY = 10.
61 aSession.startOperation()
62 aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
63                          aLineStartPoint.y() + deltaY)
64 aSession.finishOperation()
65 assert(aLineStartPoint.x() == aLineEndPoint.x())
66 #=========================================================================
67 # Move other boundary point of a line
68 #=========================================================================
69 deltaX = -3.
70 deltaY = -10.
71 aSession.startOperation()
72 aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
73                        aLineEndPoint.y() + deltaY)
74 aSession.finishOperation()
75 assert(aLineStartPoint.x() == aLineEndPoint.x())
76 #=========================================================================
77 # End of test
78 #=========================================================================