X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeRefList.cpp;h=534e52750464d88efa114ff213565bbf4e05e4f7;hb=01159d19136fded13c08b72974dc897173376eb4;hp=014592f0d3eebd58a02679f862777e510745c69c;hpb=add875fff5ce228a4914fcc323fdb911a1042b21;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index 014592f0d..534e52750 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: ModelAPI_AttributeRefList.cxx // Created: 8 May 2014 // Author: Mikhail PONIKAROV @@ -5,6 +7,7 @@ #include "Model_AttributeRefList.h" #include "Model_Application.h" #include "Model_Data.h" +#include "Model_Objects.h" #include #include @@ -12,50 +15,109 @@ using namespace std; void Model_AttributeRefList::append(ObjectPtr theObject) { - boost::shared_ptr aData = boost::dynamic_pointer_cast(theObject->data()); + std::shared_ptr aData = std::dynamic_pointer_cast(theObject->data()); myRef->Append(aData->label().Father()); // store label of the object + // do it before the transaction finish to make just created/removed objects know dependencies + // and reference from composite feature is removed automatically + ADD_BACK_REF(theObject); owner()->data()->sendAttributeUpdated(this); } void Model_AttributeRefList::remove(ObjectPtr theObject) { - boost::shared_ptr aData = boost::dynamic_pointer_cast(theObject->data()); - myRef->Remove(aData->label().Father()); - + std::shared_ptr aData; + if (theObject.get() != NULL) { + aData = std::dynamic_pointer_cast(theObject->data()); + myRef->Remove(aData->label().Father()); + REMOVE_BACK_REF(theObject); + } + else { // in case of empty object remove, the first empty object is removed from the list + std::shared_ptr aDoc = std::dynamic_pointer_cast( + owner()->document()); + if (aDoc) { + const TDF_LabelList& aList = myRef->List(); + for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) { + ObjectPtr anObj = aDoc->objects()->object(aLIter.Value()); + if (anObj.get() == NULL) { + myRef->Remove(aLIter.Value()); + REMOVE_BACK_REF(theObject); + break; + } + } + } + } owner()->data()->sendAttributeUpdated(this); } +void Model_AttributeRefList::clear() +{ + std::list anOldList = list(); + myRef->Clear(); + std::list::iterator anOldIter = anOldList.begin(); + for(; anOldIter != anOldList.end(); anOldIter++) { + REMOVE_BACK_REF((*anOldIter)); + } +} + int Model_AttributeRefList::size() const { return myRef->Extent(); } +bool Model_AttributeRefList::isInitialized() +{ + if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo + return false; + } + return ModelAPI_AttributeRefList::isInitialized(); +} + list Model_AttributeRefList::list() { std::list aResult; - boost::shared_ptr aDoc = boost::dynamic_pointer_cast( + std::shared_ptr aDoc = std::dynamic_pointer_cast( owner()->document()); if (aDoc) { const TDF_LabelList& aList = myRef->List(); for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) { - ObjectPtr anObj = aDoc->object(aLIter.Value()); + ObjectPtr anObj = aDoc->objects()->object(aLIter.Value()); aResult.push_back(anObj); } } return aResult; } +bool Model_AttributeRefList::isInList(const ObjectPtr& theObj) +{ + std::list aResult; + std::shared_ptr aDoc = std::dynamic_pointer_cast( + owner()->document()); + if (aDoc) { + std::shared_ptr aData = std::dynamic_pointer_cast(theObj->data()); + if (aData.get() && aData->isValid()) { + TDF_Label anObjLab = aData->label().Father(); + const TDF_LabelList& aList = myRef->List(); + for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) { + if (aLIter.Value().IsEqual(anObjLab)) { + return true; + } + } + } + } + return false; +} + ObjectPtr Model_AttributeRefList::object(const int theIndex) const { - boost::shared_ptr aDoc = boost::dynamic_pointer_cast( + std::shared_ptr aDoc = std::dynamic_pointer_cast( owner()->document()); if (aDoc) { const TDF_LabelList& aList = myRef->List(); int anIndex = 0; for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) { if (anIndex == theIndex) - return aDoc->object(aLIter.Value()); + return aDoc->objects()->object(aLIter.Value()); } } return ObjectPtr();