3 Unit test of SketchPlugin_Fillet class
6 static const std::string MY_CONSTRAINT_FILLET_ID("SketchFillet");
7 data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
8 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());
9 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId());
10 data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefAttrList::typeId());
13 from GeomDataAPI import *
14 from ModelAPI import *
16 from salome.shaper import model
18 #=========================================================================
20 #=========================================================================
23 def createSketch1(theSketch):
24 global aEndPoint1, aEndPoint2
25 # Initialize sketch by three lines with coincident boundaries
28 aSession.startOperation()
30 aSketchLine1 = theSketch.addFeature("SketchLine")
31 aStartPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint"))
32 aEndPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint"))
33 aStartPoint1.setValue(-10., -10.)
34 aEndPoint1.setValue(-10., 10.)
35 allFeatures.append(aSketchLine1)
37 aSketchLine2 = theSketch.addFeature("SketchLine")
38 aStartPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("StartPoint"))
39 aEndPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint"))
40 aStartPoint2.setValue(-10., 10.)
41 aEndPoint2.setValue(10., 10.)
42 allFeatures.append(aSketchLine2)
44 aSketchLine3 = theSketch.addFeature("SketchLine")
45 aStartPoint3 = geomDataAPI_Point2D(aSketchLine3.attribute("StartPoint"))
46 aEndPoint3 = geomDataAPI_Point2D(aSketchLine3.attribute("EndPoint"))
47 aStartPoint3.setValue(10., 10.)
48 aEndPoint3.setValue(10., -10.)
49 allFeatures.append(aSketchLine3)
51 aCoincidence1 = theSketch.addFeature("SketchConstraintCoincidence")
52 aCoincidence1.refattr("ConstraintEntityA").setAttr(aEndPoint1)
53 aCoincidence1.refattr("ConstraintEntityB").setAttr(aStartPoint2)
55 aCoincidence2 = theSketch.addFeature("SketchConstraintCoincidence")
56 aCoincidence2.refattr("ConstraintEntityA").setAttr(aEndPoint2)
57 aCoincidence2.refattr("ConstraintEntityB").setAttr(aStartPoint3)
59 aSession.finishOperation()
63 def createSketch2(theSketch):
65 # Initialize sketch by line and arc with coincident boundary
68 aSession.startOperation()
70 aSketchLine = theSketch.addFeature("SketchLine")
71 aStartPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
72 aEndPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
73 aStartPoint1.setValue(10., 10.)
74 aEndPoint1.setValue(30., 15.)
75 allFeatures.append(aSketchLine)
77 aSketchArc = theSketch.addFeature("SketchArc")
78 aStartPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
79 aEndPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
80 aCenterPoint = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
81 aCenterPoint.setValue(20., 10.)
82 aStartPoint2.setValue(10., 10.)
83 aEndPoint2.setValue(20., 0.)
84 allFeatures.append(aSketchArc)
86 aCoincidence = theSketch.addFeature("SketchConstraintCoincidence")
87 aCoincidence.refattr("ConstraintEntityA").setAttr(aStartPoint1)
88 aCoincidence.refattr("ConstraintEntityB").setAttr(aStartPoint2)
90 aSession.finishOperation()
93 def checkSmoothness(theSketch):
94 aPtPtCoincidences = getCoincidences(theSketch)
95 for coinc in aPtPtCoincidences:
96 aConnectedFeatures = connectedFeatures(coinc)
97 assert(len(aConnectedFeatures) == 2)
98 if aConnectedFeatures[0].getKind() == "SketchArc":
99 if aConnectedFeatures[1].getKind() == "SketchArc":
100 checkArcArcSmoothness(aConnectedFeatures[0], aConnectedFeatures[1])
101 elif aConnectedFeatures[1].getKind() == "SketchLine":
102 checkArcLineSmoothness(aConnectedFeatures[0], aConnectedFeatures[1])
103 elif aConnectedFeatures[0].getKind() == "SketchLine" and aConnectedFeatures[1].getKind() == "SketchArc":
104 checkArcLineSmoothness(aConnectedFeatures[1], aConnectedFeatures[0])
106 def checkArcLineSmoothness(theArc, theLine):
107 aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
108 aDistance = model.distancePointLine(aCenter, theLine)
109 aRadius = arcRadius(theArc)
110 assert(math.fabs(aRadius - aDistance) < TOLERANCE)
112 def checkArcArcSmoothness(theArc1, theArc2):
113 aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point"))
114 aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point"))
115 aDistance = model.distancePointPoint(aCenter1, aCenter2)
116 aRadius1 = arcRadius(theArc1)
117 aRadius2 = arcRadius(theArc2)
118 aRadSum = aRadius1 + aRadius2
119 aRadDiff = math.fabs(aRadius1 - aRadius2)
120 assert(math.fabs(aDistance - aRadSum) < TOLERANCE or math.fabs(aDistance - aRadDiff) < TOLERANCE)
122 def getCoincidences(theSketch):
124 for anIndex in range(0, theSketch.numberOfSubs()):
125 aSubFeature = theSketch.subFeature(anIndex)
126 if aSubFeature.getKind() == "SketchConstraintCoincidence":
127 anEntityA = aSubFeature.refattr("ConstraintEntityA")
128 anEntityB = aSubFeature.refattr("ConstraintEntityB")
129 if not anEntityA.isObject() and not anEntityB.isObject():
130 aCoincidences.append(aSubFeature)
133 def connectedFeatures(theCoincidence):
134 anEntityA = theCoincidence.refattr("ConstraintEntityA")
135 anEntityB = theCoincidence.refattr("ConstraintEntityB")
136 aFeatureA = ModelAPI.ModelAPI_Feature.feature(anEntityA.attr().owner())
137 aFeatureB = ModelAPI.ModelAPI_Feature.feature(anEntityB.attr().owner())
138 return [aFeatureA, aFeatureB]
140 def arcRadius(theArc):
141 aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
142 aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
143 return model.distancePointPoint(aCenter, aStart)
146 #=========================================================================
147 # Initialization of the test
148 #=========================================================================
150 __updated__ = "2015-09-18"
152 aSession = ModelAPI_Session.get()
153 aDocument = aSession.moduleDocument()
154 #=========================================================================
155 # Creation of a sketch
156 #=========================================================================
157 aSession.startOperation()
158 aSketchCommonFeature = aDocument.addFeature("Sketch")
159 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
160 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
161 origin.setValue(0, 0, 0)
162 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
163 dirx.setValue(1, 0, 0)
164 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
165 norm.setValue(0, 0, 1)
166 aSession.finishOperation()
167 #=========================================================================
168 # Initialize sketch by three connected lines
169 #=========================================================================
170 createSketch1(aSketchFeature)
171 assert (model.dof(aSketchFeature) == 8)
172 #=========================================================================
174 #=========================================================================
175 aSession.startOperation()
176 aFillet = aSketchFeature.addFeature("SketchFillet")
177 aFillet.refattr("fillet_point").setAttr(aEndPoint1);
178 aSession.finishOperation()
179 aSession.startOperation()
180 aFillet = aSketchFeature.addFeature("SketchFillet")
181 aFillet.refattr("fillet_point").setAttr(aEndPoint2);
182 aSession.finishOperation()
183 #=========================================================================
184 # Verify the objects of fillet are created
185 #=========================================================================
186 checkSmoothness(aSketchFeature)
187 assert (model.dof(aSketchFeature) == 10)
188 #=========================================================================
189 # Move a line and check the fillet is correct
190 #=========================================================================
191 DELTA_X = DELTA_Y = 10.
192 aSession.startOperation()
193 aEndPoint1.setValue(aEndPoint1.x() + DELTA_X, aEndPoint1.y() + DELTA_Y)
194 aSession.finishOperation()
195 checkSmoothness(aSketchFeature)
196 assert (model.dof(aSketchFeature) == 10)
199 #=========================================================================
200 # Create another sketch
201 #=========================================================================
202 aSession.startOperation()
203 aSketchCommonFeature = aDocument.addFeature("Sketch")
204 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
205 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
206 origin.setValue(0, 0, 0)
207 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
208 dirx.setValue(1, 0, 0)
209 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
210 norm.setValue(0, 1, 0)
211 aSession.finishOperation()
212 #=========================================================================
213 # Initialize sketch by line and arc
214 #=========================================================================
215 createSketch2(aSketchFeature)
216 assert (model.dof(aSketchFeature) == 7)
217 #=========================================================================
219 #=========================================================================
220 aSession.startOperation()
221 aFillet = aSketchFeature.addFeature("SketchFillet")
222 aFillet.refattr("fillet_point").setAttr(aStartPoint1)
223 aSession.finishOperation()
224 #=========================================================================
225 # Verify the objects of fillet are created
226 #=========================================================================
227 checkSmoothness(aSketchFeature)
228 assert (model.dof(aSketchFeature) == 8)
229 #=========================================================================
230 # Move a line and check the fillet is correct
231 #=========================================================================
234 aSession.startOperation()
235 aStartPoint1.setValue(aStartPoint1.x() + DELTA_X, aStartPoint1.y() + DELTA_Y)
236 aSession.finishOperation()
237 checkSmoothness(aSketchFeature)
238 assert (model.dof(aSketchFeature) == 8)
239 #=========================================================================
241 #=========================================================================
243 # TODO: Improve Fillet test case by moving one of filleted objectes and check coincidence and tangency are correct
245 assert(model.checkPythonDump())