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 <ModelAPI_Attribute.h>
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_Object.h>
16 bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
17 const std::list<std::string>& theArguments) const
19 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
20 // "Action" features has no data, but still valid. e.g "Remove Part"
22 return theFeature->isAction();
24 if (!aData->isValid())
26 const std::string kAllTypes = "";
27 std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
28 std::list<std::string>::iterator it = aLtAttributes.begin();
29 for (; it != aLtAttributes.end(); it++) {
30 AttributePtr anAttr = aData->attribute(*it);
31 if (!anAttr->isInitialized()) { // attribute is not initialized
32 std::map<std::string, std::set<std::string> >::const_iterator aFeatureFind =
33 myNotObligatory.find(theFeature->getKind());
34 if (aFeatureFind == myNotObligatory.end() || // and it is obligatory for filling
35 aFeatureFind->second.find(*it) == aFeatureFind->second.end()) {
43 void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
45 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
46 anAttrs.insert(theAttribute);
49 bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
51 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
52 return anAttrs.find(theAttribute) != anAttrs.end();