3 Unit test of SketchPlugin_Ractangle class
6 from GeomDataAPI import *
9 from salome.shaper import model
11 #=========================================================================
12 # Initialization of the test
13 #=========================================================================
15 __updated__ = "2016-02-05"
18 #=========================================================================
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()
27 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
28 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
29 return aStart.x() == aEnd.x()
32 #=========================================================================
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 #=========================================================================
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()
64 for i in range (0, aNbSubs):
65 aFeature = objectToFeature(aSketchFeature.subFeature(i))
66 if aFeature.getKind() == "SketchLine":
68 assert (isHorizontal(aLastLine) or isVertical(aLastLine))
69 aNbLines = aNbLines + 1
70 assert (aNbLines == 4)
71 assert (model.dof(aSketchFeature) == 4)
72 #=========================================================================
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()
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 #=========================================================================
96 assert(model.checkPythonDump())