Salome HOME
c89e909cc682082ccd1a4450648bfd0f2145eef5
[modules/shaper.git] / src / FiltersPlugin / FiltersPlugin_Selection.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "FiltersPlugin_Selection.h"
21
22 #include <ModelAPI_Session.h>
23 #include <ModelAPI_AttributeBoolean.h>
24
25 // identifier of the reverse flag of a filter
26 static const std::string kReverseAttrID("");
27
28 void FiltersPlugin_Selection::addFilter(const std::string theFilterID)
29 {
30   ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
31   FilterPtr aFilter = aFactory->filter(theFilterID);
32   if (aFilter.get()) {
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
38   }
39 }
40
41 void FiltersPlugin_Selection::removeFilter(const std::string theFilterID)
42 {
43   ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
44   FilterPtr aFilter = aFactory->filter(theFilterID);
45   if (aFilter.get()) {
46     data()->removeAttributes(theFilterID);
47   }
48 }
49
50 std::list<std::string> FiltersPlugin_Selection::filters() const
51 {
52   std::list<std::string> aFilters;
53   data()->allGroups(aFilters);
54   return aFilters;
55 }
56
57 void FiltersPlugin_Selection::setReversed(const std::string theFilterID, const bool theReversed)
58 {
59   std::string anAttrID = theFilterID + kFilterSeparator + kReverseAttrID;
60   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = boolean(anAttrID);
61   if (aBool.get())
62     aBool->setValue(theReversed);
63 }
64
65 bool FiltersPlugin_Selection::isReversed(const std::string theFilterID)
66 {
67   std::string anAttrID = theFilterID + kFilterSeparator + kReverseAttrID;
68   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = boolean(anAttrID);
69   return aBool->value();
70 }
71
72 std::list<AttributePtr> FiltersPlugin_Selection::filterArgs(const std::string theFilterID) const
73 {
74   std::list<AttributePtr> aList;
75   data()->attributesOfGroup(theFilterID, aList);
76   return aList;
77 }