2 TestCreateCircleChangeType.py
4 Test attributes reset when changing creation method of a circle 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-03-22"
20 ##=========================================================================
21 ## Auxiliary functions
22 ##=========================================================================
24 def assertNotInitializedByCenterAndPassed(theMacroCircle):
26 aCenterPoint = geomDataAPI_Point2D(theMacroCircle.attribute("center_point"))
27 aPassedPoint = geomDataAPI_Point2D(theMacroCircle.attribute("passed_point"))
28 assert (not aCenterPoint.isInitialized())
29 assert (not aPassedPoint.isInitialized())
31 aCenterPointRef = theMacroCircle.refattr("center_point_ref")
32 aPassedPointRef = theMacroCircle.refattr("passed_point_ref")
33 assert (not aCenterPointRef.isInitialized())
34 assert (not aPassedPointRef.isInitialized())
36 def assertNotInitializedByThreePoints(theMacroCircle):
38 aFirstPoint = geomDataAPI_Point2D(theMacroCircle.attribute("first_point"))
39 aSecondPoint = geomDataAPI_Point2D(theMacroCircle.attribute("second_point"))
40 aThirdPoint = geomDataAPI_Point2D(theMacroCircle.attribute("third_point"))
41 assert (not aFirstPoint.isInitialized())
42 assert (not aSecondPoint.isInitialized())
43 assert (not aThirdPoint.isInitialized())
45 aFirstPointRef = theMacroCircle.refattr("first_point_ref")
46 aSecondPointRef = theMacroCircle.refattr("second_point_ref")
47 aThirdPointRef = theMacroCircle.refattr("third_point_ref")
48 assert (not aFirstPointRef.isInitialized())
49 assert (not aSecondPointRef.isInitialized())
50 assert (not aThirdPointRef.isInitialized())
52 def distancePointPoint(thePoint1, thePoint2):
53 return thePoint1.pnt().distance(thePoint2.pnt())
56 #=========================================================================
58 #=========================================================================
60 aSession = ModelAPI_Session.get()
61 aDocument = aSession.moduleDocument()
62 #=========================================================================
63 # Creation of a sketch
64 #=========================================================================
65 aSession.startOperation()
66 aSketchCommonFeature = aDocument.addFeature("Sketch")
67 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
68 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
69 origin.setValue(0, 0, 0)
70 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
71 dirx.setValue(1, 0, 0)
72 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
73 norm.setValue(0, 0, 1)
74 aSession.finishOperation()
75 aSketch = SketchAPI_Sketch(aSketchFeature)
77 #=========================================================================
78 # Creation of auxiliary features
79 #=========================================================================
80 aSession.startOperation()
81 aSession.startOperation()
82 aLine = aSketchFeature.addFeature("SketchLine")
83 aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
84 aLineStart.setValue(10., 0.)
85 aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
86 aLineEnd.setValue(10., 50.)
87 aSession.finishOperation()
89 aSession.startOperation()
90 #=========================================================================
91 # Test 1. Create a circle as a macro-feature and check all attributes are not initialized
92 #=========================================================================
93 aCircle = aSketchFeature.addFeature("SketchMacroCircle")
94 assert (aCircle.getKind() == "SketchMacroCircle")
95 aCenterPoint = geomDataAPI_Point2D(aCircle.attribute("center_point"))
96 aPassedPoint = geomDataAPI_Point2D(aCircle.attribute("passed_point"))
97 aFirstPoint = geomDataAPI_Point2D(aCircle.attribute("first_point"))
98 aSecondPoint = geomDataAPI_Point2D(aCircle.attribute("second_point"))
99 aThirdPoint = geomDataAPI_Point2D(aCircle.attribute("third_point"))
100 aCenterPointRef = aCircle.refattr("center_point_ref")
101 aPassedPointRef = aCircle.refattr("passed_point_ref")
102 aFirstPointRef = aCircle.refattr("first_point_ref")
103 aSecondPointRef = aCircle.refattr("second_point_ref")
104 aThirdPointRef = aCircle.refattr("third_point_ref")
105 assertNotInitializedByCenterAndPassed(aCircle)
106 assertNotInitializedByThreePoints(aCircle)
107 aCircleType = aCircle.string("circle_type")
108 assert (not aCircleType.isInitialized())
109 #=========================================================================
110 # Test 2. Initialize center of circle, check the three points are not initialized
111 #=========================================================================
112 aCircleType.setValue("circle_type_by_center_and_passed_points")
113 aCenterPoint.setValue(-25., -25.)
114 assertNotInitializedByThreePoints(aCircle)
115 #=========================================================================
116 # Test 3. Change type of circle and check the attributes related to center and passed point became uninitilized
117 #=========================================================================
118 aCircleType.setValue("circle_type_by_three_points")
119 assertNotInitializedByCenterAndPassed(aCircle)
120 #=========================================================================
121 # Test 4. Initialize two points and change type, they should became uninitialized
122 #=========================================================================
123 aFirstPoint.setValue(-10., 10.)
124 aSecondPoint.setValue(10., 10.)
125 aCircleType.setValue("circle_type_by_center_and_passed_points")
126 assertNotInitializedByThreePoints(aCircle)
127 #=========================================================================
128 # Test 5. Initialize center and passed point then change the type
129 #=========================================================================
130 aCenterPoint.setValue(-25., -25.)
131 aPassedPoint.setValue(0., 0.)
132 aCircleType.setValue("circle_type_by_three_points")
133 assertNotInitializedByCenterAndPassed(aCircle)
134 #=========================================================================
135 # Test 6. Initialize all three points then change the type twice
136 #=========================================================================
137 aFirstPoint.setValue(-10., 10.)
138 aSecondPoint.setValue(10., 10.)
139 aThirdPoint.setValue(0., 0.)
140 aCircleType.setValue("circle_type_by_center_and_passed_points")
141 assertNotInitializedByThreePoints(aCircle)
142 aCircleType.setValue("circle_type_by_three_points")
143 assertNotInitializedByCenterAndPassed(aCircle)
144 #=========================================================================
145 # Test 7. Initialize first and third points then change the type
146 #=========================================================================
147 aFirstPointRef.setAttr(aLineStart)
148 aFirstPoint.setValue(aLineStart.pnt())
149 aThirdPointRef.setObject(aLine.lastResult())
150 aThirdPoint.setValue(aLineEnd.pnt())
151 aCircleType.setValue("circle_type_by_center_and_passed_points")
152 assertNotInitializedByThreePoints(aCircle)
153 #=========================================================================
154 # Test 8. Initialize center and passed points and finish operation
155 #=========================================================================
156 aCenterPointRef.setAttr(aLineStart)
157 aCenterPoint.setValue(aLineStart.pnt())
158 aPassedPointRef.setAttr(aLineEnd)
159 aPassedPoint.setValue(aLineEnd.pnt())
160 aSession.finishOperation()
162 aRadius = distancePointPoint(aLineStart, aLineEnd)
163 assert (aSketchFeature.numberOfSubs() == 2)
164 verifyLastCircle(aSketchFeature, aLineStart.x(), aLineStart.y(), aRadius)
166 #=========================================================================
168 #=========================================================================
170 from salome.shaper import model
171 assert(model.checkPythonDump())