+
+ data()->real(RADIUS_ID())->setValue(aCirc->radius());
+ double aStartAngle, aEndAngle;
+ anEdge->getRange(aStartAngle, aEndAngle);
+ data()->real(ANGLE_ID())->setValue(aEndAngle - aStartAngle);
+ myParamBefore = aEndAngle;
+ adjustPeriod(myParamBefore);
+ }
+ }
+ return;
+ }
+ AttributeStringPtr aTypeAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeString>(attribute(ARC_TYPE()));
+
+ // this is before others since here end attribute may be changed, but with the special behavior
+ if (aTypeAttr->value() == ARC_TYPE_TANGENT() && (theID == TANGENT_POINT_ID() || theID == END_ID())) {
+ SketchPlugin_Sketch* aSketch = sketch();
+ AttributeRefAttrPtr aTangPtAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ data()->attribute(TANGENT_POINT_ID()));
+
+ if (aTangPtAttr->isInitialized() && anEndAttr->isInitialized()) {
+ // compute orthogonal direction
+ std::shared_ptr<GeomAPI_Dir2d> anOrthoDir;
+ std::shared_ptr<GeomDataAPI_Point2D> aTangentPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aTangPtAttr->attr());
+ std::shared_ptr<GeomAPI_Pnt2d> aTangPnt2d = aTangentPoint->pnt();
+ if (aTangPnt2d->isEqual(anEndAttr->pnt()))
+ return;
+ FeaturePtr aTangFeature = ModelAPI_Feature::feature(aTangentPoint->owner());
+ std::shared_ptr<GeomAPI_Edge> aTangEdge = std::dynamic_pointer_cast<GeomAPI_Edge>(
+ aTangFeature->lastResult()->shape());
+ if (aTangEdge->isLine()) {
+ std::shared_ptr<GeomAPI_Dir> aDir = aTangEdge->line()->direction();
+ std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aDir->x(), aDir->y(), aDir->z()));
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aSketch->to2D(aPnt);
+ anOrthoDir = std::shared_ptr<GeomAPI_Dir2d>(new GeomAPI_Dir2d(-aPnt2d->y(), aPnt2d->x()));
+ }
+ else if (aTangEdge->isArc()) {
+ std::shared_ptr<GeomAPI_Pnt> aCenter = aTangEdge->circle()->center();
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter2d = aSketch->to2D(aCenter);
+ anOrthoDir = std::shared_ptr<GeomAPI_Dir2d>(
+ new GeomAPI_Dir2d(aTangPnt2d->xy()->decreased(aCenter2d->xy())));
+ }
+
+ // compute parameters of the middle perpendicular
+ std::shared_ptr<GeomAPI_XY> aEndPntCoord = anEndAttr->pnt()->xy();
+ std::shared_ptr<GeomAPI_XY> aTempDir = aEndPntCoord->decreased(aTangPnt2d->xy());
+ std::shared_ptr<GeomAPI_Dir2d> aMidDir(new GeomAPI_Dir2d(-aTempDir->y(), aTempDir->x()));
+ std::shared_ptr<GeomAPI_Pnt2d> aMidPnt(
+ new GeomAPI_Pnt2d(aEndPntCoord->added(aTangPnt2d->xy())->multiplied(0.5)));
+
+ // compute center of arc by calculating intersection of orthogonal line and middle perpendicular
+ std::shared_ptr<GeomAPI_Lin2d> anOrthoLine(new GeomAPI_Lin2d(aTangPnt2d, anOrthoDir));
+ std::shared_ptr<GeomAPI_Lin2d> aMiddleLine(new GeomAPI_Lin2d(aMidPnt, aMidDir));
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter = anOrthoLine->intersect(aMiddleLine);
+ if (aCenter) {
+ data()->blockSendAttributeUpdated(true);
+ aCenterAttr->setValue(aCenter);
+ aStartAttr->setValue(aTangPnt2d);
+ data()->blockSendAttributeUpdated(false);
+ }
+
+ tangencyArcConstraints();
+ }
+ return;
+ }
+
+ // if changed the base attributes, update all other (is necessary) without recursion
+ if (theID == CENTER_ID() || theID == START_ID() || theID == END_ID() || theID == ARC_TYPE()) {
+ if (!isFeatureValid())
+ return;
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter = aCenterAttr->pnt();
+ std::shared_ptr<GeomAPI_Pnt2d> aStart = aStartAttr->pnt();
+ std::shared_ptr<GeomAPI_Pnt2d> anEnd = anEndAttr->pnt();
+ double aRadius = aCenter->distance(aStart);
+ if (aRadius < tolerance)
+ return;
+ std::shared_ptr<GeomAPI_Circ2d> aCircleForArc(new GeomAPI_Circ2d(aCenter, aStart));
+
+ data()->blockSendAttributeUpdated(true);
+ if (theID == END_ID() && isStable()) {
+ // The arc is under construction, so its end point projected
+ // on the circle formed by center and start points
+ std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEnd);
+ if (aProjection && anEnd->distance(aProjection) > tolerance) {
+ anEndAttr->setValue(aProjection);
+ anEnd = aProjection;
+ }
+ }
+ // update all other attributes due to the base attributes values
+ if (aTypeAttr->value() == ARC_TYPE_THREE_POINTS()) { // update passed point due to start, end and center
+ if (aCenter->distance(aStart) > tolerance && aCenter->distance(anEnd) > tolerance) {
+ // project passed point t othe circle
+ std::shared_ptr<GeomDataAPI_Point2D> aPassedAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(PASSED_POINT_ID()));
+ if (aPassedAttr->isInitialized()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(aPassedAttr->pnt());
+ if (aProjection && aPassedAttr->pnt()->distance(aProjection) > tolerance) {
+ aPassedAttr->setValue(aProjection);
+ }
+ } else { // initialize it by some middle - value
+ std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
+ aStart->xy()->decreased(aCenter->xy())));
+ std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
+ anEnd->xy()->decreased(aCenter->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) ^ !isReversed())
+ aMidDir->reverse();
+ std::shared_ptr<GeomAPI_XY> aPassedPnt =
+ aCenter->xy()->added(aMidDir->xy()->multiplied(aCenter->distance(aStart)));
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(PASSED_POINT_ID()))->
+ setValue(aPassedPnt->x(), aPassedPnt->y());
+ }