X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeRefAttr.cpp;h=402935bb29440d5fa18e02c98473354881bfac63;hb=a94fc319f2aa64b43c9a73b5ff7063923648faec;hp=2d900eb142221d089617a372e714d182ebf54aa2;hpb=ed3006032ada5642cbd0b1152c01170c815526a6;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index 2d900eb14..402935bb2 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -1,16 +1,29 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModelAPI_AttributeRefAttr.cxx -// Created: 2 Apr 2014 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2017 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_Data.h" +#include "Model_Objects.h" #include -using namespace std; - bool Model_AttributeRefAttr::isObject() { return myID->Get().Length() == 0; @@ -20,11 +33,14 @@ 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); } @@ -43,16 +59,9 @@ void Model_AttributeRefAttr::setObject(ObjectPtr theObject) { // the back reference from the previous object to the attribute should be removed ObjectPtr anObject = object(); - if (anObject.get() && anObject != theObject) { - FeaturePtr anOwnerFeature = std::dynamic_pointer_cast(owner()); - if (anOwnerFeature.get()) { - std::shared_ptr aData = std::dynamic_pointer_cast( - anObject->data()); - aData->removeBackReference(anOwnerFeature, id()); - } - } + if (theObject.get() && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) { + REMOVE_BACK_REF(anObject); - if (theObject && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) { std::shared_ptr aData = std::dynamic_pointer_cast( theObject->data()); myRef->Set(aData->label().Father()); @@ -64,8 +73,10 @@ void Model_AttributeRefAttr::setObject(ObjectPtr theObject) 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); @@ -79,21 +90,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); } }