- data()->addAttribute(SketchPlugin_ConstraintMiddle::MIDDLE_TYPE(), ModelAPI_AttributeString::typeId());
-
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
+ // To maintain compatibility with older study versions, keep the order of all previously existing attributes:
+ // 1) ENTITY_A
+ // 2) ENTITY_B
+ // ----------- new attributes start here:
+ // 3) MIDDLE_TYPE
+ // 4) POINT_REF_ID
+ AttributeRefAttrPtr aAttrEntA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()));
+
+ AttributeRefAttrPtr aAttrEntB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()));
+
+ AttributeStringPtr aMethodAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
+ data()->addAttribute(SketchPlugin_ConstraintMiddle::MIDDLE_TYPE(), ModelAPI_AttributeString::typeId()));
+
+ // When loading studies from older versions (<9.12), the MIDDLE_TYPE attribute did not exist
+ // and is therefore not initialized!
+ // BUT: in case of a valid middle point constraint, the ENTITY_A and ENTITY_B attributes must be initialized
+ bool useDefaultMethod = !aMethodAttr->isInitialized();
+ if (aAttrEntA->isInitialized() && aAttrEntB->isInitialized() && useDefaultMethod)
+ {
+ // Initialize the creation method attribute (MIDDLE_TYPE) with the previously default
+ // creation method: "mid point from line and point".
+ // NOTE: ensure that the other attributes are NOT reset, as we want to keep the current inputs
+ RaiiSetBoolFlag blockEntityReset(myBlockAttribInit);
+ aMethodAttr->setValue(MIDDLE_TYPE_BY_LINE_AND_POINT());
+ }