Salome HOME
Copyright update 2022
[modules/shaper.git] / src / FiltersAPI / FiltersAPI_Feature.cpp
index 14bdbf6658c60cd8c39246a5c5428455b47cb201..bd0b4435dda9588f8d346121c8dea4eb5fb71980 100644 (file)
@@ -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
@@ -20,6 +20,8 @@
 #include "FiltersAPI_Feature.h"
 
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_FiltersFactory.h>
+#include <ModelAPI_Session.h>
 
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
@@ -39,14 +41,19 @@ FiltersAPI_Feature::~FiltersAPI_Feature()
 static void separateArguments(const std::list<FiltersAPI_Argument>& theArguments,
                               std::list<ModelHighAPI_Selection>& theSelections,
                               std::list<std::string>& theTextArgs,
-                              std::list<bool>& theBoolArgs)
+                              std::list<bool>& theBoolArgs,
+                              std::list<ModelHighAPI_Double>& theDoubleArgs)
 {
   std::list<FiltersAPI_Argument>::const_iterator anIt = theArguments.begin();
   for (; anIt != theArguments.end(); ++anIt) {
     if (anIt->selection().variantType() != ModelHighAPI_Selection::VT_Empty)
       theSelections.push_back(anIt->selection());
-    else if (anIt->string().empty())
+    else if (anIt->dble().value() > std::numeric_limits<double>::lowest()) {
+      theDoubleArgs.push_back(anIt->dble());
+    }
+    else if (anIt->string().empty()) {
       theBoolArgs.push_back(anIt->boolean());
+    }
     else
       theTextArgs.push_back(anIt->string());
   }
@@ -57,8 +64,8 @@ void FiltersAPI_Feature::setFilters(const std::list<FilterAPIPtr>& theFilters)
   FiltersFeaturePtr aBase = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(feature());
   for (std::list<FilterAPIPtr>::const_iterator anIt = theFilters.begin();
        anIt != theFilters.end(); ++anIt) {
-    aBase->addFilter((*anIt)->name());
-    aBase->setReversed((*anIt)->name(), (*anIt)->isReversed());
+    std::string aFilterID = aBase->addFilter((*anIt)->name());
+    aBase->setReversed(aFilterID, (*anIt)->isReversed());
 
     const std::list<FiltersAPI_Argument>& anArgs = (*anIt)->arguments();
     if (!anArgs.empty()) {
@@ -66,9 +73,10 @@ void FiltersAPI_Feature::setFilters(const std::list<FilterAPIPtr>& theFilters)
       std::list<ModelHighAPI_Selection> aSelections;
       std::list<std::string> aTexts;
       std::list<bool> aBools;
-      separateArguments(anArgs, aSelections, aTexts, aBools);
+      std::list<ModelHighAPI_Double> aDoubles;
+      separateArguments(anArgs, aSelections, aTexts, aBools, aDoubles);
 
-      std::list<AttributePtr> aFilterArgs = aBase->filterArgs((*anIt)->name());
+      std::list<AttributePtr> aFilterArgs = aBase->filterArgs(aFilterID);
       std::list<AttributePtr>::iterator aFIt = aFilterArgs.begin();
       // first boolean argument is always "Reversed" flag
       AttributeBooleanPtr aReversedFlag =
@@ -76,6 +84,7 @@ void FiltersAPI_Feature::setFilters(const std::list<FilterAPIPtr>& theFilters)
       if (aReversedFlag)
         ++aFIt;
       // fill arguments of the filter
+      std::list<ModelHighAPI_Double>::const_iterator anItDle = aDoubles.begin();
       for (; aFIt != aFilterArgs.end(); ++aFIt) {
         AttributeSelectionListPtr aSelList =
             std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aFIt);
@@ -96,8 +105,17 @@ void FiltersAPI_Feature::setFilters(const std::list<FilterAPIPtr>& theFilters)
             else {
               AttributeBooleanPtr aBoolean =
                   std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(*aFIt);
-              if (aBoolean && aBools.size() == 1)
-                fillAttribute(aBools.front(), aBoolean);
+              if (aBoolean) {
+                if (aBools.size() == 1)
+                  fillAttribute(aBools.front(), aBoolean);
+              } else {
+                AttributeDoublePtr aDouble =
+                    std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(*aFIt);
+                if (aDouble) {
+                  fillAttribute((*anItDle).value(), aDouble);
+                  anItDle++;
+                }
+              }
             }
           }
         }
@@ -115,9 +133,12 @@ void FiltersAPI_Feature::dump(ModelHighAPI_Dumper& theDumper) const
   const std::string& aDocName = theDumper.name(aBase->document());
   theDumper << "model.filters(" << aDocName << ", [";
 
+  ModelAPI_FiltersFactory* aFFactory = ModelAPI_Session::get()->filters();
   std::list<std::string> aFilters = aBase->filters();
   for (std::list<std::string>::iterator aFIt = aFilters.begin(); aFIt != aFilters.end(); ++aFIt) {
-    FiltersAPI_Filter aFilter(*aFIt, aBase->filterArgs(*aFIt));
+    // for multiple filters get original id
+    std::string aFilterKind = aFFactory->id(aFFactory->filter(*aFIt));
+    FiltersAPI_Filter aFilter(aFilterKind, aBase->filterArgs(*aFIt));
     if (aFIt != aFilters.begin())
       theDumper << ", ";
     aFilter.dump(theDumper);