Salome HOME
Issue #653 - Double and triple click edges -- Fix Debian dynamic_pointer_cast problem...
[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_Error.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_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<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, 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           ModuleBase_Filter* aFilter = aFound->second;
69           aFilter->setArguments(aValIter->second);
70           //if (aFilter.IsNull())
71           //  continue;
72
73           theFilters.Append(aFilter->getFilter());//aFound->second);
74           //theArguments.push_back(aValIter->second);
75         }
76       }
77     }
78   }
79 }
80
81 ModuleBase_FilterFactory::ModuleBase_FilterFactory()
82 {
83   //const static std::string kDefaultId = "Model_FeatureFilter";
84   //registerFilter(kDefaultId, new Model_FeatureFilter);
85 }
86
87 const ModuleBase_Filter* ModuleBase_FilterFactory::filter(const std::string& theID) const
88 {
89   std::map<std::string, ModuleBase_Filter*>::const_iterator aIt = myIDs.find(theID);
90   if (aIt != myIDs.end()) {
91     return aIt->second;
92   }
93   return NULL;
94 }