+void SketchPlugin_ConstraintRadius::attributeChanged(const std::string& theID) {
+ if (theID == SketchPlugin_Constraint::ENTITY_A()) {
+ std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+ if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+ std::shared_ptr<ModelAPI_Feature> aCyrcFeature;
+ double aRadius = circleRadius(aCyrcFeature);
+ if (aRadius > 0) { // set as value the radius of updated reference to another circle
+ aValueAttr->setValue(aRadius);
+ }
+ }
+ } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
+ // Recalculate flyout point in local coordinates of the circle (or arc):
+ // coordinates are calculated according to center of the shape
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ attribute(SketchPlugin_Constraint::ENTITY_A()));
+ if (!aRefAttr || !aRefAttr->isObject())
+ return;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+ if (!aFeature || (aFeature->getKind() != SketchPlugin_Arc::ID() &&
+ aFeature->getKind() != SketchPlugin_Circle::ID()))
+ return;
+
+ std::string aCenterAttrName;
+ if (aFeature->getKind() == SketchPlugin_Circle::ID())
+ aCenterAttrName = SketchPlugin_Circle::CENTER_ID();
+ else if (aFeature->getKind() == SketchPlugin_Arc::ID())
+ aCenterAttrName = SketchPlugin_Arc::CENTER_ID();
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(aFeature->data()->attribute(aCenterAttrName));
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter = aCenterAttr->pnt();
+ std::shared_ptr<ModelAPI_AttributeDouble> aRadius = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(attribute(SketchPlugin_Constraint::VALUE()));
+
+ std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
+ double aDist = aFlyoutPnt->distance(aCenter);
+ if (aDist < tolerance)
+ return;
+
+ myFlyoutUpdate = true;
+ std::shared_ptr<GeomAPI_XY> aFlyoutDir = aFlyoutPnt->xy()->decreased(aCenter->xy());
+ aFlyoutAttr->setValue(aFlyoutDir->x(), aFlyoutDir->y());
+ myFlyoutUpdate = false;
+ }