X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeReference.cpp;h=134516972b2a2eecfacab366f3bb46f9204d5a8c;hb=b5e6786b95d33825a3d1537d5453492e774d6399;hp=ab247fdc9d72db1835ca3635e3731cbcfeb15e5d;hpb=e9da4a58641d63176d3214d2f5e3440b917f611d;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeReference.cpp b/src/Model/Model_AttributeReference.cpp index ab247fdc9..134516972 100644 --- a/src/Model/Model_AttributeReference.cpp +++ b/src/Model/Model_AttributeReference.cpp @@ -7,47 +7,69 @@ #include "Model_Events.h" #include "Model_Data.h" #include -#include using namespace std; -void Model_AttributeReference::setValue(boost::shared_ptr theFeature) +void Model_AttributeReference::setValue(ObjectPtr theObject) { - if (value() != theFeature) { - boost::shared_ptr aData = - boost::dynamic_pointer_cast(theFeature->data()); - if (myRef.IsNull()) { - boost::shared_ptr aMyData = - boost::dynamic_pointer_cast(feature()->data()); - TDF_Reference::Set(aMyData->label(), aData->label()); - } else { - myRef->Set(aData->label()); - } + if(!theObject) + return; + if (!myIsInitialized || value() != theObject) { + boost::shared_ptr aData = boost::dynamic_pointer_cast( + theObject->data()); + + boost::shared_ptr aDoc = + boost::dynamic_pointer_cast(owner()->document()); + if (aDoc) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get())); + myRef->Set(aData->label().Father()); // references to the feature label + boost::shared_dynamic_cast(owner()->document())->objectIsReferenced(theObject); - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); - Model_FeatureUpdatedMessage aMsg(feature(), anEvent); - Events_Loop::loop()->send(aMsg); + owner()->data()->sendAttributeUpdated(this); } } -boost::shared_ptr Model_AttributeReference::value() +ObjectPtr Model_AttributeReference::value() { - if (!myRef.IsNull()) { - boost::shared_ptr aDoc = - boost::dynamic_pointer_cast(feature()->document()); + if (myIsInitialized) { + boost::shared_ptr aDoc = boost::dynamic_pointer_cast( + owner()->document()); if (aDoc) { TDF_Label aRefLab = myRef->Get(); - return aDoc->feature(aRefLab); + return aDoc->object(aRefLab); } } // not initialized - return boost::shared_ptr(); + return FeaturePtr(); } Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel) { - // check the attribute could be already presented in this doc (after load document) - if (!theLabel.FindAttribute(TDF_Reference::GetID(), myRef)) { - // create attribute: not initialized by value yet: attribute is not set to the label! + myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True; + if (!myIsInitialized) { + myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized references to itself + } else { + if (owner()) { + boost::shared_ptr aDoc = + boost::dynamic_pointer_cast(owner()->document()); + if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get())); + } + } +} + +void Model_AttributeReference::setObject(const boost::shared_ptr& theObject) +{ + if (owner() != theObject) { + ModelAPI_AttributeReference::setObject(theObject); + boost::shared_ptr aDoc = + boost::dynamic_pointer_cast(owner()->document()); + if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get())); } } + +Model_AttributeReference::~Model_AttributeReference() +{ + boost::shared_ptr aDoc = + boost::dynamic_pointer_cast(owner()->document()); + TDF_Label aLab = myRef->Get(); + if (aDoc && !aLab.IsNull()) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get())); +}