From: mbs Date: Thu, 9 Nov 2023 11:53:46 +0000 (+0000) Subject: fixed bos#38593 - middle point was incorrectly loaded X-Git-Tag: V9_12_0b1~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=44e97b585b0024eaa49740408692c092e2d4c5d7;p=modules%2Fshaper.git fixed bos#38593 - middle point was incorrectly loaded --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp index 9d478833b..ddfe2b9c2 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp @@ -30,8 +30,27 @@ #include #include + +class RaiiSetBoolFlag { +public: + RaiiSetBoolFlag() = delete; + RaiiSetBoolFlag(bool &theFlag) + { + myBoolPtr = &theFlag; + *myBoolPtr = true; + } + ~RaiiSetBoolFlag() + { + *myBoolPtr = false; + } +private: + bool *myBoolPtr; +}; + + SketchPlugin_ConstraintMiddle::SketchPlugin_ConstraintMiddle() { + myBlockAttribInit = false; } // Create new point for Middle constraint @@ -73,10 +92,33 @@ void SketchPlugin_ConstraintMiddle::CreatePoint() void SketchPlugin_ConstraintMiddle::initAttributes() { - 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( + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId())); + + AttributeRefAttrPtr aAttrEntB = std::dynamic_pointer_cast( + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId())); + + AttributeStringPtr aMethodAttr = std::dynamic_pointer_cast( + 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()); + } data()->addAttribute(POINT_REF_ID(), GeomDataAPI_Point2D::typeId()); @@ -105,8 +147,10 @@ void SketchPlugin_ConstraintMiddle::attributeChanged(const std::string& theID) { if (theID == MIDDLE_TYPE()) { - SketchPlugin_Tools::resetAttribute(this, ENTITY_A()); - SketchPlugin_Tools::resetAttribute(this, ENTITY_B()); + if (!myBlockAttribInit) { + SketchPlugin_Tools::resetAttribute(this, ENTITY_A()); + SketchPlugin_Tools::resetAttribute(this, ENTITY_B()); + } } else if (theID == POINT_REF_ID()) { diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.h b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.h index ddb3c2faa..686e60b15 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.h @@ -97,6 +97,7 @@ private: void CreatePoint(); std::shared_ptr myPoint; + bool myBlockAttribInit; }; #endif