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 "FiltersPlugin_Selection.h"
22 #include <ModelAPI_Session.h>
23 #include <ModelAPI_AttributeBoolean.h>
25 // identifier of the reverse flag of a filter
26 static const std::string kReverseAttrID("");
28 void FiltersPlugin_Selection::addFilter(const std::string theFilterID)
30 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
31 FilterPtr aFilter = aFactory->filter(theFilterID);
33 std::shared_ptr<ModelAPI_AttributeBoolean> aBool =
34 std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(data()->addFloatingAttribute(
35 kReverseAttrID, ModelAPI_AttributeBoolean::typeId(), theFilterID));
36 aBool->setValue(false); // not reversed by default
37 // TODO: to add attributes related to the filter
41 void FiltersPlugin_Selection::removeFilter(const std::string theFilterID)
43 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
44 FilterPtr aFilter = aFactory->filter(theFilterID);
46 data()->removeAttributes(theFilterID);
50 std::list<std::string> FiltersPlugin_Selection::filters() const
52 std::list<std::string> aFilters;
53 data()->allGroups(aFilters);
57 void FiltersPlugin_Selection::setReversed(const std::string theFilterID, const bool theReversed)
59 std::string anAttrID = theFilterID + kFilterSeparator + kReverseAttrID;
60 std::shared_ptr<ModelAPI_AttributeBoolean> aBool = boolean(anAttrID);
62 aBool->setValue(theReversed);
65 bool FiltersPlugin_Selection::isReversed(const std::string theFilterID)
67 std::string anAttrID = theFilterID + kFilterSeparator + kReverseAttrID;
68 std::shared_ptr<ModelAPI_AttributeBoolean> aBool = boolean(anAttrID);
69 return aBool->value();
72 std::list<AttributePtr> FiltersPlugin_Selection::filterArgs(const std::string theFilterID) const
74 std::list<AttributePtr> aList;
75 data()->attributesOfGroup(theFilterID, aList);