3 Unit test of SketchPlugin_ConstraintFillet class
5 SketchPlugin_ConstraintFillet
6 static const std::string MY_CONSTRAINT_FILLET_ID("SketchConstraintFillet");
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 *
17 #=========================================================================
19 #=========================================================================
22 def createSketch1(theSketch):
23 global aEndPoint1, aEndPoint2
24 # Initialize sketch by two lines with coincident boundary
27 aSketchLine1 = theSketch.addFeature("SketchLine")
28 aStartPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint"))
29 aEndPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint"))
30 aStartPoint1.setValue(-10., -10.)
31 aEndPoint1.setValue(-10., 10.)
32 allFeatures.append(aSketchLine1)
34 aSketchLine2 = theSketch.addFeature("SketchLine")
35 aStartPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("StartPoint"))
36 aEndPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint"))
37 aStartPoint2.setValue(-10., 10.)
38 aEndPoint2.setValue(10., 10.)
39 allFeatures.append(aSketchLine2)
41 aSketchLine3 = theSketch.addFeature("SketchLine")
42 aStartPoint3 = geomDataAPI_Point2D(aSketchLine3.attribute("StartPoint"))
43 aEndPoint3 = geomDataAPI_Point2D(aSketchLine3.attribute("EndPoint"))
44 aStartPoint3.setValue(10., 10.)
45 aEndPoint3.setValue(10., -10.)
46 allFeatures.append(aSketchLine3)
48 aCoincidence1 = theSketch.addFeature("SketchConstraintCoincidence")
49 aCoincidence1.refattr("ConstraintEntityA").setAttr(aEndPoint1)
50 aCoincidence1.refattr("ConstraintEntityB").setAttr(aStartPoint2)
52 aCoincidence2 = theSketch.addFeature("SketchConstraintCoincidence")
53 aCoincidence2.refattr("ConstraintEntityA").setAttr(aEndPoint2)
54 aCoincidence2.refattr("ConstraintEntityB").setAttr(aStartPoint3)
60 def createSketch2(theSketch):
62 # Initialize sketch by line and arc with coincident boundary
65 aSketchLine = theSketch.addFeature("SketchLine")
66 aStartPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
67 aEndPoint1 = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
68 aStartPoint1.setValue(10., 10.)
69 aEndPoint1.setValue(30., 5.)
70 allFeatures.append(aSketchLine)
72 aSketchArc = theSketch.addFeature("SketchArc")
73 aStartPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
74 aEndPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
75 aCenterPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
76 aCenterPoint.setValue(20., 10.)
77 aStartPoint2.setValue(10., 10.)
78 aEndPoint2.setValue(20., 0.)
79 allFeatures.append(aSketchArc)
81 aCoincidence = theSketch.addFeature("SketchConstraintCoincidence")
82 aCoincidence.refattr("ConstraintEntityA").setAttr(aStartPoint1)
83 aCoincidence.refattr("ConstraintEntityB").setAttr(aStartPoint2)
88 def checkFillet(theObjects, theRadius):
89 # Verify the arc and lines are connected smoothly
93 aSize = theObjects.size()
94 for i in range (0, aSize):
95 feat = ModelAPI_Feature.feature(theObjects.object(i))
96 assert(feat is not None)
97 if (feat.getKind() == "SketchLine"):
99 elif (feat.getKind() == "SketchArc"):
101 aFilletArc = anArc[-1]
102 assert(aFilletArc is not None)
106 aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcStartPoint"))
107 print "ArcStartPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
108 anArcPoints.append((aPoint.x(), aPoint.y()))
109 aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcEndPoint"))
110 print "ArcEndPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
111 anArcPoints.append((aPoint.x(), aPoint.y()))
112 aPoint = geomDataAPI_Point2D(aFilletArc.attribute("ArcCenter"))
113 print "ArcCenter " + repr(aPoint.x()) + " " + repr(aPoint.y())
114 aCenterX = aPoint.x()
115 aCenterY = aPoint.y()
116 aFilletRadius = math.hypot(anArcPoints[0][0]-aCenterX, anArcPoints[0][1]-aCenterY)
119 aStartPoint = geomDataAPI_Point2D(line.attribute("StartPoint"))
120 aEndPoint = geomDataAPI_Point2D(line.attribute("EndPoint"))
123 aLinePoints.append((aStartPoint.x(), aStartPoint.y()))
124 print "aLineStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
125 aLinePoints.append((aEndPoint.x(), aEndPoint.y()))
126 print "aLineEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
128 aLineDirX = aEndPoint.x() - aStartPoint.x()
129 aLineDirY = aEndPoint.y() - aStartPoint.y()
131 for arcPt in anArcPoints:
132 for linePt in aLinePoints:
133 if (math.hypot(linePt[0]-arcPt[0], linePt[1]-arcPt[1]) < 1.e-10):
134 aDirX = linePt[0] - aCenterX
135 aDirY = linePt[1] - aCenterY
136 assert(math.fabs(math.hypot(aDirX, aDirY) - theRadius) < 1.e-7)
137 aDot = aDirX * aLineDirX + aDirY * aLineDirY
143 aStartPoint = geomDataAPI_Point2D(arc.attribute("ArcStartPoint"))
144 aEndPoint = geomDataAPI_Point2D(arc.attribute("ArcEndPoint"))
145 aCenterPoint = geomDataAPI_Point2D(arc.attribute("ArcCenter"))
148 aBaseArcPoints.append((aStartPoint.x(), aStartPoint.y()))
149 print "anArcStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
150 aBaseArcPoints.append((aEndPoint.x(), aEndPoint.y()))
151 print "anArcEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
152 print "anArcCenter " + repr(aCenterPoint.x()) + " " + repr(aCenterPoint.y())
154 aRadius = math.hypot(aStartPoint.x()-aCenterPoint.x(), aStartPoint.y()-aCenterPoint.y())
155 aDist = math.hypot(aCenterPoint.x() - aCenterX, aCenterPoint.y() - aCenterY)
156 assert math.fabs(aFilletRadius + aRadius - aDist) < 1.e-7 or math.fabs(math.fabs(aFilletRadius - aRadius) - aDist) < 1.e-7, \
157 "Fillet radius = {0}, Base arc radius = {1}, distance between centers = {2}".format(aFilletRadius, aRadius, aDist)
160 #=========================================================================
161 # Initialization of the test
162 #=========================================================================
164 __updated__ = "2015-09-18"
166 aSession = ModelAPI_Session.get()
167 aDocument = aSession.moduleDocument()
168 #=========================================================================
169 # Creation of a sketch
170 #=========================================================================
171 aSession.startOperation()
172 aSketchCommonFeature = aDocument.addFeature("Sketch")
173 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
174 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
175 origin.setValue(0, 0, 0)
176 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
177 dirx.setValue(1, 0, 0)
178 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
179 norm.setValue(0, 0, 1)
180 aSession.finishOperation()
181 #=========================================================================
182 # Initialize sketch by two lines
183 #=========================================================================
184 aSession.startOperation()
185 aFeaturesList = createSketch1(aSketchFeature)
186 aSession.finishOperation()
187 #=========================================================================
189 #=========================================================================
192 #=========================================================================
194 #=========================================================================
195 aSession.startOperation()
196 aFillet = aSketchFeature.addFeature("SketchConstraintFillet")
197 aRefAttrA = aFillet.data().refattrlist("ConstraintEntityA");
198 aRefAttrA.append(aEndPoint1)
199 aRefAttrA.append(aEndPoint2)
200 aRadius = aFillet.real("ConstraintValue")
201 aRadius.setValue(FILLET_RADIUS1)
203 aResObjects = aFillet.reflist("ConstraintEntityB")
204 #=========================================================================
205 # Verify the objects of fillet are created
206 #=========================================================================
208 checkFillet(aResObjects, FILLET_RADIUS1)
209 #=========================================================================
210 # Change Fillet radius
211 #=========================================================================
212 aRadius.setValue(FILLET_RADIUS2)
213 aSession.finishOperation()
214 checkFillet(aResObjects, FILLET_RADIUS2)
216 #=========================================================================
217 # Create another sketch
218 #=========================================================================
219 aSession.startOperation()
220 aSketchCommonFeature = aDocument.addFeature("Sketch")
221 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
222 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
223 origin.setValue(0, 0, 0)
224 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
225 dirx.setValue(1, 0, 0)
226 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
227 norm.setValue(0, 1, 0)
228 aSession.finishOperation()
229 #=========================================================================
230 # Initialize sketch by line and arc
231 #=========================================================================
232 aSession.startOperation()
233 aFeaturesList = createSketch2(aSketchFeature)
234 aSession.finishOperation()
235 #=========================================================================
237 #=========================================================================
238 aSession.startOperation()
239 aFillet = aSketchFeature.addFeature("SketchConstraintFillet")
240 aRefAttrA = aFillet.data().refattrlist("ConstraintEntityA");
241 aRefAttrA.append(aStartPoint1)
242 aRadius = aFillet.real("ConstraintValue")
243 aRadius.setValue(FILLET_RADIUS1)
245 aResObjects = aFillet.reflist("ConstraintEntityB")
246 #=========================================================================
247 # Verify the objects of fillet are created
248 #=========================================================================
250 checkFillet(aResObjects, FILLET_RADIUS1)
251 #=========================================================================
252 # Change Fillet radius
253 #=========================================================================
254 aRadius.setValue(FILLET_RADIUS2)
255 aSession.finishOperation()
256 checkFillet(aResObjects, FILLET_RADIUS2)
257 #=========================================================================
259 #=========================================================================