+
+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<ModelAPI_AttributeSelectionList> aSelList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttr);
+ if (aSelList.get()) {
+ std::string aStrType = aSelList->selectionType();
+ GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aStrType);
+ std::list<std::string> aFilters;
+ data()->allGroups(aFilters);
+ ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
+ std::list<std::string>::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<std::string> aFilters;
+ data()->allGroups(aFilters);
+ for(std::list<std::string>::iterator aFIt = aFilters.begin(); aFIt != aFilters.end(); aFIt++) {
+ FilterPtr aFilter = aFactory->filter(*aFIt);
+ if (aFilter.get()) {
+ std::shared_ptr<ModelAPI_AttributeBoolean> aBool =
+ std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(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<ModelAPI_FiltersFeature>(data()->owner()));
+ anArgs.setFilter(*aFIt);
+ aFilter->initAttributes(anArgs);
+ }
+ }
+}