Salome HOME
Parameters for the filters are similar to the parameters of validators.
[modules/shaper.git] / src / ModuleBase / ModuleBase_FilterFactory.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_FilterFactory.h
4 // Created:     10 Dec 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #include "ModuleBase_FilterFactory.h"
8 #include <ModuleBase_Filter.h>
9
10 //#include <Model_FeatureValidator.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_Attribute.h>
13 #include <ModelAPI_Data.h>
14 //#include <ModelAPI_AttributeValidator.h>
15 #include <Events_Error.h>
16
17
18 void ModuleBase_FilterFactory::registerFilter(const std::string& theID,
19                                               Handle(ModuleBase_Filter) theFilter)
20 {
21   if (myIDs.find(theID) != myIDs.end()) {
22     Events_Error::send(std::string("Filter ") + theID + " is already registered");
23   } else {
24     myIDs[theID] = theFilter;
25   }
26 }
27
28 void ModuleBase_FilterFactory::assignFilter(const std::string& theID,
29                                             const std::string& theFeatureID,
30                                             const std::string& theAttrID,
31                                             const std::list<std::string>& theArguments)
32 {
33   // create feature-structures if not exist
34   std::map<std::string, std::map<std::string, AttrFilters> >::iterator aFeature = myAttrs.find(
35     theFeatureID);
36   if (aFeature == myAttrs.end()) {
37     myAttrs[theFeatureID] = std::map<std::string, AttrFilters>();
38     aFeature = myAttrs.find(theFeatureID);
39   }
40   // add attr-structure if not exist, or generate error if already exist
41   std::map<std::string, AttrFilters>::iterator anAttr = aFeature->second.find(theAttrID);
42   if (anAttr == aFeature->second.end()) {
43     aFeature->second[theAttrID] = AttrFilters();
44   }
45   aFeature->second[theAttrID][theID] = theArguments;
46 }
47
48 void ModuleBase_FilterFactory::filters(const std::string& theFeatureID,
49                                        const std::string& theAttrID,
50                                        SelectMgr_ListOfFilter& theFilters/*,
51                                         std::list<Handle(ModuleBase_Filter)>& theFilters/*,
52                                         std::list<std::list<std::string> >& theArguments*/) const
53 {
54   SelectMgr_ListOfFilter aFilters;
55
56   std::map<std::string, std::map<std::string, AttrFilters> >::const_iterator aFeature = 
57     myAttrs.find(theFeatureID);
58   if (aFeature != myAttrs.cend()) {
59     std::map<std::string, AttrFilters>::const_iterator anAttr = aFeature->second.find(theAttrID);
60     if (anAttr != aFeature->second.end()) {
61       AttrFilters::const_iterator aValIter = anAttr->second.cbegin();
62       for (; aValIter != anAttr->second.cend(); aValIter++) {
63         std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aFound = myIDs.find(
64           aValIter->first);
65         if (aFound == myIDs.end()) {
66           Events_Error::send(std::string("Filter ") + aValIter->first + " was not registered");
67         } else {
68           Handle(ModuleBase_Filter) aFilter = aFound->second;
69           if (aFilter.IsNull())
70             continue;
71
72           theFilters.Append(aFilter);//aFound->second);
73           //theArguments.push_back(aValIter->second);
74         }
75       }
76     }
77   }
78 }
79
80 ModuleBase_FilterFactory::ModuleBase_FilterFactory()
81 {
82   //const static std::string kDefaultId = "Model_FeatureFilter";
83   //registerFilter(kDefaultId, new Model_FeatureFilter);
84 }
85
86 const Handle(ModuleBase_Filter) ModuleBase_FilterFactory::filter(const std::string& theID) const
87 {
88   std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aIt = myIDs.find(theID);
89   if (aIt != myIDs.end()) {
90     return aIt->second;
91   }
92   return NULL;
93 }