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) const
21 static Model_ValidatorsFactory* aValidators =
22 static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
24 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
25 // "Action" features has no data, but still valid. e.g "Remove Part"
27 return theFeature->isAction();
29 if (!aData->isValid())
31 const std::string kAllTypes = "";
32 std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
33 std::list<std::string>::iterator it = aLtAttributes.begin();
34 for (; it != aLtAttributes.end(); it++) {
35 AttributePtr anAttr = aData->attribute(*it);
36 if (!aValidators->isCase(theFeature, anAttr->id()))
37 continue; // this attribute is not participated in the current case
38 if (!anAttr->isInitialized()) { // attribute is not initialized
39 std::map<std::string, std::set<std::string> >::const_iterator aFeatureFind =
40 myNotObligatory.find(theFeature->getKind());
41 if (aFeatureFind == myNotObligatory.end() || // and it is obligatory for filling
42 aFeatureFind->second.find(*it) == aFeatureFind->second.end()) {
50 void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
52 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
53 anAttrs.insert(theAttribute);
56 bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
58 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
59 return anAttrs.find(theAttribute) != anAttrs.end();