Salome HOME
891d74370621fb944a2ff2789ec631cdf0927a95
[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 {
32   // create feature-structures if not exist
33   std::map<std::string, std::map<std::string, AttrFilters> >::iterator aFeature = myAttrs.find(
34     theFeatureID);
35   if (aFeature == myAttrs.end()) {
36     myAttrs[theFeatureID] = std::map<std::string, AttrFilters>();
37     aFeature = myAttrs.find(theFeatureID);
38   }
39   // add attr-structure if not exist, or generate error if already exist
40   std::map<std::string, AttrFilters>::iterator anAttr = aFeature->second.find(theAttrID);
41   if (anAttr == aFeature->second.end()) {
42     aFeature->second[theAttrID] = AttrFilters();
43   }
44   aFeature->second[theAttrID][theID] = std::list<std::string>();
45 }
46
47 void ModuleBase_FilterFactory::filters(const std::string& theFeatureID,
48                                        const std::string& theAttrID,
49                                        SelectMgr_ListOfFilter& theFilters/*,
50                                         std::list<Handle(ModuleBase_Filter)>& theFilters/*,
51                                         std::list<std::list<std::string> >& theArguments*/) const
52 {
53   SelectMgr_ListOfFilter aFilters;
54
55   std::map<std::string, std::map<std::string, AttrFilters> >::const_iterator aFeature = 
56     myAttrs.find(theFeatureID);
57   if (aFeature != myAttrs.cend()) {
58     std::map<std::string, AttrFilters>::const_iterator anAttr = aFeature->second.find(theAttrID);
59     if (anAttr != aFeature->second.end()) {
60       AttrFilters::const_iterator aValIter = anAttr->second.cbegin();
61       for (; aValIter != anAttr->second.cend(); aValIter++) {
62         std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aFound = myIDs.find(
63           aValIter->first);
64         if (aFound == myIDs.end()) {
65           Events_Error::send(std::string("Filter ") + aValIter->first + " was not registered");
66         } else {
67           Handle(ModuleBase_Filter) aFilter = aFound->second;
68           if (aFilter.IsNull())
69             continue;
70
71           theFilters.Append(aFilter);//aFound->second);
72           //theArguments.push_back(aValIter->second);
73         }
74       }
75     }
76   }
77 }
78
79 ModuleBase_FilterFactory::ModuleBase_FilterFactory()
80 {
81   //const static std::string kDefaultId = "Model_FeatureFilter";
82   //registerFilter(kDefaultId, new Model_FeatureFilter);
83 }
84
85 const Handle(ModuleBase_Filter) ModuleBase_FilterFactory::filter(const std::string& theID) const
86 {
87   std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aIt = myIDs.find(theID);
88   if (aIt != myIDs.end()) {
89     return aIt->second;
90   }
91   return NULL;
92 }