From 55026eca2455683fd776d5d168e1f224f6a4fb57 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 24 Sep 2014 16:49:21 +0400 Subject: [PATCH] Use not obligatory AXML flag in general validator --- src/Model/Model_FeatureValidator.cpp | 21 +++++++++++++++++---- src/Model/Model_FeatureValidator.h | 7 +++++++ src/Model/Model_Validator.cpp | 20 ++++++++++++++++---- src/Model/Model_Validator.h | 6 +++++- src/ModelAPI/ModelAPI_Validator.h | 4 ++++ src/ModuleBase/ModuleBase_ModelWidget.cpp | 1 + src/ModuleBase/ModuleBase_WidgetFactory.cpp | 12 ++++++++++++ 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/Model/Model_FeatureValidator.cpp b/src/Model/Model_FeatureValidator.cpp index dd28371d7..bcc09d11e 100644 --- a/src/Model/Model_FeatureValidator.cpp +++ b/src/Model/Model_FeatureValidator.cpp @@ -20,11 +20,24 @@ bool Model_FeatureValidator::isValid(const boost::shared_ptr& if (!aData->isValid()) return false; const std::string kAllTypes = ""; - std::list aLtAttributes = aData->attributes(kAllTypes); - std::list::iterator it = aLtAttributes.begin(); + std::list aLtAttributes = aData->attributesIDs(kAllTypes); + std::list::iterator it = aLtAttributes.begin(); for (; it != aLtAttributes.end(); it++) { - if (!(*it)->isInitialized()) - return false; + AttributePtr anAttr = aData->attribute(*it); + if (!anAttr->isInitialized()) { + std::map >::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& anAttrs = myNotObligatory[theFeature]; + anAttrs.insert(theAttribute); +} diff --git a/src/Model/Model_FeatureValidator.h b/src/Model/Model_FeatureValidator.h index 901f48ef7..95a4ce1c5 100644 --- a/src/Model/Model_FeatureValidator.h +++ b/src/Model/Model_FeatureValidator.h @@ -10,14 +10,21 @@ #include #include +#include +#include class Model_FeatureValidator : public ModelAPI_FeatureValidator { + // not obligatory attributes, not checked for initialization + std::map > 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& theFeature, const std::list& theArguments) const; + + // sets not obligatory attributes, not checked for initialization + void registerNotObligatory(std::string theFeature, std::string theAttribute); }; #endif diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index 408b20cf5..ee5ab1a9c 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -10,7 +10,7 @@ #include #include -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) @@ -121,7 +121,7 @@ void Model_ValidatorsFactory::validators(const std::string& theFeatureID, 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 @@ -135,7 +135,7 @@ const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string& void Model_ValidatorsFactory::addDefaultValidators(std::list& theValidators) const { - std::map::const_iterator it = myIDs.find(DefaultId); + std::map::const_iterator it = myIDs.find(kDefaultId); if(it == myIDs.end()) return; theValidators.push_back(it->second); @@ -164,7 +164,7 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr } } // check default validator - std::map::const_iterator aDefaultVal = myIDs.find(DefaultId); + std::map::const_iterator aDefaultVal = myIDs.find(kDefaultId); if(aDefaultVal != myIDs.end()) { static const std::list anEmptyArgList; const ModelAPI_FeatureValidator* aFValidator = @@ -210,3 +210,15 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr } return true; } + +void Model_ValidatorsFactory::registerNotObligatory( + std::string theFeature, std::string theAttribute) +{ + std::map::const_iterator it = myIDs.find(kDefaultId); + if (it != myIDs.end()) { + Model_FeatureValidator* aValidator = dynamic_cast(it->second); + if (aValidator) { + aValidator->registerNotObligatory(theFeature, theAttribute); + } + } +} \ No newline at end of file diff --git a/src/Model/Model_Validator.h b/src/Model/Model_Validator.h index 031295485..38d2d7bf5 100644 --- a/src/Model/Model_Validator.h +++ b/src/Model/Model_Validator.h @@ -68,7 +68,11 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory /// Returns true if feature and all its attributes are valid. MODEL_EXPORT virtual bool validate(const boost::shared_ptr& 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& theValidators) const; /// Get instance from Session Model_ValidatorsFactory(); diff --git a/src/ModelAPI/ModelAPI_Validator.h b/src/ModelAPI/ModelAPI_Validator.h index 9c83a9d7e..ea47856f4 100644 --- a/src/ModelAPI/ModelAPI_Validator.h +++ b/src/ModelAPI/ModelAPI_Validator.h @@ -79,6 +79,10 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory /// Returns true if feature and all its attributes are valid. virtual bool validate(const boost::shared_ptr& 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() diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index f3da462d4..939345b51 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 1063cfa9a..00a479ad1 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -161,6 +162,17 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType 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; } -- 2.39.2