1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_FeatureValidator.cpp
5 // Author: Vitaly SMETANNIKOV
7 #include <Model_FeatureValidator.h>
8 #include <Model_Validator.h>
9 #include <ModelAPI_Attribute.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_Object.h>
13 #include <ModelAPI_Session.h>
18 bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
19 const std::list<std::string>& theArguments,
20 std::string& theError) const
22 static Model_ValidatorsFactory* aValidators =
23 static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
25 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
26 // "Action" features has no data, but still valid. e.g "Remove Part"
27 if (!aData->isValid()) {
28 if (!theFeature->isAction())
29 theError = "There is no data.";
30 return theFeature->isAction();
32 const std::string kAllTypes = "";
33 std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
34 std::list<std::string>::iterator it = aLtAttributes.begin();
35 for (; it != aLtAttributes.end(); it++) {
36 AttributePtr anAttr = aData->attribute(*it);
37 if (!aValidators->isCase(theFeature, anAttr->id()))
38 continue; // this attribute is not participated in the current case
39 if (!anAttr->isInitialized()) { // attribute is not initialized
40 std::map<std::string, std::set<std::string> >::const_iterator aFeatureFind =
41 myNotObligatory.find(theFeature->getKind());
42 if (aFeatureFind == myNotObligatory.end() || // and it is obligatory for filling
43 aFeatureFind->second.find(*it) == aFeatureFind->second.end()) {
44 theError = "Attribute \"" + anAttr->id() + "\" is not initialized.";
52 void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
54 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
55 anAttrs.insert(theAttribute);
58 bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
60 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
61 return anAttrs.find(theAttribute) != anAttrs.end();