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_AttributeRefAttr::typeId());
9 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
10 data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefList::typeId());
13 from GeomDataAPI import *
14 from ModelAPI import *
17 #=========================================================================
19 #=========================================================================
20 def createSketch(theSketch):
21 # Initialize sketch by two lines with coincident boundary
24 aSketchLine1 = theSketch.addFeature("SketchLine")
25 aStartPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint"))
26 aEndPoint1 = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint"))
27 aStartPoint1.setValue(10., 5.)
28 aEndPoint1.setValue(-10., 10.)
29 allFeatures.append(aSketchLine1)
31 aSketchLine2 = theSketch.addFeature("SketchLine")
32 aStartPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("StartPoint"))
33 aEndPoint2 = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint"))
34 aStartPoint2.setValue(10., 5.)
35 aEndPoint2.setValue(15., 20.)
36 allFeatures.append(aSketchLine2)
38 aCoincidence = theSketch.addFeature("SketchConstraintCoincidence")
39 aCoincidence.refattr("ConstraintEntityA").setAttr(aStartPoint1)
40 aCoincidence.refattr("ConstraintEntityB").setAttr(aStartPoint2)
45 def checkFillet(theObjects, theRadius):
46 # Verify the arc and lines are connected smoothly
49 aSize = theObjects.size()
50 for i in range (0, aSize):
51 feat = ModelAPI_Feature.feature(theObjects.object(i))
52 assert(feat is not None)
53 if (feat.getKind() == "SketchLine"):
55 elif (feat.getKind() == "SketchArc"):
58 assert(anArc[0] is not None)
61 aPoint = geomDataAPI_Point2D(anArc[0].attribute("ArcStartPoint"))
62 anArcPoints.append((aPoint.x(), aPoint.y()))
63 aPoint = geomDataAPI_Point2D(anArc[0].attribute("ArcEndPoint"))
64 anArcPoints.append((aPoint.x(), aPoint.y()))
65 aPoint = geomDataAPI_Point2D(anArc[0].attribute("ArcCenter"))
70 aStartPoint = geomDataAPI_Point2D(line.attribute("StartPoint"))
71 aEndPoint = geomDataAPI_Point2D(line.attribute("EndPoint"))
74 aLinePoints.append((aStartPoint.x(), aStartPoint.y()))
75 aLinePoints.append((aEndPoint.x(), aEndPoint.y()))
77 aLineDirX = aEndPoint.x() - aStartPoint.x()
78 aLineDirY = aEndPoint.y() - aStartPoint.y()
80 for arcPt in anArcPoints:
81 for linePt in aLinePoints:
82 if (math.hypot(linePt[0]-arcPt[0], linePt[1]-arcPt[1]) < 1.e-10):
83 aDirX = linePt[0] - aCenterX
84 aDirY = linePt[1] - aCenterY
85 assert(math.fabs(math.hypot(aDirX, aDirY) - theRadius) < 1.e-7)
86 aDot = aDirX * aLineDirX + aDirY * aLineDirY
87 assert(math.fabs(aDot) < 1.e-7)
91 #=========================================================================
92 # Initialization of the test
93 #=========================================================================
95 __updated__ = "2015-09-18"
97 aSession = ModelAPI_Session.get()
98 aDocument = aSession.moduleDocument()
99 #=========================================================================
100 # Creation of a sketch
101 #=========================================================================
102 aSession.startOperation()
103 aSketchCommonFeature = aDocument.addFeature("Sketch")
104 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
105 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
106 origin.setValue(0, 0, 0)
107 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
108 dirx.setValue(1, 0, 0)
109 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
110 norm.setValue(0, 0, 1)
111 aSession.finishOperation()
112 #=========================================================================
114 #=========================================================================
115 aSession.startOperation()
116 aFeaturesList = createSketch(aSketchFeature)
117 aSession.finishOperation()
118 #=========================================================================
120 #=========================================================================
123 #=========================================================================
125 #=========================================================================
126 aSession.startOperation()
127 aFillet = aSketchFeature.addFeature("SketchConstraintFillet")
128 aRefAttrA = aFillet.refattr("ConstraintEntityA");
129 aRefAttrB = aFillet.refattr("ConstraintEntityB");
130 aResConstr = modelAPI_ResultConstruction(aFeaturesList[0].lastResult())
132 aRefAttrA.setObject(aResConstr)
133 aResConstr = modelAPI_ResultConstruction(aFeaturesList[1].lastResult())
135 aRefAttrB.setObject(aResConstr)
136 aRadius = aFillet.real("ConstraintValue")
137 aRadius.setValue(FILLET_RADIUS1)
139 aResObjects = aFillet.reflist("ConstraintEntityC")
140 #=========================================================================
141 # Verify the objects of fillet are created
142 #=========================================================================
144 checkFillet(aResObjects, FILLET_RADIUS1)
145 aSession.finishOperation()
146 #=========================================================================
148 #=========================================================================