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>
23 Unit test of SketchPlugin_Ractangle class
26 from GeomDataAPI import *
27 from ModelAPI import *
29 from salome.shaper import model
31 #=========================================================================
32 # Initialization of the test
33 #=========================================================================
35 __updated__ = "2016-02-05"
38 #=========================================================================
40 #=========================================================================
41 def isHorizontal(line):
42 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
43 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
44 return aStart.y() == aEnd.y()
47 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
48 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
49 return aStart.x() == aEnd.x()
52 #=========================================================================
54 #=========================================================================
55 aSession = ModelAPI_Session.get()
56 aDocument = aSession.moduleDocument()
57 #=========================================================================
58 # Creation of a sketch
59 #=========================================================================
60 aSession.startOperation()
61 aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
62 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
63 origin.setValue(0, 0, 0)
64 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
65 dirx.setValue(1, 0, 0)
66 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
67 norm.setValue(0, 0, 1)
68 aSession.finishOperation()
69 #=========================================================================
71 #=========================================================================
72 aSession.startOperation()
73 aRectangle = aSketchFeature.addFeature("SketchRectangle")
74 aStartCorner = geomDataAPI_Point2D(aRectangle.attribute("RectStartPoint"))
75 aEndCorner = geomDataAPI_Point2D(aRectangle.attribute("RectEndPoint"))
76 aStartCorner.setValue(10., 10.)
77 aEndCorner.setValue(40., 30.)
78 aSession.finishOperation()
79 #=========================================================================
80 # Check the lines of rectangle are parallel to the axes
81 #=========================================================================
82 aNbSubs = aSketchFeature.numberOfSubs()
84 for i in range (0, aNbSubs):
85 aFeature = objectToFeature(aSketchFeature.subFeature(i))
86 if aFeature.getKind() == "SketchLine":
88 assert (isHorizontal(aLastLine) or isVertical(aLastLine))
89 aNbLines = aNbLines + 1
90 assert (aNbLines == 4)
91 assert (model.dof(aSketchFeature) == 4)
92 #=========================================================================
94 #=========================================================================
95 aSession.startOperation()
96 aLineEnd = geomDataAPI_Point2D(aLastLine.attribute("EndPoint"))
97 aLineEnd.setValue(50., 50.)
98 aSession.finishOperation()
99 #=========================================================================
100 # Check the lines of rectangle are parallel to the axes
101 #=========================================================================
102 aNbSubs = aSketchFeature.numberOfSubs()
104 for i in range (0, aNbSubs):
105 aFeature = objectToFeature(aSketchFeature.subFeature(i))
106 if aFeature.getKind() == "SketchLine":
108 assert (isHorizontal(aLastLine) or isVertical(aLastLine))
109 aNbLines = aNbLines + 1
110 assert (aNbLines == 4)
111 assert (model.dof(aSketchFeature) == 4)
112 #=========================================================================
114 #=========================================================================
116 assert(model.checkPythonDump())