Salome HOME
Change icons for chamfer
[modules/shaper.git] / src / FiltersPlugin / FiltersPlugin_Selection.cpp
index 4b656d847d900f1bbeaa04a47881869ff4b94d92..7fe056aba5aee9fadbf2b5d2f65023ac9b21a4e8 100644 (file)
 
 #include "FiltersPlugin_Selection.h"
 
-#include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_FiltersFactory.h>
+#include <ModelAPI_Session.h>
 
 // identifier of the reverse flag of a filter
 static const std::string kReverseAttrID("");
@@ -71,7 +72,9 @@ bool FiltersPlugin_Selection::isReversed(const std::string theFilterID)
 {
   std::string anAttrID = theFilterID + kFilterSeparator + kReverseAttrID;
   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = boolean(anAttrID);
-  return aBool->value();
+  if (aBool.get())
+    return aBool->value();
+  return false;
 }
 
 std::list<AttributePtr> FiltersPlugin_Selection::filterArgs(const std::string theFilterID) const
@@ -83,14 +86,6 @@ std::list<AttributePtr> 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<std::string> aFilters;
-    data()->allGroups(aFilters);
-    std::list<std::string>::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<ModelAPI_AttributeSelectionList> aSelList =
@@ -116,3 +111,24 @@ 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);
+    }
+  }
+}