Salome HOME
Use not obligatory AXML flag in general validator
authormpv <mikhail.ponikarov@opencascade.com>
Wed, 24 Sep 2014 12:49:21 +0000 (16:49 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Wed, 24 Sep 2014 12:49:21 +0000 (16:49 +0400)
src/Model/Model_FeatureValidator.cpp
src/Model/Model_FeatureValidator.h
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/ModelAPI_Validator.h
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_WidgetFactory.cpp

index dd28371d775ffb84868fe277c2a7d6f6e7ca94b8..bcc09d11e13002fbef87b969afac32f1fba66894 100644 (file)
@@ -20,11 +20,24 @@ bool Model_FeatureValidator::isValid(const boost::shared_ptr<ModelAPI_Feature>&
   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);
+}
index 901f48ef7fbbf5f656c4d36c6aba2cf25fe0c6d6..95a4ce1c5672e973f535ba4c7ffa2a8f6c54cd8f 100644 (file)
 #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
index 408b20cf5b48659b95d4ccd3f372f9ed3a095492..ee5ab1a9ccad2ed6178752e68faec45fa51bfbdb 100644 (file)
@@ -10,7 +10,7 @@
 #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)
@@ -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<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);
@@ -164,7 +164,7 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr<ModelAPI_Feature>
     }
   }
   // 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 = 
@@ -210,3 +210,15 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr<ModelAPI_Feature>
   }
   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
index 0312954859cb0a1709f89591fb436e424ac4763e..38d2d7bf5bca0b60b539bb4499000e0b7824c03c 100644 (file)
@@ -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<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();
index 9c83a9d7e3f4c63e9dda372255a40dc0a70eaab2..ea47856f4afd2b34b2a70191c165443d2d8be3f0 100644 (file)
@@ -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<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()
index f3da462d45ad1bd06f9fc6915ce6c0c7a5c6383e..939345b517beefd395652896b194802d34b728a9 100644 (file)
@@ -7,6 +7,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_Events.h>
+#include <ModelAPI_Session.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
index 1063cfa9acf272b0d1bc6fc1c2e7001ce718b90a..00a479ad10c1ec8fb14a88cdc04c796ab1ab6463 100644 (file)
@@ -22,6 +22,7 @@
 #include <ModuleBase_WidgetChoice.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IModule.h>
+#include <ModelAPI_Validator.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -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;
 }