Salome HOME
Issue #273: Add copyright string
[modules/shaper.git] / src / Model / Model_FeatureValidator.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_FeatureValidator.cpp
4 // Created:     8 Jul 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include <Model_FeatureValidator.h>
8 #include <ModelAPI_Attribute.h>
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_Object.h>
12
13 #include <list>
14 #include <memory>
15
16 bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
17   const std::list<std::string>& theArguments) const
18 {
19   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
20   // "Action" features has no data, but still valid. e.g "Remove Part"  
21   if (!aData) {
22     return theFeature->isAction();
23   }
24   if (!aData->isValid())
25     return false;
26   const std::string kAllTypes = "";
27   std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
28   std::list<std::string>::iterator it = aLtAttributes.begin();
29   for (; it != aLtAttributes.end(); it++) {
30     AttributePtr anAttr = aData->attribute(*it);
31     if (!anAttr->isInitialized()) { // attribute is not initialized
32       std::map<std::string, std::set<std::string> >::const_iterator aFeatureFind = 
33         myNotObligatory.find(theFeature->getKind());
34       if (aFeatureFind == myNotObligatory.end() || // and it is obligatory for filling
35           aFeatureFind->second.find(*it) == aFeatureFind->second.end()) {
36         return false;
37       }
38     }
39   }
40   return true;
41 }
42
43 void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
44 {
45   std::set<std::string>& anAttrs = myNotObligatory[theFeature];
46   anAttrs.insert(theAttribute);
47 }
48
49 bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
50 {
51   std::set<std::string>& anAttrs = myNotObligatory[theFeature];
52   return anAttrs.find(theAttribute) != anAttrs.end();
53 }