2 TestCreateArcChangeType.py
4 Test attributes reset when changing creation method of an arc on-the-fly
7 #=========================================================================
8 # Initialization of the test
9 #=========================================================================
10 from GeomDataAPI import *
12 from ModelAPI import *
13 from SketchAPI import SketchAPI_Sketch
14 from salome.shaper import model
17 __updated__ = "2017-04-06"
20 ##=========================================================================
21 ## Auxiliary functions
22 ##=========================================================================
24 def assertNotInitializedByCenterAndPassed(theMacroArc):
26 aCenterPoint = geomDataAPI_Point2D(theMacroArc.attribute("center_point"))
27 aStartPoint = geomDataAPI_Point2D(theMacroArc.attribute("start_point_1"))
28 aEndPoint = geomDataAPI_Point2D(theMacroArc.attribute("end_point_1"))
29 assert (not aCenterPoint.isInitialized())
30 assert (not aStartPoint.isInitialized())
31 assert (not aEndPoint.isInitialized())
33 aCenterPointRef = theMacroArc.refattr("center_point_ref")
34 aStartPointRef = theMacroArc.refattr("start_point_ref")
35 aEndPointRef = theMacroArc.refattr("end_point_ref")
36 assert (not aCenterPointRef.isInitialized())
37 assert (not aStartPointRef.isInitialized())
38 assert (not aEndPointRef.isInitialized())
40 def assertNotInitializedByThreePoints(theMacroArc):
42 aStartPoint = geomDataAPI_Point2D(theMacroArc.attribute("start_point_2"))
43 aEndPoint = geomDataAPI_Point2D(theMacroArc.attribute("end_point_2"))
44 aPassedPoint = geomDataAPI_Point2D(theMacroArc.attribute("passed_point"))
45 assert (not aStartPoint.isInitialized())
46 assert (not aEndPoint.isInitialized())
47 assert (not aPassedPoint.isInitialized())
49 aStartPointRef = theMacroArc.refattr("start_point_ref")
50 aEndPointRef = theMacroArc.refattr("end_point_ref")
51 aPassedPointRef = theMacroArc.refattr("passed_point_ref")
52 assert (not aStartPointRef.isInitialized())
53 assert (not aEndPointRef.isInitialized())
54 assert (not aPassedPointRef.isInitialized())
56 def assertNotInitializedByTangentEdge(theMacroArc):
58 aEndPoint = geomDataAPI_Point2D(theMacroArc.attribute("end_point_3"))
59 assert (not aEndPoint.isInitialized())
61 aTangentPointRef = theMacroArc.refattr("passed_point_ref")
62 aEndPointRef = theMacroArc.refattr("end_point_ref")
63 assert (not aTangentPointRef.isInitialized())
64 assert (not aEndPointRef.isInitialized())
66 def verifyLastArc(theSketch, theCenter, theStart, theEnd):
68 subroutine to verify position of last arc in the sketch
70 aLastArc = model.lastSubFeature(theSketch, "SketchArc")
71 aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
72 aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point"))
73 aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point"))
75 verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1])
77 verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
79 verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
80 model.assertSketchArc(aLastArc)
82 def verifyPointCoordinates(thePoint, theX, theY):
83 assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY)
86 #=========================================================================
88 #=========================================================================
90 aSession = ModelAPI_Session.get()
91 aDocument = aSession.moduleDocument()
92 #=========================================================================
93 # Creation of a sketch
94 #=========================================================================
95 aSession.startOperation()
96 aSketchCommonFeature = aDocument.addFeature("Sketch")
97 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
98 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
99 origin.setValue(0, 0, 0)
100 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
101 dirx.setValue(1, 0, 0)
102 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
103 norm.setValue(0, 0, 1)
104 aSession.finishOperation()
105 aSketch = SketchAPI_Sketch(aSketchFeature)
107 #=========================================================================
108 # Creation of auxiliary features
109 #=========================================================================
110 aSession.startOperation()
111 aSession.startOperation()
112 aLine = aSketchFeature.addFeature("SketchLine")
113 aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
114 aLineStart.setValue(10., 0.)
115 aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
116 aLineEnd.setValue(10., 50.)
117 aSession.finishOperation()
119 aSession.startOperation()
120 #=========================================================================
121 # Test 1. Create an arc as a macro-feature and check all attributes are not initialized
122 #=========================================================================
123 anArc = aSketchFeature.addFeature("SketchMacroArc")
124 assert (anArc.getKind() == "SketchMacroArc")
125 aCenterPoint = geomDataAPI_Point2D(anArc.attribute("center_point"))
126 aPassedPoint = geomDataAPI_Point2D(anArc.attribute("passed_point"))
127 aStartPoint1 = geomDataAPI_Point2D(anArc.attribute("start_point_1"))
128 aStartPoint2 = geomDataAPI_Point2D(anArc.attribute("start_point_2"))
129 aEndPoint1 = geomDataAPI_Point2D(anArc.attribute("end_point_1"))
130 aEndPoint2 = geomDataAPI_Point2D(anArc.attribute("end_point_2"))
131 aEndPoint3 = geomDataAPI_Point2D(anArc.attribute("end_point_3"))
132 aTangentPoint = anArc.refattr("tangent_point")
133 aCenterPointRef = anArc.refattr("center_point_ref")
134 aStartPointRef = anArc.refattr("start_point_ref")
135 aEndPointRef = anArc.refattr("end_point_ref")
136 aPassedPointRef = anArc.refattr("passed_point_ref")
137 assertNotInitializedByCenterAndPassed(anArc)
138 assertNotInitializedByThreePoints(anArc)
139 assertNotInitializedByTangentEdge(anArc)
140 anArcType = anArc.string("arc_type")
141 assert (not anArcType.isInitialized())
142 #=========================================================================
143 # Test 2. Initialize center of arc, check the three points are not initialized
144 #=========================================================================
145 anArcType.setValue("by_center_and_points")
146 aCenterPoint.setValue(-25., -25.)
147 assertNotInitializedByThreePoints(anArc)
148 assertNotInitializedByTangentEdge(anArc)
149 #=========================================================================
150 # Test 3. Change type of circle and check the attributes related to center and passed point became uninitilized
151 #=========================================================================
152 anArcType.setValue("by_three_points")
153 assertNotInitializedByCenterAndPassed(anArc)
154 assertNotInitializedByTangentEdge(anArc)
155 #=========================================================================
156 # Test 4. Initialize two points and change type, they should became uninitialized
157 #=========================================================================
158 aStartPoint2.setValue(-10., 10.)
159 aEndPoint2.setValue(10., 10.)
160 anArcType.setValue("by_center_and_points")
161 assertNotInitializedByThreePoints(anArc)
162 assertNotInitializedByTangentEdge(anArc)
163 #=========================================================================
164 # Test 5. Initialize center and passed points then change the type
165 #=========================================================================
166 aCenterPoint.setValue(-25., -25.)
167 aStartPoint1.setValue(0., 0.)
168 aEndPoint1.setValue(-50., 0.)
169 anArcType.setValue("by_three_points")
170 assertNotInitializedByCenterAndPassed(anArc)
171 assertNotInitializedByTangentEdge(anArc)
172 #=========================================================================
173 # Test 6. Initialize all three points then change the type twice
174 #=========================================================================
175 aStartPoint2.setValue(-10., 10.)
176 aEndPoint2.setValue(10., 10.)
177 aPassedPoint.setValue(0., 0.)
178 anArcType.setValue("by_tangent_edge")
179 assertNotInitializedByThreePoints(anArc)
180 anArcType.setValue("by_center_and_points")
181 assertNotInitializedByTangentEdge(anArc)
182 anArcType.setValue("by_three_points")
183 assertNotInitializedByCenterAndPassed(anArc)
184 #=========================================================================
185 # Test 7. Initialize first and third points then change the type
186 #=========================================================================
187 aStartPointRef.setAttr(aLineStart)
188 aStartPoint2.setValue(aLineStart.pnt())
189 aPassedPointRef.setObject(aLine.lastResult())
190 aPassedPoint.setValue(aLineEnd.pnt())
191 anArcType.setValue("by_tangent_edge")
192 assertNotInitializedByCenterAndPassed(anArc)
193 assertNotInitializedByThreePoints(anArc)
194 #=========================================================================
195 # Test 8. Initialize tangent point then change type
196 #=========================================================================
197 aTangentPoint.setAttr(aLineEnd)
198 anArcType.setValue("by_three_points")
199 assertNotInitializedByCenterAndPassed(anArc)
200 assertNotInitializedByTangentEdge(anArc)
201 #=========================================================================
202 # Test 9. Initialize tangent point and end point then change type
203 #=========================================================================
204 anArcType.setValue("by_tangent_edge")
205 aTangentPoint.setAttr(aLineEnd)
206 aEndPoint3.setValue(50., 50.)
207 anArcType.setValue("by_center_and_points")
208 assertNotInitializedByThreePoints(anArc)
209 assertNotInitializedByTangentEdge(anArc)
210 #=========================================================================
211 # Test 10. Initialize center and passed points and finish operation
212 #=========================================================================
213 aCenterPointRef.setObject(aLine.lastResult())
214 aCenterPoint.setValue((aLineStart.x() + aLineEnd.x()) * 0.5, (aLineStart.y() + aLineEnd.y()) * 0.5)
215 aStartPointRef.setAttr(aLineStart)
216 aStartPoint1.setValue(aLineStart.pnt())
217 aEndPointRef.setObject(aLine.lastResult())
218 aEndPoint1.setValue(aLineEnd.pnt())
219 aSession.finishOperation()
221 NB_FEATURES_EXPECTED = 5 # line, arc and three coincidences
222 assert (aSketchFeature.numberOfSubs() == NB_FEATURES_EXPECTED), "Number of features in sketch {}, expected {}".format(aSketchFeature.numberOfSubs(), NB_FEATURES_EXPECTED)
223 verifyLastArc(aSketchFeature, [], [aLineStart.x(), aLineStart.y()], [])
225 #=========================================================================
227 #=========================================================================
229 from salome.shaper import model
230 assert(model.checkPythonDump())