1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_FeatureValidator.cpp
5 // Author: Vitaly SMETANNIKOV
7 #include <Model_FeatureValidator.h>
9 #include <Events_InfoMessage.h>
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>
21 bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22 const std::list<std::string>& theArguments,
23 Events_InfoMessage& theError) const
25 static Model_ValidatorsFactory* aValidators =
26 static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
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();
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.";
55 void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
57 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
58 anAttrs.insert(theAttribute);
61 bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
63 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
64 return anAttrs.find(theAttribute) != anAttrs.end();