4 static const std::string MY_SKETCH_ARC_ID("SketchArc");
5 static const std::string MY_CENTER_ID = "ArcCenter";
6 static const std::string MY_START_ID = "ArcStartPoint";
7 static const std::string MY_END_ID = "ArcEndPoint";
8 data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::type());
9 data()->addAttribute(SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D::type());
10 data()->addAttribute(SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D::type());
12 static const std::string MY_CIRCLE_ID("SketchCircle");
13 static const std::string MY_CIRCLE_CENTER_ID("CircleCenter");
14 static const std::string MY_CIRCLE_RADIUS_ID("CircleRadius");
15 data()->addAttribute(SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D::type());
16 data()->addAttribute(SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble::type());
19 #=========================================================================
20 # Initialization of the test
21 #=========================================================================
22 from GeomDataAPI import *
23 from ModelAPI import *
25 __updated__ = "2014-07-25"
27 aPluginManager = ModelAPI_PluginManager.get()
28 aDocument = aPluginManager.rootDocument()
29 #=========================================================================
30 # Creation of a sketch
31 #=========================================================================
32 aDocument.startOperation()
33 aSketchFeature = aDocument.addFeature("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 aDocument.finishOperation()
44 #=========================================================================
46 # 1. Test SketchPlugin_Arc attributes
48 #=========================================================================
49 aDocument.startOperation()
50 aSketchReflist = aSketchFeatureData.reflist("Features")
51 assert (not aSketchReflist.isInitialized())
52 assert (aSketchReflist.size() == 0)
53 assert (len(aSketchReflist.list()) == 0)
54 aSketchArc = aDocument.addFeature("SketchArc")
55 assert (aSketchArc.getKind() == "SketchArc")
56 aSketchReflist.append(aSketchArc)
57 aSketchArcData = aSketchArc.data()
58 anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
59 assert (anArcCentr.x() == 0)
60 assert (anArcCentr.y() == 0)
61 assert (not anArcCentr.isInitialized())
62 anArcCentr.setValue(10.,10.)
63 anArcStartPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcStartPoint"))
64 assert (anArcStartPoint.x() == 0)
65 assert (anArcStartPoint.y() == 0)
66 assert (not anArcStartPoint.isInitialized())
67 anArcStartPoint.setValue(0., 50.)
68 anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
69 assert (anArcEndPoint.x() == 0)
70 assert (anArcEndPoint.y() == 0)
71 assert (not anArcEndPoint.isInitialized())
72 anArcEndPoint.setValue(50., 0.)
73 aDocument.finishOperation()
74 # check that values have been changed
75 aSketchReflist = aSketchFeatureData.reflist("Features")
76 assert (aSketchReflist.size() == 1)
77 assert (len(aSketchReflist.list()) == 1)
78 assert (anArcCentr.x() == 10.0)
79 assert (anArcCentr.y() == 10.0)
80 assert (anArcStartPoint.x() == 0.0)
81 assert (anArcStartPoint.y() == 50.0)
82 assert (anArcEndPoint.x() == 50.0)
83 assert (anArcEndPoint.y() == 0.0)
84 #===============================================================================
87 # 2. Change the start point
88 #===============================================================================
89 aDocument.startOperation()
90 deltaX, deltaY = 5., 10.
91 anArcCentr.setValue(anArcCentr.x() + deltaX, anArcCentr.y() + deltaY)
92 anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY)
93 anArcEndPoint.setValue(anArcEndPoint.x() + deltaX, anArcEndPoint.y() + deltaY)
94 aDocument.finishOperation()
95 assert (anArcCentr.x() == 15)
96 assert (anArcCentr.y() == 20)
97 assert (anArcStartPoint.x() == 5)
98 assert (anArcStartPoint.y() == 60)
99 assert (anArcEndPoint.x() == 55)
100 assert (anArcEndPoint.y() == 10)
101 # Change the start point
102 aDocument.startOperation()
103 anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y())
104 aPrevEndPointX = anArcEndPoint.x()
105 aPrevEndPointY = anArcEndPoint.y()
106 aDocument.finishOperation()
107 assert (anArcCentr.x() == 15)
108 assert (anArcCentr.y() == 20)
109 assert (anArcStartPoint.x() == 10)
110 assert (anArcStartPoint.y() == 60)
111 assert (anArcEndPoint.x() != aPrevEndPointX)
112 assert (anArcEndPoint.y() != aPrevEndPointY)
113 #=========================================================================
114 # Check results of the Arc
115 #=========================================================================
116 aResult = aSketchArc.firstResult()
117 aResultConstruction = modelAPI_ResultConstruction(aResult)
118 aShape = aResultConstruction.shape()
119 assert (aShape is not None)
120 assert (not aShape.isNull())
121 #===============================================================================
123 # 1. Test SketchPlugin_Circle.h attributes
124 # 2. ModelAPI_AttributeDouble attribute
125 #===============================================================================
126 aDocument.startOperation()
127 aSketchReflist = aSketchFeatureData.reflist("Features")
128 # Arc is already added
129 assert (aSketchReflist.size() == 1)
130 assert (len(aSketchReflist.list()) == 1)
131 aSketchCircle = aDocument.addFeature("SketchCircle")
132 assert (aSketchCircle.getKind() == "SketchCircle")
133 aSketchReflist.append(aSketchCircle)
134 aSketchCircleData = aSketchCircle.data()
135 anCircleCentr = geomDataAPI_Point2D(aSketchCircleData.attribute("CircleCenter"))
136 assert (anCircleCentr.x() == 0)
137 assert (anCircleCentr.y() == 0)
138 assert (not anCircleCentr.isInitialized())
139 aCircleRadius = aSketchCircleData.real("CircleRadius");
140 assert (type(aCircleRadius) == ModelAPI_AttributeDouble)
141 # ModelAPI_AttributeDouble.type() is checked in ModelAPI_TestConstants
142 assert (aCircleRadius.attributeType() == ModelAPI_AttributeDouble.type())
143 assert (aCircleRadius.value() == 0)
144 anCircleCentr.setValue(-25., -25)
145 aCircleRadius.setValue(25.)
146 assert (anCircleCentr.x() == -25)
147 assert (anCircleCentr.y() == -25)
148 assert (aCircleRadius.value() == 25)
149 aDocument.finishOperation()
150 #===============================================================================
152 # 1. Check that changing the centr of a circle does not affects radius
153 # 2. and vise versa; also check that int is acceptable as well as a real
154 #===============================================================================
155 aDocument.startOperation()
156 anCircleCentr.setValue(10, 60)
157 aDocument.finishOperation()
158 assert (anCircleCentr.x() == 10)
159 assert (anCircleCentr.y() == 60)
160 assert (aCircleRadius.value() == 25)
161 aDocument.startOperation()
162 aCircleRadius.setValue(int(20))
163 aDocument.finishOperation()
164 assert (anCircleCentr.x() == 10)
165 assert (anCircleCentr.y() == 60)
166 assert (aCircleRadius.value() == 20)
167 #===============================================================================
169 #===============================================================================