From 83e925a876b26a470e513b0a229258b145c82bc8 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 27 Feb 2015 17:22:47 +0300 Subject: [PATCH] Case-specific attributes validation implementation --- src/Model/Model_FeatureValidator.cpp | 7 ++++++ src/Model/Model_Session.cpp | 5 ++++- src/Model/Model_Validator.cpp | 32 ++++++++++++++++++++++++++++ src/Model/Model_Validator.h | 13 +++++++++++ src/ModelAPI/ModelAPI_Validator.h | 4 ++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/Model/Model_FeatureValidator.cpp b/src/Model/Model_FeatureValidator.cpp index b3b1b8216..a809abe46 100644 --- a/src/Model/Model_FeatureValidator.cpp +++ b/src/Model/Model_FeatureValidator.cpp @@ -5,10 +5,12 @@ // Author: Vitaly SMETANNIKOV #include +#include #include #include #include #include +#include #include #include @@ -16,6 +18,9 @@ bool Model_FeatureValidator::isValid(const std::shared_ptr& theFeature, const std::list& theArguments) const { + static Model_ValidatorsFactory* aValidators = + static_cast(ModelAPI_Session::get()->validators()); + std::shared_ptr aData = theFeature->data(); // "Action" features has no data, but still valid. e.g "Remove Part" if (!aData) { @@ -28,6 +33,8 @@ bool Model_FeatureValidator::isValid(const std::shared_ptr& th std::list::iterator it = aLtAttributes.begin(); for (; it != aLtAttributes.end(); it++) { AttributePtr anAttr = aData->attribute(*it); + if (!aValidators->isCase(theFeature, anAttr->id())) + continue; // this attribute is not participated in the current case if (!anAttr->isInitialized()) { // attribute is not initialized std::map >::const_iterator aFeatureFind = myNotObligatory.find(theFeature->getKind()); diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 8b81240a2..1791c3ad6 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -299,7 +299,10 @@ void Model_Session::processEvent(const std::shared_ptr& theMessa if(aMsgAttr->isConcealment()) { validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId()); } - + if (!aMsgAttr->caseId().empty()) { + validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(), + aMsgAttr->switchId(), aMsgAttr->caseId()); + } } } // plugins information was started to load, so, it will be loaded diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index c2c994da9..9875f7427 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include void Model_ValidatorsFactory::registerValidator(const std::string& theID, @@ -260,3 +261,34 @@ bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string th std::map >::iterator aFind = myConcealed.find(theFeature); return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end(); } + +void Model_ValidatorsFactory::registerCase(std::string theFeature, std::string theAttribute, + std::string theSwitchId, std::string theCaseId) +{ + std::map > >::iterator + aFindFeature = myCases.find(theFeature); + if (aFindFeature == myCases.end()) { + myCases[theFeature] = std::map >(); + aFindFeature = myCases.find(theFeature); + } + (aFindFeature->second)[theAttribute] = std::pair(theSwitchId, theCaseId); +} + +bool Model_ValidatorsFactory::isCase( + FeaturePtr theFeature, std::string theAttribute) +{ + std::map > >::iterator + aFindFeature = myCases.find(theFeature->getKind()); + if (aFindFeature != myCases.end()) { + std::map >::iterator + aFindAttr = aFindFeature->second.find(theAttribute); + if (aFindAttr != aFindFeature->second.end()) { + // the the switch-attribute that contains the case value + AttributeStringPtr aSwitch = theFeature->string(aFindAttr->second.first); + if (aSwitch.get()) { + return aSwitch->value() == aFindAttr->second.second; // the second is the case identifier + } + } + } + return true; // if no additional conditions, this attribute is the case to be validated +} diff --git a/src/Model/Model_Validator.h b/src/Model/Model_Validator.h index 4747c534b..b3324c458 100644 --- a/src/Model/Model_Validator.h +++ b/src/Model/Model_Validator.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -37,6 +38,10 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory /// Stores the registered attributes that leads to the concealment of referenced objects in /// data tree. Map from feature kind to set of attribute IDs. std::map > myConcealed; + /// Stores the registered attributes must be checked only if the particular case is activated + /// Map from feature kind to map of attribute IDs to pair + // (switchId (ID of the attribute) and case Id (possible values of the switch attribute)) + std::map > > myCases; public: /// Registers the instance of the validator by the ID @@ -88,6 +93,14 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory /// Returns true that it was registered that attribute conceals the referenced result virtual bool isConcealed(std::string theFeature, std::string theAttribute); + /// register the case-attribute (\a myCases set definition) + virtual void registerCase(std::string theFeature, std::string theAttribute, + std::string theSwitchId, std::string theCaseId); + + /// Returns true if the attribute must be checked (the case is selected) + virtual bool isCase(FeaturePtr theFeature, std::string theAttribute); + + protected: /// Adds the defualt validators that are usefull for all features. void addDefaultValidators(std::list& theValidators, diff --git a/src/ModelAPI/ModelAPI_Validator.h b/src/ModelAPI/ModelAPI_Validator.h index 1c7d0fecb..42662b10d 100644 --- a/src/ModelAPI/ModelAPI_Validator.h +++ b/src/ModelAPI/ModelAPI_Validator.h @@ -95,6 +95,10 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory /// Returns true that it was registered that attribute conceals the referenced result virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0; + /// Register the case-attribute: this attribute is checked only if its case is selected + virtual void registerCase(std::string theFeature, std::string theAttribute, + std::string theSwitchId, std::string theCaseId) = 0; + protected: /// Get instance from Session ModelAPI_ValidatorsFactory() -- 2.30.2