X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeRefAttr.cpp;h=14e6eb4a18d394929af5d30dc2d89d11f10ac4c6;hb=2f89053146098946372bae4d1a3fe2e5272ab9e2;hp=39797722609130ae4fc3d7cf42ee4bcb5dcce231;hpb=f581964034f8df715c46a07c5ecb762492d6b4cf;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index 397977226..14e6eb4a1 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -1,85 +1,76 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: ModelAPI_AttributeRefAttr.cxx // Created: 2 Apr 2014 // Author: Mikhail PONIKAROV #include "Model_AttributeRefAttr.h" #include "Model_Application.h" -#include "Model_Events.h" #include "Model_Data.h" #include -#include using namespace std; -bool Model_AttributeRefAttr::isFeature() +bool Model_AttributeRefAttr::isObject() { return myID->Get().Length() == 0; } -void Model_AttributeRefAttr::setAttr(boost::shared_ptr theAttr) +void Model_AttributeRefAttr::setAttr(std::shared_ptr theAttr) { - boost::shared_ptr aData = - boost::dynamic_pointer_cast(theAttr->owner()->data()); + std::shared_ptr aData = std::dynamic_pointer_cast( + theAttr->owner()->data()); string anID = aData->id(theAttr); - if (feature() == theAttr->owner() && myID->Get().IsEqual(anID.c_str())) - return; // nothing is changed - - myRef->Set(aData->label()); + if (myIsInitialized && object() == theAttr->owner() && myID->Get().IsEqual(anID.c_str())) + return; // nothing is changed + myRef->Set(aData->label().Father()); myID->Set(aData->id(theAttr).c_str()); - - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); - Model_FeatureUpdatedMessage aMsg(owner(), anEvent); - Events_Loop::loop()->send(aMsg); + owner()->data()->sendAttributeUpdated(this); } -boost::shared_ptr Model_AttributeRefAttr::attr() +std::shared_ptr Model_AttributeRefAttr::attr() { - FeaturePtr aFeature = feature(); - if (aFeature) { - boost::shared_ptr aData = - boost::dynamic_pointer_cast(aFeature->data()); + ObjectPtr anObj = object(); + if (anObj) { + std::shared_ptr aData = std::dynamic_pointer_cast(anObj->data()); return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString()); } // not initialized - return boost::shared_ptr(); + return std::shared_ptr(); } -void Model_AttributeRefAttr::setFeature(FeaturePtr theFeature) +void Model_AttributeRefAttr::setObject(ObjectPtr theObject) { - if (myID->Get().Length() != 0 || feature() != theFeature) { - boost::shared_ptr aData = - boost::dynamic_pointer_cast(theFeature->data()); - myRef->Set(aData->label()); - myID->Set(""); // feature is identified by the empty ID - - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); - Model_FeatureUpdatedMessage aMsg(owner(), anEvent); - Events_Loop::loop()->send(aMsg); + if (theObject && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) { + std::shared_ptr aData = std::dynamic_pointer_cast( + theObject->data()); + myRef->Set(aData->label().Father()); + myID->Set(""); // feature is identified by the empty ID + owner()->data()->sendAttributeUpdated(this); } } -FeaturePtr Model_AttributeRefAttr::feature() +ObjectPtr Model_AttributeRefAttr::object() { - if (myRef->Get() != myRef->Label()) { // initialized - boost::shared_ptr aDoc = - boost::dynamic_pointer_cast(owner()->document()); + if (myRef->Get() != myRef->Label()) { // initialized + std::shared_ptr aDoc = std::dynamic_pointer_cast( + owner()->document()); if (aDoc) { TDF_Label aRefLab = myRef->Get(); - TDF_Label aFeatureLab = aRefLab.Father(); - return aDoc->feature(aRefLab); + return aDoc->object(aRefLab); } } // not initialized - return FeaturePtr(); + return ObjectPtr(); } Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel) { - // check the attribute could be already presented in this doc (after load document) - if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myID)) { + myIsInitialized = theLabel.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 + myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized: reference to itself } else { theLabel.FindAttribute(TDF_Reference::GetID(), myRef); }