Salome HOME
Issue #1659 New widget for supporting optional inputs : correction for enclosed cases.
[modules/shaper.git] / src / Model / Model_Validator.h
index 0be3d21c87b12163468bc68f613e19d781144172..87a9b02da198fec2edf95b2d01b6c43df3fe770f 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        Model_Validator.hxx
 // Created:     2 Jul 2014
 // Author:      Mikhail PONIKAROV
 
 /**\class Model_ValidatorsFactory
  * \ingroup DataModel
- * \breif Manages the registered validators
+ * \brief Manages the registered validators
  *
  * Allows to get a validator by the feature identifier and 
  * the attribute identifier (if attribute is validated).
  * All accessible validators mustbe registered by the ID string first.
- * The instance of this factory can be get in the PluginManager.
+ * The instance of this factory can be get in the Session.
  * Keeps the validator objects alive and just returns one of it by request.
  * All the needed information is provided to the validator as an argument,
  * this allows to work with them independently from the feature specific object.
@@ -26,12 +28,21 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
 {
  private:
   std::map<std::string, ModelAPI_Validator*> myIDs;  ///< map from ID to registered validator
+  /// validators IDs to list of arguments
+  typedef std::map<std::string, std::list<std::string> > AttrValidators;
   /// validators IDs by feature ID
-  std::map<std::string, std::set<std::string> > myFeatures;
-  /// set of pairs: validators IDs, list of arguments
-  typedef std::set<std::pair<std::string, std::list<std::string> > > AttrValidators;
+  std::map<std::string, AttrValidators> myFeatures;
   /// validators IDs and arguments by feature and attribute IDs
   std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
+  /// 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 Ids (possible values of the switch attribute))
+  std::map<std::string, std::map<std::string,
+          std::map<std::string, std::set<std::string> > > > myCases;
+
  public:
   /// Registers the instance of the validator by the ID
   MODEL_EXPORT virtual void registerValidator(const std::string& theID,
@@ -41,6 +52,11 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
                                             const std::string& theFeatureID);
 
+  /// Assigns validator to the feature with arguments of the validator
+  MODEL_EXPORT virtual void assignValidator(const std::string& theID,
+                                            const std::string& theFeatureID,
+                                            const std::list<std::string>& theArguments);
+
   /// Assigns validator to the attribute of the feature
   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
                                             const std::string& theFeatureID,
@@ -49,26 +65,56 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
 
   /// Provides a validator for the feature, returns NULL if no validator
   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
-                                       std::list<ModelAPI_Validator*>& theResult) const;
+                                       Validators& theResult) const;
   /// Provides a validator for the attribute, returns NULL if no validator
-  MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
-                                       const std::string& theAttrID,
-                                       std::list<ModelAPI_Validator*>& theValidators,
-                                       std::list<std::list<std::string> >& theArguments) const;
+  MODEL_EXPORT virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
+                                       Validators& theResult) const;
 
   /// Returns registered validator by its Id
-  virtual const ModelAPI_Validator* validator(const std::string& theID) const;
+  MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theID) const;
+
+  /// Returns true if feature and all its attributes are valid.
+  MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
+
+  /// Returns true if the attribute is valid.
+  MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
+                                     std::string& theValidator, Events_InfoMessage& theError) const;
+
+  /// 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);
+
+  /// Returns true if the attribute in feature is not obligatory for the feature execution
+  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+
+  /// register that this attribute conceals in the object browser
+  /// all referenced features after execution
+  virtual void registerConcealment(std::string theFeature, std::string theAttribute);
+
+  /// 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);
+
+  /// register the case-attribute (\a myCases set definition)
+  virtual void registerCase(std::string theFeature, std::string theAttribute,
+                            const std::list<std::pair<std::string, std::string> >& theCases);
+
+  /// Returns true if the attribute must be checked (the case is selected)
+  virtual bool isCase(FeaturePtr theFeature, std::string theAttribute);
 
-  /// Returns the result of "validate" method for attribute of validator.
-  /// If validator is not exists, returns true: everything is valid by default.
-  //MODEL_EXPORT virtual bool validate(
-  //  const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const;
 
- protected:
-  /// Get instance from PluginManager
+protected:
+  /// Adds the defualt validators that are usefull for all features.
+  void addDefaultValidators(Validators& theValidators) const;
+  /// Adds the defualt validators that are usefull for all attributes.
+  void addDefaultAttributeValidators(Validators& theValidators) const;
+  /// Get instance from Session
   Model_ValidatorsFactory();
 
-  friend class Model_PluginManager;
+  friend class Model_Session;
 };
 
 #endif