From 511077a7b523665c695a4408a5a81747aaf7b2c5 Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 24 Nov 2023 15:50:10 +0000 Subject: [PATCH] Fix ConstraintAngle value treatment for very old studies. There is no proved profit. --- .../SketchPlugin_ConstraintAngle.cpp | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index cdb3309ec..fc6fdc736 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -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 + (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 -- 2.39.2