]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix ConstraintAngle value treatment for very old studies. There is no proved profit. jfa/37570_ConstraintAngle
authorjfa <jfa@opencascade.com>
Fri, 24 Nov 2023 15:50:10 +0000 (15:50 +0000)
committerjfa <jfa@opencascade.com>
Fri, 24 Nov 2023 15:50:10 +0000 (15:50 +0000)
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp

index cdb3309ecf47c08e50ea813d3c2e0ec5ce2730a6..fc6fdc736cfccceb60d1bce65fbd1a1c9191d22f 100644 (file)
@@ -74,7 +74,9 @@ void SketchPlugin_ConstraintAngle::initAttributes()
 {
   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
 
-  data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
+  AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>
+    (data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()));
+
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
   data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
@@ -107,9 +109,15 @@ void SketchPlugin_ConstraintAngle::initAttributes()
   aVerAttr->setIsArgument(false);
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VERSION_ID());
   if (!aVerAttr->isInitialized()) {
-    // this is a newly created feature (not read from file),
-    // so, initialize the latest version
-    aVerAttr->setValue(THE_VERSION_1);
+    if (aValueAttr->isInitialized()) {
+      // very old feature, read from file
+      aVerAttr->setValue(THE_VERSION_0);
+    }
+    else {
+      // this is a newly created feature (not read from file),
+      // so, initialize the latest version
+      aVerAttr->setValue(THE_VERSION_1);
+    }
   }
 }
 
@@ -130,9 +138,7 @@ void SketchPlugin_ConstraintAngle::execute()
   if (!anAttrA->isInitialized() || !anAttrB->isInitialized())
     return;
 
-  AttributeIntegerPtr aVersion = integer(VERSION_ID());
-  if (!aVersion->isInitialized() || aVersion->value() < THE_VERSION_1)
-    updateVersion();
+  updateVersion();
 
   AttributeDoublePtr anAttrValue = real(ANGLE_VALUE_ID());
   if (!anAttrValue->isInitialized())
@@ -153,6 +159,8 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious
   if (!sketch())
     return thePrevious;
 
+  updateVersion();
+
   AISObjectPtr anAIS = SketcherPrs_Factory::angleConstraint(this, sketch(),
                                                             thePrevious);
   if (anAIS.get() && !thePrevious.get())
@@ -195,9 +203,7 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
   if (!aLineA || !aLineB)
     return;
 
-  AttributeIntegerPtr aVersion = integer(VERSION_ID());
-  if (!aVersion->isInitialized() || aVersion->value() < THE_VERSION_1)
-    updateVersion();
+  updateVersion();
 
   if (theID == ENTITY_A() || theID == ENTITY_B() ||
       theID == TYPE_ID() || theID == ANGLE_VALUE_ID()) {
@@ -529,6 +535,10 @@ bool SketchPlugin_ConstraintAngle::compute(const std::string& theAttributeId)
 
 void SketchPlugin_ConstraintAngle::updateVersion()
 {
+  AttributeIntegerPtr aVersion = integer(VERSION_ID());
+  if (aVersion->isInitialized() && aVersion->value() > THE_VERSION_0)
+    return;
+
   bool aWasBlocked = data()->blockSendAttributeUpdated(true);
 
   // Calculate angle value by the old algorithm and