X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeRefAttr.cpp;h=3ea876bd1ddb3d599e8fa75fab43345483a416ec;hb=97917d3698f5a2f7fc9596e7c755ff8f6751e373;hp=daa53a1a6075b5aaa9a558e32087c88bf23df557;hpb=1faf79937e639b380c9d48fda5c1932522718548;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index daa53a1a6..3ea876bd1 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -1,84 +1,123 @@ -// File: ModelAPI_AttributeRefAttr.cxx -// Created: 2 Apr 2014 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "Model_AttributeRefAttr.h" #include "Model_Application.h" -#include "Model_Events.h" #include "Model_Data.h" +#include "Model_Objects.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()); - string anID = aData->id(theAttr); - if (feature() == theAttr->owner() && myID->Get().IsEqual(anID.c_str())) - return; // nothing is changed - - myRef->Set(aData->label()); + std::shared_ptr aData = std::dynamic_pointer_cast( + theAttr->owner()->data()); + 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()); - - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); - Model_FeatureUpdatedMessage aMsg(owner(), anEvent); - Events_Loop::loop()->send(aMsg); + ADD_BACK_REF(theAttr->owner()); + owner()->data()->sendAttributeUpdated(this); } -boost::shared_ptr Model_AttributeRefAttr::attr() +std::shared_ptr Model_AttributeRefAttr::attr() { - boost::shared_ptr aFeature = feature(); - if (aFeature) { - boost::shared_ptr aData = - boost::dynamic_pointer_cast(aFeature->data()); + ObjectPtr anObj = object(); + if (anObj && anObj->data()) { + 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(boost::shared_ptr 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 + // 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); - static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); - Model_FeatureUpdatedMessage aMsg(owner(), anEvent); - Events_Loop::loop()->send(aMsg); + 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); } } -boost::shared_ptr 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->objects()->object(aRefLab); } } // not initialized - return boost::shared_ptr(); + 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) { - // check the attribute could be already presented in this doc (after load document) - if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myID)) { + 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 { + myLab.FindAttribute(TDF_Reference::GetID(), myRef); } }