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