From: sbh Date: Thu, 11 Sep 2014 12:17:50 +0000 (+0400) Subject: Issue #115 The "computed" for all constraints X-Git-Tag: V_0.4.4~73 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a5ffc4b734b71d9a78da1e18909ff3526cf2a188;p=modules%2Fshaper.git Issue #115 The "computed" for all constraints --- diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index e868e0d31..a73044d4a 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -22,7 +22,6 @@ class ModelAPI_Attribute protected: // accessible from the attributes bool myIsInitialized; - bool myIsComputedDefault; bool myIsArgument; public: @@ -58,19 +57,6 @@ class ModelAPI_Attribute myIsInitialized = true; } - /// Returns true if attribute's default value was computed - MODELAPI_EXPORT bool isComputedDefault() - { - return myIsComputedDefault; - } - - /// Tells that attribute's default value was computed - MODELAPI_EXPORT void setComputedDefault() - { - myIsComputedDefault = true; - myIsInitialized = false; - } - /// Set this attribute is argument for result (change of this attribute requires update of result). /// By default it is true. MODELAPI_EXPORT void setIsArgument(const bool theFlag) @@ -89,7 +75,6 @@ class ModelAPI_Attribute ModelAPI_Attribute() { myIsInitialized = false; - myIsComputedDefault = false; myIsArgument = true; } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 11d5f15fc..12e0e034c 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -28,12 +28,6 @@ bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const return theObject->data()->attribute(attributeID())->isInitialized(); } -void ModuleBase_ModelWidget::setAttributeComputedState(ObjectPtr theObject) const -{ - if(myIsComputedDefault) - theObject->data()->attribute(attributeID())->setComputedDefault(); -} - bool ModuleBase_ModelWidget::focusTo() { QList aControls = getControls(); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 9e790a336..400a90249 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -52,8 +52,6 @@ Q_OBJECT /// \return the boolean result bool isInitialized(ObjectPtr theObject) const; - void setAttributeComputedState(ObjectPtr theObject) const; - bool isComputedDefault() { return myIsComputedDefault; @@ -95,8 +93,6 @@ Q_OBJECT void setFeature(const FeaturePtr& theFeature) { myFeature = theFeature; - if(theFeature) - setAttributeComputedState(theFeature); } signals: diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp index e7c510a83..ec61e8443 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -137,10 +137,9 @@ bool ModuleBase_WidgetFeature::restoreValue() boost::shared_ptr aRef = boost::dynamic_pointer_cast< ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); - ObjectPtr aObj = aRef->object(); - FeaturePtr aFeature = boost::dynamic_pointer_cast(aRef->object()); - if (aFeature) { - myObject = aFeature; + ObjectPtr anObjPtr = aRef->object(); + if (anObjPtr) { + myObject = anObjPtr; myEditor->setText(myObject ? myObject->data()->name().c_str() : ""); return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp index 4481c2034..d9674c4d4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp @@ -30,8 +30,9 @@ #include #include -ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute( - QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) +ModuleBase_WidgetFeatureOrAttribute::ModuleBase_WidgetFeatureOrAttribute(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) : ModuleBase_WidgetFeature(theParent, theData, theParentId) { } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 97a08e134..60c3e23b1 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -33,29 +33,37 @@ void SketchPlugin_ConstraintDistance::initAttributes() void SketchPlugin_ConstraintDistance::execute() { boost::shared_ptr aData = data(); - AttributeDoublePtr anAttr_Value = boost::dynamic_pointer_cast( + AttributeDoublePtr anAttrValue = boost::dynamic_pointer_cast( aData->attribute(SketchPlugin_Constraint::VALUE())); - boost::shared_ptr aPoint_A = getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_A()); - boost::shared_ptr aPoint_B = getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_B()); - - if (aPoint_A && aPoint_B) { // both points - anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt())); + if(anAttrValue->isInitialized()) + return; + boost::shared_ptr aPointA = + getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A()); + boost::shared_ptr aPointB = + getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B()); + + double aDistance = -1.; + if (aPointA && aPointB) { // both points + aDistance = aPointA->pnt()->distance(aPointB->pnt()); } else { - if (!aPoint_A && aPoint_B) { //Line and point - boost::shared_ptr aLine = getFeatureLine( - aData, SketchPlugin_Constraint::ENTITY_A()); - if (aLine) - anAttr_Value->setValue(aLine->distanceToPoint(aPoint_B->pnt())); - } else if (aPoint_A && !aPoint_B) { // Point and line - boost::shared_ptr aLine = getFeatureLine( - aData, SketchPlugin_Constraint::ENTITY_B()); - if (aLine) - anAttr_Value->setValue(aLine->distanceToPoint(aPoint_A->pnt())); + if (!aPointA && aPointB) { //Line and point + boost::shared_ptr aLine = + getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); + if (aLine) { + aDistance = aLine->distanceToPoint(aPointB->pnt()); + } + } else if (aPointA && !aPointB) { // Point and line + boost::shared_ptr aLine = + getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); + if (aLine) { + aDistance = aLine->distanceToPoint(aPointA->pnt()); + } } } + if(aDistance >= 0) { + anAttrValue->setValue(aDistance); + } } //************************************************************************************* diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index e7ed5411c..d0ca9f88b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -45,7 +45,9 @@ void SketchPlugin_ConstraintLength::execute() boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); - aValueAttr->setValue(aLenght); + if(!aValueAttr->isInitialized()) { + aValueAttr->setValue(aLenght); + } } } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 133bc91bb..36ec6c384 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -55,7 +55,9 @@ void SketchPlugin_ConstraintRadius::execute() } boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); - aValueAttr->setValue(aRadius); + if(!aValueAttr->isInitialized()) { + aValueAttr->setValue(aRadius); + } } } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 4a0088d51..c40bcaffb 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -40,7 +40,7 @@ - + @@ -50,7 +50,7 @@ - +