Salome HOME
050c60f249e7084053c6cad865e887c80661c520
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintHorizontal.py
1 """
2     TestConstraintHorizontal.py
3     Unit test of SketchPlugin_ConstraintHorizontal class
4         
5     SketchPlugin_ConstraintHorizontal
6         static const std::string MY_CONSTRAINT_HORIZONTAL_ID("SketchConstraintHorizontal");
7         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
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-horizontal 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 horizontal constraint for a line
47 #=========================================================================
48 aSession.startOperation()
49 aHorizontalConstraint = aSketchFeature.addFeature("SketchConstraintHorizontal")
50 refattrA = aHorizontalConstraint.refattr("ConstraintEntityA")
51 aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
52 assert (aResult is not None)
53 refattrA.setObject(aResult)
54 aHorizontalConstraint.execute()
55 aSession.finishOperation()
56 assert(aLineStartPoint.y() == aLineEndPoint.y())
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.y() == aLineEndPoint.y())
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.y() == aLineEndPoint.y())
76 #=========================================================================
77 # End of test
78 #=========================================================================