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 #=========================================================================
22 def createSketch(theSketch):
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., 5.)
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., 5.)
38 aEndPoint2.setValue(15., 20.)
39 allFeatures.append(aSketchLine2)
41 aCoincidence = theSketch.addFeature("SketchConstraintCoincidence")
42 aCoincidence.refattr("ConstraintEntityA").setAttr(aStartPoint1)
43 aCoincidence.refattr("ConstraintEntityB").setAttr(aStartPoint2)
48 def checkFillet(theObjects, theRadius):
49 # Verify the arc and lines are connected smoothly
52 aSize = theObjects.size()
53 for i in range (0, aSize):
54 feat = ModelAPI_Feature.feature(theObjects.object(i))
55 assert(feat is not None)
56 if (feat.getKind() == "SketchLine"):
58 elif (feat.getKind() == "SketchArc"):
61 assert(anArc[0] is not None)
64 aPoint = geomDataAPI_Point2D(anArc[0].attribute("ArcStartPoint"))
65 print "ArcStartPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
66 anArcPoints.append((aPoint.x(), aPoint.y()))
67 aPoint = geomDataAPI_Point2D(anArc[0].attribute("ArcEndPoint"))
68 print "ArcEndPoint " + repr(aPoint.x()) + " " + repr(aPoint.y())
69 anArcPoints.append((aPoint.x(), aPoint.y()))
70 aPoint = geomDataAPI_Point2D(anArc[0].attribute("ArcCenter"))
71 print "ArcCenter " + repr(aPoint.x()) + " " + repr(aPoint.y())
76 aStartPoint = geomDataAPI_Point2D(line.attribute("StartPoint"))
77 aEndPoint = geomDataAPI_Point2D(line.attribute("EndPoint"))
80 aLinePoints.append((aStartPoint.x(), aStartPoint.y()))
81 print "aLineStartPoint " + repr(aStartPoint.x()) + " " + repr(aStartPoint.y())
82 aLinePoints.append((aEndPoint.x(), aEndPoint.y()))
83 print "aLineEndPoint " + repr(aEndPoint.x()) + " " + repr(aEndPoint.y())
85 aLineDirX = aEndPoint.x() - aStartPoint.x()
86 aLineDirY = aEndPoint.y() - aStartPoint.y()
88 for arcPt in anArcPoints:
89 for linePt in aLinePoints:
90 if (math.hypot(linePt[0]-arcPt[0], linePt[1]-arcPt[1]) < 1.e-10):
91 aDirX = linePt[0] - aCenterX
92 aDirY = linePt[1] - aCenterY
93 assert(math.fabs(math.hypot(aDirX, aDirY) - theRadius) < 1.e-7)
94 aDot = aDirX * aLineDirX + aDirY * aLineDirY
100 #=========================================================================
101 # Initialization of the test
102 #=========================================================================
104 __updated__ = "2015-09-18"
106 aSession = ModelAPI_Session.get()
107 aDocument = aSession.moduleDocument()
108 #=========================================================================
109 # Creation of a sketch
110 #=========================================================================
111 aSession.startOperation()
112 aSketchCommonFeature = aDocument.addFeature("Sketch")
113 aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
114 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
115 origin.setValue(0, 0, 0)
116 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
117 dirx.setValue(1, 0, 0)
118 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
119 norm.setValue(0, 0, 1)
120 aSession.finishOperation()
121 #=========================================================================
123 #=========================================================================
124 aSession.startOperation()
125 aFeaturesList = createSketch(aSketchFeature)
126 aSession.finishOperation()
127 #=========================================================================
129 #=========================================================================
132 #=========================================================================
134 #=========================================================================
135 aSession.startOperation()
136 aFillet = aSketchFeature.addFeature("SketchConstraintFillet")
137 aRefAttrA = aFillet.refattr("ConstraintEntityA");
138 aResConstr = modelAPI_ResultConstruction(aFeaturesList[0].lastResult())
140 aRefAttrA.setAttr(aStartPoint1)
141 aRadius = aFillet.real("ConstraintValue")
142 aRadius.setValue(FILLET_RADIUS1)
144 aResObjects = aFillet.reflist("ConstraintEntityB")
145 #=========================================================================
146 # Verify the objects of fillet are created
147 #=========================================================================
149 aSession.finishOperation()
150 checkFillet(aResObjects, FILLET_RADIUS1)
151 #=========================================================================
153 #=========================================================================