}
std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters,
- const DocumentPtr& theDocument)
+ const FeaturePtr& theParam)
{
std::list<ResultParameterPtr> aResult;
std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
const std::string& aName = *aParamIt;
double aValue;
ResultParameterPtr aParam;
- if (ModelAPI_Tools::findVariable(aName, aValue, aParam, theDocument))
+ if (ModelAPI_Tools::findVariable(theParam, aName, aValue, aParam))
aResult.push_back(aParam);
}
return aResult;
AttributeIntegerPtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttr->second);
std::set<std::string> anUsedParameters = anAttribute->usedParameters();
- std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
+ std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature);
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
} else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute
AttributeDoublePtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr->second);
std::set<std::string> anUsedParameters = anAttribute->usedParameters();
- std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
+ std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature);
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
} else if (aType == GeomDataAPI_Point::typeId()) { // point attribute
AttributePointPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr->second);
std::set<std::string> anUsedParameters = usedParameters(anAttribute);
- std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
+ std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature);
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
} else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute
AttributePoint2DPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->second);
std::set<std::string> anUsedParameters = usedParameters(anAttribute);
- std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
+ std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature);
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
} else
continue; // nothing to do, not reference
void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
{
- if (theAfterThis == currentFeature(false))
- setCurrentFeature(theMoved, true);
- else if (theMoved == currentFeature(false))
+ bool aCurrentUp = theMoved == currentFeature(false);
+ if (aCurrentUp) {
setCurrentFeatureUp();
+ }
+
myObjs->moveFeature(theMoved, theAfterThis);
+ if (aCurrentUp) { // make the moved feature enabled or disabled due to the real status
+ setCurrentFeature(currentFeature(false), false);
+ } else if (theAfterThis == currentFeature(false)) {
+ // must be after move to make enabled all features which are before theMoved
+ setCurrentFeature(theMoved, true);
+ }
}
void Model_Document::updateHistory(const std::shared_ptr<ModelAPI_Object> theObject)
}
return aResult;
}
+
+bool Model_Document::isLater(FeaturePtr theLater, FeaturePtr theCurrent) const
+{
+ return myObjs->isLater(theLater, theCurrent);
+}
std::shared_ptr<ModelAPI_Result> theResult,
const std::shared_ptr<GeomAPI_Shape>& theShape);
+ /// Returns true if theLater is in history of features creation later than theCurrent
+ MODEL_EXPORT virtual bool isLater(FeaturePtr theLater, FeaturePtr theCurrent) const;
+
protected:
//! Returns (creates if needed) the general label
TDF_Label generalLabel() const;
std::shared_ptr<ModelAPI_Result> theResult,
const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+ /// Returns true if theLater is in history of features creation later than theCurrent
+ virtual bool isLater(std::shared_ptr<ModelAPI_Feature> theLater,
+ std::shared_ptr<ModelAPI_Feature> theCurrent) const = 0;
protected:
//! Only for SWIG wrapping it is here
return ObjectPtr();
}
-bool findVariable(const DocumentPtr& theDocument,
+bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher,
const std::string& theName, double& outValue, ResultParameterPtr& theParam)
{
ObjectPtr aParamObj = objectByName(theDocument, ModelAPI_ResultParameter::group(), theName);
theParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParamObj);
if (!theParam.get())
return false;
+ // avoid usage of parameters created later than the initial parameter
+ if (theSearcher.get() && theDocument->isLater(theDocument->feature(theParam), theSearcher))
+ return false;
AttributeDoublePtr aValueAttribute = theParam->data()->real(ModelAPI_ResultParameter::VALUE());
outValue = aValueAttribute->value();
return true;
}
-bool findVariable(const std::string& theName, double& outValue, ResultParameterPtr& theParam,
- const DocumentPtr& theDocument /*= DocumentPtr()*/)
+bool findVariable(FeaturePtr theSearcher, const std::string& theName, double& outValue, ResultParameterPtr& theParam,
+ const DocumentPtr& theDocument)
{
SessionPtr aSession = ModelAPI_Session::get();
std::list<DocumentPtr> aDocList;
DocumentPtr aDocument = theDocument.get() ? theDocument : aSession->activeDocument();
+ if (findVariable(aDocument, theSearcher, theName, outValue, theParam))
+ return true;
DocumentPtr aRootDocument = aSession->moduleDocument();
- aDocList.push_back(aDocument);
if (aDocument != aRootDocument) {
- aDocList.push_back(aRootDocument);
- }
- for(std::list<DocumentPtr>::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) {
- if (findVariable(*it, theName, outValue, theParam))
- return true;
+ ResultPtr aPartResult = findPartResult(aRootDocument, aDocument);
+ if (aPartResult.get()) {
+ FeaturePtr aPartFeature = aRootDocument->feature(aPartResult);
+ if (findVariable(aRootDocument, aPartFeature, theName, outValue, theParam))
+ return true;
+ }
}
return false;
}
/*!
* Searches for variable with name \param theName in \param theDocument.
* If found, set it value in the \param outValue and returns true.
+ * theSearcher must be located later in the history than the found variable.
*/
-MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument,
- const std::string& theName, double& outValue, ResultParameterPtr& theParam);
+MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher,
+ const std::string& theName, double& outValue, ResultParameterPtr& theParam);
/*!
* Searches for variable with name \param theName in the active document (Part), when
* in the root document (PartSet). If found, set it value in the \param outValue
* and returns true. If \param theDocument is empty active document is used.
+ * theSearcher must be located later in the history than the found variable.
*/
-MODELAPI_EXPORT bool findVariable(const std::string& theName, double& outValue, ResultParameterPtr& theParam,
- const DocumentPtr& theDocument = DocumentPtr());
+MODELAPI_EXPORT bool findVariable(FeaturePtr theSearcher, const std::string& theName,
+ double& outValue, ResultParameterPtr& theParam,
+ const DocumentPtr& theDocument = DocumentPtr());
/*!
* Returns the values of the next random color. The values are in range [0, 255]
double& outValue) const
{
ResultParameterPtr aParam;
- return ModelAPI_Tools::findVariable(theName.toStdString(), outValue, aParam);
+ return ModelAPI_Tools::findVariable(FeaturePtr(), theName.toStdString(), outValue, aParam);
}
/*!
double& outValue) const
{
ResultParameterPtr aParam;
- return ModelAPI_Tools::findVariable(theName.toStdString(), outValue, aParam);
+ return ModelAPI_Tools::findVariable(FeaturePtr(), theName.toStdString(), outValue, aParam);
}
/*!
}
}
-double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression, std::string& theError,
- const std::shared_ptr<ModelAPI_Document>& theDocument)
+double ParametersPlugin_EvalListener::evaluate(FeaturePtr theParameter,
+ const std::string& theExpression, std::string& theError)
{
std::list<std::string> anExprParams = myInterp->compile(theExpression);
// find expression's params in the model
double aValue;
ResultParameterPtr aParamRes;
// If variable does not exist python interpreter will generate an error. It is OK.
- if (!ModelAPI_Tools::findVariable(*it, aValue, aParamRes, theDocument)) continue;
+ if (!ModelAPI_Tools::findVariable(theParameter, *it, aValue, aParamRes, theParameter->document()))
+ continue;
aContext.push_back(*it + "=" + toStdString(aValue));
}
std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
std::dynamic_pointer_cast<ModelAPI_AttributeEvalMessage>(theMessage);
+ FeaturePtr aParamFeature =
+ std::dynamic_pointer_cast<ModelAPI_Feature>(aMessage->attribute()->owner());
if (aMessage->attribute()->attributeType() == ModelAPI_AttributeInteger::typeId()) {
AttributeIntegerPtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aMessage->attribute());
std::string anError;
- int aValue = (int)evaluate(anAttribute->text(), anError, anAttribute->owner()->document());
+ int aValue = (int)evaluate(aParamFeature, anAttribute->text(), anError);
bool isValid = anError.empty();
if (isValid)
anAttribute->setCalculatedValue(aValue);
AttributeDoublePtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aMessage->attribute());
std::string anError;
- double aValue = evaluate(anAttribute->text(), anError, anAttribute->owner()->document());
+ double aValue = evaluate(aParamFeature, anAttribute->text(), anError);
bool isValid = anError.empty();
if (isValid)
anAttribute->setCalculatedValue(aValue);
};
for (int i = 0; i < 3; ++i) {
std::string anError;
- double aValue = evaluate(aText[i], anError, anAttribute->owner()->document());
+ double aValue = evaluate(aParamFeature, aText[i], anError);
bool isValid = anError.empty();
if (isValid) aCalculatedValue[i] = aValue;
anAttribute->setUsedParameters(i, isValid ? toSet(myInterp->compile(aText[i])) : std::set<std::string>());
};
for (int i = 0; i < 2; ++i) {
std::string anError;
- double aValue = evaluate(aText[i], anError, anAttribute->owner()->document());
+ double aValue = evaluate(aParamFeature, aText[i], anError);
bool isValid = anError.empty();
if (isValid) aCalculatedValue[i] = aValue;
anAttribute->setUsedParameters(i, isValid ? toSet(myInterp->compile(aText[i])) : std::set<std::string>());
class ModelAPI_Attribute;
class ModelAPI_Document;
+class ModelAPI_Feature;
class ModelAPI_ResultParameter;
class ParametersPlugin_Parameter;
class ParametersPlugin_PyInterp;
protected:
/// Evaluates theExpression and returns its value.
- double evaluate(const std::string& theExpression, std::string& theError,
- const std::shared_ptr<ModelAPI_Document>& theDocument);
+ double evaluate(std::shared_ptr<ModelAPI_Feature> theParameter,
+ const std::string& theExpression, std::string& theError);
/// Processes Evaluation event.
void processEvaluationEvent(const std::shared_ptr<Events_Message>& theMessage);
double aValue;
ResultParameterPtr aParamRes;
- if (!ModelAPI_Tools::findVariable(aVariableName, aValue, aParamRes, aDocument)) continue;
+ if (!ModelAPI_Tools::findVariable(std::dynamic_pointer_cast<ModelAPI_Feature>(data()->owner()),
+ aVariableName, aValue, aParamRes, aDocument)) continue;
aParamsList.push_back(aParamRes);
std::ostringstream sstream;
else
aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos - 2));
-
- Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
+ // add the updated also the feature that goes down
+ Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
+ static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos - 1), EVENT_UPD);
+ Events_Loop::loop()->flush(EVENT_UPD);
+ Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
updateParametersFeatures();
SessionPtr aMgr = ModelAPI_Session::get();
std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
aDoc->moveFeature(aCurFeature, myParametersList.at(aCurrentPos + 1));
+ // add the updated also the feature that goes up
+ static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(myParametersList.at(aCurrentPos + 1), EVENT_UPD);
+ Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED));
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
updateParametersFeatures();
if (std::dynamic_pointer_cast<ModelAPI_ResultParameter>(theObject).get()) {
double aValue;
ResultParameterPtr aParam;
- if (ModelAPI_Tools::findVariable(theObject->document(), qPrintable(theName), aValue, aParam)) {
+ if (ModelAPI_Tools::findVariable(theObject->document(),
+ FeaturePtr(), qPrintable(theName), aValue, aParam)) {
QString aErrMsg(QObject::tr("Selected parameter can not be renamed to: %1. \
There is a parameter with the same name. Its value is: %2.").arg(qPrintable(theName)).arg(aValue));
// We can not use here a dialog box for message - it will crash editing process in ObjectBrowser