Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into azv/SketchSolver_Refactoring
[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 from salome.shaper import model
10
11 #=========================================================================
12 # Initialization of the test
13 #=========================================================================
14
15 __updated__ = "2016-02-05"
16
17
18 #=========================================================================
19 # Auxiliary functions
20 #=========================================================================
21 def isHorizontal(line):
22     aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
23     aEnd   = geomDataAPI_Point2D(line.attribute("EndPoint"))
24     return aStart.y() == aEnd.y()
25
26 def isVertical(line):
27     aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
28     aEnd   = geomDataAPI_Point2D(line.attribute("EndPoint"))
29     return aStart.x() == aEnd.x()
30
31
32 #=========================================================================
33 # Start of test
34 #=========================================================================
35 aSession = ModelAPI_Session.get()
36 aDocument = aSession.moduleDocument()
37 #=========================================================================
38 # Creation of a sketch
39 #=========================================================================
40 aSession.startOperation()
41 aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch"))
42 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
43 origin.setValue(0, 0, 0)
44 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
45 dirx.setValue(1, 0, 0)
46 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
47 norm.setValue(0, 0, 1)
48 aSession.finishOperation()
49 #=========================================================================
50 # Create a rectangle
51 #=========================================================================
52 aSession.startOperation()
53 aRectangle = aSketchFeature.addFeature("SketchRectangle")
54 aStartCorner = geomDataAPI_Point2D(aRectangle.attribute("RectStartPoint"))
55 aEndCorner = geomDataAPI_Point2D(aRectangle.attribute("RectEndPoint"))
56 aStartCorner.setValue(10., 10.)
57 aEndCorner.setValue(40., 30.)
58 aSession.finishOperation()
59 #=========================================================================
60 # Check the lines of rectangle are parallel to the axes
61 #=========================================================================
62 aNbSubs = aSketchFeature.numberOfSubs()
63 aNbLines = 0
64 for i in range (0, aNbSubs):
65     aFeature = objectToFeature(aSketchFeature.subFeature(i))
66     if aFeature.getKind() == "SketchLine":
67         aLastLine = aFeature
68         assert (isHorizontal(aLastLine) or isVertical(aLastLine))
69         aNbLines = aNbLines + 1
70 assert (aNbLines == 4)
71 assert (model.dof(aSketchFeature) == 4)
72 #=========================================================================
73 # Move one of lines
74 #=========================================================================
75 aSession.startOperation()
76 aLineEnd = geomDataAPI_Point2D(aLastLine.attribute("EndPoint"))
77 aLineEnd.setValue(50., 50.)
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 # End of test
94 #=========================================================================
95
96 assert(model.checkPythonDump())