X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelectionList.cpp;h=caaee41f407425e0767de254bfb905c8e4c3f496;hb=fe8cab988ae59927f68da8e184cce6767e052206;hp=9fbef11c6911236e985f44ba8a97e08ebae35ddb;hpb=622ac935fd1d8a5bc282ee127666a3e9d1954713;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 9fbef11c6..caaee41f4 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -10,9 +10,12 @@ #include "Model_Events.h" #include "Model_Data.h" +#include + #include #include #include +#include #include #include #include @@ -20,8 +23,8 @@ #include #include #include - -using namespace std; +#include +#include void Model_AttributeSelectionList::append( const ResultPtr& theContext, const std::shared_ptr& theSubShape, @@ -35,20 +38,25 @@ void Model_AttributeSelectionList::append( } } + if (myIsCashed && !theTemporarily) { + myCash[theContext].push_back(theSubShape); + } + int aNewTag = mySize->Get() + 1; TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); - std::shared_ptr aNewAttr = + std::shared_ptr aNewAttr = std::shared_ptr(new Model_AttributeSelection(aNewLab)); if (owner()) { aNewAttr->setObject(owner()); + aNewAttr->setParent(this); } aNewAttr->setID(id()); mySize->Set(aNewTag); aNewAttr->setValue(theContext, theSubShape, theTemporarily); if (theTemporarily) myTmpAttr = aNewAttr; - else + else myTmpAttr.reset(); owner()->data()->sendAttributeUpdated(this); } @@ -59,10 +67,11 @@ void Model_AttributeSelectionList::append( int aNewTag = mySize->Get() + 1; TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); - std::shared_ptr aNewAttr = + std::shared_ptr aNewAttr = std::shared_ptr(new Model_AttributeSelection(aNewLab)); if (owner()) { aNewAttr->setObject(owner()); + aNewAttr->setParent(this); } aNewAttr->setID(id()); mySize->Set(aNewTag); @@ -70,13 +79,20 @@ void Model_AttributeSelectionList::append( owner()->data()->sendAttributeUpdated(this); } -void Model_AttributeSelectionList::removeLast() +void Model_AttributeSelectionList::removeTemporaryValues() +{ + if (myTmpAttr.get()) { + myTmpAttr.reset(); + } +} + +void Model_AttributeSelectionList::removeLast() { int anOldSize = mySize->Get(); if (anOldSize != 0) { mySize->Set(anOldSize - 1); TDF_Label aLab = mySize->Label().FindChild(anOldSize); - std::shared_ptr aOldAttr = + std::shared_ptr aOldAttr = std::shared_ptr(new Model_AttributeSelection(aLab)); aOldAttr->setObject(owner()); REMOVE_BACK_REF(aOldAttr->context()); @@ -86,34 +102,45 @@ void Model_AttributeSelectionList::removeLast() } } -// copies named shapes: we need the implementation of this +// copies named shapes: we need the implementation of this static void CopyNS(const Handle(TNaming_NamedShape)& theFrom, const Handle(TDF_Attribute)& theTo) -{ +{ TDF_Label aLab = theTo->Label(); TNaming_Builder B(aLab); - TNaming_Iterator It (theFrom); - for ( ;It.More() ; It.Next()) { - const TopoDS_Shape& OS = It.OldShape(); - const TopoDS_Shape& NS = It.NewShape(); - TNaming_Evolution Status = It.Evolution(); + // TNaming_Iterator iterates in reversed way than it was put in Builder, so, keep it in container + // and iterate from end to begin + NCollection_List aOlds; + NCollection_List aNews; + NCollection_List aStatuses; + + TNaming_Iterator anIt (theFrom); + for ( ;anIt.More() ; anIt.Next()) { + aOlds.Prepend(anIt.OldShape()); + aNews.Prepend(anIt.NewShape()); + aStatuses.Prepend(anIt.Evolution()); + } - switch (Status) { + NCollection_List::Iterator aOldIter(aOlds); + NCollection_List::Iterator aNewIter(aNews); + NCollection_List::Iterator aStatIter(aStatuses); + for(; aOldIter.More(); aOldIter.Next(), aNewIter.Next(), aStatIter.Next()) { + switch (aStatIter.Value()) { case TNaming_PRIMITIVE : - B.Generated(NS); + B.Generated(aNewIter.Value()); break; case TNaming_GENERATED : - B.Generated(OS, NS); + B.Generated(aOldIter.Value(), aNewIter.Value()); break; - case TNaming_MODIFY : - B.Modify(OS, NS); + case TNaming_MODIFY : + B.Modify(aOldIter.Value(), aNewIter.Value()); break; - case TNaming_DELETE : - B.Delete (OS); + case TNaming_DELETE : + B.Delete (aOldIter.Value()); break; case TNaming_SELECTED : - B.Select(NS, OS); + B.Select(aNewIter.Value(), aOldIter.Value()); break; default: break; @@ -134,7 +161,8 @@ static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) { // for named shape copy exact shapes (in NamedShape Paste method the CopyTool is used) Handle(TNaming_NamedShape) aNS = Handle(TNaming_NamedShape)::DownCast(anAttrIter.Value()); if (aNS.IsNull()) { - Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(); // no relocation, empty map + // no special relocation, empty map, but self-relocation is on: copy references w/o changes + Handle(TDF_RelocationTable) aRelocTable = new TDF_RelocationTable(Standard_True); anAttrIter.Value()->Paste(aTargetAttr, aRelocTable); } else { CopyNS(aNS, aTargetAttr); @@ -163,7 +191,7 @@ void Model_AttributeSelectionList::remove(const std::set& theIndices) } } else { // this is removed, so remove everything from this label TDF_Label aLab = mySize->Label().FindChild(aCurrent + 1); - std::shared_ptr aOldAttr = + std::shared_ptr aOldAttr = std::shared_ptr(new Model_AttributeSelection(aLab)); aOldAttr->setObject(owner()); REMOVE_BACK_REF(aOldAttr->context()); @@ -187,18 +215,19 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily) { - if (!myCash.empty()) { // the cashing is active + if (myIsCashed) { // the cashing is active std::map > >::iterator aContext = myCash.find(theContext); if (aContext != myCash.end()) { - // iterate shapes because "isEqual" method must be called for each shape + // iterate shapes because "isSame" method must be called for each shape std::list >::iterator aShapes = aContext->second.begin(); for(; aShapes != aContext->second.end(); aShapes++) { if (!theSubShape.get()) { if (!aShapes->get()) return true; } else { - if (theSubShape->isEqual(*aShapes)) + // we need to call here isSame instead of isEqual to do not check shapes orientation + if (theSubShape->isSame(*aShapes)) return true; } } @@ -216,7 +245,8 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext, return true; } } else { - if (aValue->isEqual(theSubShape)) // shapes are equal + // we need to call here isSame instead of isEqual to do not check shapes orientation + if (aValue->isSame(theSubShape)) // shapes are equal return true; } } @@ -235,7 +265,7 @@ void Model_AttributeSelectionList::setSelectionType(const std::string& theType) mySelectionType->Set(theType.c_str()); } -std::shared_ptr +std::shared_ptr Model_AttributeSelectionList::value(const int theIndex) { if (myTmpAttr.get() && theIndex == size() - 1) { @@ -245,10 +275,12 @@ std::shared_ptr // 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 aNewAttr = std::shared_ptr(new Model_AttributeSelection(aLabel)); + aNewAttr->setID(id()); if (owner()) { aNewAttr->setObject(owner()); + aNewAttr->setParent(this); } return aNewAttr; } @@ -261,10 +293,11 @@ void Model_AttributeSelectionList::clear() TDF_ChildIterator aSubIter(mySize->Label()); for(; aSubIter.More(); aSubIter.Next()) { TDF_Label aLab = aSubIter.Value(); - std::shared_ptr aNewAttr = + std::shared_ptr aNewAttr = std::shared_ptr(new Model_AttributeSelection(aLab)); if (owner()) { aNewAttr->setObject(owner()); + aNewAttr->setParent(this); } REMOVE_BACK_REF(aNewAttr->context()); @@ -284,16 +317,26 @@ bool Model_AttributeSelectionList::isInitialized() Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) { - myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True; + myLab = theLabel; + reinit(); +} + +void Model_AttributeSelectionList::reinit() +{ + myIsInitialized = myLab.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True; if (!myIsInitialized) { - mySize = TDataStd_Integer::Set(theLabel, 0); - mySelectionType = TDataStd_Comment::Set(theLabel, ""); + mySize = TDataStd_Integer::Set(myLab, 0); + mySelectionType = TDataStd_Comment::Set(myLab, ""); } else { // recollect mySubs - theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType); + myLab.FindAttribute(TDataStd_Comment::GetID(), mySelectionType); } + myIsCashed = false; } -void Model_AttributeSelectionList::cashValues(const bool theEnabled) { + +void Model_AttributeSelectionList::cashValues(const bool theEnabled) +{ + myIsCashed = theEnabled; myCash.clear(); // empty list as indicator that cash is not used if (theEnabled) { for(int anIndex = size() - 1; anIndex >= 0; anIndex--) {