1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
22 TestConstraintHorizontal.py
23 Unit test of SketchPlugin_ConstraintHorizontal class
25 SketchPlugin_ConstraintHorizontal
26 static const std::string MY_CONSTRAINT_HORIZONTAL_ID("SketchConstraintHorizontal");
27 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
30 from GeomDataAPI import *
31 from ModelAPI import *
32 from salome.shaper import model
34 #=========================================================================
35 # Initialization of the test
36 #=========================================================================
38 __updated__ = "2015-03-16"
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-horizontal 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 horizontal constraint for a line
68 #=========================================================================
69 aSession.startOperation()
70 aHorizontalConstraint = aSketchFeature.addFeature("SketchConstraintHorizontal")
71 refattrA = aHorizontalConstraint.refattr("ConstraintEntityA")
72 aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
73 assert (aResult is not None)
74 refattrA.setObject(aResult)
75 aHorizontalConstraint.execute()
76 aSession.finishOperation()
77 assert(aLineStartPoint.y() == aLineEndPoint.y())
78 assert(model.dof(aSketchFeature) == 3)
79 #=========================================================================
80 # Move one of boundary points of a line
81 #=========================================================================
83 aSession.startOperation()
84 aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
85 aLineStartPoint.y() + deltaY)
86 aSession.finishOperation()
87 assert(aLineStartPoint.y() == aLineEndPoint.y())
88 assert(model.dof(aSketchFeature) == 3)
89 #=========================================================================
90 # Move other boundary point of a line
91 #=========================================================================
94 aSession.startOperation()
95 aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
96 aLineEndPoint.y() + deltaY)
97 aSession.finishOperation()
98 assert(aLineStartPoint.y() == aLineEndPoint.y())
99 assert(model.dof(aSketchFeature) == 3)
100 #=========================================================================
102 #=========================================================================
104 assert(model.checkPythonDump())