1 #=========================================================================
2 # Initialization of the test
3 #=========================================================================
4 from GeomDataAPI import *
7 __updated__ = "2014-07-23"
9 aPluginManager = ModelAPI_PluginManager.get()
10 aDocument = aPluginManager.rootDocument()
11 aDocument.startOperation()
12 #===============================================================================
13 # Test ModelAPI static methods
14 # TODO: Move this test in the ModelAPI progect
15 #===============================================================================
16 assert (ModelAPI_Feature.group() == "Features")
17 assert (ModelAPI_AttributeDocRef.type() == "DocRef")
18 assert (ModelAPI_AttributeDouble.type() == "Double")
19 assert (ModelAPI_AttributeReference.type() == "Reference")
20 assert (ModelAPI_AttributeRefAttr.type() == "RefAttr")
21 assert (ModelAPI_AttributeRefList.type() == "RefList")
22 #===============================================================================
23 # Test GeomDataAPI static methods
24 # TODO: Move this test in the GeomDataAPI progect
25 #===============================================================================
26 assert (GeomDataAPI_Point.type() == "Point")
27 assert (GeomDataAPI_Dir.type() == "Dir")
28 assert (GeomDataAPI_Point2D.type() == "Point2D")
29 #=========================================================================
30 # Creation of a sketch
31 #=========================================================================
32 aSketchFeature = aDocument.addFeature("Sketch")
33 assert (aSketchFeature.getKind() == "Sketch")
34 aSketchFeatureData = aSketchFeature.data()
35 origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
36 origin.setValue(0, 0, 0)
37 dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
38 dirx.setValue(1, 0, 0)
39 diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
40 diry.setValue(0, 1, 0)
41 norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
42 norm.setValue(0, 0, 1)
43 # check that values have been changed
44 origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
45 assert (origin.x() == 0)
46 assert (origin.y() == 0)
47 assert (origin.z() == 0)
48 dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
49 assert (dirx.x() == 1)
50 assert (dirx.y() == 0)
51 assert (dirx.z() == 0)
52 diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
53 assert (diry.x() == 0)
54 assert (diry.y() == 1)
55 assert (diry.z() == 0)
56 norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
57 assert (norm.x() == 0)
58 assert (norm.y() == 0)
59 assert (norm.z() == 1)
60 #=========================================================================
62 #=========================================================================
63 aSketchReflist = aSketchFeatureData.reflist("Features")
64 assert (not aSketchReflist.isInitialized())
65 assert(aSketchReflist.size() == 0)
66 assert (len(aSketchReflist.list()) == 0)
67 aSketchPoint = aDocument.addFeature("SketchPoint")
68 assert (aSketchPoint.getKind() == "SketchPoint")
69 aSketchReflist.append(aSketchPoint)
70 aSketchPointData = aSketchPoint.data()
71 coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
72 assert (coords.x() == 0)
73 assert (coords.y() == 0)
74 assert (not coords.isInitialized())
75 # Simulate SketchPlugin_Point::move(...)
76 coords.setValue(10., 10.)
77 assert (coords.isInitialized())
78 # check that values have been changed
79 aSketchReflist = aSketchFeatureData.reflist("Features")
80 assert (aSketchReflist.size() == 1)
81 assert (len(aSketchReflist.list()) == 1)
82 aSketchPointData = aSketchPoint.data()
83 coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
84 assert (coords.x() == 10.0)
85 assert (coords.y() == 10.0)
86 #===============================================================================
88 #===============================================================================
89 aSketchLine = aDocument.addFeature("SketchLine")
90 aSketchReflist.append(aSketchLine)
91 assert (aSketchReflist.size() == 2)
92 assert (len(aSketchReflist.list()) == 2)
93 aSketchLineData = aSketchLine.data()
94 aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
95 aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
96 assert (aLineStartPoint.x() == 0)
97 assert (aLineStartPoint.y() == 0)
98 assert (not aLineStartPoint.isInitialized())
99 assert (aLineEndPoint.x() == 0)
100 assert (aLineEndPoint.y() == 0)
101 assert (not aLineEndPoint.isInitialized())
102 # Simulate SketchPlugin_Line::move(...)
103 aLineStartPoint.setValue(50., 50.)
104 aLineEndPoint.setValue(60., 60.)
105 assert (aLineStartPoint.isInitialized())
106 assert (aLineEndPoint.isInitialized())
107 # check that values have been changed
108 aSketchLineData = aSketchLine.data()
109 aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
110 aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
111 assert (aLineStartPoint.x() == 50.0)
112 assert (aLineStartPoint.y() == 50.0)
113 assert (aLineEndPoint.x() == 60.0)
114 assert (aLineEndPoint.y() == 60.0)
115 aSketchLine.firstResult()
116 #==============================================================================
118 #==============================================================================
119 aDocument.finishOperation()