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