X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintDistance.cpp;h=bdd410ec06de64bf7fb35e2f163e16f8c3de869b;hb=c685af45eca598fce4a5d40837f6b7d203c60976;hp=611d85a0fba3c238f4605bf9d0ca953736a02906;hpb=4783f146b71a48c651523fcf0e12367bcf3d1fa8;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 611d85a0f..bdd410ec0 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + // File: SketchPlugin_ConstraintDistance.cpp // Created: 23 May 2014 // Author: Artem ZHIDKOV @@ -101,12 +103,12 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi // value calculation std::shared_ptr aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE())); - double aValue = aValueAttr->value(); + double aValue = 0; // Issue #196: checking the positivity of the distance constraint // there is a validator for a distance constraint, that the value should be positive // in case if an invalid value is set, the current distance value is shown - if (aValue <= 0) - aValue = calculateCurrentDistance(); + if (aValueAttr->isInitialized()) + aValue = aValueAttr->value(); AISObjectPtr anAIS = thePrevious; if (!anAIS) @@ -162,6 +164,20 @@ double SketchPlugin_ConstraintDistance::calculateCurrentDistance() const return aDistance; } +void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID) { + if (theID == SketchPlugin_Constraint::ENTITY_A() || + theID == SketchPlugin_Constraint::ENTITY_B()) + { + std::shared_ptr aValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); + if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value + double aDistance = calculateCurrentDistance(); + if (aDistance > 0) { // set as value the length of updated references + aValueAttr->setValue(aDistance); + } + } + } +} //************************************************************************************* std::shared_ptr getFeaturePoint(DataPtr theData,