Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / SketchPlugin / Test / TestRectangle.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     TestRectangle.py
23     Unit test of SketchPlugin_Ractangle class
24
25 """
26 from GeomDataAPI import *
27 from ModelAPI import *
28 import math
29 from salome.shaper import model
30
31 #=========================================================================
32 # Initialization of the test
33 #=========================================================================
34
35 __updated__ = "2016-02-05"
36
37
38 #=========================================================================
39 # Auxiliary functions
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()
45
46 def isVertical(line):
47     aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
48     aEnd   = geomDataAPI_Point2D(line.attribute("EndPoint"))
49     return aStart.x() == aEnd.x()
50
51
52 #=========================================================================
53 # Start of test
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 #=========================================================================
70 # Create a rectangle
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()
83 aNbLines = 0
84 for i in range (0, aNbSubs):
85     aFeature = objectToFeature(aSketchFeature.subFeature(i))
86     if aFeature.getKind() == "SketchLine":
87         aLastLine = aFeature
88         assert (isHorizontal(aLastLine) or isVertical(aLastLine))
89         aNbLines = aNbLines + 1
90 assert (aNbLines == 4)
91 assert (model.dof(aSketchFeature) == 4)
92 #=========================================================================
93 # Move one of lines
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()
103 aNbLines = 0
104 for i in range (0, aNbSubs):
105     aFeature = objectToFeature(aSketchFeature.subFeature(i))
106     if aFeature.getKind() == "SketchLine":
107         aLastLine = aFeature
108         assert (isHorizontal(aLastLine) or isVertical(aLastLine))
109         aNbLines = aNbLines + 1
110 assert (aNbLines == 4)
111 assert (model.dof(aSketchFeature) == 4)
112 #=========================================================================
113 # End of test
114 #=========================================================================
115
116 assert(model.checkPythonDump())