if (!aData->isValid())
return false;
const std::string kAllTypes = "";
- std::list<AttributePtr> aLtAttributes = aData->attributes(kAllTypes);
- std::list<AttributePtr>::iterator it = aLtAttributes.begin();
+ std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
+ std::list<std::string>::iterator it = aLtAttributes.begin();
for (; it != aLtAttributes.end(); it++) {
- if (!(*it)->isInitialized())
- return false;
+ AttributePtr anAttr = aData->attribute(*it);
+ if (!anAttr->isInitialized()) {
+ std::map<std::string, std::set<std::string> >::const_iterator aFeatureFind =
+ myNotObligatory.find(theFeature->getKind());
+ if (aFeatureFind == myNotObligatory.end() ||
+ aFeatureFind->second.find(*it) == aFeatureFind->second.end()) {
+ return false;
+ }
+ }
}
return true;
}
+
+void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::string theAttribute)
+{
+ std::set<std::string>& anAttrs = myNotObligatory[theFeature];
+ anAttrs.insert(theAttribute);
+}
#include <ModelAPI_FeatureValidator.h>
#include <boost/shared_ptr.hpp>
+#include <set>
+#include <map>
class Model_FeatureValidator : public ModelAPI_FeatureValidator
{
+ // not obligatory attributes, not checked for initialization
+ std::map<std::string, std::set<std::string> > myNotObligatory;
public:
/// Returns true if feature and/or attributes are valid
/// \param theFeature the validated feature
MODEL_EXPORT virtual bool isValid(const boost::shared_ptr<ModelAPI_Feature>& theFeature,
const std::list<std::string>& theArguments) const;
+
+ // sets not obligatory attributes, not checked for initialization
+ void registerNotObligatory(std::string theFeature, std::string theAttribute);
};
#endif
#include <ModelAPI_AttributeValidator.h>
#include <Events_Error.h>
-const static std::string DefaultId = "Model_FeatureValidator";
+const static std::string kDefaultId = "Model_FeatureValidator";
void Model_ValidatorsFactory::registerValidator(const std::string& theID,
ModelAPI_Validator* theValidator)
Model_ValidatorsFactory::Model_ValidatorsFactory()
: ModelAPI_ValidatorsFactory()
{
- registerValidator("Model_FeatureValidator", new Model_FeatureValidator);
+ registerValidator(kDefaultId, new Model_FeatureValidator);
}
const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string& theID) const
void Model_ValidatorsFactory::addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const
{
- std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(DefaultId);
+ std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
if(it == myIDs.end())
return;
theValidators.push_back(it->second);
}
}
// check default validator
- std::map<std::string, ModelAPI_Validator*>::const_iterator aDefaultVal = myIDs.find(DefaultId);
+ std::map<std::string, ModelAPI_Validator*>::const_iterator aDefaultVal = myIDs.find(kDefaultId);
if(aDefaultVal != myIDs.end()) {
static const std::list<std::string> anEmptyArgList;
const ModelAPI_FeatureValidator* aFValidator =
}
return true;
}
+
+void Model_ValidatorsFactory::registerNotObligatory(
+ std::string theFeature, std::string theAttribute)
+{
+ std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
+ if (it != myIDs.end()) {
+ Model_FeatureValidator* aValidator = dynamic_cast<Model_FeatureValidator*>(it->second);
+ if (aValidator) {
+ aValidator->registerNotObligatory(theFeature, theAttribute);
+ }
+ }
+}
\ No newline at end of file
/// Returns true if feature and all its attributes are valid.
MODEL_EXPORT virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const;
- protected:
+ /// register that this attribute in feature is not obligatory for the feature execution
+ /// so, it is not needed for the standard validation mechanism
+ virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
+
+protected:
void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
/// Get instance from Session
Model_ValidatorsFactory();
/// Returns true if feature and all its attributes are valid.
virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
+ /// register that this attribute in feature is not obligatory for the feature execution
+ /// so, it is not needed for the standard validation mechanism
+ virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
+
protected:
/// Get instance from Session
ModelAPI_ValidatorsFactory()
#include <ModelAPI_Data.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Session.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
#include <ModuleBase_WidgetChoice.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IModule.h>
+#include <ModelAPI_Validator.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
if (!result) {qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");}
#endif
}
+ if (result) {
+ // register that this attribute in feature is not obligatory for the feature execution
+ // so, it is not needed for the standard validation mechanism
+ bool isObligatory =
+ myWidgetApi ? myWidgetApi->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
+ if (!isObligatory) {
+ ModelAPI_Session::get()->validators()->registerNotObligatory(
+ myParentId, myWidgetApi->widgetId());
+ }
+ }
+
return result;
}