1 // File: Model_FeatureValidator.cpp
3 // Author: Vitaly SMETANNIKOV
5 #include <Model_FeatureValidator.h>
6 #include <ModelAPI_Attribute.h>
7 #include <ModelAPI_Data.h>
8 #include <ModelAPI_Feature.h>
9 #include <ModelAPI_Object.h>
14 bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
15 const std::list<std::string>& theArguments) const
17 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
18 // "Action" features has no data, but still valid. e.g "Remove Part"
20 return theFeature->isAction();
22 if (!aData->isValid())
24 const std::string kAllTypes = "";
25 std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
26 std::list<std::string>::iterator it = aLtAttributes.begin();
27 for (; it != aLtAttributes.end(); it++) {
28 AttributePtr anAttr = aData->attribute(*it);
29 if (!anAttr->isInitialized()) { // attribute is not initialized
30 std::map<std::string, std::set<std::string> >::const_iterator aFeatureFind =
31 myNotObligatory.find(theFeature->getKind());
32 if (aFeatureFind == myNotObligatory.end() || // and it is obligatory for filling
33 aFeatureFind->second.find(*it) == aFeatureFind->second.end()) {
41 void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
43 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
44 anAttrs.insert(theAttribute);
47 bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
49 std::set<std::string>& anAttrs = myNotObligatory[theFeature];
50 return anAttrs.find(theAttribute) != anAttrs.end();