X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeRefAttr.cpp;h=eff39c6f7167ad1e7ad33ffe30a2c12946f6cae3;hb=d5297c3500d8f3ab40d554a6749ddeec0d4871e6;hp=14e6eb4a18d394929af5d30dc2d89d11f10ac4c6;hpb=7bf19255421b34594c7b0a76d0ce28166d0ce895;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index 14e6eb4a1..eff39c6f7 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -7,10 +7,9 @@ #include "Model_AttributeRefAttr.h" #include "Model_Application.h" #include "Model_Data.h" +#include "Model_Objects.h" #include -using namespace std; - bool Model_AttributeRefAttr::isObject() { return myID->Get().Length() == 0; @@ -20,18 +19,21 @@ void Model_AttributeRefAttr::setAttr(std::shared_ptr theAttr { std::shared_ptr aData = std::dynamic_pointer_cast( theAttr->owner()->data()); - string anID = aData->id(theAttr); - if (myIsInitialized && object() == theAttr->owner() && myID->Get().IsEqual(anID.c_str())) + std::string anID = aData->id(theAttr); + ObjectPtr anObj = object(); + if (myIsInitialized && anObj == theAttr->owner() && myID->Get().IsEqual(anID.c_str())) return; // nothing is changed + REMOVE_BACK_REF(anObj); myRef->Set(aData->label().Father()); myID->Set(aData->id(theAttr).c_str()); + ADD_BACK_REF(theAttr->owner()); owner()->data()->sendAttributeUpdated(this); } std::shared_ptr Model_AttributeRefAttr::attr() { ObjectPtr anObj = object(); - if (anObj) { + if (anObj && anObj->data()) { std::shared_ptr aData = std::dynamic_pointer_cast(anObj->data()); return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString()); } @@ -41,11 +43,28 @@ std::shared_ptr Model_AttributeRefAttr::attr() void Model_AttributeRefAttr::setObject(ObjectPtr theObject) { - if (theObject && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) { + // the back reference from the previous object to the attribute should be removed + ObjectPtr anObject = object(); + if (theObject.get() && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) { + REMOVE_BACK_REF(anObject); + std::shared_ptr aData = std::dynamic_pointer_cast( theObject->data()); myRef->Set(aData->label().Father()); myID->Set(""); // feature is identified by the empty ID + + // do it before the transaction finish to make just created/removed objects know dependencies + // and reference from composite feature is removed automatically + FeaturePtr anOwnerFeature = std::dynamic_pointer_cast(owner()); + if (anOwnerFeature.get()) { + aData->addBackReference(anOwnerFeature, id(), false); + } + ADD_BACK_REF(theObject); + owner()->data()->sendAttributeUpdated(this); + } else if (theObject.get() == NULL) { + REMOVE_BACK_REF(anObject); + myRef->Set(myRef->Label()); // reference to itself means that object is null + myID->Set(""); // feature is identified by the empty ID owner()->data()->sendAttributeUpdated(this); } } @@ -57,21 +76,35 @@ ObjectPtr Model_AttributeRefAttr::object() owner()->document()); if (aDoc) { TDF_Label aRefLab = myRef->Get(); - return aDoc->object(aRefLab); + return aDoc->objects()->object(aRefLab); } } // not initialized return ObjectPtr(); } +bool Model_AttributeRefAttr::isInitialized() +{ + if (myRef->Get() == myRef->Label()) { // empty is not initialized: sketch parallelity + return false; + } + return ModelAPI_AttributeRefAttr::isInitialized(); +} + Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel) { - myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True; + myLab = theLabel; + reinit(); +} + +void Model_AttributeRefAttr::reinit() +{ + myIsInitialized = myLab.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True; if (!myIsInitialized) { // create attribute: not initialized by value yet - myID = TDataStd_Comment::Set(theLabel, ""); - myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized: reference to itself + myID = TDataStd_Comment::Set(myLab, ""); + myRef = TDF_Reference::Set(myLab, myLab); // not initialized: reference to itself } else { - theLabel.FindAttribute(TDF_Reference::GetID(), myRef); + myLab.FindAttribute(TDF_Reference::GetID(), myRef); } }