// Author: Vitaly SMETANNIKOV
#include <Model_FeatureValidator.h>
+#include <Model_Validator.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_Session.h>
#include <list>
#include <memory>
bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::list<std::string>& theArguments) const
{
+ static Model_ValidatorsFactory* aValidators =
+ static_cast<Model_ValidatorsFactory*>(ModelAPI_Session::get()->validators());
+
std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
// "Action" features has no data, but still valid. e.g "Remove Part"
if (!aData) {
std::list<std::string>::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<std::string, std::set<std::string> >::const_iterator aFeatureFind =
myNotObligatory.find(theFeature->getKind());
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
#include <ModelAPI_Attribute.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_AttributeString.h>
#include <Events_Error.h>
void Model_ValidatorsFactory::registerValidator(const std::string& theID,
std::map<std::string, std::set<std::string> >::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<std::string, std::map<std::string, std::pair<std::string, std::string> > >::iterator
+ aFindFeature = myCases.find(theFeature);
+ if (aFindFeature == myCases.end()) {
+ myCases[theFeature] = std::map<std::string, std::pair<std::string, std::string> >();
+ aFindFeature = myCases.find(theFeature);
+ }
+ (aFindFeature->second)[theAttribute] = std::pair<std::string, std::string>(theSwitchId, theCaseId);
+}
+
+bool Model_ValidatorsFactory::isCase(
+ FeaturePtr theFeature, std::string theAttribute)
+{
+ std::map<std::string, std::map<std::string, std::pair<std::string, std::string> > >::iterator
+ aFindFeature = myCases.find(theFeature->getKind());
+ if (aFindFeature != myCases.end()) {
+ std::map<std::string, std::pair<std::string, std::string> >::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
+}
#include <Model.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_Feature.h>
#include <map>
#include <set>
/// 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<std::string, std::set<std::string> > 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<std::string, std::map<std::string, std::pair<std::string, std::string> > > myCases;
public:
/// Registers the instance of the validator by the ID
/// 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<ModelAPI_Validator*>& theValidators,
/// 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()