Salome HOME
605abad933e2928088ee9d96937ee8e613754624
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintHorizontal.py
1 # Copyright (C) 2014-2023  CEA, EDF
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 email : webmaster.salome@opencascade.com
18 #
19
20 """
21     TestConstraintHorizontal.py
22     Unit test of SketchPlugin_ConstraintHorizontal class
23
24     SketchPlugin_ConstraintHorizontal
25         static const std::string MY_CONSTRAINT_HORIZONTAL_ID("SketchConstraintHorizontal");
26         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
27
28 """
29 from GeomDataAPI import *
30 from ModelAPI import *
31 from salome.shaper import model
32
33 #=========================================================================
34 # Initialization of the test
35 #=========================================================================
36
37 __updated__ = "2015-03-16"
38
39 aSession = ModelAPI_Session.get()
40 aDocument = aSession.moduleDocument()
41 #=========================================================================
42 # Creation of a sketch
43 #=========================================================================
44 aSession.startOperation()
45 aSketchCommonFeature = aDocument.addFeature("Sketch")
46 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
47 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
48 origin.setValue(0, 0, 0)
49 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
50 dirx.setValue(1, 0, 0)
51 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
52 norm.setValue(0, 0, 1)
53 aSession.finishOperation()
54 #=========================================================================
55 # Create non-horizontal line
56 #=========================================================================
57 aSession.startOperation()
58 aSketchLine = aSketchFeature.addFeature("SketchLine")
59 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
60 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
61 aLineStartPoint.setValue(0., 15.)
62 aLineEndPoint.setValue(20., 25.)
63 aSession.finishOperation()
64 assert(model.dof(aSketchFeature) == 4)
65 #=========================================================================
66 # Assign horizontal constraint for a line
67 #=========================================================================
68 aSession.startOperation()
69 aHorizontalConstraint = aSketchFeature.addFeature("SketchConstraintHorizontal")
70 refattrA = aHorizontalConstraint.refattr("ConstraintEntityA")
71 aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
72 assert (aResult is not None)
73 refattrA.setObject(aResult)
74 aHorizontalConstraint.execute()
75 aSession.finishOperation()
76 assert(aLineStartPoint.y() == aLineEndPoint.y())
77 assert(model.dof(aSketchFeature) == 3)
78 #=========================================================================
79 # Move one of boundary points of a line
80 #=========================================================================
81 deltaX = deltaY = 10.
82 aSession.startOperation()
83 aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
84                          aLineStartPoint.y() + deltaY)
85 aSession.finishOperation()
86 assert(aLineStartPoint.y() == aLineEndPoint.y())
87 assert(model.dof(aSketchFeature) == 3)
88 #=========================================================================
89 # Move other boundary point of a line
90 #=========================================================================
91 deltaX = -3.
92 deltaY = -10.
93 aSession.startOperation()
94 aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
95                        aLineEndPoint.y() + deltaY)
96 aSession.finishOperation()
97 assert(aLineStartPoint.y() == aLineEndPoint.y())
98 assert(model.dof(aSketchFeature) == 3)
99 #=========================================================================
100 # End of test
101 #=========================================================================
102
103 assert(model.checkPythonDump())