1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FiltersAPI_Filter.h"
22 #include <ModelAPI_Attribute.h>
23 #include <ModelAPI_AttributeBoolean.h>
24 #include <ModelAPI_AttributeSelectionList.h>
25 #include <ModelAPI_AttributeString.h>
27 #include <ModelHighAPI_Dumper.h>
29 FiltersAPI_Filter::FiltersAPI_Filter(
30 const std::string& theName,
31 const bool theRevertFilter,
32 const std::list<FiltersAPI_Argument>& theArguments)
33 : myName(theName), myReversed(theRevertFilter), myFilterArguments(theArguments)
37 FiltersAPI_Filter::FiltersAPI_Filter(const std::string& theName,
38 const std::list<AttributePtr>& theArguments)
41 for (std::list<AttributePtr>::const_iterator anArgIt = theArguments.begin();
42 anArgIt != theArguments.end(); ++anArgIt) {
43 AttributeBooleanPtr aBoolAttr =
44 std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(*anArgIt);
46 myReversed = aBoolAttr->value();
50 AttributeSelectionListPtr aSelList =
51 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*anArgIt);
53 int aSize = aSelList->size();
54 for (int i = 0; i < aSize; ++i) {
55 AttributeSelectionPtr aSelection = aSelList->value(i);
56 myFilterArguments.push_back(FiltersAPI_Argument(aSelection));
61 AttributeSelectionPtr aSelection =
62 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*anArgIt);
64 myFilterArguments.push_back(FiltersAPI_Argument(aSelection));
68 AttributeStringPtr aString = std::dynamic_pointer_cast<ModelAPI_AttributeString>(*anArgIt);
70 myFilterArguments.push_back(FiltersAPI_Argument(aString->value()));
76 FiltersAPI_Filter::~FiltersAPI_Filter()
80 void FiltersAPI_Filter::dump(ModelHighAPI_Dumper& theDumper) const
82 theDumper << "model.addFilter(name = \"" << myName << "\"";
84 theDumper << ", exclude = " << myReversed;
85 if (!myFilterArguments.empty()) {
86 theDumper << ", args = [";
87 bool isFirstArg = true;
88 for (std::list<FiltersAPI_Argument>::const_iterator anIt = myFilterArguments.begin();
89 anIt != myFilterArguments.end(); ++anIt) {
94 anIt->dump(theDumper);
101 // ================================================================================================
102 FilterAPIPtr addFilter(const std::string& name,
104 const std::list<FiltersAPI_Argument>& args)
106 return FilterAPIPtr(new FiltersAPI_Filter(name, exclude, args));