]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Validator.cpp
Salome HOME
Distance constraint optimization
[modules/shaper.git] / src / Model / Model_Validator.cpp
1 // File:        Model_Validator.cpp
2 // Created:     2 Jul 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include <Model_Validator.h>
6 #include <ModelAPI_Feature.h>
7 #include <Events_Error.h>
8
9 void Model_ValidatorsFactory::registerValidator(
10   const std::string& theID, ModelAPI_Validator* theValidator)
11 {
12   if (myIDs.find(theID) != myIDs.end()) {
13     Events_Error::send(std::string("Validator ") + theID + " is already registered");
14   } else {
15     myIDs[theID] = theValidator;
16   }
17 }
18
19 void Model_ValidatorsFactory::assignValidator(
20   const std::string& theID, const std::string& theFeatureID)
21 {
22   if (myFeatures.find(theFeatureID) == myFeatures.end()) {
23     myFeatures[theFeatureID] = std::set<std::string>();
24   }
25   myFeatures[theFeatureID].insert(theID);
26 }
27
28 void Model_ValidatorsFactory::assignValidator(const std::string& theID, 
29   const std::string& theFeatureID, const std::string& theAttrID, 
30   const std::list<std::string>& theArguments)
31 {
32   // create feature-structures if not exist
33   std::map<std::string, std::map<std::string, AttrValidators> >::iterator aFeature = 
34     myAttrs.find(theFeatureID);
35   if (aFeature == myAttrs.end()) {
36     myAttrs[theFeatureID] = std::map<std::string, AttrValidators>();
37     aFeature = myAttrs.find(theFeatureID);
38   }
39   // add attr-structure if not exist, or generate error if already exist
40   std::map<std::string, AttrValidators>::iterator anAttr = aFeature->second.find(theAttrID);
41   if (anAttr == aFeature->second.end()) {
42     aFeature->second[theAttrID] = AttrValidators();
43   }
44   aFeature->second[theAttrID].insert(
45     std::pair<std::string, std::list<std::string> >(theID, theArguments));
46 }
47
48 void Model_ValidatorsFactory::validators(
49   const std::string& theFeatureID, std::list<ModelAPI_Validator*>& theResult ) const
50 {
51   std::map<std::string, std::set<std::string> >::const_iterator aFeature =
52     myFeatures.find(theFeatureID);
53   if (aFeature != myFeatures.cend()) {
54     std::set<std::string>::const_iterator aValIter = aFeature->second.cbegin();
55     for(; aValIter != aFeature->second.cend(); aValIter++) {
56       std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = myIDs.find(*aValIter);
57       if (aFound == myIDs.end()) {
58         Events_Error::send(std::string("Validator ") + *aValIter + " was not registered");
59       } else {
60         theResult.push_back(aFound->second);
61       }
62     }
63   }
64 }
65
66 void Model_ValidatorsFactory::validators(const std::string& theFeatureID, 
67   const std::string& theAttrID, std::list<ModelAPI_Validator*>& theValidators, 
68   std::list<std::list<std::string> >& theArguments) const
69 {
70   std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeature =
71     myAttrs.find(theFeatureID);
72   if (aFeature != myAttrs.cend()) {
73     std::map<std::string, AttrValidators>::const_iterator anAttr =
74       aFeature->second.find(theAttrID);
75     if (anAttr != aFeature->second.end()) {
76       AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
77       for(; aValIter != anAttr->second.cend(); aValIter++) {
78         std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = 
79           myIDs.find(aValIter->first);
80         if (aFound == myIDs.end()) {
81           Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered");
82         } else {
83           theValidators.push_back(aFound->second);
84           theArguments.push_back(aValIter->second);
85         }
86       }
87     }
88   }
89 }
90
91 Model_ValidatorsFactory::Model_ValidatorsFactory() : ModelAPI_ValidatorsFactory()
92 {
93 }