1 #=========================================================================
2 # Initialization of the test
3 #=========================================================================
4 from GeomDataAPI import *
7 __updated__ = "2014-10-28"
9 aSession = ModelAPI_Session.get()
10 aDocument = aSession.moduleDocument()
11 #=========================================================================
12 # Creation of a sketch
13 #=========================================================================
14 aSession.startOperation()
15 aSketchCommonFeature = aDocument.addFeature("Sketch")
16 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
17 assert (aSketchFeature.getKind() == "Sketch")
18 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
19 origin.setValue(0, 0, 0)
20 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
21 dirx.setValue(1, 0, 0)
22 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
23 norm.setValue(0, 0, 1)
24 aSession.finishOperation()
25 # check that values have been changed
26 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
27 assert (origin.x() == 0)
28 assert (origin.y() == 0)
29 assert (origin.z() == 0)
30 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
31 assert (dirx.x() == 1)
32 assert (dirx.y() == 0)
33 assert (dirx.z() == 0)
34 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
35 assert (norm.x() == 0)
36 assert (norm.y() == 0)
37 assert (norm.z() == 1)
38 #=========================================================================
40 #=========================================================================
41 aSession.startOperation()
42 aSketchReflist = aSketchFeature.reflist("Features")
43 assert (not aSketchReflist.isInitialized())
44 assert(aSketchReflist.size() == 0)
45 assert (len(aSketchReflist.list()) == 0)
46 # aSketchPoint = aDocument.addFeature("SketchPoint")
47 aSketchPoint = aSketchFeature.addFeature("SketchPoint")
48 assert (aSketchPoint.getKind() == "SketchPoint")
49 coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordinates"))
50 assert (coords.x() == 0)
51 assert (coords.y() == 0)
52 assert (not coords.isInitialized())
53 # Simulate SketchPlugin_Point::move(...)
54 coords.setValue(10., 10.)
55 assert (coords.isInitialized())
56 aSession.finishOperation()
57 # check that values have been changed
58 aSketchReflist = aSketchFeature.reflist("Features")
59 assert (aSketchReflist.size() == 1)
60 assert (len(aSketchReflist.list()) == 1)
61 coords = geomDataAPI_Point2D(aSketchPoint.attribute("PointCoordinates"))
62 assert (coords.x() == 10.0)
63 assert (coords.y() == 10.0)
64 #=========================================================================
66 #=========================================================================
67 aSession.startOperation()
68 # aSketchLine = aDocument.addFeature("SketchLine")
69 aSketchLine = aSketchFeature.addFeature("SketchLine")
70 assert (aSketchLine.getKind() == "SketchLine")
71 assert (aSketchReflist.size() == 2)
72 assert (len(aSketchReflist.list()) == 2)
73 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
74 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
75 assert (aLineStartPoint.x() == 0)
76 assert (aLineStartPoint.y() == 0)
77 assert (not aLineStartPoint.isInitialized())
78 assert (aLineEndPoint.x() == 0)
79 assert (aLineEndPoint.y() == 0)
80 assert (not aLineEndPoint.isInitialized())
81 # Simulate SketchPlugin_Line::move(...)
82 aLineStartPoint.setValue(50., 50.)
83 aLineEndPoint.setValue(60., 60.)
84 assert (aLineStartPoint.isInitialized())
85 assert (aLineEndPoint.isInitialized())
86 aSession.finishOperation()
87 # check that values have been changed
88 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
89 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
90 assert (aLineStartPoint.x() == 50.0)
91 assert (aLineStartPoint.y() == 50.0)
92 assert (aLineEndPoint.x() == 60.0)
93 assert (aLineEndPoint.y() == 60.0)
94 #=========================================================================
96 #=========================================================================
97 aResult = aSketchLine.firstResult()
98 assert (aResult is not None)
99 aResultConstruction = modelAPI_ResultConstruction(aResult)
100 aShape = aResultConstruction.shape()
101 assert (aShape is not None)
102 assert (not aShape.isNull())