X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Data.cpp;h=d7d14ad8cae6bea66468270675810de020136356;hb=b73fb7468bea81901dbeed8e229d742f788ec282;hp=49bca1d2752823a715467acb473d742a254b4a2b;hpb=016814c4673909dcd7fd9591694cf599623dfbc7;p=modules%2Fshaper.git diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 49bca1d27..d7d14ad8c 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include @@ -58,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +75,9 @@ static const int kFlagInHistory = 0; static const int kFlagDisplayed = 1; // 2 - is deleted (for results) or not static const int kFlagDeleted = 2; +// TDataStd_Integer - 0 if the name of the object is generated automatically, +// otherwise the name is defined by user +Standard_GUID kUSER_DEFINED_NAME("9c694d18-a83c-4a56-bc9b-8020628a8244"); // invalid data const static std::shared_ptr kInvalid(new Model_Data()); @@ -127,8 +130,22 @@ void Model_Data::setName(const std::string& theName) isModified = true; } else { isModified = !aName->Get().IsEqual(theName.c_str()); - if (isModified) + if (isModified) { aName->Set(theName.c_str()); + + // check the name of result is defined by user + // (name of result does not composed of the name of feature and the result index) + bool isUserDefined = true; + ResultPtr aResult = std::dynamic_pointer_cast(myObject); + if (aResult) { + std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult, false).first; + isUserDefined = aDefaultName != theName; + } + if (isUserDefined) { + // name is user-defined, thus special attribute is set + TDataStd_UAttribute::Set(myLab, kUSER_DEFINED_NAME); + } + } } if (mySendAttributeUpdated && isModified) ModelAPI_ObjectRenamedMessage::send(myObject, anOldName, theName, this); @@ -141,6 +158,11 @@ void Model_Data::setName(const std::string& theName) #endif } +bool Model_Data::hasUserDefinedName() const +{ + return myLab.IsAttribute(kUSER_DEFINED_NAME); +} + AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType) { AttributePtr aResult; @@ -462,10 +484,10 @@ int Model_Data::featureId() const void Model_Data::eraseBackReferences() { myRefsToMe.clear(); - std::shared_ptr aRes = - std::dynamic_pointer_cast(myObject); - if (aRes) + std::shared_ptr aRes = std::dynamic_pointer_cast(myObject); + if (aRes) { aRes->setIsConcealed(false); + } } void Model_Data::removeBackReference(ObjectPtr theObject, std::string theAttrID) @@ -496,8 +518,7 @@ void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID, if (theApplyConcealment && theFeature->isStable() && ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) { - std::shared_ptr aRes = - std::dynamic_pointer_cast(myObject); + std::shared_ptr aRes = std::dynamic_pointer_cast(myObject); // the second condition is for history upper than concealment causer, so the feature result may // be displayed and previewed; also for avoiding of quick show/hide on history // moving deep down @@ -566,7 +587,8 @@ std::set usedParameters(const AttributePoint2DPtr& theAttribute) return anUsedParameters; } -std::list findVariables(const std::set& theParameters) +std::list findVariables(const std::set& theParameters, + const DocumentPtr& theDocument) { std::list aResult; std::set::const_iterator aParamIt = theParameters.cbegin(); @@ -576,7 +598,7 @@ std::list findVariables(const std::set& thePara ResultParameterPtr aParam; // theSearcher is not needed here: in expressions // of features the parameters history is not needed - if (ModelAPI_Tools::findVariable(FeaturePtr(), aName, aValue, aParam)) + if (ModelAPI_Tools::findVariable(FeaturePtr(), aName, aValue, aParam, theDocument)) aResult.push_back(aParam); } return aResult; @@ -614,15 +636,34 @@ void Model_Data::referencesToObjects( } } else if (aType == ModelAPI_AttributeRefList::typeId()) { // list of references aReferenced = std::dynamic_pointer_cast(anAttr)->list(); - } else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute + } + else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute std::shared_ptr aRef = std::dynamic_pointer_cast< - ModelAPI_AttributeSelection>(anAttr); - aReferenced.push_back(aRef->context()); + ModelAPI_AttributeSelection>(anAttr); + FeaturePtr aRefFeat = aRef->contextFeature(); + if (aRefFeat.get()) { // reference to all results of the referenced feature + const std::list& allRes = aRefFeat->results(); + std::list::const_iterator aRefRes = allRes.cbegin(); + for(; aRefRes != allRes.cend(); aRefRes++) { + aReferenced.push_back(*aRefRes); + } + } else { + aReferenced.push_back(aRef->context()); + } } else if (aType == ModelAPI_AttributeSelectionList::typeId()) { // list of selection attributes std::shared_ptr aRef = std::dynamic_pointer_cast< ModelAPI_AttributeSelectionList>(anAttr); for(int a = 0, aSize = aRef->size(); a < aSize; ++a) { - aReferenced.push_back(aRef->value(a)->context()); + FeaturePtr aRefFeat = aRef->value(a)->contextFeature(); + if (aRefFeat.get()) { // reference to all results of the referenced feature + const std::list& allRes = aRefFeat->results(); + std::list::const_iterator aRefRes = allRes.cbegin(); + for (; aRefRes != allRes.cend(); aRefRes++) { + aReferenced.push_back(*aRefRes); + } + } else { + aReferenced.push_back(aRef->value(a)->context()); + } } } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { std::shared_ptr aRefAttr = std::dynamic_pointer_cast< @@ -637,25 +678,29 @@ void Model_Data::referencesToObjects( AttributeIntegerPtr anAttribute = std::dynamic_pointer_cast(anAttr); std::set anUsedParameters = anAttribute->usedParameters(); - std::list aParameters = findVariables(anUsedParameters); + std::list aParameters = + findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute AttributeDoublePtr anAttribute = std::dynamic_pointer_cast(anAttr); std::set anUsedParameters = anAttribute->usedParameters(); - std::list aParameters = findVariables(anUsedParameters); + std::list aParameters = + findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute AttributePointPtr anAttribute = std::dynamic_pointer_cast(anAttr); std::set anUsedParameters = usedParameters(anAttribute); - std::list aParameters = findVariables(anUsedParameters); + std::list aParameters = + findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute AttributePoint2DPtr anAttribute = std::dynamic_pointer_cast(anAttr); std::set anUsedParameters = usedParameters(anAttribute); - std::list aParameters = findVariables(anUsedParameters); + std::list aParameters = + findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else continue; // nothing to do, not reference