]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_FeatureValidator.cpp
Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[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         // TODO(spo): exceptional case for translation
48         theError = "Attribute \"" + anAttr->id() + "\" is not initialized.";
49 //        theError.arg(anAttr->id());
50         return false;
51       }
52     }
53   }
54   return true;
55 }
56
57 void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
58 {
59   std::set<std::string>& anAttrs = myNotObligatory[theFeature];
60   anAttrs.insert(theAttribute);
61 }
62
63 bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
64 {
65   std::set<std::string>& anAttrs = myNotObligatory[theFeature];
66   return anAttrs.find(theAttribute) != anAttrs.end();
67 }