Salome HOME
bos #37570: Correctly restore from opened study disordered attributes of Fuse and...
authorjfa <jfa@opencascade.com>
Tue, 3 Oct 2023 13:09:29 +0000 (14:09 +0100)
committerjfa <jfa@opencascade.com>
Wed, 4 Oct 2023 23:20:23 +0000 (00:20 +0100)
src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp
src/SketchPlugin/SketchPlugin_Offset.cpp

index bccfaf13a5960cd96ecd14e3475f559ab76fb0b5..6b19e7e5c6a006cb37769d84ffe943b73f162ddf 100644 (file)
@@ -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<ModelAPI_AttributeString>
+    (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<ModelAPI_AttributeDouble>
+      (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<ModelAPI_AttributeBoolean>
+      (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<ModelAPI_AttributeBoolean>
+      (data()->addAttribute(FeaturesPlugin_Boolean::USE_FUZZY_ID(),
+                            ModelAPI_AttributeBoolean::typeId(),
+                            5)); // #5
+    // Fuzzy value
+    aValFuzzyAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>
+      (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());
index aabe5babf323d012e53506460274b187302edcb1..119a7373b60819071753ac9b17ab97472b3d2a7c 100644 (file)
@@ -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<ModelAPI_AttributeBoolean>(
-    data()->addAttribute(APPROX_ID(), ModelAPI_AttributeBoolean::typeId()));
-  approxAttr->setValue(false);
+  AttributeRefListPtr anEdgesAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>
+    (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<ModelAPI_AttributeRefList>
+    (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<ModelAPI_AttributeBoolean>
+      (data()->addAttribute(APPROX_ID(),
+                            ModelAPI_AttributeBoolean::typeId(),
+                            4)); // #4
+
+    entaAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>
+      (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<ModelAPI_AttributeBoolean>
+      (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()