assert(isinstance(item, ModelAPI.ModelAPI_Object))
attribute.append(item)
+ elif isinstance(attribute, ModelAPI.ModelAPI_AttributeRefAttrList):
+ attribute.clear()
+ if not value:
+ return
+
+ assert(isinstance(value, collections.Iterable))
+ for item in value:
+ assert(isinstance(item, ModelAPI.ModelAPI_Attribute))
+ attribute.append(item)
+
elif isinstance(attribute, ModelAPI.ModelAPI_AttributeSelection):
if value is None:
attribute.setValue(None, None)
theStartPoint->xy()->decreased(theCenter->xy())));
std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
theEndPoint->xy()->decreased(theCenter->xy())));
- std::shared_ptr<GeomAPI_Dir2d> aMidDir(new GeomAPI_Dir2d(
- aStartDir->xy()->added(aEndDir->xy())));
+ std::shared_ptr<GeomAPI_XY> aMidDirXY = aStartDir->xy()->added(aEndDir->xy());
+ if (aMidDirXY->dot(aMidDirXY) < tolerance * tolerance) {
+ // start and end directions are opposite, so middle direction will be orthogonal
+ aMidDirXY->setX(-aStartDir->y());
+ aMidDirXY->setY(aStartDir->x());
+ }
+ std::shared_ptr<GeomAPI_Dir2d> aMidDir(new GeomAPI_Dir2d(aMidDirXY));
if ((aStartDir->cross(aMidDir) > 0) ^ !theArcReversed)
aMidDir->reverse();
dirx.setValue(1, 0, 0)
norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
- # add circle
+ # add circle defined by 3 points
circle = aSketchFeature.addFeature("SketchCircle")
- circleCenter = geomDataAPI_Point2D(circle.attribute("CircleCenter"))
- circleRadius = circle.real("CircleRadius")
- circleCenter.setValue(-50., 50.)
- circleRadius.setValue(10.)
+ circle.string("CircleType").setValue("ThreePoints")
+ geomDataAPI_Point2D(circle.attribute("FirstPoint")).setValue(-40., 50.)
+ geomDataAPI_Point2D(circle.attribute("SecondPoint")).setValue(-50., 60.)
+ geomDataAPI_Point2D(circle.attribute("ThirdPoint")).setValue(-60., 50.)
# add line
line = aSketchFeature.addFeature("SketchLine")
lineStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
# Arc 2
aSession.startOperation()
aSketchArc2 = aSketchFeature.addFeature("SketchArc")
+aSketchArc2.string("ArcType").setValue("ThreePoints")
anArc2Centr = geomDataAPI_Point2D(aSketchArc2.attribute("ArcCenter"))
-anArc2Centr.setValue(-10., 10.)
anArc2StartPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcStartPoint"))
anArc2StartPoint.setValue(0., 50.)
anArc2EndPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcEndPoint"))
anArc2EndPoint.setValue(-50., 0.)
+anArc2PassedPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcPassedPoint"))
+anArc2PassedPoint.setValue(-40., 40.)
aSession.finishOperation()
#=========================================================================
# Link points of arcs by the coincidence constraint
assert(anArc2CenterNew == anArc2CenterPrev)
assert(anArc2StartPointNew == anArc2StartPointPrev)
assert(anArc2EndPointNew == anArc2EndPointPrev)
+aSession.startOperation()
+aSketchFeature.removeFeature(aTangency)
+aSession.finishOperation()
+
+#=========================================================================
+# TEST 4. Creating of tangency arc by the option of the SketchArc feature
+#=========================================================================
+aSession.startOperation()
+aSketchArc3 = aSketchFeature.addFeature("SketchArc")
+aSketchArc3.string("ArcType").setValue("Tangent")
+anArc3Start = aSketchArc3.refattr("ArcTangentPoint")
+anArc3Start.setAttr(anArc1StartPoint)
+anArc3EndPoint = geomDataAPI_Point2D(aSketchArc3.attribute("ArcEndPoint"))
+anArc3EndPoint.setValue(100., 0.)
+aSession.finishOperation()
+anArc3Center = geomDataAPI_Point2D(aSketchArc2.attribute("ArcCenter"))
+anArc3StartPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcStartPoint"))
+
+anArc1VecX = anArc1EndPoint.x() - anArc1Centr.x()
+anArc1VecY = anArc1EndPoint.y() - anArc1Centr.y()
+aLen = math.sqrt(anArc1VecX**2 + anArc1VecY**2)
+anArc3VecX = anArc3StartPoint.x() - anArc3Center.x()
+anArc3VecY = anArc3StartPoint.y() - anArc3Center.y()
+aLen = aLen * math.sqrt(anArc3VecX**2 + anArc3VecY**2)
+aCross = anArc1VecX * anArc3VecY - anArc1VecY * anArc3VecX
+assert math.fabs(aCross) <= 2.e-6 * aLen, "Observed cross product: {0}".format(aCross)
#=========================================================================
# End of test
#=========================================================================