// value calculation
std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
- // TODO: has to be calculated on definition of reference object
- double aValue;
+ 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 (aValueAttr->isInitialized())
aValue = aValueAttr->value();
- else {
- aValue = calculateCurrentDistance();
- aValueAttr->setValue(aValue);
- }
- // End TODO
AISObjectPtr anAIS = thePrevious;
if (!anAIS)
return aDistance;
}
+void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID) {
+ if (theID == SketchPlugin_Constraint::ENTITY_A() ||
+ theID == SketchPlugin_Constraint::ENTITY_B())
+ {
+ std::shared_ptr<ModelAPI_AttributeDouble> 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<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,