-// 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
#include "FiltersAPI_Feature.h"
#include <ModelAPI_Feature.h>
+#include <ModelAPI_FiltersFactory.h>
+#include <ModelAPI_Session.h>
#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Tools.h>
: ModelHighAPI_Interface(theFeature)
{
initialize();
+ std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theFeature)->initAttributes();
}
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());
}
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()) {
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 =
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);
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++;
+ }
+ }
}
}
}
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);