Example #1
0
//------------------------------------------------------------------------------
bool UserInputValidator::CheckFileName(const std::string &str,
                                       const std::string &field, bool onlyMsg)
{
   if (onlyMsg)
   {
      std::string msg = GmatFileUtil::GetInvalidFileNameMessage(1);
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), str.c_str(), field.c_str(), "",
          msg.c_str());
      
      SetErrorFlag();
      return false;
   }

   // We don't want allow blank file name so pass false
   if (!GmatFileUtil::IsValidFileName(str, false))
   {
      std::string msg = GmatFileUtil::GetInvalidFileNameMessage(1);
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), str.c_str(), field.c_str(), "",
          msg.c_str());
      
      SetErrorFlag();
      return false;
   }
   
   return true;
}
Example #2
0
//------------------------------------------------------------------------------
bool UserInputValidator::CheckTimeFormatAndValue(const std::string &format, const std::string& value,
                                                 const std::string &field,  bool checkRange)
{
   std::string timeFormat = "ModJulian";
   if (format.find("Gregorian") != format.npos)
      timeFormat = "Gregorian";

   std::string expRange;
   try
   {
      TimeConverterUtil::ValidateTimeFormat(format, value, false);
   }
   catch (BaseException &)
   {
      if (timeFormat == "Gregorian")
      {
         expRange = "DD Mon YYYY HH:MM:SS.sss";
      }
      else
      {
         expRange = "Real Number";
      }
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), value.c_str(), field.c_str(), "",
          expRange.c_str());
      SetErrorFlag();
      return false;
   }
   if (checkRange)
   {
      try
      {
         TimeConverterUtil::ValidateTimeFormat(format, value, true);
      }
      catch (BaseException &)
      {
         std::string expRange = "";
         if (timeFormat == "Gregorian")
         {
            expRange = "\"" + DateUtil::EARLIEST_VALID_GREGORIAN;
            expRange += "\" to \"" + DateUtil::LATEST_VALID_GREGORIAN;
            expRange += "\"";
         }
         else
         {
            expRange = DateUtil::EARLIEST_VALID_MJD;
            expRange += " <= Real Number <= " + DateUtil::LATEST_VALID_MJD;
         }
         MessageInterface::PopupMessage
            (Gmat::ERROR_, mMsgFormat.c_str(), value.c_str(), field.c_str(), "",
             expRange.c_str());
         SetErrorFlag();
         return false;
       }
   }
   return true;
}
Example #3
0
//------------------------------------------------------------------------------
bool UserInputValidator::CheckReal(Real &rvalue, const std::string &str,
                          const std::string &field, const std::string &expRange,
                          bool onlyMsg, bool checkRange, bool positive, bool zeroOk)
{
   #ifdef DEBUG_CHECK_REAL
   MessageInterface::ShowMessage
      ("UserInputValidator::CheckReal() str='%s', field='%s', expRange='%s'\n", str.c_str(),
       field.c_str(), expRange.c_str());
   #endif
   
   if (onlyMsg)
   {
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), str.c_str(), field.c_str(), "",
          expRange.c_str());

      SetErrorFlag();
      return false;
   }
   
   // check for real value
   Real rval;
   if (GmatStringUtil::ToReal(str, &rval, false, false))
   {
      rvalue = rval;
      #ifdef DEBUG_CHECK_REAL
      MessageInterface::ShowMessage
         ("UserInputValidator::CheckReal() rval = %12.10f\n", rval);
      #endif
      
      if (checkRange)
      {
         if (!positive || (positive && rval > 0) || (zeroOk && rval >= 0))
            return true;
      }
      else
         return true;
   }
   
   #ifdef DEBUG_CHECK_REAL
   MessageInterface::ShowMessage
      ("UserInputValidator::CheckReal() NOT a valid real number\n");
   #endif
   MessageInterface::PopupMessage
      (Gmat::ERROR_, mMsgFormat.c_str(), str.c_str(), field.c_str(), "",
       expRange.c_str());
   
   SetErrorFlag();
   return false;
}
Example #4
0
//------------------------------------------------------------------------------
bool UserInputValidator::CheckIntegerRange(Integer &ivalue, const std::string &str, 
                                           const std::string &field, Integer lower,
                                           Integer upper, bool checkLower, bool checkUpper,
                                           bool includeLower, bool includeUpper)
{
   Integer ival;
   if (GmatStringUtil::ToInteger(str, &ival, false, false))
   {
      Real rval = (Real)ival;
      
      bool retval = CheckRealRange(str, rval, field, lower, upper, checkLower,
                                   checkUpper, includeLower, includeUpper, true);
      if (retval)
         ivalue = ival;
      
      return retval;
   }
   
   std::string expRange = "Integer";
   MessageInterface::PopupMessage
      (Gmat::ERROR_, mMsgFormat.c_str(), str.c_str(), field.c_str(), "",
       expRange.c_str());
   
   SetErrorFlag();
   return false;
}
Example #5
0
//------------------------------------------------------------------------------
bool UserInputValidator::IsValidName(const wxString &name)
{
   if (name == "")
   {
      MessageInterface::PopupMessage
         (Gmat::ERROR_, "The name is blank, please enter a valid name");
      
      SetErrorFlag();
      return false;
   }
   
   if (!GmatStringUtil::IsValidName(name.c_str()))
   {
      std::string format = GmatStringUtil::GetInvalidNameMessageFormat();
      MessageInterface::PopupMessage
         (Gmat::ERROR_, format.c_str(), name.c_str());
      
      SetErrorFlag();
      return false;
   }
   
   return true;
}
Example #6
0
//------------------------------------------------------------------------------
bool UserInputValidator::CheckInteger(Integer &ivalue, const std::string &str,
                                      const std::string &field,
                                      const std::string &expRange, bool onlyMsg,
                                      bool checkRange, bool positive, bool zeroOk)
{
   if (onlyMsg)
   {
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), str.c_str(), field.c_str(), "",
          expRange.c_str());
      
      SetErrorFlag();
      return false;
   }
   
   // check for integer value
   Integer ival;
   if (GmatStringUtil::ToInteger(str, &ival, false, false))
   {
      ivalue = ival;

      if (checkRange)
      {
         if (!positive || (positive && ival > 0) || (zeroOk && ival >= 0))
            return true;
      }
      else
         return true;
   }
   
   MessageInterface::PopupMessage
      (Gmat::ERROR_, mMsgFormat.c_str(), str.c_str(), field.c_str(), "",
       expRange.c_str());
   
   SetErrorFlag();
   return false;
}
Example #7
0
//------------------------------------------------------------------------------
bool UserInputValidator::CheckRealRange(const std::string &sValue,
                                        Real value,        const std::string &field,
                                        Real lower,        Real upper,
                                        bool checkLower,   bool checkUpper,
                                        bool includeLower, bool includeUpper,
                                        bool isInteger)
{
   if ((!checkLower) && (!checkUpper)) return true;
   
   if (checkLower && checkUpper)
   {
      if ((value > lower) && (value < upper))                  return true;
      if (includeLower && GmatMathUtil::IsEqual(value, lower)) return true;
      if (includeUpper && GmatMathUtil::IsEqual(value, upper)) return true;
   }
   else if (checkLower)
   {
      if (value > lower) return true;
      if (includeLower && GmatMathUtil::IsEqual(value, lower)) return true;
   }
   else // checkUpper only
   {
      if (value < upper) return true;
      if (includeUpper && GmatMathUtil::IsEqual(value, upper)) return true;
   }

   std::string inputType = "Real Number";
   if (isInteger)
      inputType = "Integer Number";
   
   // range check failed; generate error message
   std::stringstream ss("");
   if (checkLower && checkUpper)
   {
      ss << lower;
      if (includeLower) ss << lessOrEq;
      else              ss << lessThan;
      ss << inputType;
      if (includeUpper) ss << lessOrEq;
      else              ss << lessThan;
      ss << upper;
   }
   else if (checkLower)
   {
      ss << inputType;
      if (includeLower) ss << moreOrEq;
      else              ss << moreThan;
      ss << lower;
   }
   else if (checkUpper)
   {
      ss << inputType;
      if (includeUpper) ss << lessOrEq;
      else              ss << lessThan;
      ss << upper;
   }

   std::string expRange = ss.str();
   MessageInterface::PopupMessage
      (Gmat::ERROR_, mMsgFormat.c_str(), sValue.c_str(), field.c_str(), "",
       expRange.c_str());

   SetErrorFlag();
   return false;
}
Example #8
0
//------------------------------------------------------------------------------
bool UserInputValidator::CheckVariable(const std::string &varName, ObjectTypeArray ownerTypes,
                                       const std::string &field, const std::string &expRange,
                                       bool allowNumber, bool allowNonPlottable,
                                       bool allowObjectProperty, bool allowWholeArray)
{
   #ifdef DEBUG_CHECK_VARIABLE
   MessageInterface::ShowMessage
      ("UserInputValidator::CheckVariable() entered, varName='%s', ownerTypes[0]=%d, field='%s'\n"
       "   expRange='%s'\n   allowNumber=%d, allowNonPlottable=%d, allowObjectProperty=%d, "
       "allowWholeArray=%d\n", varName.c_str(), ownerTypes.at(0), field.c_str(), expRange.c_str(),
       allowNumber, allowNonPlottable, allowObjectProperty, allowWholeArray);
   #endif
   
   if (mGuiManager == NULL)
   {
      MessageInterface::ShowMessage
         ("UserInputValidator::CheckVariable() mGuiManager is NULL\n");
      return false;
   }
   
   int retval = -1;
   try
   {
      for (unsigned int ii = 0; ii < ownerTypes.size(); ii++)
      {
         retval = mGuiManager->
            IsValidVariable(varName.c_str(), ownerTypes.at(ii), allowNumber, allowNonPlottable,
                            allowObjectProperty, allowWholeArray);
         if (retval != 0) break;
      }
   }
   catch (BaseException &e)
   {
      MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage());
      SetErrorFlag();
      return false;
   }
   
   if (retval == -1)
   {
      std::string lastMsg = mGuiManager->GetLastErrorMessage().c_str();
      lastMsg = " - " + lastMsg;
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), varName.c_str(), field.c_str(),
          lastMsg.c_str(), expRange.c_str());
      
      mGuiManager->SetLastErrorMessage("");
      SetErrorFlag();
      return false;
   }
   else if (retval == 3)
   {
      std::string type, ownerName, depObj;
      GmatStringUtil::ParseParameter(varName, type, ownerName, depObj);
      
      MessageInterface::PopupMessage
         (Gmat::ERROR_, "The value of \"%s\" for field \"%s\" "
          "has undefined object \"%s\".\nPlease create proper object first "
          "from the Resource Tree.\n", varName.c_str(), field.c_str(), ownerName.c_str());
      
      SetErrorFlag();
      return false;
   }
   else if (retval == 4)
   {
      std::string type, ownerName, depObj;
      GmatStringUtil::ParseParameter(varName, type, ownerName, depObj);
      
      MessageInterface::PopupMessage
         (Gmat::ERROR_, "The value \"%s\" for field \"%s\" "
          "has unknown Parameter type \"%s\".\n", varName.c_str(), field.c_str(),
          type.c_str());
      
      SetErrorFlag();
      return false;
   }
   else if (retval == 5)
   {
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), varName.c_str(), field.c_str(),
          " - invalid array index", expRange.c_str());
      
      SetErrorFlag();
      return false;
   }
   else if (retval == 6)
   {
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), varName.c_str(), field.c_str(),
          " - invalid object field", expRange.c_str());
      
      SetErrorFlag();
      return false;
   }
   else if (retval == 0)
   {
      MessageInterface::PopupMessage
         (Gmat::ERROR_, mMsgFormat.c_str(), varName.c_str(), field.c_str(), "",
          expRange.c_str());
      
      SetErrorFlag();
      return false;
   }
   
   return true;
}
Example #9
0
void
SetupWizard::ReportError (/*[in]*/ const exception & e)
{
  SetErrorFlag ();
  ::ReportError (e);
}