1 #=========================================================================
2 # Initialization of the test
3 #=========================================================================
4 from GeomDataAPI import *
7 __updated__ = "2014-07-24"
9 aPluginManager = ModelAPI_PluginManager.get()
10 aDocument = aPluginManager.rootDocument()
11 #===============================================================================
12 # Test ModelAPI static methods
13 # TODO: Move this test in the ModelAPI progect
14 #===============================================================================
15 assert (ModelAPI_Feature.group() == "Features")
16 assert (ModelAPI_AttributeDocRef.type() == "DocRef")
17 assert (ModelAPI_AttributeDouble.type() == "Double")
18 assert (ModelAPI_AttributeReference.type() == "Reference")
19 assert (ModelAPI_AttributeRefAttr.type() == "RefAttr")
20 assert (ModelAPI_AttributeRefList.type() == "RefList")
21 #===============================================================================
22 # Test GeomDataAPI static methods
23 # TODO: Move this test in the GeomDataAPI progect
24 #===============================================================================
25 assert (GeomDataAPI_Point.type() == "Point")
26 assert (GeomDataAPI_Dir.type() == "Dir")
27 assert (GeomDataAPI_Point2D.type() == "Point2D")
28 #=========================================================================
29 # Creation of a sketch
30 #=========================================================================
31 aDocument.startOperation()
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 aDocument.finishOperation()
61 #=========================================================================
63 #=========================================================================
64 aDocument.startOperation()
65 aSketchReflist = aSketchFeatureData.reflist("Features")
66 assert (not aSketchReflist.isInitialized())
67 assert(aSketchReflist.size() == 0)
68 assert (len(aSketchReflist.list()) == 0)
69 aSketchPoint = aDocument.addFeature("SketchPoint")
70 assert (aSketchPoint.getKind() == "SketchPoint")
71 aSketchReflist.append(aSketchPoint)
72 aSketchPointData = aSketchPoint.data()
73 coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
74 assert (coords.x() == 0)
75 assert (coords.y() == 0)
76 assert (not coords.isInitialized())
77 # Simulate SketchPlugin_Point::move(...)
78 coords.setValue(10., 10.)
79 assert (coords.isInitialized())
80 # check that values have been changed
81 aSketchReflist = aSketchFeatureData.reflist("Features")
82 assert (aSketchReflist.size() == 1)
83 assert (len(aSketchReflist.list()) == 1)
84 aSketchPointData = aSketchPoint.data()
85 coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates"))
86 assert (coords.x() == 10.0)
87 assert (coords.y() == 10.0)
88 aDocument.finishOperation()
89 #===============================================================================
91 #===============================================================================
92 aDocument.startOperation()
93 aSketchLine = aDocument.addFeature("SketchLine")
94 aSketchReflist.append(aSketchLine)
95 assert (aSketchReflist.size() == 2)
96 assert (len(aSketchReflist.list()) == 2)
97 aSketchLineData = aSketchLine.data()
98 aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
99 aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
100 assert (aLineStartPoint.x() == 0)
101 assert (aLineStartPoint.y() == 0)
102 assert (not aLineStartPoint.isInitialized())
103 assert (aLineEndPoint.x() == 0)
104 assert (aLineEndPoint.y() == 0)
105 assert (not aLineEndPoint.isInitialized())
106 # Simulate SketchPlugin_Line::move(...)
107 aLineStartPoint.setValue(50., 50.)
108 aLineEndPoint.setValue(60., 60.)
109 assert (aLineStartPoint.isInitialized())
110 assert (aLineEndPoint.isInitialized())
111 # check that values have been changed
112 aSketchLineData = aSketchLine.data()
113 aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
114 aLineEndPoint= geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
115 assert (aLineStartPoint.x() == 50.0)
116 assert (aLineStartPoint.y() == 50.0)
117 assert (aLineEndPoint.x() == 60.0)
118 assert (aLineEndPoint.y() == 60.0)
119 aDocument.finishOperation()
120 #===============================================================================
122 #===============================================================================
123 aResult = aSketchLine.firstResult()
124 aResultConstruction = modelAPI_ResultConstruction(aResult)
125 aShape = aResultConstruction.shape()
126 assert (aShape is not None)
127 assert (not aShape.isNull())
128 #==============================================================================
130 #==============================================================================