Salome HOME
Issue #2130: arc is done not as desired
[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::typeId());
8
9 """
10 from GeomDataAPI import *
11 from ModelAPI import *
12 from salome.shaper import model
13
14 #=========================================================================
15 # Initialization of the test
16 #=========================================================================
17
18 __updated__ = "2015-03-16"
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 = featureToCompositeFeature(aSketchCommonFeature)
28 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
29 origin.setValue(0, 0, 0)
30 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
31 dirx.setValue(1, 0, 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 assert (model.dof(aSketchFeature) == 4)
46 #=========================================================================
47 # Assign vertical constraint for a line
48 #=========================================================================
49 aSession.startOperation()
50 aVerticalConstraint = aSketchFeature.addFeature("SketchConstraintVertical")
51 refattrA = aVerticalConstraint.refattr("ConstraintEntityA")
52 aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
53 assert (aResult is not None)
54 refattrA.setObject(aResult)
55 aVerticalConstraint.execute()
56 aSession.finishOperation()
57 assert(aLineStartPoint.x() == aLineEndPoint.x())
58 assert (model.dof(aSketchFeature) == 3)
59 #=========================================================================
60 # Move one of boundary points of a line
61 #=========================================================================
62 deltaX = deltaY = 10.
63 aSession.startOperation()
64 aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
65                          aLineStartPoint.y() + deltaY)
66 aSession.finishOperation()
67 assert(aLineStartPoint.x() == aLineEndPoint.x())
68 assert (model.dof(aSketchFeature) == 3)
69 #=========================================================================
70 # Move other boundary point of a line
71 #=========================================================================
72 deltaX = -3.
73 deltaY = -10.
74 aSession.startOperation()
75 aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
76                        aLineEndPoint.y() + deltaY)
77 aSession.finishOperation()
78 assert(aLineStartPoint.x() == aLineEndPoint.x())
79 assert (model.dof(aSketchFeature) == 3)
80 #=========================================================================
81 # End of test
82 #=========================================================================
83
84 assert(model.checkPythonDump())