+
+ // 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 anEditArcType = string(EDIT_ARC_TYPE_ID())->value();
+ aMessage->setTypeOfCreation(!anEditArcType.empty() ? anEditArcType : anArcType);
+ aMessage->setCreatedFeature(anArcFeature);
+ Events_Loop::loop()->send(aMessage);
+}
+
+// LCOV_EXCL_START
+std::string SketchPlugin_MacroArc::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()) {
+ FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
+ std::string anArcType = aReentrantMessage->typeOfCreation();
+
+ string(ARC_TYPE())->setValue(anArcType);
+
+ aFilledAttributeName = ARC_TYPE();
+ if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
+ aFilledAttributeName = TANGENT_POINT_ID();
+ AttributeRefAttrPtr aRefAttr = refattr(aFilledAttributeName);
+ aRefAttr->setAttr(aCreatedFeature->attribute(SketchPlugin_Arc::END_ID()));
+ }
+ else if (anArcType == ARC_TYPE_BY_TRANSVERSAL_LINE()) {
+ AttributeRefAttrPtr aRefAttr = refattr(TRANSVERSAL_POINT_ID());
+ AttributePtr anAttribute = aReentrantMessage->selectedAttribute();
+ if (anAttribute) {
+ aRefAttr->setAttr(anAttribute);
+ aFilledAttributeName = TRANSVERSAL_POINT_ID();
+ }
+ }
+ else {
+ ObjectPtr anObject = aReentrantMessage->selectedObject();
+ AttributePtr anAttribute = aReentrantMessage->selectedAttribute();
+ std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = aReentrantMessage->clickedPoint();
+
+ if (aClickedPoint.get() && (anObject.get() || anAttribute.get())) {
+ if (anArcType == ARC_TYPE_BY_CENTER_AND_POINTS() ||
+ anArcType == ARC_TYPE_BY_THREE_POINTS()) {
+ std::string aReferenceAttributeName;
+ if (anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
+ aFilledAttributeName = CENTER_POINT_ID();
+ aReferenceAttributeName = CENTER_POINT_REF_ID();
+ }
+ else {
+ aFilledAttributeName = START_POINT_2_ID();
+ aReferenceAttributeName = START_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()) {
+ if (aCreatedFeature.get()) {
+ std::string anID = anAttribute->id();
+ std::string anArcID;
+ if (anID == END_POINT_1_ID() || anID == END_POINT_2_ID() ||
+ anID == END_POINT_3_ID())
+ anArcID = SketchPlugin_Arc::END_ID();
+ else if (anID == START_POINT_1_ID() || anID ==START_POINT_2_ID())
+ anArcID = SketchPlugin_Arc::START_ID();
+ else if (anID == CENTER_POINT_ID())
+ anArcID = SketchPlugin_Arc::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 = ARC_TYPE();
+ }
+ }
+ }
+ }
+ }
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+ return aFilledAttributeName;