]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Error management -- Improve validators.
authorspo <sergey.pokhodenko@opencascade.com>
Wed, 22 Jul 2015 06:21:15 +0000 (09:21 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Wed, 5 Aug 2015 14:59:37 +0000 (17:59 +0300)
src/Model/Model_FeatureValidator.cpp
src/ParametersPlugin/ParametersPlugin_Validators.cpp

index 99fc08fe733470d57f2a35afedcc34d5b5938a6d..303a465676c90fe08fc484e5a8689856d86db470 100644 (file)
@@ -25,10 +25,10 @@ bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& th
   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
   // "Action" features has no data, but still valid. e.g "Remove Part"  
   if (!aData->isValid()) {
+    if (!theFeature->isAction())
+      theError = "There is no data.";
     return theFeature->isAction();
   }
-  if (!aData->isValid())
-    return false;
   const std::string kAllTypes = "";
   std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
   std::list<std::string>::iterator it = aLtAttributes.begin();
@@ -41,6 +41,7 @@ bool Model_FeatureValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& th
         myNotObligatory.find(theFeature->getKind());
       if (aFeatureFind == myNotObligatory.end() || // and it is obligatory for filling
           aFeatureFind->second.find(*it) == aFeatureFind->second.end()) {
+        theError = "Attribute \"" + anAttr->id() + "\" is not initialized.";
         return false;
       }
     }
index 8242713d8b579b9592bc8fdf027820988973c684..d0b00ca8e8bff0494247b5cd4af0956a2c650333 100644 (file)
@@ -25,8 +25,15 @@ bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribut
                                                  std::string& theError) const
 {
   AttributeStringPtr aStrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
-  bool result = isVariable(aStrAttr->value()) && isUnique(theAttribute, aStrAttr->value());
-  return result;
+  if (!isVariable(aStrAttr->value())) {
+    theError = "Incorrect variable name.";
+    return false;
+  } 
+  if (!isUnique(theAttribute, aStrAttr->value())) {
+    theError = "Variable name is not unique.";
+    return false;
+  }
+  return true;
 }
 
 bool ParametersPlugin_VariableValidator::isVariable(const std::string& theString) const
@@ -84,13 +91,18 @@ bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttrib
       std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aFeature->firstResult());
 
   AttributeStringPtr aStrAttr =
-    std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+      std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
   bool isEmptyExpr = aStrAttr->value().empty();
-  if(isEmptyExpr)
+  if(isEmptyExpr) {
+    theError = "Expression is empty.";
     return false;
+  }
 
-  if(!aParam.get())
+  if(!aParam.get()) {
+    theError = "Result is empty.";
     return false;
+  }
 
+  theError = aFeature->error();
   return aFeature->error().empty();
 }