3 Unit test of SketchPlugin_Ractangle class
6 from GeomDataAPI import *
9 #=========================================================================
10 # Initialization of the test
11 #=========================================================================
13 __updated__ = "2016-02-05"
16 #=========================================================================
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()
25 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
26 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
27 return aStart.x() == aEnd.x()
30 #=========================================================================
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 #=========================================================================
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()
62 for i in range (0, aNbSubs):
63 aFeature = objectToFeature(aSketchFeature.subFeature(i))
64 if aFeature.getKind() == "SketchLine":
66 assert (isHorizontal(aLastLine) or isVertical(aLastLine))
67 aNbLines = aNbLines + 1
68 assert (aNbLines == 4)
69 #=========================================================================
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()
81 for i in range (0, aNbSubs):
82 aFeature = objectToFeature(aSketchFeature.subFeature(i))
83 if aFeature.getKind() == "SketchLine":
85 assert (isHorizontal(aLastLine) or isVertical(aLastLine))
86 aNbLines = aNbLines + 1
87 assert (aNbLines == 4)
88 #=========================================================================
90 #=========================================================================
93 assert(model.checkPythonDump())