예제 #1
0
   const dtDAL::ObjectType* AIPluginInterface::GetWaypointTypeByName( const std::string& name ) const
   {
      typedef std::vector<dtCore::RefPtr<const dtDAL::ObjectType> > ObjectTypeArray;

      ObjectTypeArray waypointTypes;
      GetSupportedWaypointTypes(waypointTypes);

      ObjectTypeArray::iterator ob_iter = waypointTypes.begin();
      ObjectTypeArray::iterator ob_iterEnd = waypointTypes.end();

      for(;ob_iter != ob_iterEnd; ++ob_iter)
      {
         if((**ob_iter).GetName() == name)
         {
            return (*ob_iter).get();
         }
      }

      return NULL;
   }
예제 #2
0
//------------------------------------------------------------------------------
// void SaveData()
//------------------------------------------------------------------------------
void AchievePanel::SaveData()
{   
   #if DEBUG_ACHIEVE_PANEL_SAVE
   MessageInterface::ShowMessage
      ("AchievePanel::SaveData() entered, mIsTextModified=%d\n", mIsTextModified);
   #endif
   
   canClose = true;
   std::string inputString;
   
   //-----------------------------------------------------------------
   // check input values: Number, Variable, Array element, Parameter
   //-----------------------------------------------------------------
   if (mIsTextModified)
   {
      ObjectTypeArray objTypes;
      objTypes.push_back(Gmat::SPACE_POINT);
      objTypes.push_back(Gmat::IMPULSIVE_BURN);

      inputString = mGoalValue.c_str();
      CheckVariable(mGoalValue.c_str(), objTypes, "GoalValue",
                    "Real Number, Variable, Array element, plottable Parameter", true);
      
      inputString = mToleranceTextCtrl->GetValue();
      CheckVariable(inputString.c_str(), objTypes, "Tolerance",
                    "Real Number, Variable, Array element, plottable Parameter", true);
   }
   
   if (!canClose)
      return;
   
   //-------------------------------------------------------
   // Saving Solver Data
   //-------------------------------------------------------
   try
   {
      #if DEBUG_ACHIEVE_PANEL_SAVE
      MessageInterface::ShowMessage("   Setting Solver to '%s'\n", mSolverName.c_str());
      #endif
      
      mAchieveCommand->SetStringParameter
         (mAchieveCommand->GetParameterID("TargeterName"), mSolverName.c_str());
      
      if (mIsTextModified)
      {
         #if DEBUG_ACHIEVE_PANEL_SAVE
         MessageInterface::ShowMessage
            ("   Setting Goal to '%s', Value to '%s', Tolerance to '%s'\n",
             mGoalName.c_str(), mGoalValue.c_str(), mTolerance.c_str());
         #endif
         
         mAchieveCommand->SetStringParameter
            (mAchieveCommand->GetParameterID("Goal"), mGoalName.c_str());
         
         mAchieveCommand->SetStringParameter
            (mAchieveCommand->GetParameterID("GoalValue"), mGoalValue.c_str());
         
         mTolerance = mToleranceTextCtrl->GetValue();      
         mAchieveCommand->SetStringParameter
            (mAchieveCommand->GetParameterID("Tolerance"), mTolerance.c_str());
         
         mIsTextModified = false;
         
         #if DEBUG_ACHIEVE_PANEL_SAVE
         MessageInterface::ShowMessage("   Calling theGuiInterpreter->ValidateCommand()\n");
         #endif
         
         if (!theGuiInterpreter->ValidateCommand(mAchieveCommand))
         {
            #if DEBUG_ACHIEVE_PANEL_SAVE
            MessageInterface::ShowMessage("   Failed to validate command\n");
            #endif
            canClose = false;
         }
      }
   }
   catch (BaseException &e)
   {
      MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage());
      canClose = false;
   }
   
   #if DEBUG_ACHIEVE_PANEL_SAVE
   MessageInterface::ShowMessage
      ("AchievePanel::SaveData() leaving, canClose=%d\n", canClose);
   #endif
}
예제 #3
0
//------------------------------------------------------------------------------
// void SaveData()
//------------------------------------------------------------------------------
void VaryPanel::SaveData()
{   
   #ifdef DEBUG_VARYPANEL_SAVE
   MessageInterface::ShowMessage("VaryPanel::SaveData() entered\n");
   #endif
   
   canClose = true;
   std::string strInitVal, strPert, strLower, strUpper, strMaxStep;
   std::string strAddSf, strMultSf;
   
   //-----------------------------------------------------------------
   // check input values: Number, Variable, Array element, Parameter
   //-----------------------------------------------------------------
   
   std::string expRange = "Real Number, Variable, Array element, Plottable Parameter";
   ObjectTypeArray objTypes;
   objTypes.push_back(Gmat::UNKNOWN_OBJECT);
   
   // Any plottable Parameters allowed, so use UNKNOWN_OBJECT
   if (mInitialTextCtrl->IsModified())
   {
      strInitVal = mInitialTextCtrl->GetValue().c_str();
      CheckVariable(strInitVal, objTypes,
                    "InitialValue", expRange, true);
   }
   
   if (mPertTextCtrl->IsModified())
   {
      strPert = mPertTextCtrl->GetValue().c_str();
      CheckVariable(strPert, objTypes,
                    "Perturbation", expRange, true);
   }
   
   if (mLowerValueTextCtrl->IsModified())
   {
      strLower = mLowerValueTextCtrl->GetValue().c_str();
      CheckVariable(strLower, objTypes,
                    "Lower", expRange, true);
   }
   
   if (mUpperValueTextCtrl->IsModified())
   {
      strUpper = mUpperValueTextCtrl->GetValue().c_str();
      CheckVariable(strUpper.c_str(), objTypes,
                    "Upper", expRange, true);
   }
   
   if (mMaxStepTextCtrl->IsModified())
   {
      strMaxStep = mMaxStepTextCtrl->GetValue().c_str();
      CheckVariable(strMaxStep.c_str(), objTypes,
                    "MaxStep", expRange, true);
   }
   
   if (mAdditiveTextCtrl->IsModified())
   {
      strAddSf = mAdditiveTextCtrl->GetValue().c_str();
      CheckVariable(strAddSf.c_str(), objTypes,
                    "AdditiveScaleFactor", expRange, true);
   }
   
   if (mMultiplicativeTextCtrl->IsModified())
   {
      strMultSf = mMultiplicativeTextCtrl->GetValue().c_str();
      CheckVariable(strMultSf.c_str(), objTypes,
                    "MultiplicativeScaleFactor", expRange, true);
   }
   
   if (!canClose)
      return;
   
   //-----------------------------------------------------------------
   // save values to base, base code should do the range checking
   //-----------------------------------------------------------------
   
   #ifdef DEBUG_VARYPANEL_SAVE
   MessageInterface::ShowMessage("   solverName=%s, variableName=%s\n",
       solverName.c_str(), variableName.c_str());
   #endif
   
   Solver *solver = (Solver*)theGuiInterpreter->GetConfiguredObject(solverName);
   
   if (solver == NULL)
      throw GmatBaseException("Cannot find the solver: " + solverName);
   
   bool validateCommand = false;
   
   try
   {
      bool changed = false;

      if (solverChanged)
      {
         #ifdef DEBUG_VARYPANEL_SAVE
         MessageInterface::ShowMessage
            ("   Solver changed, solver=<%p>'%s'\n", solver, solver->GetName().c_str());
         #endif
         mVaryCommand->SetStringParameter("SolverName", solverName);
         mVaryCommand->SetRefObject(solver, Gmat::SOLVER, solverName);
         solverChanged = false;
         changed = true;
      }
      
      if (variableChanged)
      {
         #ifdef DEBUG_VARYPANEL_SAVE
         MessageInterface::ShowMessage
            ("   Variable changed, variableName='%s'\n", variableName.c_str());
         #endif
         validateCommand = true;
         mVaryCommand->SetStringParameter("Variable", variableName);
         solver->SetStringParameter("Variables", variableName);
         variableChanged = false;
         changed = true;
      }
      
      if (mInitialTextCtrl->IsModified())
      {
         validateCommand = true;
         mVaryCommand->SetStringParameter("InitialValue", strInitVal.c_str());
         mInitialTextCtrl->DiscardEdits();
         changed = true;
      }
      
      if (mPertTextCtrl->IsModified())
      {
         validateCommand = true;
         mVaryCommand->SetStringParameter("Perturbation", strPert.c_str());
         mPertTextCtrl->DiscardEdits();
         changed = true;
      }
      
      if (mLowerValueTextCtrl->IsModified())
      {
         validateCommand = true;
         mVaryCommand->SetStringParameter("Lower", strLower.c_str());
         mLowerValueTextCtrl->DiscardEdits();
         changed = true;
      }
      
      if (mUpperValueTextCtrl->IsModified())
      {
         validateCommand = true;
         mVaryCommand->SetStringParameter("Upper", strUpper.c_str());
         mUpperValueTextCtrl->DiscardEdits();
         changed = true;
      }
      
      if (mMaxStepTextCtrl->IsModified())
      {
         validateCommand = true;
         mVaryCommand->SetStringParameter("MaxStep", strMaxStep.c_str());
         mMaxStepTextCtrl->DiscardEdits();
         changed = true;
      }
      
      if (mAdditiveTextCtrl->IsModified())
      {
         validateCommand = true;
         mVaryCommand->SetStringParameter("AdditiveScaleFactor", strAddSf.c_str());
         mAdditiveTextCtrl->DiscardEdits();
         changed = true;
      }
      
      if (mMultiplicativeTextCtrl->IsModified())
      {
         validateCommand = true;
         mVaryCommand->SetStringParameter("MultiplicativeScaleFactor", strMultSf.c_str());
         mMultiplicativeTextCtrl->DiscardEdits();
         changed = true;
      }
      
      if (changed)
         mVaryCommand->SetRefObject(solver, Gmat::SOLVER, solverName);


      // avoid unnecessary validation since it clears all wrappers and recreates them
      if (validateCommand)
      {
         #ifdef DEBUG_VARYPANEL_SAVE
         MessageInterface::ShowMessage("   Calling ValidateCommand()\n");
         #endif
         
         if (!theGuiInterpreter->ValidateCommand(mVaryCommand))
            canClose = false;
      }
      
   }
   catch (BaseException &e)
   {
      MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage());
      canClose = false;
   }
   
   #ifdef DEBUG_VARYPANEL_SAVE
   MessageInterface::ShowMessage("VaryPanel::SaveData() leaving\n");
   #endif
}
예제 #4
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;
}
예제 #5
0
//------------------------------------------------------------------------------
void ForPanel::SaveData()
{
   #if DEBUG_FOR_PANEL_SAVE
   MessageInterface::ShowMessage("ForPanel::SaveData() entered\n");
   #endif
   
   canClose = true;
   ObjectTypeArray objTypes;
   objTypes.push_back(Gmat::SPACE_POINT);
   objTypes.push_back(Gmat::IMPULSIVE_BURN);
   
   //-----------------------------------------------------------------
   // check input values: Number, Variable, Array element, Parameter
   //-----------------------------------------------------------------
   CheckVariable(mIndexString.c_str(), objTypes, "Index",
                 "Variable", false);
   CheckVariable(mStartString.c_str(), objTypes, "Start",
                 "Real Number, Variable, Array element, plottable Parameter", true);
   CheckVariable(mIncrString.c_str(), objTypes, "Increment",
                 "Real Number, Variable, Array element, plottable Parameter", true);
   CheckVariable(mEndString.c_str(), objTypes, "End",
                 "Real Number, Variable, Array element, plottable Parameter", true);
   
   if (!canClose)
   {
      #if DEBUG_FOR_PANEL_SAVE
      MessageInterface::ShowMessage("ForPanel::SaveData() leaving, error encountered\n");
      #endif
      return;
   }

   
   //-----------------------------------------------------------------
   // save values to base, base code should do the range checking
   //-----------------------------------------------------------------
   try
   {
      // Since validation is not done until element wrappers are created,
      // need to create a clone
      For *clonedForCommand = (For*)theForCommand->Clone();
      
      Integer paramId;
      paramId = clonedForCommand->GetParameterID("IndexName");
      clonedForCommand->SetStringParameter(paramId, mIndexString.c_str());
      
      paramId = clonedForCommand->GetParameterID("StartName");
      clonedForCommand->SetStringParameter(paramId, mStartString.c_str());
      
      paramId = clonedForCommand->GetParameterID("EndName");
      clonedForCommand->SetStringParameter(paramId, mEndString.c_str());
      
      paramId = clonedForCommand->GetParameterID("IncrementName");
      clonedForCommand->SetStringParameter(paramId, mIncrString.c_str());
      
      bool contOnError = theGuiInterpreter->GetContinueOnError();
      theGuiInterpreter->SetContinueOnError(false);
      if (!theGuiInterpreter->ValidateCommand(clonedForCommand))
         canClose = false;
      theGuiInterpreter->SetContinueOnError(contOnError);
      
      // Copy cloned command to original and validate if cloned validation was successful
      if (canClose)
      {
         #if DEBUG_FOR_PANEL_SAVE
         MessageInterface::ShowMessage
            ("   Copying cloned <%p> to original <%p>, and validating command to create wrppers\n",
             clonedForCommand, theForCommand);
         #endif
         theForCommand->Copy(clonedForCommand);
         theGuiInterpreter->ValidateCommand(theForCommand);
      }
      
      delete clonedForCommand;
   }
   catch (BaseException &e)
   {
      MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage());
      canClose = false;
   }
   
   #if DEBUG_FOR_PANEL_SAVE
   MessageInterface::ShowMessage("ForPanel::SaveData() leaving, canClose=%d\n", canClose);
   #endif
}