1 # Copyright (C) 2014-2021 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 email : webmaster.salome@opencascade.com
22 Unit test of SketchPlugin_Ractangle class
25 from GeomDataAPI import *
26 from ModelAPI import *
28 from salome.shaper import model
30 #=========================================================================
31 # Initialization of the test
32 #=========================================================================
34 __updated__ = "2016-02-05"
37 #=========================================================================
39 #=========================================================================
40 def isHorizontal(line):
41 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
42 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
43 return aStart.y() == aEnd.y()
46 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
47 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
48 return aStart.x() == aEnd.x()
51 #=========================================================================
53 #=========================================================================
54 aSession = ModelAPI_Session.get()
55 aDocument = aSession.moduleDocument()
56 #=========================================================================
57 # Creation of a sketch
58 #=========================================================================
59 aSession.startOperation()
60 aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
61 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
62 origin.setValue(0, 0, 0)
63 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
64 dirx.setValue(1, 0, 0)
65 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
66 norm.setValue(0, 0, 1)
67 aSession.finishOperation()
68 #=========================================================================
70 #=========================================================================
71 aSession.startOperation()
72 aRectangle = aSketchFeature.addFeature("SketchRectangle")
73 aRectangle.string("RectangleType").setValue("RectangleTypeByCorners")
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())