From: jfa Date: Tue, 3 Oct 2023 13:09:29 +0000 (+0100) Subject: bos #37570: Try fixing order of attributes for Fuse and Offset X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1324622d4598124ac6c1ba53b9dfc4606be27076;p=modules%2Fshaper.git bos #37570: Try fixing order of attributes for Fuse and Offset --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp index bccfaf13a..7a2fab792 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp @@ -70,17 +70,67 @@ 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 + + AttributeBooleanPtr aREAttr = std::dynamic_pointer_cast + (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 + aREAttr = std::dynamic_pointer_cast + (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..a32d1e835 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()); + 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 - // 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); + // SketchPlugin_Constraint::ENTITY_A() stores original entities + + bool badOrder = false; + if (anEdgesAttr->isInitialized()) { // restoring data from saved study + AttributeRefListPtr entaAttr = std::dynamic_pointer_cast + (data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), + ModelAPI_AttributeRefList::typeId())); // #4 + + 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 + + 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()