From: spo Date: Wed, 5 Aug 2015 14:16:32 +0000 (+0300) Subject: Issue #763 - It is possible to remove parameter which is used in features -- Add... X-Git-Tag: V_1.4.0_beta4~424 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d41b09234c411b20f4473c46939a8afa0b932afa;p=modules%2Fshaper.git Issue #763 - It is possible to remove parameter which is used in features -- Add used parameters in attributes --- diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 0e8d64bd1..3e7a5407e 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -20,9 +20,14 @@ #include #include #include +#include #include #include #include +#include + +#include +#include #include #include @@ -397,6 +402,45 @@ void Model_Data::updateConcealmentFlag() #include +std::set set_union(const std::set& theLeft, + const std::set& theRight) +{ + std::set aResult; + aResult.insert(theLeft.begin(), theLeft.end()); + aResult.insert(theRight.begin(), theRight.end()); + return aResult; +} + +std::set usedParameters(const AttributePointPtr& theAttribute) +{ + std::set anUsedParameters; + for (int aComponent = 0; aComponent < 3; ++aComponent) + anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent)); + return anUsedParameters; +} + +std::set usedParameters(const AttributePoint2DPtr& theAttribute) +{ + std::set anUsedParameters; + for (int aComponent = 0; aComponent < 2; ++aComponent) + anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent)); + return anUsedParameters; +} + +std::list findVariables(const std::set& theParameters) +{ + std::list aResult; + std::set::const_iterator aParamIt = theParameters.cbegin(); + for (; aParamIt != theParameters.cend(); ++aParamIt) { + const std::string& aName = *aParamIt; + double aValue; + ResultParameterPtr aParam; + if (ModelAPI_Tools::findVariable(aName, aValue, aParam)) + aResult.push_back(aParam); + } + return aResult; +} + void Model_Data::referencesToObjects( std::list > >& theRefs) { @@ -432,6 +476,24 @@ void Model_Data::referencesToObjects( for(int a = aRef->size() - 1; a >= 0; a--) { aReferenced.push_back(aRef->value(a)->context()); } + } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute + AttributeDoublePtr anAttribute = + std::dynamic_pointer_cast(anAttr->second); + std::set anUsedParameters = anAttribute->usedParameters(); + std::list aParameters = findVariables(anUsedParameters); + aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); + } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute + AttributePointPtr anAttribute = + std::dynamic_pointer_cast(anAttr->second); + std::set anUsedParameters = usedParameters(anAttribute); + std::list aParameters = findVariables(anUsedParameters); + aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); + } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute + AttributePoint2DPtr anAttribute = + std::dynamic_pointer_cast(anAttr->second); + std::set anUsedParameters = usedParameters(anAttribute); + std::list aParameters = findVariables(anUsedParameters); + aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else continue; // nothing to do, not reference diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index 13dfc182a..b5acdb33e 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -25,6 +25,7 @@ #include #include +#include #include ParametersPlugin_EvalListener::ParametersPlugin_EvalListener() @@ -84,6 +85,11 @@ double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression, return result; } +std::set toSet(const std::list& theContainer) +{ + return std::set(theContainer.begin(), theContainer.end()); +} + void ParametersPlugin_EvalListener::processEvaluationEvent( const std::shared_ptr& theMessage) { @@ -98,6 +104,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( bool isValid = anError.empty(); if (isValid) anAttribute->setCalculatedValue(aValue); + anAttribute->setUsedParameters(isValid ? toSet(myInterp->compile(anAttribute->text())) : std::set()); anAttribute->setExpressionInvalid(!isValid); anAttribute->setExpressionError(anAttribute->text().empty() ? "" : anError); } else @@ -119,6 +126,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( double aValue = evaluate(aText[i], anError); bool isValid = anError.empty(); if (isValid) aCalculatedValue[i] = aValue; + anAttribute->setUsedParameters(i, isValid ? toSet(myInterp->compile(aText[i])) : std::set()); anAttribute->setExpressionInvalid(i, !isValid); anAttribute->setExpressionError(i, aText[i].empty() ? "" : anError); } @@ -142,6 +150,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( double aValue = evaluate(aText[i], anError); bool isValid = anError.empty(); if (isValid) aCalculatedValue[i] = aValue; + anAttribute->setUsedParameters(i, isValid ? toSet(myInterp->compile(aText[i])) : std::set()); anAttribute->setExpressionInvalid(i, !isValid); anAttribute->setExpressionError(i, aText[i].empty() ? "" : anError); }