From 858c637019b6d468b41e0b68bd94ee823ec36f73 Mon Sep 17 00:00:00 2001 From: jfa Date: Tue, 3 Oct 2023 14:09:29 +0100 Subject: [PATCH] bos #37570: Correctly restore from opened study disordered attributes of Fuse and Offset --- .../FeaturesPlugin_BooleanFuse.cpp | 66 ++++++++++++++++--- src/SketchPlugin/SketchPlugin_Offset.cpp | 53 ++++++++++++--- 2 files changed, 100 insertions(+), 19 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp index bccfaf13a..6b19e7e5c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp @@ -70,17 +70,65 @@ FeaturesPlugin_BooleanFuse::FeaturesPlugin_BooleanFuse() //================================================================================================== void FeaturesPlugin_BooleanFuse::initAttributes() { - data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); - - data()->addAttribute(OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); - data()->addAttribute(TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); + AttributeStringPtr aMethodAttr = std::dynamic_pointer_cast + (data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId())); // #1 + + data()->addAttribute(OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); // #2 + data()->addAttribute(TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); // #3 + + data()->addAttribute(REMOVE_INTERSECTION_EDGES_ID(), + ModelAPI_AttributeBoolean::typeId()); // #4 ??? + + AttributeBooleanPtr aUseFuzzyAttr; // #5 ??? + AttributeDoublePtr aValFuzzyAttr; // #6 ??? + + bool badOrder = false; + if (aMethodAttr->isInitialized()) { // restoring data from saved study + // It is a fix for 37570 Tuleap issue. + // We could have studies with aValFuzzyAttr at the 5th position instead of expected 6th. + + // Fuzzy value (check, is it present at 5th label) + aValFuzzyAttr = std::dynamic_pointer_cast + (data()->addAttribute(FUZZY_PARAM_ID(), + ModelAPI_AttributeDouble::typeId())); // #5 + if (aValFuzzyAttr->isInitialized()) { + badOrder = true; + // bad order of attributes in saved study + // 4 - is fuzzy + // 5 - fuzzy value + // 6 - remove edges + aUseFuzzyAttr = std::dynamic_pointer_cast + (data()->addAttribute(FeaturesPlugin_Boolean::USE_FUZZY_ID(), + ModelAPI_AttributeBoolean::typeId(), + 4)); // #4 + data()->addAttribute(REMOVE_INTERSECTION_EDGES_ID(), + ModelAPI_AttributeBoolean::typeId(), + 6); // #6 + } + } - data()->addAttribute(FeaturesPlugin_Boolean::USE_FUZZY_ID(), ModelAPI_AttributeBoolean::typeId()); - data()->addAttribute(FUZZY_PARAM_ID(), ModelAPI_AttributeDouble::typeId()); - boolean(USE_FUZZY_ID())->setValue(false); // Do NOT use the fuzzy parameter by default. - real(FUZZY_PARAM_ID())->setValue(DEFAULT_FUZZY); + if (!badOrder) { + // good order of attributes + // 4 - remove edges + // 5 - is fuzzy + // 6 - fuzzy value + + // Is fuzzy value + aUseFuzzyAttr = std::dynamic_pointer_cast + (data()->addAttribute(FeaturesPlugin_Boolean::USE_FUZZY_ID(), + ModelAPI_AttributeBoolean::typeId(), + 5)); // #5 + // Fuzzy value + aValFuzzyAttr = std::dynamic_pointer_cast + (data()->addAttribute(FUZZY_PARAM_ID(), + ModelAPI_AttributeDouble::typeId(), + 6)); // #6 + } - data()->addAttribute(REMOVE_INTERSECTION_EDGES_ID(), ModelAPI_AttributeBoolean::typeId()); + if (!aUseFuzzyAttr->isInitialized()) + aUseFuzzyAttr->setValue(false); // Do NOT use the fuzzy parameter by default. + if (!aValFuzzyAttr->isInitialized()) + aValFuzzyAttr->setValue(DEFAULT_FUZZY); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID()); diff --git a/src/SketchPlugin/SketchPlugin_Offset.cpp b/src/SketchPlugin/SketchPlugin_Offset.cpp index aabe5babf..119a7373b 100644 --- a/src/SketchPlugin/SketchPlugin_Offset.cpp +++ b/src/SketchPlugin/SketchPlugin_Offset.cpp @@ -75,17 +75,40 @@ SketchPlugin_Offset::SketchPlugin_Offset() void SketchPlugin_Offset::initAttributes() { - data()->addAttribute(EDGES_ID(), ModelAPI_AttributeRefList::typeId()); - data()->addAttribute(VALUE_ID(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId()); - - // Always initialize approximation to false by default for backward compatibility - AttributeBooleanPtr approxAttr = std::dynamic_pointer_cast( - data()->addAttribute(APPROX_ID(), ModelAPI_AttributeBoolean::typeId())); - approxAttr->setValue(false); + AttributeRefListPtr anEdgesAttr = std::dynamic_pointer_cast + (data()->addAttribute(EDGES_ID(), ModelAPI_AttributeRefList::typeId())); // #1 + data()->addAttribute(VALUE_ID(), ModelAPI_AttributeDouble::typeId()); // #2 + data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId()); // #3 + + // SketchPlugin_Constraint::ENTITY_A() stores original entities + AttributeRefListPtr entaAttr = std::dynamic_pointer_cast + (data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), + ModelAPI_AttributeRefList::typeId())); // #4 + + bool badOrder = false; + if (anEdgesAttr->isInitialized()) { // restoring data from saved study + badOrder = !entaAttr->isInitialized(); + // we have not found AttributeRefList at 4th position, + // so, we suppose a study with wrong order of offset attributes + } + + AttributeBooleanPtr approxAttr; + if (badOrder) { + // It is a fix for 37570 Tuleap issue. + // We could have studies with approxAttr at the 4th position. + // Using directly attribute index 4, we create approxAttr on label #4, + // otherwise (with default -1 index) it would be created on the next one. + approxAttr = std::dynamic_pointer_cast + (data()->addAttribute(APPROX_ID(), + ModelAPI_AttributeBoolean::typeId(), + 4)); // #4 + + entaAttr = std::dynamic_pointer_cast + (data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), + ModelAPI_AttributeRefList::typeId(), + 5)); // #5 + } - // store original entities - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId()); // store offset entities data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId()); // store mapping between original entity and index of the corresponding offset entity @@ -102,6 +125,16 @@ void SketchPlugin_Offset::initAttributes() (data()->addAttribute(JOINT_ID(), ModelAPI_AttributeString::typeId())); if (!aJointAttr->isInitialized()) aJointAttr->setValue(JOINT_KEEP_DISTANCE()); + + if (!badOrder) { + // Good place for approxAttr is here + approxAttr = std::dynamic_pointer_cast + (data()->addAttribute(APPROX_ID(), ModelAPI_AttributeBoolean::typeId())); + } + + // Initialize approximation to false by default for backward compatibility + if (!approxAttr->isInitialized()) + approxAttr->setValue(false); } void SketchPlugin_Offset::execute() -- 2.39.2