X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelectionList.cpp;h=3b67df9eb0a9063e23a7874fde696432fdaa9857;hb=2e39226506e4b82f6ae5dcc26e776571801b1555;hp=e150fb56c0bc83455050b3cace2ee10e8be4e777;hpb=f47c90a323b39a5c01cee810005e2094ffbb07ea;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index e150fb56c..3b67df9eb 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,55 +11,89 @@ #include "Model_Data.h" #include +#include + +#include +#include +#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) { - updateSubs(); + // do not use the degenerated edge as a shape, a list is not incremented in this case + if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) { + const TopoDS_Shape& aSubShape = theSubShape->impl(); + if (aSubShape.ShapeType() == TopAbs_EDGE && BRep_Tool::Degenerated(TopoDS::Edge(aSubShape))) { + return; + } + } int aNewTag = mySize->Get() + 1; TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); - boost::shared_ptr aNewAttr = - boost::shared_ptr(new Model_AttributeSelection(aNewLab)); + std::shared_ptr aNewAttr = + std::shared_ptr(new Model_AttributeSelection(aNewLab)); if (owner()) { aNewAttr->setObject(owner()); } - mySubs.push_back(aNewAttr); + aNewAttr->setID(id()); 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); + + std::shared_ptr aNewAttr = + std::shared_ptr(new Model_AttributeSelection(aNewLab)); + if (owner()) { + aNewAttr->setObject(owner()); + } + mySize->Set(aNewTag); + aNewAttr->selectSubShape(selectionType(), theNamingName); + owner()->data()->sendAttributeUpdated(this); +} + int Model_AttributeSelectionList::size() { return mySize->Get(); } -int Model_AttributeSelectionList::selectionType() +const std::string Model_AttributeSelectionList::selectionType() const { - return (int) mySelectionType->Get(); + return TCollection_AsciiString(mySelectionType->Get()).ToCString(); } -void Model_AttributeSelectionList::setSelectionType(int theType) +void Model_AttributeSelectionList::setSelectionType(const std::string& theType) { - mySelectionType->Set((double) theType); + mySelectionType->Set(theType.c_str()); } -boost::shared_ptr +std::shared_ptr Model_AttributeSelectionList::value(const int theIndex) { - updateSubs(); - 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() { if (mySize->Get() != 0) { mySize->Set(0); - mySubs.clear(); TDF_ChildIterator aSubIter(mySize->Label()); for(; aSubIter.More(); aSubIter.Next()) { aSubIter.Value().ForgetAllAttributes(Standard_True); @@ -66,48 +102,21 @@ void Model_AttributeSelectionList::clear() } } +bool Model_AttributeSelectionList::isInitialized() +{ + if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo + return false; + } + return ModelAPI_AttributeSelectionList::isInitialized(); +} + 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); + mySelectionType = TDataStd_Comment::Set(theLabel, ""); } else { // recollect mySubs - theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType); - updateSubs(); - } -} - -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); - } -} - -void Model_AttributeSelectionList::updateSubs() -{ - unsigned int aNum = mySize->Get(); - if (aNum > mySubs.size()) { // add subs what are not yet created - TDF_ChildIterator aSubIter(mySize->Label()); - for(int aExisting = mySubs.size(); aExisting > 0; aSubIter.Next()) aExisting--; - for(; aSubIter.More(); aSubIter.Next()) { - 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); - } - } else if (aNum < mySubs.size()) { // remove excess subs from the end - if (aNum == 0) { - mySubs.clear(); - } else { - std::vector >::iterator aSubIter = mySubs.begin(); - for(int aExisting = aNum; aExisting != 0; aSubIter++) aExisting--; - mySubs.erase(aSubIter, mySubs.end()); - } + theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType); } }