X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFiltersPlugin%2FFiltersPlugin_Selection.cpp;h=6f4b766f86aca25dbfc937588e613f480ae169fa;hb=04e2497fc973f0afc95d0a4a6f95e37fb27f45e8;hp=4b656d847d900f1bbeaa04a47881869ff4b94d92;hpb=696ce87ccb8fed24ff4451f3a1d1235cd0d89a53;p=modules%2Fshaper.git diff --git a/src/FiltersPlugin/FiltersPlugin_Selection.cpp b/src/FiltersPlugin/FiltersPlugin_Selection.cpp index 4b656d847..6f4b766f8 100644 --- a/src/FiltersPlugin/FiltersPlugin_Selection.cpp +++ b/src/FiltersPlugin/FiltersPlugin_Selection.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 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 @@ -19,28 +19,52 @@ #include "FiltersPlugin_Selection.h" -#include #include #include +#include +#include +#include // identifier of the reverse flag of a filter static const std::string kReverseAttrID(""); -void FiltersPlugin_Selection::addFilter(const std::string theFilterID) +std::string FiltersPlugin_Selection::addFilter(const std::string theFilterID) { ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters(); FilterPtr aFilter = aFactory->filter(theFilterID); + + std::string aFilterID = theFilterID; + if (aFilter->isMultiple()) { // check that there is already such filter, so, increment ID + std::list aFilters; + data()->allGroups(aFilters); + for(int anID = 0; true; anID++) { + if (anID != 0) { + std::ostringstream aStream; + aStream<<"_"<::iterator aFiltersIDs = aFilters.begin(); + for(; aFiltersIDs != aFilters.end(); aFiltersIDs++) { + if (*aFiltersIDs == aFilterID) + break; + } + if (aFiltersIDs == aFilters.end()) + break; + } + } + if (aFilter.get()) { std::shared_ptr aBool = std::dynamic_pointer_cast(data()->addFloatingAttribute( - kReverseAttrID, ModelAPI_AttributeBoolean::typeId(), theFilterID)); + kReverseAttrID, ModelAPI_AttributeBoolean::typeId(), aFilterID)); aBool->setValue(false); // not reversed by default // to add attributes related to the filter ModelAPI_FiltersArgs anArgs; anArgs.setFeature(std::dynamic_pointer_cast(data()->owner())); - anArgs.setFilter(theFilterID); + anArgs.setFilter(aFilterID); aFilter->initAttributes(anArgs); } + return aFilterID; } void FiltersPlugin_Selection::removeFilter(const std::string theFilterID) @@ -71,7 +95,9 @@ bool FiltersPlugin_Selection::isReversed(const std::string theFilterID) { std::string anAttrID = theFilterID + kFilterSeparator + kReverseAttrID; std::shared_ptr aBool = boolean(anAttrID); - return aBool->value(); + if (aBool.get()) + return aBool->value(); + return false; } std::list FiltersPlugin_Selection::filterArgs(const std::string theFilterID) const @@ -83,14 +109,6 @@ std::list FiltersPlugin_Selection::filterArgs(const std::string th void FiltersPlugin_Selection::setAttribute(const AttributePtr& theAttr) { - if (myBase != theAttr) { // clear all filters if the attribute is changed or defined a new - std::list aFilters; - data()->allGroups(aFilters); - std::list::iterator aFIter = aFilters.begin(); - for(; aFIter != aFilters.end(); aFIter++) { - data()->removeAttributes(*aFIter); - } - } myBase = theAttr; if (myBase.get()) { // check that the type of sub-elements is supported by all existing filters std::shared_ptr aSelList = @@ -116,3 +134,24 @@ const AttributePtr& FiltersPlugin_Selection::baseAttribute() const { return myBase; } + +void FiltersPlugin_Selection::initAttributes() +{ + ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters(); + std::list aFilters; + data()->allGroups(aFilters); + for(std::list::iterator aFIt = aFilters.begin(); aFIt != aFilters.end(); aFIt++) { + FilterPtr aFilter = aFactory->filter(*aFIt); + if (aFilter.get()) { + std::shared_ptr aBool = + std::dynamic_pointer_cast(data()->addFloatingAttribute( + kReverseAttrID, ModelAPI_AttributeBoolean::typeId(), *aFIt)); + if (!aBool->isInitialized()) + aBool->setValue(false); // not reversed by default + ModelAPI_FiltersArgs anArgs; + anArgs.setFeature(std::dynamic_pointer_cast(data()->owner())); + anArgs.setFilter(*aFIt); + aFilter->initAttributes(anArgs); + } + } +}