+ FeaturePtr aCircle = createCircleFeature();
+
+ std::string aType = string(CIRCLE_TYPE())->value();
+ if (aType == CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS())
+ constraintsForCircleByCenterAndPassed(aCircle);
+ else if (aType == CIRCLE_TYPE_BY_THREE_POINTS())
+ constraintsForCircleByThreePoints(aCircle);
+
+ // message to init reentrant operation
+ static Events_ID anId = SketchPlugin_MacroArcReentrantMessage::eventId();
+ std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aMessage = std::shared_ptr
+ <SketchPlugin_MacroArcReentrantMessage>(new SketchPlugin_MacroArcReentrantMessage(anId, this));
+
+ std::string anEditType = string(EDIT_CIRCLE_TYPE())->value();
+ aMessage->setTypeOfCreation(!anEditType.empty() ? anEditType : aType);
+ aMessage->setCreatedFeature(aCircle);
+ Events_Loop::loop()->send(aMessage);
+}
+
+// LCOV_EXCL_START
+std::string SketchPlugin_MacroCircle::processEvent(
+ const std::shared_ptr<Events_Message>& theMessage)
+{
+ std::string aFilledAttributeName;
+ std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aReentrantMessage =
+ std::dynamic_pointer_cast<SketchPlugin_MacroArcReentrantMessage>(theMessage);
+ if (aReentrantMessage.get()) {
+ std::string aCircleType = aReentrantMessage->typeOfCreation();
+
+ string(CIRCLE_TYPE())->setValue(aCircleType);
+
+ aFilledAttributeName = CIRCLE_TYPE();
+ ObjectPtr anObject = aReentrantMessage->selectedObject();
+ AttributePtr anAttribute = aReentrantMessage->selectedAttribute();
+ std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = aReentrantMessage->clickedPoint();
+
+ if (aClickedPoint.get() && (anObject.get() || anAttribute.get())) {
+ std::string aReferenceAttributeName;
+ if (aCircleType == CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()) {
+ aFilledAttributeName = CENTER_POINT_ID();
+ aReferenceAttributeName = CENTER_POINT_REF_ID();
+ }
+ else {
+ aFilledAttributeName = FIRST_POINT_ID();
+ aReferenceAttributeName = FIRST_POINT_REF_ID();
+ }
+ // fill 2d point attribute
+ AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ attribute(aFilledAttributeName));
+ aPointAttr->setValue(aClickedPoint);
+ // fill reference attribute
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ attribute(aReferenceAttributeName));
+ if (aRefAttr.get()) {
+ if (anAttribute.get()) {
+ if (!anAttribute->owner().get() || !anAttribute->owner()->data()->isValid()) {
+ FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
+ if (aCreatedFeature.get()) {
+ std::string anID = anAttribute->id();
+ std::string anArcID;
+ if (anID == CENTER_POINT_ID())
+ anArcID = SketchPlugin_Circle::CENTER_ID();
+ anAttribute = aCreatedFeature->attribute(anArcID);
+ }
+ }
+ aRefAttr->setAttr(anAttribute);
+ }
+ else if (anObject.get()) {
+ // if attribute is NULL, only object is defined, it should be processed outside
+ // the feature because it might be an external feature, that will be
+ // removed/created again after restart operation
+ // #2468 - Crash when sketching circles successively on a repetition
+ aFilledAttributeName = CIRCLE_TYPE();
+ }
+ }
+ }
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+ return aFilledAttributeName;
+}
+// LCOV_EXCL_STOP
+
+void SketchPlugin_MacroCircle::constraintsForCircleByCenterAndPassed(FeaturePtr theCircleFeature)
+{
+ // Create constraints.
+ SketchPlugin_Tools::createCoincidenceOrTangency(
+ this, CENTER_POINT_REF_ID(),
+ theCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()),
+ ObjectPtr(), false);
+ SketchPlugin_Tools::createCoincidenceOrTangency(
+ this, PASSED_POINT_REF_ID(), AttributePtr(),
+ theCircleFeature->lastResult(), true);
+}
+
+void SketchPlugin_MacroCircle::constraintsForCircleByThreePoints(FeaturePtr theCircleFeature)
+{
+ std::string aPointRef[3] = { FIRST_POINT_REF_ID(),
+ SECOND_POINT_REF_ID(),
+ THIRD_POINT_REF_ID() };
+
+ // Create constraints.
+ ResultPtr aCircleResult = theCircleFeature->lastResult();
+ for (int i = 0; i < 3; ++i) {
+ SketchPlugin_Tools::createCoincidenceOrTangency(
+ this, aPointRef[i], AttributePtr(), aCircleResult, true);
+ }
+}
+
+FeaturePtr SketchPlugin_MacroCircle::createCircleFeature()
+{