X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelectionList.cpp;h=0643a520bb91a23e620d37c64fefe8413ba3da90;hb=9c54fb01877c455abb5b5ff22e384468f795b328;hp=848341184cbb452fe03d9b38ff17e288976bb158;hpb=27a61e1e61c970b3bfd4b863543aadeac9b65162;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 848341184..0643a520b 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: Model_AttributeSelectionList.h // Created: 22 Oct 2014 // Author: Mikhail PONIKAROV @@ -9,17 +11,53 @@ #include "Model_Data.h" #include +#include using namespace std; void Model_AttributeSelectionList::append( - const ResultPtr& theContext, const boost::shared_ptr& theSubShape) + const ResultPtr& theContext, const std::shared_ptr& theSubShape) +{ + int aNewTag = mySize->Get() + 1; + TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); + + std::shared_ptr aNewAttr = + std::shared_ptr(new Model_AttributeSelection(aNewLab)); + if (owner()) { + aNewAttr->setObject(owner()); + } + mySize->Set(aNewTag); + aNewAttr->setValue(theContext, theSubShape); + owner()->data()->sendAttributeUpdated(this); +} + +void Model_AttributeSelectionList::append(std::string theNamingName) { int aNewTag = mySize->Get() + 1; TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); - mySubs.push_back(boost::shared_ptr( - new Model_AttributeSelection(aNewLab))); + + std::shared_ptr aNewAttr = + std::shared_ptr(new Model_AttributeSelection(aNewLab)); + if (owner()) { + aNewAttr->setObject(owner()); + } mySize->Set(aNewTag); + TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)selectionType(); + string aTypeName; + switch(aType) { + case TopAbs_VERTEX: aTypeName = "VERT"; break; + case TopAbs_EDGE: aTypeName = "EDGE"; break; + case TopAbs_WIRE: aTypeName = "WIRE"; break; + case TopAbs_FACE: aTypeName = "FACE"; break; + case TopAbs_SHELL: aTypeName = "SHEL"; break; + case TopAbs_SOLID: aTypeName = "SOLD"; break; + case TopAbs_COMPOUND: aTypeName = "COMP"; break; + case TopAbs_COMPSOLID: aTypeName = "COMS"; break; + default: + return; // invalid case => empty new attribute + }; + aNewAttr->selectSubShape(aTypeName, theNamingName); + owner()->data()->sendAttributeUpdated(this); } int Model_AttributeSelectionList::size() @@ -27,18 +65,40 @@ int Model_AttributeSelectionList::size() return mySize->Get(); } -boost::shared_ptr +int Model_AttributeSelectionList::selectionType() +{ + return (int) mySelectionType->Get(); +} + +void Model_AttributeSelectionList::setSelectionType(int theType) +{ + mySelectionType->Set((double) theType); +} + +std::shared_ptr Model_AttributeSelectionList::value(const int theIndex) { - return mySubs[theIndex]; + TDF_Label aLabel = mySize->Label().FindChild(theIndex + 1); + // create a new attribute each time, by demand + // supporting of old attributes is too slow (synch each time) and buggy on redo + // (if attribute is deleted and created, the abort updates attriute and makes the Attr invalid) + std::shared_ptr aNewAttr = + std::shared_ptr(new Model_AttributeSelection(aLabel)); + if (owner()) { + aNewAttr->setObject(owner()); + } + return aNewAttr; } void Model_AttributeSelectionList::clear() { - mySubs.clear(); - TDF_ChildIterator aSubIter(mySize->Label()); - for(; aSubIter.More(); aSubIter.Next()) { - aSubIter.Value().ForgetAllAttributes(Standard_True); + if (mySize->Get() != 0) { + mySize->Set(0); + TDF_ChildIterator aSubIter(mySize->Label()); + for(; aSubIter.More(); aSubIter.Next()) { + aSubIter.Value().ForgetAllAttributes(Standard_True); + } + owner()->data()->sendAttributeUpdated(this); } } @@ -47,25 +107,8 @@ Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True; if (!myIsInitialized) { mySize = TDataStd_Integer::Set(theLabel, 0); + mySelectionType = TDataStd_Real::Set(theLabel, 0); } else { // recollect mySubs - int aNum = mySize->Get(); - TDF_ChildIterator aSubIter(theLabel); - for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) { - TDF_Label aChildLab = aSubIter.Value(); - boost::shared_ptr aNewAttr = - boost::shared_ptr(new Model_AttributeSelection(aChildLab)); - if (owner()) - aNewAttr->setObject(owner()); - mySubs.push_back(aNewAttr); - } - } -} - -void Model_AttributeSelectionList::setObject(const boost::shared_ptr& theObject) -{ - ModelAPI_AttributeSelectionList::setObject(theObject); - std::vector >::iterator aSubIter = mySubs.begin(); - for(; aSubIter != mySubs.end(); aSubIter++) { - (*aSubIter)->setObject(theObject); + theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType); } }