Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / SketchPlugin / Test / TestRectangle.py
1 """
2     TestRectangle.py
3     Unit test of SketchPlugin_Ractangle class
4
5 """
6 from GeomDataAPI import *
7 from ModelAPI import *
8 import math
9 #=========================================================================
10 # Initialization of the test
11 #=========================================================================
12
13 __updated__ = "2016-02-05"
14
15
16 #=========================================================================
17 # Auxiliary functions
18 #=========================================================================
19 def isHorizontal(line):
20     aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
21     aEnd   = geomDataAPI_Point2D(line.attribute("EndPoint"))
22     return aStart.y() == aEnd.y()
23
24 def isVertical(line):
25     aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
26     aEnd   = geomDataAPI_Point2D(line.attribute("EndPoint"))
27     return aStart.x() == aEnd.x()
28
29
30 #=========================================================================
31 # Start of test
32 #=========================================================================
33 aSession = ModelAPI_Session.get()
34 aDocument = aSession.moduleDocument()
35 #=========================================================================
36 # Creation of a sketch
37 #=========================================================================
38 aSession.startOperation()
39 aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
40 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
41 origin.setValue(0, 0, 0)
42 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
43 dirx.setValue(1, 0, 0)
44 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
45 norm.setValue(0, 0, 1)
46 aSession.finishOperation()
47 #=========================================================================
48 # Create a rectangle
49 #=========================================================================
50 aSession.startOperation()
51 aRectangle = aSketchFeature.addFeature("SketchRectangle")
52 aStartCorner = geomDataAPI_Point2D(aRectangle.attribute("RectStartPoint"))
53 aEndCorner = geomDataAPI_Point2D(aRectangle.attribute("RectEndPoint"))
54 aStartCorner.setValue(10., 10.)
55 aEndCorner.setValue(40., 30.)
56 aSession.finishOperation()
57 #=========================================================================
58 # Check the lines of rectangle are parallel to the axes
59 #=========================================================================
60 aNbSubs = aSketchFeature.numberOfSubs()
61 aNbLines = 0
62 for i in range (0, aNbSubs):
63     aFeature = objectToFeature(aSketchFeature.subFeature(i))
64     if aFeature.getKind() == "SketchLine":
65         aLastLine = aFeature
66         assert (isHorizontal(aLastLine) or isVertical(aLastLine))
67         aNbLines = aNbLines + 1
68 assert (aNbLines == 4)
69 #=========================================================================
70 # Move one of lines
71 #=========================================================================
72 aSession.startOperation()
73 aLineEnd = geomDataAPI_Point2D(aLastLine.attribute("EndPoint"))
74 aLineEnd.setValue(50., 50.)
75 aSession.finishOperation()
76 #=========================================================================
77 # Check the lines of rectangle are parallel to the axes
78 #=========================================================================
79 aNbSubs = aSketchFeature.numberOfSubs()
80 aNbLines = 0
81 for i in range (0, aNbSubs):
82     aFeature = objectToFeature(aSketchFeature.subFeature(i))
83     if aFeature.getKind() == "SketchLine":
84         aLastLine = aFeature
85         assert (isHorizontal(aLastLine) or isVertical(aLastLine))
86         aNbLines = aNbLines + 1
87 assert (aNbLines == 4)
88 #=========================================================================
89 # End of test
90 #=========================================================================
91
92 from salome.shaper import model
93 assert(model.checkPythonDump())