Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintVertical.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22     TestConstraintVertical.py
23     Unit test of SketchPlugin_ConstraintVertical class
24
25     SketchPlugin_ConstraintVertical
26         static const std::string MY_CONSTRAINT_VERTICAL_ID("SketchConstraintVertical");
27         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
28
29 """
30 from GeomDataAPI import *
31 from ModelAPI import *
32 from salome.shaper import model
33
34 #=========================================================================
35 # Initialization of the test
36 #=========================================================================
37
38 __updated__ = "2015-03-16"
39
40 aSession = ModelAPI_Session.get()
41 aDocument = aSession.moduleDocument()
42 #=========================================================================
43 # Creation of a sketch
44 #=========================================================================
45 aSession.startOperation()
46 aSketchCommonFeature = aDocument.addFeature("Sketch")
47 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
48 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
49 origin.setValue(0, 0, 0)
50 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
51 dirx.setValue(1, 0, 0)
52 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
53 norm.setValue(0, 0, 1)
54 aSession.finishOperation()
55 #=========================================================================
56 # Create non-vertical line
57 #=========================================================================
58 aSession.startOperation()
59 aSketchLine = aSketchFeature.addFeature("SketchLine")
60 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
61 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
62 aLineStartPoint.setValue(0., 15.)
63 aLineEndPoint.setValue(20., 25.)
64 aSession.finishOperation()
65 assert (model.dof(aSketchFeature) == 4)
66 #=========================================================================
67 # Assign vertical constraint for a line
68 #=========================================================================
69 aSession.startOperation()
70 aVerticalConstraint = aSketchFeature.addFeature("SketchConstraintVertical")
71 refattrA = aVerticalConstraint.refattr("ConstraintEntityA")
72 aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
73 assert (aResult is not None)
74 refattrA.setObject(aResult)
75 aVerticalConstraint.execute()
76 aSession.finishOperation()
77 assert(aLineStartPoint.x() == aLineEndPoint.x())
78 assert (model.dof(aSketchFeature) == 3)
79 #=========================================================================
80 # Move one of boundary points of a line
81 #=========================================================================
82 deltaX = deltaY = 10.
83 aSession.startOperation()
84 aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
85                          aLineStartPoint.y() + deltaY)
86 aSession.finishOperation()
87 assert(aLineStartPoint.x() == aLineEndPoint.x())
88 assert (model.dof(aSketchFeature) == 3)
89 #=========================================================================
90 # Move other boundary point of a line
91 #=========================================================================
92 deltaX = -3.
93 deltaY = -10.
94 aSession.startOperation()
95 aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
96                        aLineEndPoint.y() + deltaY)
97 aSession.finishOperation()
98 assert(aLineStartPoint.x() == aLineEndPoint.x())
99 assert (model.dof(aSketchFeature) == 3)
100 #=========================================================================
101 # End of test
102 #=========================================================================
103
104 assert(model.checkPythonDump())