Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / Model / Model_Validator.cpp
index eecd08b33013590344a004f9e794fc7a7031ac4a..c2c994da9cd65dc1b194115c8250aa524760ae1c 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        Model_Validator.cpp
 // Created:     2 Jul 2014
 // Author:      Mikhail PONIKAROV
@@ -10,8 +12,6 @@
 #include <ModelAPI_AttributeValidator.h>
 #include <Events_Error.h>
 
-const static std::string kDefaultId = "Model_FeatureValidator";
-
 void Model_ValidatorsFactory::registerValidator(const std::string& theID,
   ModelAPI_Validator* theValidator)
 {
@@ -90,7 +90,7 @@ void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
       }
     }
   }
-  addDefaultValidators(theResult);
+  addDefaultValidators(theResult, theArguments);
 }
 
 void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
@@ -121,6 +121,7 @@ void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
 Model_ValidatorsFactory::Model_ValidatorsFactory()
   : ModelAPI_ValidatorsFactory()
 {
+  const static std::string kDefaultId = "Model_FeatureValidator";
   registerValidator(kDefaultId, new Model_FeatureValidator);
 }
 
@@ -133,16 +134,20 @@ const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string&
   return NULL;
 }
 
-void Model_ValidatorsFactory::addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const
+void Model_ValidatorsFactory::addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators,
+  std::list<std::list<std::string> >& theArguments) const
 {
+  const static std::string kDefaultId = "Model_FeatureValidator";
   std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
   if(it == myIDs.end())
     return;
   theValidators.push_back(it->second);
+  theArguments.push_back(std::list<std::string>());
 }
 
-bool Model_ValidatorsFactory::validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const
+bool Model_ValidatorsFactory::validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
 {
+  const static std::string kDefaultId = "Model_FeatureValidator";
   // check feature validators first
   std::map<std::string, AttrValidators>::const_iterator aFeature = 
     myFeatures.find(theFeature->getKind());
@@ -174,10 +179,12 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr<ModelAPI_Feature>
         return false;
     }
   }
+  
   // check all attributes for validity
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  if (!aData->isValid())
-    return false;
+  std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  // Validity of data is checked by "Model_FeatureValidator" (kDefaultId)
+  // if (!aData || !aData->isValid())
+  //   return false;
   static const std::string kAllTypes = "";
   std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeatureIter = 
     myAttrs.find(theFeature->getKind());
@@ -213,6 +220,7 @@ bool Model_ValidatorsFactory::validate(const boost::shared_ptr<ModelAPI_Feature>
 
 void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std::string theAttribute)
 {
+  const static std::string kDefaultId = "Model_FeatureValidator";
   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);
@@ -222,6 +230,19 @@ void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std:
   }
 }
 
+bool Model_ValidatorsFactory::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+  const static std::string kDefaultId = "Model_FeatureValidator";
+  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) {
+      return aValidator->isNotObligatory(theFeature, theAttribute);
+    }
+  }
+  return false; // default
+}
+
 void Model_ValidatorsFactory::registerConcealment(std::string theFeature, std::string theAttribute)
 {
   std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);