X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFiltersPlugin%2FFiltersPlugin_Selection.cpp;h=7fe056aba5aee9fadbf2b5d2f65023ac9b21a4e8;hb=09365c927ebe8d881de2eda7f96bc33a2d9511c8;hp=c89e909cc682082ccd1a4450648bfd0f2145eef5;hpb=7d3772ac2c013338f795312c48b459c80542e14e;p=modules%2Fshaper.git diff --git a/src/FiltersPlugin/FiltersPlugin_Selection.cpp b/src/FiltersPlugin/FiltersPlugin_Selection.cpp index c89e909cc..7fe056aba 100644 --- a/src/FiltersPlugin/FiltersPlugin_Selection.cpp +++ b/src/FiltersPlugin/FiltersPlugin_Selection.cpp @@ -19,8 +19,10 @@ #include "FiltersPlugin_Selection.h" -#include #include +#include +#include +#include // identifier of the reverse flag of a filter static const std::string kReverseAttrID(""); @@ -34,7 +36,11 @@ void FiltersPlugin_Selection::addFilter(const std::string theFilterID) std::dynamic_pointer_cast(data()->addFloatingAttribute( kReverseAttrID, ModelAPI_AttributeBoolean::typeId(), theFilterID)); aBool->setValue(false); // not reversed by default - // TODO: to add attributes related to the filter + // to add attributes related to the filter + ModelAPI_FiltersArgs anArgs; + anArgs.setFeature(std::dynamic_pointer_cast(data()->owner())); + anArgs.setFilter(theFilterID); + aFilter->initAttributes(anArgs); } } @@ -66,7 +72,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 @@ -75,3 +83,52 @@ std::list FiltersPlugin_Selection::filterArgs(const std::string th data()->attributesOfGroup(theFilterID, aList); return aList; } + +void FiltersPlugin_Selection::setAttribute(const AttributePtr& theAttr) +{ + myBase = theAttr; + if (myBase.get()) { // check that the type of sub-elements is supported by all existing filters + std::shared_ptr aSelList = + std::dynamic_pointer_cast(theAttr); + if (aSelList.get()) { + std::string aStrType = aSelList->selectionType(); + GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aStrType); + std::list aFilters; + data()->allGroups(aFilters); + ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters(); + std::list::iterator aFIter = aFilters.begin(); + for(; aFIter != aFilters.end(); aFIter++) { + FilterPtr aFilter = aFactory->filter(*aFIter); + if (aFilter.get() && !aFilter->isSupported(aType)) { + data()->removeAttributes(*aFIter); + } + } + } + } +} + +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); + } + } +}