]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_FeatureValidator.cpp
Salome HOME
06923d32449fc6579c0b66fbae1df529abef5cee
[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
9 #include <Events_InfoMessage.h>
10
11 #include <Model_Validator.h>
12 #include <ModelAPI_Attribute.h>
13 #include <ModelAPI_Data.h>
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Session.h>
17
18 #include <list>
19 #include <memory>
20
21 bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22                                      const std::list<std::string>& theArguments,
23                                      Events_InfoMessage& theError) const
24 {
25   static Model_ValidatorsFactory* aValidators = 
26     static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
27
28   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
29   // "Action" features has no data, but still valid. e.g "Remove Part"  
30   if (!aData->isValid()) {
31     if (!theFeature->isAction())
32       theError = "There is no data.";
33     return theFeature->isAction();
34   }
35   const std::string kAllTypes = "";
36   std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
37   std::list<std::string>::iterator it = aLtAttributes.begin();
38   for (; it != aLtAttributes.end(); it++) {
39     AttributePtr anAttr = aData->attribute(*it);
40     if (!aValidators->isCase(theFeature, anAttr->id()))
41       continue; // this attribute is not participated in the current case
42     if (!anAttr->isInitialized()) { // attribute is not initialized
43       std::map<std::string, std::set<std::string> >::const_iterator aFeatureFind = 
44         myNotObligatory.find(theFeature->getKind());
45       if (aFeatureFind == myNotObligatory.end() || // and it is obligatory for filling
46           aFeatureFind->second.find(*it) == aFeatureFind->second.end()) {
47         theError = "Attribute \"" + anAttr->id() + "\" is not initialized.";
48         return false;
49       }
50     }
51   }
52   return true;
53 }
54
55 void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
56 {
57   std::set<std::string>& anAttrs = myNotObligatory[theFeature];
58   anAttrs.insert(theAttribute);
59 }
60
61 bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
62 {
63   std::set<std::string>& anAttrs = myNotObligatory[theFeature];
64   return anAttrs.find(theAttribute) != anAttrs.end();
65 }