X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelectionList.cpp;h=caaee41f407425e0767de254bfb905c8e4c3f496;hb=fe8cab988ae59927f68da8e184cce6767e052206;hp=81ce0984cb9a856808b9439a51fdaee82f571fb5;hpb=782ddee7ec183e10378487f5bdd27d4b00124f81;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 81ce0984c..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,10 +23,9 @@ #include #include #include +#include #include -using namespace std; - void Model_AttributeSelectionList::append( const ResultPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily) @@ -43,17 +45,18 @@ 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); aNewAttr->setValue(theContext, theSubShape, theTemporarily); if (theTemporarily) myTmpAttr = aNewAttr; - else + else myTmpAttr.reset(); owner()->data()->sendAttributeUpdated(this); } @@ -64,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); @@ -75,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()); @@ -91,10 +102,10 @@ 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); @@ -122,10 +133,10 @@ static void CopyNS(const Handle(TNaming_NamedShape)& theFrom, case TNaming_GENERATED : B.Generated(aOldIter.Value(), aNewIter.Value()); break; - case TNaming_MODIFY : + case TNaming_MODIFY : B.Modify(aOldIter.Value(), aNewIter.Value()); break; - case TNaming_DELETE : + case TNaming_DELETE : B.Delete (aOldIter.Value()); break; case TNaming_SELECTED : @@ -150,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); @@ -179,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()); @@ -207,14 +219,15 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext, 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; } } @@ -232,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; } } @@ -251,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) { @@ -261,11 +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; } @@ -278,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());