X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeSelectionList.cpp;h=170190ef66879e1e44f82e71e4be35340ea4f2ca;hb=a77dbd7613ee788b69415a11c06542387f38371b;hp=b813dcd1880e015fe9c55661cffb8ec11e0651cd;hpb=9b61e5ee5eafe9d6948d9a78667efa2abec132c3;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index b813dcd18..170190ef6 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "Model_AttributeSelectionList.h" @@ -23,6 +22,7 @@ #include "Model_Application.h" #include "Model_Events.h" #include "Model_Data.h" +#include "Model_Objects.h" #include #include @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,10 @@ /// topology" flag enabled static const Standard_GUID kIS_GEOMETRICAL_SELECTION("f16987b6-e6c8-435c-99fa-03a7e0b06e83"); +/// GUID for TDataStd_ReferenceList attribute that refers the selection filters feature +static const Standard_GUID kSELECTION_FILTERS_REF("ea5b1dbf-a740-4a0b-a1b2-3c3c756e691a"); + + void Model_AttributeSelectionList::append( const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily) @@ -288,17 +293,19 @@ bool Model_AttributeSelectionList::isInList(const ObjectPtr& theContext, const std::shared_ptr& theSubShape, const bool theTemporarily) { - ResultPtr aResCont = std::dynamic_pointer_cast(theContext); if (myIsCashed) { // the cashing is active - if (aResCont.get()) { - std::map > >::iterator aContext = - myCash.find(aResCont); + if (theContext.get()) { + std::map > >::iterator aContext = + myCash.find(theContext); if (aContext != myCash.end()) { // 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() || (*aShapes)->isSame(aContext->first->shape())) + if (!aShapes->get()) + return true; + ResultPtr aRes = std::dynamic_pointer_cast(aContext->first); + if (aRes.get() && (*aShapes)->isSame(aRes->shape())) return true; } else { // we need to call here isSame instead of isEqual to do not check shapes orientation @@ -311,15 +318,21 @@ bool Model_AttributeSelectionList::isInList(const ObjectPtr& theContext, } } // no-cash method + bool isFeature = std::dynamic_pointer_cast(theContext).get() != NULL; + ResultPtr aRes; + if (!isFeature) + aRes = std::dynamic_pointer_cast(theContext); for(int anIndex = size() - 1; anIndex >= 0; anIndex--) { AttributeSelectionPtr anAttr = value(anIndex); if (anAttr.get()) { - if (anAttr->context() == theContext) { // contexts are equal, so, check that values are also + if (isFeature && anAttr->contextFeature() == theContext) + return true; // for the feature value should not be compared + if (!isFeature && anAttr->context() == theContext) { + // contexts are equal, so, check that values are also std::shared_ptr aValue = anAttr->value(); if (!theSubShape.get()) { - if (!aValue.get() || (aResCont.get() && aValue->isSame(aResCont->shape()))) {// both null + if (!aValue.get() || (aRes.get() && aValue->isSame(aRes->shape()))) return true; - } } else { // we need to call here isSame instead of isEqual to do not check shapes orientation if (isIn(aValue, theSubShape)) // shapes are equal @@ -393,7 +406,7 @@ bool Model_AttributeSelectionList::isInitialized() } Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) -: myLab(theLabel) +: ModelAPI_AttributeSelectionList(), myLab(theLabel) { reinit(); } @@ -481,3 +494,44 @@ void Model_AttributeSelectionList::setGeometricalSelection(const bool theIsGeome myCash.clear(); // empty list as indicator that cash is not used owner()->data()->sendAttributeUpdated(this); } + +FiltersFeaturePtr Model_AttributeSelectionList::filters() const +{ + Handle(TDataStd_ReferenceList) aRef; + if (myLab.FindAttribute(kSELECTION_FILTERS_REF, aRef) && !aRef->IsEmpty()) { + if (owner().get()) { + std::shared_ptr aDoc = std::dynamic_pointer_cast( + owner()->document()); + if (aDoc) { + const TDF_Label& aRefLab = aRef->First(); + if (!aRefLab.IsNull()) { // it may happen with old document, issue #285 + ObjectPtr anObj = aDoc->objects()->object(aRefLab); + FiltersFeaturePtr aFeat = std::dynamic_pointer_cast(anObj); + if (aFeat.get()) { + aFeat->setAttribute(owner()->data()->attribute(id())); + return aFeat; + } + } + } + } + } + return FiltersFeaturePtr(); // null pointer if nothing is defined +} + +void Model_AttributeSelectionList::setFilters(FiltersFeaturePtr theFeature) +{ + Handle(TDataStd_ReferenceList) aRef = TDataStd_ReferenceList::Set(myLab, kSELECTION_FILTERS_REF); + if (theFeature.get()) { + std::shared_ptr aData = std::dynamic_pointer_cast(theFeature->data()); + if (aData->isValid()) { + TDF_Label anObjLab = aData->label().Father(); // object label + if (!aRef->IsEmpty()) + aRef->Clear(); + aRef->Append(anObjLab); + theFeature->setAttribute(owner()->data()->attribute(id())); + return; + } + } + // remove attribute if something is wrong + myLab.ForgetAttribute(TDataStd_ReferenceList::GetID()); +}