コード例 #1
0
//------------------------------------------------------------------------------
bool BeginScript::RenameRefObject(const Gmat::ObjectType type,
                                  const wxString &oldName,
                                  const wxString &newName)
{   
   GmatCommand *current = next;
   
   while (current != NULL)
   {
      #if DEBUG_RENAME
      MessageInterface::ShowMessage
         (wxT("BeginScript::RenameRefObject() current=%s\n"),
          current->GetTypeName().c_str());
      #endif
      
      if (current->GetTypeName() != wxT("EndScript"))
      {
         current->RenameRefObject(type, oldName, newName);
         current = current->GetNext();
      }
      else
      {
         current = NULL;
      }
   }
   
   return true;
}
コード例 #2
0
//------------------------------------------------------------------------------
PropSetup *GetFirstPropagator(GmatCommand *cmd)
{
   static PropSetup *retval = NULL;
   GmatCommand *current = cmd;

   #ifdef DEBUG_ODE_SEARCH
      extraMsg = "Commands checked:\n";
   #endif
   while (current != NULL)
   {
      #ifdef DEBUG_ODE_SEARCH
            extraMsg += "   '" + current->GetTypeName() + "'\n";
      #endif
      if (current->GetTypeName() == "Propagate")
      {
         try
         {
            // Set all of the internal connections
//               current->TakeAction("PrepareToPropagate");
            current->Execute();
         }
         catch (BaseException &ex)
         {
            lastMsg = ex.GetFullMessage();
         }
         #ifdef DEBUG_ODE_SEARCH
            extraMsg += "      Checking in this command\n";
         #endif
         GmatBase *obj = current->GetRefObject(Gmat::PROP_SETUP, "", 0);

         #ifdef DEBUG_ODE_SEARCH
            if (obj != NULL)
               extraMsg += "      Found an object of type PROPSETUP\n";
            else
               extraMsg += "      Propagate command returns NULL PROPSETUP\n";
         #endif

         if (obj->IsOfType("PropSetup"))
         {
            retval = (PropSetup*)(obj);
            break;
         }
      }

      current = current->GetNext();
   }

   return retval;
}
コード例 #3
0
bool PrintUtility::PrintBranch(GmatCommand* brCmd, Integer level)
{
   GmatCommand* current = brCmd;
   Integer childNo = 0;
   GmatCommand* nextInBranch;
   GmatCommand* child;
   
   while((child = current->GetChildCommand(childNo))!=NULL)
   {
      nextInBranch = child;
      while ((nextInBranch != NULL) && (nextInBranch != current))
      {
         cout << _T("   ");
         for (int i = 0; i <= level ; i++)
            cout << _T("...");
         cout << _T(" branch ") << childNo << _T("::") << nextInBranch->GetTypeName() << endl;
         if (nextInBranch->GetChildCommand() != NULL)
         {
            PrintBranch(nextInBranch, level+1);
         }
         nextInBranch = nextInBranch->GetNext();
      }
      ++childNo;
   }
   
   return true;
}
コード例 #4
0
   //---------------------------------------------------------------------------
   int FindOdeModel(const char* modelName)
   {
      #ifdef DEBUG_INTERFACE_FROM_MATLAB
         fprintf(fp, "Looking for ODE model '%s'\n", modelName);
      #endif
      int retval = -1;
      ode = NULL;
      pSetup = NULL;
      lastMsg = "";

      // First see if it has been located before
      if (odeNameTable.find(modelName) != odeNameTable.end())
      {
         ode = odeTable[odeNameTable[modelName]];
         pSetup = setupTable[odeNameTable[modelName]];
         extraMsg = ode->GetName().c_str();

         lastMsg = "ODE Model \"";
         lastMsg += extraMsg;
         lastMsg += "\" was previously located";

         return odeNameTable[modelName];
      }
      else if ((odeTable.size() > 0) && (strcmp(modelName, "") == 0))
      {
         // If no name specified, return first one in table if there is an entry
         ode = odeTable.begin()->second;
         extraMsg = ode->GetName().c_str();
         pSetup = setupTable.begin()->second;

         lastMsg = "Unnamed model; using ODE Model \"";
         lastMsg += ode->GetName();
         lastMsg += "\" previously located";

         return 0;
      }

      Moderator *theModerator = Moderator::Instance();
      if (theModerator == NULL)
      {
         lastMsg = "Cannot find the Moderator";
         return retval;
      }

      GmatCommand *current = theModerator->GetFirstCommand(1);
      #ifdef DEBUG_INTERFACE_FROM_MATLAB
         fprintf(fp, "FirstCommand: <%p> of type %s\n", current,
               current->GetTypeName().c_str());
      #endif

      int modelIndex = GetODEModel(&current, modelName);

      if (ode != NULL)
         retval = modelIndex;
      else
         retval = -2;
   
      return retval;
   }
コード例 #5
0
//------------------------------------------------------------------------------
bool GmatCommandUtil:: HasCommandSequenceChanged(GmatCommand *cmd)
{
   if (cmd == NULL)
      return false;
   
   GmatCommand *current = cmd;
   std::string cmdstr = cmd->GetTypeName();
   
   #ifdef DEBUG_COMMAND_CHANGED
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::HasCommandSequenceChanged() entered, "
       "cmd=<%p><%s>\n", cmd, cmdstr.c_str());
   #endif
   
   
   while (current != NULL)
   {
      cmdstr = "--- " + current->GetTypeName() + "\n";
      
      #ifdef DEBUG_COMMAND_CHANGED
      MessageInterface::ShowMessage(cmdstr);
      #endif
      
      if (current->HasConfigurationChanged())
      {
         #ifdef DEBUG_COMMAND_CHANGED
         MessageInterface::ShowMessage
            ("CommandUtil::HasCommandSequenceChanged() returning true\n");
         #endif
         return true;
      }
      
      // go through sub commands
      if ((current->GetChildCommand(0)) != NULL)
      {
         if (HasBranchCommandChanged(current, 0))
         {
            #ifdef DEBUG_COMMAND_CHANGED
            MessageInterface::ShowMessage
               ("CommandUtil::HasCommandSequenceChanged() returning true\n");
            #endif
            
            return true;
         }
      }
      
      current = current->GetNext();
   }
   
   #ifdef DEBUG_COMMAND_CHANGED
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::HasCommandSequenceChanged() returning false\n");
   #endif
   return false;
}
コード例 #6
0
//------------------------------------------------------------------------------
bool GmatCommandUtil::IsElseFoundInIf(GmatCommand *ifCmd)
{
   if (ifCmd == NULL)
      return false;
   
   #ifdef DEBUG_IF_ELSE
   ShowCommand
      ("===> GmatCommandUtil::IsElseFoundInIf() ifCmd = ", ifCmd);
   #endif
   
   if (!ifCmd->IsOfType("If"))
   {
      #ifdef DEBUG_IF_ELSE
      MessageInterface::ShowMessage
         ("IsElseFoundInIf() returning false, it is not If command\n");
      #endif
      return false;
   }
   
   GmatCommand *current = ifCmd;
   GmatCommand *child = NULL;
   Integer branch = 0;
   
   // Check only one level first branch
   child = current->GetChildCommand(branch);
   
   while (child != NULL)
   {
      #ifdef DEBUG_IF_ELSE
      ShowCommand("   child = ", child);
      #endif
      
      if (child->IsOfType("BranchEnd"))
      {
         if (child->GetTypeName() == "Else")
         {
            #ifdef DEBUG_IF_ELSE
            MessageInterface::ShowMessage("IsElseFoundInIf() returning true\n");
            #endif
            return true;
         }            
         break;
      }
      
      child = child->GetNext();
   }
   
   #ifdef DEBUG_IF_ELSE
   MessageInterface::ShowMessage("IsElseFoundInIf() returning false\n");
   #endif
   
   return false;
}
コード例 #7
0
//------------------------------------------------------------------------------
// bool SetBranchCommandChanged(GmatCommand *brCmd, Integer level)
//------------------------------------------------------------------------------
bool GmatCommandUtil::HasBranchCommandChanged(GmatCommand *brCmd, Integer level)
{
   GmatCommand* current = brCmd;
   Integer childNo = 0;
   GmatCommand* nextInBranch = NULL;
   GmatCommand* child;
   std::string cmdstr;
   
   while((child = current->GetChildCommand(childNo)) != NULL)
   {
      nextInBranch = child;
      
      while ((nextInBranch != NULL) && (nextInBranch != current))
      {         
         #ifdef DEBUG_COMMAND_CHANGED
         for (int i=0; i<=level; i++)
            cmdstr = "---" + cmdstr;         
         cmdstr = "--- " + nextInBranch->GetTypeName() + "\n";        
         MessageInterface::ShowMessage("%s", cmdstr.c_str());
         #endif
         
         if (nextInBranch->HasConfigurationChanged())
         {
            #ifdef DEBUG_COMMAND_CHANGED
            MessageInterface::ShowMessage
               ("CommandUtil::HasBranchCommandChanged() returning true\n");
            #endif
            return true;
         }
         
         if (nextInBranch->GetChildCommand() != NULL)
            if (HasBranchCommandChanged(nextInBranch, level+1))
            {
               #ifdef DEBUG_COMMAND_CHANGED
               MessageInterface::ShowMessage
                  ("CommandUtil::HasBranchCommandChanged() returning true\n");
               #endif
               return true;
            }
         nextInBranch = nextInBranch->GetNext();
      }
      
      ++childNo;
   }
   
   #ifdef DEBUG_COMMAND_CHANGED
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::HasBranchCommandChanged() returning false\n");
   #endif
   return false;
}
コード例 #8
0
bool PrintUtility::PrintEntireSequence(GmatCommand* firstCmd)
{
   cout << _T(".................... Print out the whole sequence ........................................") << endl;
   GmatCommand *current = firstCmd;
   while (current != NULL)
   {
      cout << _T("   Command::") << current->GetTypeName() << endl;
      if ((current->GetChildCommand(0))!=NULL)
         PrintBranch(current, 0);
      current = current->GetNext();
   }
   cout << _T(".................... End sequence ........................................................") << endl;
   return true;
}
コード例 #9
0
//------------------------------------------------------------------------------
// void Finalize()
//------------------------------------------------------------------------------
void GmatFunction::Finalize()
{
   #ifdef DEBUG_TRACE
   static Integer callCount = 0;
   callCount++;      
   clock_t t1 = clock();
   ShowTrace(callCount, t1, wxT("GmatFunction::Finalize() entered"));
   #endif
   
   #ifdef DEBUG_FUNCTION_FINALIZE
   MessageInterface::ShowMessage
      (wxT("======================================================================\n")
       wxT("GmatFunction::Finalize() entered for '%s', FCS %s\n"),
       functionName.c_str(), fcsFinalized ? wxT("already finalized, so skp fcs") :
       wxT("NOT finalized, so call fcs->RunComplete"));
   #endif
   
   // Call RunComplete on each command in fcs
   if (!fcsFinalized)
   {
      fcsFinalized = true;
      GmatCommand *current = fcs;
      while (current)
      {
         #ifdef DEBUG_FUNCTION_FINALIZE
            if (!current)
               MessageInterface::ShowMessage
                  (wxT("   GmatFunction:Finalize() Current is NULL!!!\n"));
            else
               MessageInterface::ShowMessage
                  (wxT("   GmatFunction:Finalize() Now about to finalize ")
                   wxT("(call RunComplete on) command %s\n"),
                   (current->GetTypeName()).c_str());
         #endif
         current->RunComplete();
         current = current->GetNext();
      }
   }
   
   Function::Finalize();
   
   #ifdef DEBUG_FUNCTION_FINALIZE
   MessageInterface::ShowMessage(wxT("GmatFunction::Finalize() leaving\n"));
   #endif
   
   #ifdef DEBUG_TRACE
   ShowTrace(callCount, t1, wxT("GmatFunction::Finalize() exiting"), true, true);
   #endif
   
}
コード例 #10
0
   //---------------------------------------------------------------------------
   const char *GetRunSummary()
   {
      Moderator *theModerator = Moderator::Instance();
      if (theModerator == NULL)
      {
         lastMsg = "Cannot find the Moderator";
         return "Error accessing the Moderator";
      }

      GmatCommand *current = theModerator->GetFirstCommand(1);
      lastMsg = "";
      while (current != NULL)
      {
         if (current->GetTypeName() != "NoOp")
         {
            lastMsg += current->GetStringParameter("Summary");
            lastMsg += "\n-----------------------------------\n";
         }
         current = current->GetNext();
      }

      return lastMsg.c_str();
   }
コード例 #11
0
//------------------------------------------------------------------------------
// void ResetBranchCommandChanged(GmatCommand *brCmd, Integer level)
//------------------------------------------------------------------------------
void GmatCommandUtil::ResetBranchCommandChanged(GmatCommand *brCmd, Integer level)
{
   GmatCommand* current = brCmd;
   Integer childNo = 0;
   GmatCommand* nextInBranch = NULL;
   GmatCommand* child;
   std::string cmdstr;
   
   while((child = current->GetChildCommand(childNo)) != NULL)
   {
      nextInBranch = child;
      
      while ((nextInBranch != NULL) && (nextInBranch != current))
      {         
         #ifdef DEBUG_COMMAND_CHANGED
         for (int i=0; i<=level; i++)
            cmdstr = "---" + cmdstr;         
         cmdstr = "--- " + nextInBranch->GetTypeName() + "\n";        
         MessageInterface::ShowMessage("%s", cmdstr.c_str());
         #endif
         
         nextInBranch->ConfigurationChanged(false);
         
         if (nextInBranch->GetChildCommand() != NULL)
            ResetBranchCommandChanged(nextInBranch, level+1);
         
         nextInBranch = nextInBranch->GetNext();
      }
      
      ++childNo;
   }
   
   #ifdef DEBUG_COMMAND_CHANGED
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::ResetBranchCommandChanged() leaving\n");
   #endif
}
コード例 #12
0
//------------------------------------------------------------------------------
// void ResetCommandSequenceChanged(GmatCommand *cmd)
//------------------------------------------------------------------------------
void GmatCommandUtil::ResetCommandSequenceChanged(GmatCommand *cmd)
{
   if (cmd == NULL)
      return;
   
   GmatCommand *current = cmd;
   std::string cmdstr = cmd->GetTypeName();
   
   #ifdef DEBUG_COMMAND_CHANGED
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::ResetCommandSequenceChanged() entered, "
       "cmd=<%p><%s>\n", cmd, cmdstr.c_str());
   #endif
   
   while (current != NULL)
   {
      cmdstr = "--- " + current->GetTypeName() + "\n";
      
      #ifdef DEBUG_COMMAND_CHANGED
      MessageInterface::ShowMessage(cmdstr);
      #endif
      
      current->ConfigurationChanged(false);
      
      // go through sub commands
      if ((current->GetChildCommand(0)) != NULL)
         ResetBranchCommandChanged(current, 0);
      
      current = current->GetNext();
   }
   
   #ifdef DEBUG_COMMAND_CHANGED
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::ResetCommandSequenceChanged() leaving\n");
   #endif
}
コード例 #13
0
//------------------------------------------------------------------------------
bool GmatCommandUtil::FindObjectFromSubCommands(GmatCommand *brCmd, Integer level,
                         Gmat::ObjectType objType, const std::string &objName,
                         std::string &cmdName, GmatCommand **cmdUsing, bool checkWrappers)
{
   GmatCommand* current = brCmd;
   Integer      childNo = 0;
   GmatCommand* nextInBranch = NULL;
   GmatCommand* child;
   std::string  cmdstr;
   
   while((child = current->GetChildCommand(childNo)) != NULL)
   {
      nextInBranch = child;
      
      while ((nextInBranch != NULL) && (nextInBranch != current))
      {         
         #ifdef DEBUG_COMMAND_FIND_OBJECT
         for (int i=0; i<=level; i++)
            cmdstr = "---" + cmdstr;         
         cmdstr = "--- " + nextInBranch->GetTypeName() + "\n";        
         MessageInterface::ShowMessage("%s", cmdstr.c_str());
         #endif
         
         try
         {
            StringArray names = nextInBranch->GetRefObjectNameArray(objType);
            
            for (UnsignedInt i=0; i<names.size(); i++)
            {
               #ifdef DEBUG_COMMAND_FIND_OBJECT
               MessageInterface::ShowMessage("names[%d]=%s\n", i, names[i].c_str());
               #endif
               
               if (names[i] == objName)
               {
                  cmdName   = nextInBranch->GetTypeName();
                  *cmdUsing = nextInBranch;
                  #ifdef DEBUG_COMMAND_FIND_OBJECT
                  MessageInterface::ShowMessage
                     ("CommandUtil::FindObjectFromSubCommands() returning true, "
                      "cmdName='%s', cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                      (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
                  #endif
                  return true;
               }
            }
         }
         catch (BaseException &e)
         {
            // Use exception to remove Visual C++ warning
            e.GetMessageType();
            #ifdef DEBUG_COMMAND_FIND_OBJECT
            MessageInterface::ShowMessage("*** INTERNAL WARNING *** " + e.GetFullMessage());
            #endif
         }
         
         if (nextInBranch->GetChildCommand() != NULL)
            if (FindObjectFromSubCommands(nextInBranch, level+1, objType, objName, cmdName,
                                          cmdUsing, checkWrappers))
            {
               #ifdef DEBUG_COMMAND_FIND_OBJECT
               MessageInterface::ShowMessage
                  ("CommandUtil::FindObjectFromSubCommands() returning true, "
                   "cmdName='%s', cmdUsing=<%p>'%s'\n", cmdName.c_str(), cmdUsing,
                   (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               #endif
               return true;
            }

         // Check for references in the wrappers, if requested
         if (checkWrappers)
         {
            if (nextInBranch->HasOtherReferenceToObject(objName))
            {
               cmdName   = nextInBranch->GetTypeName();
               *cmdUsing = nextInBranch;
               #ifdef DEBUG_COMMAND_FIND_OBJECT
               MessageInterface::ShowMessage
                  ("CommandUtil::FindObjectFromSubCommands() returning true (for wrappers), cmdName='%s', "
                   "cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                   (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               #endif
               return true;
            }
         }
         nextInBranch = nextInBranch->GetNext();
      }
      
      ++childNo;
   }
   
   #ifdef DEBUG_COMMAND_FIND_OBJECT
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::FindObjectFromSubCommands() returning false\n");
   #endif
   return false;
}
コード例 #14
0
//------------------------------------------------------------------------------
bool GmatCommandUtil::ClearCommandSeq(GmatCommand *seq, bool leaveFirstCmd,
                                      bool callRunComplete)
{
   #ifdef DEBUG_SEQUENCE_CLEARING
   MessageInterface::ShowMessage("CommandUtil::ClearCommandSeq() entered\n");
   #endif
   
   GmatCommand *cmd = seq, *removedCmd = NULL;
   
   if (cmd == NULL)
   {
      #ifdef DEBUG_SEQUENCE_CLEARING
      MessageInterface::ShowMessage
         ("CommandUtil::ClearCommandSeq() exiting, first command is NULL\n");
      #endif
      return true;
   }
   
   #ifdef DEBUG_SEQUENCE_CLEARING
   GmatCommand *current = cmd;
   MessageInterface::ShowMessage("\nClearing this command list:\n");
   while (current)
   {
      ShowCommand("   ", current);
      current = current->GetNext();
   }
   MessageInterface::ShowMessage("\n");
   #endif
   
   cmd = cmd->GetNext();
   while (cmd)
   {
      if (callRunComplete)
      {
         // Be sure we're in an idle state first
         #ifdef DEBUG_SEQUENCE_CLEARING
         MessageInterface::ShowMessage
            ("   Calling %s->RunComplete\n", cmd->GetTypeName().c_str());
         #endif
         
         cmd->RunComplete();
      }
      
      removedCmd = RemoveCommand(seq, cmd);
      
      if (removedCmd != NULL)
      {
         #ifdef DEBUG_MEMORY
         MemoryTracker::Instance()->Remove
            (removedCmd, removedCmd->GetTypeName(), "CommandUtil::ClearCommandSeq()");
         #endif
         delete removedCmd;
      }
      removedCmd = NULL;
      cmd = seq->GetNext();
   }
   
   // if first command is to be delete
   if (!leaveFirstCmd)
   {
      #ifdef DEBUG_SEQUENCE_CLEARING
      MessageInterface::ShowMessage("   seq=<%p>\n", seq);
      #endif
      
      #ifdef DEBUG_MEMORY
      MemoryTracker::Instance()->Remove
         (seq, seq->GetTypeName(), "CommandUtil::ClearCommandSeq()");
      #endif
      delete seq;
      seq = NULL;
   }
   
   #ifdef DEBUG_SEQUENCE_CLEARING
   MessageInterface::ShowMessage("CommandUtil::ClearCommandSeq() returning true\n");
   #endif
   
   return true;
}
コード例 #15
0
//------------------------------------------------------------------------------
GmatCommand* GmatCommandUtil::RemoveCommand(GmatCommand *seq, GmatCommand *cmd)
{
   #ifdef DEBUG_COMMAND_DELETE
   ShowCommand("==========> CommandUtil::RemoveCommand() removing ", cmd,
               " from ", seq);
   #endif
   
   if (cmd == NULL)
      return NULL;
   
   GmatCommand *remvCmd;
   if (cmd->GetTypeName() != "BeginScript")
   {
      GmatCommand *remvCmd = seq->Remove(cmd);
      
      #ifdef DEBUG_COMMAND_DELETE
      ShowCommand("   Removed = ", remvCmd);
      #endif
      
      #ifdef DEBUG_COMMAND_DELETE
      ShowCommand("==========> CommandUtil::RemoveCommand() Returning ", remvCmd);
      #endif
      
      return remvCmd;
   }
   
   //-------------------------------------------------------
   // Remove commands inside Begin/EndScript block
   //-------------------------------------------------------

   // Check for previous command, it should not be NULL,
   // since "NoOp" is the first command
   
   GmatCommand *prevCmd = cmd->GetPrevious();
   if (prevCmd == NULL)
   {
      MessageInterface::PopupMessage
         (Gmat::ERROR_, "CommandUtil::RemoveCommand() *** INTERNAL ERROR *** \n"
          "The previous command cannot be NULL.\n");
      return NULL;
   }
   
   ////GmatCommand *first = GetFirstCommand();
   GmatCommand *first = seq;
   
   #ifdef DEBUG_COMMAND_DELETE
   std::string cmdString1 = GmatCommandUtil::GetCommandSeqString(first);
   MessageInterface::ShowMessage("     ==> Current sequence:");
   MessageInterface::ShowMessage(cmdString1);
   #endif
   
   GmatCommand *current = cmd->GetNext();
   
   #ifdef DEBUG_COMMAND_DELETE
   GmatCommand *nextCmd = GmatCommandUtil::GetNextCommand(cmd);
   ShowCommand("     prevCmd = ", prevCmd, " nextCmd = ", nextCmd);
   #endif
   
   // Get matching EndScript for BeginScript
   GmatCommand *endScript = GmatCommandUtil::GetMatchingEnd(cmd);
   
   #ifdef DEBUG_COMMAND_DELETE
   ShowCommand("     endScript = ", endScript);
   #endif
   
   GmatCommand* next;
   while (current != NULL)
   {
      #ifdef DEBUG_COMMAND_DELETE
      ShowCommand("     current = ", current);
      #endif
      
      if (current == endScript)
         break;
      
      next = current->GetNext();
      
      #ifdef DEBUG_COMMAND_DELETE
      ShowCommand("     removing and deleting ", current);
      #endif
      
      remvCmd = cmd->Remove(current);
      
      // per kw report - check remvCmd first
      if (remvCmd != NULL)
      {
         remvCmd->ForceSetNext(NULL);
         
         #ifdef DEBUG_MEMORY
         MemoryTracker::Instance()->Remove
            (remvCmd, remvCmd->GetTypeName(), "CommandUtil::RemoveCommand()");
         #endif
         delete remvCmd;
      }
      
      current = next;
   }
   
   //-------------------------------------------------------
   // Remove and delete EndScript
   //-------------------------------------------------------
   #ifdef DEBUG_COMMAND_DELETE
   ShowCommand("     removing and deleting ", current);
   #endif
   
   remvCmd = cmd->Remove(current);
   
   // per kw report - check remvCmd first
   if (remvCmd != NULL)
   {
      remvCmd->ForceSetNext(NULL);
      
      #ifdef DEBUG_MEMORY
      MemoryTracker::Instance()->Remove
         (remvCmd, remvCmd->GetTypeName(), "CommandUtil::RemoveCommand()");
      #endif
      delete remvCmd;
      remvCmd = NULL;
   }
   
   next = cmd->GetNext();
   
   #ifdef DEBUG_COMMAND_DELETE
   ShowCommand("     next    = ", next, " nextCmd = ", nextCmd);
   #endif
   
   //-------------------------------------------------------
   // Remove and delete BeginScript
   //-------------------------------------------------------
   #ifdef DEBUG_COMMAND_DELETE
   ShowCommand("     removing and deleting ", cmd);
   #endif
   
   // Remove BeginScript
   remvCmd = first->Remove(cmd);
   
   // Set next command NULL
   cmd->ForceSetNext(NULL);
   if (cmd != NULL)
   {
      #ifdef DEBUG_MEMORY
      MemoryTracker::Instance()->Remove
         (cmd, cmd->GetTypeName(), "CommandUtil::RemoveCommand()");
      #endif
      delete cmd;
      cmd = NULL;
   }
   
   #ifdef DEBUG_COMMAND_DELETE
   std::string cmdString2 = GmatCommandUtil::GetCommandSeqString(first);
   MessageInterface::ShowMessage("     ==> sequence after delete:");
   MessageInterface::ShowMessage(cmdString2);
   ShowCommand("==========> CommandUtil::RemoveCommand() Returning cmd = ", cmd);
   #endif
   
   // Just return cmd, it should be deleted by the caller.
   return cmd;
}
コード例 #16
0
//------------------------------------------------------------------------------
GmatCommand* GmatCommandUtil::GetMatchingEnd(GmatCommand *cmd, bool getMatchingElse)
{
   if (cmd == NULL)
      return NULL;
   
   #ifdef DEBUG_MATCHING_END
   ShowCommand
      ("===> GmatCommandUtil::GetMatchingEnd() cmd = ", cmd);
   #endif
   
   if (cmd->GetTypeName() != "BeginScript" && !cmd->IsOfType("BranchCommand"))
      return NULL;
   
   GmatCommand *current = cmd;
   
   if (cmd->GetTypeName() == "BeginScript")
   {
      Integer scriptEventCount = 0;
   
      while (current != NULL)
      {
         if (current->GetTypeName() == "BeginScript")
            scriptEventCount++;
      
         if (current->GetTypeName() == "EndScript")
            scriptEventCount--;

         #ifdef DEBUG_MATCHING_END
         MessageInterface::ShowMessage
            ("     scriptEventCount=%d, current=<%p><%s>\n", scriptEventCount, current,
             current->GetTypeName().c_str());
         #endif
      
         if (scriptEventCount == 0)
            break;
      
         current = current->GetNext();
      }
      
      #ifdef DEBUG_MATCHING_END
      ShowCommand("===> GmatCommandUtil::GetMatchingEnd() returning ", current);
      #endif
   
      return current;
   }
   else
   {
      GmatCommand *child = NULL;
      Integer branch = 0;
      bool elseFound = false;
      
      while ((current->GetChildCommand(branch)) != NULL)
      {
         child = current->GetChildCommand(branch);
         
         while (child != NULL)
         {
            #ifdef DEBUG_MATCHING_END
            ShowCommand("   child = ", child);
            #endif
            
            if (child->IsOfType("BranchEnd"))
            {
               if (child->GetTypeName() == "Else")
               {
                  elseFound = true;
                  if (getMatchingElse)
                     break;
                  
                  branch++;
               }
               
               break;
            }
            
            child = child->GetNext();
         }
         
         if (elseFound && branch == 1)
         {
            elseFound = false;
            continue;
         }
         else
            break;
      }
      
      #ifdef DEBUG_MATCHING_END
      ShowCommand("===> GmatCommandUtil::GetMatchingEnd() returning ", child);
      #endif
      
      return child;
   }
}
コード例 #17
0
//------------------------------------------------------------------------------
// void GetSubCommandString(GmatCommand* brCmd, Integer level, std::string &cmdseq,
//                          bool showAddr = true, bool showGenStr = false,
//                          bool showSummaryName = false,
//                          const std::string &indentStr = "---")
//------------------------------------------------------------------------------
void GmatCommandUtil::
GetSubCommandString(GmatCommand* brCmd, Integer level, std::string &cmdseq,
                    bool showAddr, bool showGenStr, bool showSummaryName,
                    const std::string &indentStr)
{
   char buf[13];
   GmatCommand* current = brCmd;
   Integer childNo = 0;
   GmatCommand* nextInBranch;
   GmatCommand* child;
   std::string cmdstr, genStr;
   buf[0] = '\0';
   
   while((child = current->GetChildCommand(childNo)) != NULL)
   {
      nextInBranch = child;
      
      while ((nextInBranch != NULL) && (nextInBranch != current))
      {
         for (int i=0; i<=level; i++)
         {
            cmdseq.append(indentStr);
            
            #ifdef DEBUG_COMMAND_SEQ_STRING
            MessageInterface::ShowMessage(indentStr);
            #endif
         }
         
         if (showAddr)
            sprintf(buf, "(%p)", nextInBranch);
         
         genStr = "";
			if (showGenStr)
			{
				if (nextInBranch->GetTypeName() == "BeginScript")
					genStr = "<BeginScript>";
				else if (nextInBranch->GetTypeName() == "EndScript")
					genStr = "<EndScript>";
				else
					genStr = " <" + nextInBranch->GetGeneratingString(Gmat::NO_COMMENTS) + ">";
         }
			else if (showSummaryName)
         {
            // Show summary name
            genStr = "(" + nextInBranch->GetSummaryName() + ")";
			}
			
         // if indentation string is not blank, use it from the first sub level
         if (indentStr.find(" ") == indentStr.npos)
            cmdstr = indentStr + " " + std::string(buf) + nextInBranch->GetTypeName() + genStr + "\n";
         else
            cmdstr = std::string(buf) + nextInBranch->GetTypeName() + genStr + "\n";
         
         cmdseq.append(cmdstr);
         
         #ifdef DEBUG_COMMAND_SEQ_STRING
         MessageInterface::ShowMessage("%s", cmdstr.c_str());
         #endif
         
         if (nextInBranch->GetChildCommand() != NULL)
            GetSubCommandString(nextInBranch, level+1, cmdseq, showAddr, showGenStr,
                                showSummaryName, indentStr);
         
         nextInBranch = nextInBranch->GetNext();
      }
      
      ++childNo;
   }
}
コード例 #18
0
//------------------------------------------------------------------------------
// bool GmatFunction::Execute(ObjectInitializer *objInit, bool reinitialize)
//------------------------------------------------------------------------------
bool GmatFunction::Execute(ObjectInitializer *objInit, bool reinitialize)
{
   if (!fcs) return false;
   if (!objInit) return false;
   
   #ifdef DEBUG_TRACE
   static Integer callCount = 0;
   callCount++;      
   clock_t t1 = clock();
   ShowTrace(callCount, t1, wxT("GmatFunction::Execute() entered"));
   #endif
   
   #ifdef DEBUG_FUNCTION_EXEC
   MessageInterface::ShowMessage
      (wxT("======================================================================\n")
       wxT("GmatFunction::Execute() entered for '%s'\n   internalCS is <%p>, ")
       wxT("reinitialize = %d\n"), functionName.c_str(), internalCoordSys, reinitialize);
   #endif
   
   GmatCommand *current = fcs;
   GmatCommand *last = NULL;
   
   // We want to initialize local objects with new object map,
   // so do it everytime (loj: 2008.09.26)
   // This causes to slow down function execution, so initialize if necessary
   if (reinitialize)
      objectsInitialized = false;
   
   // Reinitialize CoordinateSystem to fix bug 1599 (LOJ: 2009.11.05)
   // Reinitialize Parameters to fix bug 1519 (LOJ: 2009.09.16)
   if (objectsInitialized)
   {
      if (!objInit->InitializeObjects(true, Gmat::COORDINATE_SYSTEM))
         throw FunctionException
            (wxT("Failed to re-initialize Parameters in the \"") + functionName + wxT("\""));
      if (!objInit->InitializeObjects(true, Gmat::PARAMETER))
         throw FunctionException
            (wxT("Failed to re-initialize Parameters in the \"") + functionName + wxT("\""));
   }
   
   // Go through each command in the sequence and execute.
   // Once it gets to a real command, initialize local and automatic objects.
   while (current)
   {
      // Call to IsNextAFunction is necessary for branch commands in particular
      #ifdef DEBUG_FUNCTION_EXEC
      MessageInterface::ShowMessage
         (wxT("......Function executing <%p><%s> [%s]\n"), current, current->GetTypeName().c_str(),
          current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
      MessageInterface::ShowMessage(wxT("      objectsInitialized=%d\n"), objectsInitialized);
      #endif
      
      last = current;
      
      if (!objectsInitialized)
      {
         // Since we don't know where actual mission sequence starts, just check
         // for command that is not NoOp, Create, Global, and GMAT with equation.
         // Can we have simple command indicating beginning of the sequence,
         // such as BeginSequence? (loj: 2008.06.19)
         // @todo: Now we have BeginMissionSequence, but not all functions have it,
         // so check it first otherwise do in the old way. (loj: 2010.07.16)
         Function *func = current->GetCurrentFunction();
         bool isEquation = false;
         wxString cmdType = current->GetTypeName();
         if (func && cmdType == wxT("GMAT"))
            if (((Assignment*)current)->GetMathTree() != NULL)
               isEquation = true;
         
         if (cmdType != wxT("NoOp") && cmdType != wxT("Create") && cmdType != wxT("Global"))
         {
            bool beginInit = true;            
            if (cmdType == wxT("GMAT") && !isEquation)
               beginInit = false;

            if (cmdType == wxT("BeginMissionSequence") || cmdType == wxT("BeginScript"))
               beginInit = true;
            
            if (beginInit)
            {
               objectsInitialized = true;
               validator->HandleCcsdsEphemerisFile(objectStore, true);
               #ifdef DEBUG_FUNCTION_EXEC
               MessageInterface::ShowMessage
                  (wxT("============================ Initializing LocalObjects at current\n")
                   wxT("%s\n"), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               #endif
               InitializeLocalObjects(objInit, current, true);
            }
         }
      }
      
      // Now execute the function sequence
      try
      {
         #ifdef DEBUG_FUNCTION_EXEC
         MessageInterface::ShowMessage
            (wxT("Now calling <%p>[%s]->Execute()\n"), current->GetTypeName().c_str(),
             current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
         #endif
         
         if (!(current->Execute()))
            return false;
      }
      catch (BaseException &e)
      {
         // If it is user interrupt, rethrow (loj: 2008.10.16)
         // How can we tell if it is thrown by Stop command?
         // For now just find the phrase wxT("interrupted by Stop command")
         wxString msg = e.GetFullMessage();
         if (msg.find(wxT("interrupted by Stop command")) != msg.npos)
         {
            #ifdef DEBUG_FUNCTION_EXEC
            MessageInterface::ShowMessage
               (wxT("*** Interrupted by Stop commaned, so re-throwing...\n"));
            #endif
            throw;
         }
         
         if (e.IsFatal())
         {
            #ifdef DEBUG_FUNCTION_EXEC
            MessageInterface::ShowMessage
               (wxT("*** The exception is fatal, so re-throwing...\n"));
            #endif
            // Add command line to error message (LOJ: 2010.04.13)
            throw FunctionException
               (wxT("In ") + current->GetGeneratingString(Gmat::NO_COMMENTS) + wxT(", ") +
                e.GetFullMessage());
            //throw;
         }
         
         // Let's try initialzing local objects here again (2008.10.14)
         try
         {
            #ifdef DEBUG_FUNCTION_EXEC
            MessageInterface::ShowMessage
               (wxT("============================ Reinitializing LocalObjects at current\n")
                wxT("%s\n"), current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
            #endif
            
            InitializeLocalObjects(objInit, current, false);
            
            #ifdef DEBUG_FUNCTION_EXEC
            MessageInterface::ShowMessage
               (wxT("......Function re-executing <%p><%s> [%s]\n"), current,
                current->GetTypeName().c_str(),
                current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
            #endif
            
            if (!(current->Execute()))
               return false;
         }
         catch (HardwareException &he)
         {
            // Ignore for hardware exception since spacecraft is associated with Thruster
            // but Thruster binds with Tank later in the fcs
         }
         catch (BaseException &be)
         {
            throw FunctionException
               (wxT("During initialization of local objects before \"") +
                current->GetGeneratingString(Gmat::NO_COMMENTS) + wxT("\", ") +
                e.GetFullMessage());
         }
      }
      
      // If current command is BranchCommand and still executing, continue to next
      // command in the branch (LOJ: 2009.03.24)
      if (current->IsOfType(wxT("BranchCommand")) && current->IsExecuting())
      {
         #ifdef DEBUG_FUNCTION_EXEC
         MessageInterface::ShowMessage
            (wxT("In Function '%s', still executing current command is <%p><%s>\n"),
             functionName.c_str(), current, current ? current->GetTypeName().c_str() : wxT("NULL"));
         #endif
         
         continue;
      }
      
      current = current->GetNext();
      
      #ifdef DEBUG_FUNCTION_EXEC
      MessageInterface::ShowMessage
         (wxT("In Function '%s', the next command is <%p><%s>\n"), functionName.c_str(),
          current, current ? current->GetTypeName().c_str() : wxT("NULL"));
      #endif
   }
   
   // Set ObjectMap from the last command to Validator in order to create
   // valid output wrappers (loj: 2008.11.12)
   validator->SetObjectMap(last->GetObjectMap());
   
   #ifdef DEBUG_FUNCTION_EXEC
   MessageInterface::ShowMessage
      (wxT("   Now about to create %d output wrapper(s) to set results, objectsInitialized=%d\n"),
       outputNames.size(), objectsInitialized);
   #endif
   
   // create output wrappers and put into map
   GmatBase *obj;
   wrappersToDelete.clear();
   for (unsigned int jj = 0; jj < outputNames.size(); jj++)
   {
      if (!(obj = FindObject(outputNames.at(jj))))
      {
         wxString errMsg = wxT("Function: Output \"") + outputNames.at(jj);
         errMsg += wxT(" not found for function \"") + functionName + wxT("\"");
         throw FunctionException(errMsg);
      }
      wxString outName = outputNames.at(jj);
      ElementWrapper *outWrapper =
         validator->CreateElementWrapper(outName, false, false);
      #ifdef DEBUG_MORE_MEMORY
      MessageInterface::ShowMessage
         (wxT("+++ GmatFunction::Execute() *outWrapper = validator->")
          wxT("CreateElementWrapper(%s), <%p> '%s'\n"), outName.c_str(), outWrapper,
          outWrapper->GetDescription().c_str());
      #endif
      
      outWrapper->SetRefObject(obj);
      
      // nested CallFunction crashes if old outWrappers are deleted here. (loj: 2008.11.24)
      // so collect here and delete when FunctionRunner completes.
      wrappersToDelete.push_back(outWrapper);         
      
      // Set new outWrapper
      outputArgMap[outName] = outWrapper;
      #ifdef DEBUG_FUNCTION_EXEC // --------------------------------------------------- debug ---
         MessageInterface::ShowMessage(wxT("GmatFunction: Output wrapper created for %s\n"),
                                       (outputNames.at(jj)).c_str());
      #endif // -------------------------------------------------------------- end debug ---
   }
   
   #ifdef DEBUG_FUNCTION_EXEC
   MessageInterface::ShowMessage
      (wxT("GmatFunction::Execute() exiting true for '%s'\n"), functionName.c_str());
   #endif
   
   #ifdef DEBUG_TRACE
   ShowTrace(callCount, t1, wxT("GmatFunction::Execute() exiting"), true);
   #endif
   
   return true; 
}
コード例 #19
0
//------------------------------------------------------------------------------
bool Target::Initialize()
{
    GmatBase *mapObj = NULL;
    cloneCount = 0;

    if ((mapObj = FindObject(solverName)) == NULL)
    {
        wxString errorString = wxT("Target command cannot find targeter \"");
        errorString += solverName;
        errorString += wxT("\"");
        throw CommandException(errorString, Gmat::ERROR_);
    }

    // Clone the targeter for local use
#ifdef DEBUG_TARGET_INIT
    MessageInterface::ShowMessage
    (wxT("Target::Initialize() cloning mapObj <%p>'%s'\n"), mapObj,
     mapObj->GetName().c_str());
    MessageInterface::ShowMessage
    (wxT("mapObj maxIter=%d\n"),
     mapObj->GetIntegerParameter(mapObj->GetParameterID(wxT("MaximumIterations"))));
#endif

    // Delete the old cloned solver
    if (theSolver)
    {
#ifdef DEBUG_MEMORY
        MemoryTracker::Instance()->Remove
        (theSolver, wxT("local solver", "Target::Initialize()"),
         wxT("deleting local cloned solver"));
#endif
        delete theSolver;
    }

    theSolver = (Solver *)(mapObj->Clone());
    if (theSolver != NULL)
        ++cloneCount;

#ifdef DEBUG_MEMORY
    MemoryTracker::Instance()->Add
    (theSolver, theSolver->GetName(), wxT("Target::Initialize()"),
     wxT("theSolver = (Solver *)(mapObj->Clone())"));
#endif

    theSolver->TakeAction(wxT("ResetInstanceCount"));
    mapObj->TakeAction(wxT("ResetInstanceCount"));

    theSolver->TakeAction(wxT("IncrementInstanceCount"));
    mapObj->TakeAction(wxT("IncrementInstanceCount"));

    if (theSolver->GetStringParameter(wxT("ReportStyle")) == wxT("Debug"))
        targeterInDebugMode = true;
    theSolver->SetStringParameter(wxT("SolverMode"),
                                  GetStringParameter(SOLVER_SOLVE_MODE));
    theSolver->SetStringParameter(wxT("ExitMode"),
                                  GetStringParameter(SOLVER_EXIT_MODE));

    // Set the local copy of the targeter on each node
    std::vector<GmatCommand*>::iterator node;
    GmatCommand *current;
    specialState = Solver::INITIALIZING;

    for (node = branch.begin(); node != branch.end(); ++node)
    {
        current = *node;

#ifdef DEBUG_TARGET_COMMANDS
        Integer nodeNum = 0;
#endif
        while ((current != NULL) && (current != this))
        {
#ifdef DEBUG_TARGET_COMMANDS
            MessageInterface::ShowMessage(
                wxT("   Target Command %d:  %s\n"), ++nodeNum,
                current->GetTypeName().c_str());
#endif
            if ((current->GetTypeName() == wxT("Vary")) ||
                    (current->GetTypeName() == wxT("Achieve")))
                current->SetRefObject(theSolver, Gmat::SOLVER, solverName);
            current = current->GetNext();
        }
    }

    bool retval = SolverBranchCommand::Initialize();

    if (retval == true) {
        // Targeter specific initialization goes here:
        if (FindObject(solverName) == NULL)
        {
            wxString errorString = wxT("Target command cannot find targeter \"");
            errorString += solverName;
            errorString += wxT("\"");
            throw CommandException(errorString);
        }

        retval = theSolver->Initialize();
    }

    targeterInFunctionInitialized = false;
    return retval;
}
コード例 #20
0
//------------------------------------------------------------------------------
const wxString& BeginScript::GetGeneratingString(Gmat::WriteMode mode,
                                                    const wxString &prefix,
                                                    const wxString &useName)
{
   //Note: This method is called only once from the ScriptInterpreter::WriteScript()
   // So all nested ScriptEvent generating string should be handled here
   
   wxString gen;
   wxString indent;
   wxString commentLine = GetCommentLine();
   wxString inlineComment = GetInlineComment();
   wxString beginPrefix = prefix;

   if (mode != Gmat::GUI_EDITOR)
   {
      if (mode == Gmat::NO_COMMENTS)
      {
         gen << prefix << wxT("BeginScript") << wxT("\n");
      }
      else
      {
         IndentComment(gen, commentLine, prefix);
         gen << prefix << wxT("BeginScript");   
         
         if (inlineComment != wxT(""))
            gen << inlineComment << wxT("\n");
         else
            gen << wxT("\n");
      }
   }
   
   #if DBGLVL_GEN_STRING
   MessageInterface::ShowMessage
      (wxT("BeginScript::GetGeneratingString() this=(%p)%s, mode=%d, prefix='%s', ")
       wxT("useName='%s'\n"), this, this->GetTypeName().c_str(), mode, prefix.c_str(),
       useName.c_str());
   #endif
   
   if (mode == Gmat::GUI_EDITOR)
      indent = wxT("");
   else
      indent = wxT("   ");
   
   GmatCommand *current = next;
   while (current != NULL)
   {      
      #if DBGLVL_GEN_STRING > 1
      MessageInterface::ShowMessage
         (wxT("BeginScript::GetGeneratingString() current=(%p)%s\n"), current,
          current->GetTypeName().c_str());
      #endif
      
      if (current->GetTypeName() != wxT("EndScript"))
      {
         // Indent whole block within Begin/EndScript
         IndentChildString(gen, current, indent, mode, prefix, useName, false);
         
         // Get command after EndScript
         current = GmatCommandUtil::GetNextCommand(current);
         
         if (current == NULL)
            IndentChildString(gen, current, indent, mode, beginPrefix, useName, true);
      }
      else
      {
         if (mode != Gmat::GUI_EDITOR)
         {
            // Indent whole block within Begin/EndScript
            IndentChildString(gen, current, indent, mode, beginPrefix, useName, true);
         }
         current = NULL;
      }
   }
   
   generatingString = gen;
   
   #if DBGLVL_GEN_STRING
   MessageInterface::ShowMessage
      (wxT("BeginScript::GetGeneratingString() returnning generatingString\n"));
   MessageInterface::ShowMessage(wxT("<<<\n%s>>>\n\n"), generatingString.c_str());
   #endif
   
   return generatingString;
}
コード例 #21
0
//------------------------------------------------------------------------------
const std::string& BeginScript::GetGeneratingString(Gmat::WriteMode mode,
                                                    const std::string &prefix,
                                                    const std::string &useName)
{
   //Note: This method is called only once from the ScriptInterpreter::WriteScript(),
   // so all nested ScriptEvent generating strings should be handled here.
   
   std::stringstream gen;
   std::string indent;
   std::string commentLine = GetCommentLine();
   std::string inlineComment = GetInlineComment();
   std::string beginPrefix = prefix;

   if (mode != Gmat::GUI_EDITOR)
   {
      if (mode == Gmat::NO_COMMENTS)
      {
         gen << prefix << "BeginScript" << "\n";
      }
      else
      {
         IndentComment(gen, commentLine, prefix);
         
         // Insert command name (Fix for GMT-2612, LOJ: 2012.10.22)
         //gen << prefix << "BeginScript";
         std::string tempString = prefix + "BeginScript";
         
         InsertCommandName(tempString);
         gen << tempString;
         
         if (inlineComment != "")
            gen << inlineComment << "\n";
         else
            gen << "\n";
      }
   }
   
   #if DBGLVL_GEN_STRING
   MessageInterface::ShowMessage
      ("BeginScript::GetGeneratingString() this=(%p)%s, mode=%d, prefix='%s', "
       "useName='%s'\n", this, this->GetTypeName().c_str(), mode, prefix.c_str(),
       useName.c_str());
   #endif
   
   if (mode == Gmat::GUI_EDITOR)
      indent = "";
   else
      indent = "   ";
   
   GmatCommand *current = next;
   while (current != NULL)
   {      
      #if DBGLVL_GEN_STRING > 1
      MessageInterface::ShowMessage
         ("BeginScript::GetGeneratingString() current=(%p)%s\n", current,
          current->GetTypeName().c_str());
      #endif
      
      if (current->GetTypeName() != "EndScript")
      {
         // Indent whole block within Begin/EndScript
         IndentChildString(gen, current, indent, mode, prefix, useName, false);
         
         // Get command after EndScript
         current = GmatCommandUtil::GetNextCommand(current);
         
         if (current == NULL)
            IndentChildString(gen, current, indent, mode, beginPrefix, useName, true);
      }
      else
      {
         if (mode != Gmat::GUI_EDITOR)
         {
            // Indent whole block within Begin/EndScript
            IndentChildString(gen, current, indent, mode, beginPrefix, useName, true);
         }
         else
         {
            std::string comment = current->GetCommentLine();
            #if DBGLVL_GEN_STRING
            MessageInterface::ShowMessage("   EndScript comment = '%s'\n", comment.c_str());
            #endif
            // Only indent inline comment of EndScript (LOJ: 2013.03.27)
            gen << indent << comment;
         }
         current = NULL;
      }
   }
   
   generatingString = gen.str();
   
   #if DBGLVL_GEN_STRING
   MessageInterface::ShowMessage
      ("BeginScript::GetGeneratingString() returnning generatingString\n");
   MessageInterface::ShowMessage("<<<\n%s>>>\n\n", generatingString.c_str());
   #endif
   
   return generatingString;
}
コード例 #22
0
//------------------------------------------------------------------------------
bool GmatCommandUtil::FindObject(GmatCommand *cmd, Gmat::ObjectType objType,
                                 const std::string &objName, std::string &cmdName,
                                 GmatCommand **cmdUsing, bool checkWrappers)
{
   if (cmd == NULL)
      return false;
   
   GmatCommand *current = cmd;
   std::string cmdstr = cmd->GetTypeName();
   
   #ifdef DEBUG_COMMAND_FIND_OBJECT
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::FindObject() entered, objType=%d, objName='%s', "
       "cmd=<%p><%s>\n", objType, objName.c_str(), cmd, cmdstr.c_str());
   #endif
   
   
   while (current != NULL)
   {
      cmdstr = "--- " + current->GetTypeName() + "\n";
      
      #ifdef DEBUG_COMMAND_FIND_OBJECT
      MessageInterface::ShowMessage(cmdstr);
      #endif
      
      try
      {
         StringArray names = current->GetRefObjectNameArray(objType);
         
         for (UnsignedInt i=0; i<names.size(); i++)
         {
            #ifdef DEBUG_COMMAND_FIND_OBJECT
            MessageInterface::ShowMessage("names[%d]=%s\n", i, names[i].c_str());
            #endif
            
            if (names[i] == objName)
            {
               cmdName = current->GetTypeName();
               *cmdUsing = current;
               #ifdef DEBUG_COMMAND_FIND_OBJECT
               MessageInterface::ShowMessage
                  ("CommandUtil::FindObject() returning true, cmdName='%s', "
                   "cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                   (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               #endif
               return true;
            }
         }
      }
      catch (BaseException &e)
      {
         // Use exception to remove Visual C++ warning
         e.GetMessageType();
         #ifdef DEBUG_COMMAND_FIND_OBJECT
         MessageInterface::ShowMessage("*** INTERNAL WARNING *** " + e.GetFullMessage());
         #endif
      }
      
      // go through sub commands
      if ((current->GetChildCommand(0)) != NULL)
      {
         if (FindObjectFromSubCommands(current, 0, objType, objName, cmdName, cmdUsing, checkWrappers))
         {
            #ifdef DEBUG_COMMAND_FIND_OBJECT
            MessageInterface::ShowMessage
               ("CommandUtil::FindObject() returning true, cmdName='%s', "
                "cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
            #endif
            
            return true;
         }
      }
      
      // Check for references in the wrappers, if requested
      if (checkWrappers)
      {
         if (current->HasOtherReferenceToObject(objName))
         {
            cmdName = current->GetTypeName();
            *cmdUsing = current;
            #ifdef DEBUG_COMMAND_FIND_OBJECT
            MessageInterface::ShowMessage
               ("CommandUtil::FindObject() returning true (for wrappers), cmdName='%s', "
                "cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
            #endif
            return true;
         }
      }

      current = current->GetNext();
   }
   
   #ifdef DEBUG_COMMAND_FIND_OBJECT
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::FindObject() returning false\n");
   #endif
   return false;
}
コード例 #23
0
//------------------------------------------------------------------------------
std::string GmatCommandUtil::
GetCommandSeqString(GmatCommand *cmd, bool showAddr, bool showGenStr,
                    bool showSummaryName, const std::string &indentStr)
{
   char buf[13];
   GmatCommand *current = cmd;
   std::string cmdseq, cmdstr, genStr;
   cmdstr = "\n---------- Mission Sequence ----------\n";
   cmdseq.append(cmdstr);
   buf[0] = '\0';
   
   #ifdef DEBUG_COMMAND_SEQ_STRING
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::GetCommandSeqString(%p)\n", cmd);
   MessageInterface::ShowMessage("%s", cmdstr.c_str());
   #endif
   
   
   while (current != NULL)
   {
      if (showAddr)
         sprintf(buf, "(%p)", current);
      
      genStr = "";
      if (showGenStr)
      {
         if (current->GetTypeName() == "BeginScript")
            genStr = "<BeginScript>";
         else if (current->GetTypeName() == "EndScript")
            genStr = "<EndScript>";
         else
            genStr = " <" + current->GetGeneratingString(Gmat::NO_COMMENTS) + ">";
      }
		else if (showSummaryName)
		{
			// Show summary name
         genStr = "(" + current->GetSummaryName() + ")";
		}
		
      // if indentation string is not blank, use it from the first level
      if (indentStr.find(" ") == indentStr.npos)
         cmdstr = indentStr + " " + std::string(buf) + current->GetTypeName() + genStr + "\n";
      else
         cmdstr = std::string(buf) + current->GetTypeName() + genStr + "\n";
      
      cmdseq.append(cmdstr);
      
      #ifdef DEBUG_COMMAND_SEQ_STRING
      MessageInterface::ShowMessage("%s", cmdstr.c_str());
      #endif
      
      if ((current->GetChildCommand(0)) != NULL)
         GetSubCommandString(current, 0, cmdseq, showAddr, showGenStr, showSummaryName, indentStr);
      
      current = current->GetNext();
   }
   
   cmdseq.append("\n");
   
   return cmdseq;
}
コード例 #24
0
//------------------------------------------------------------------------------
bool Target::Execute()
{
#ifdef DEBUG_TARGET_EXEC
    MessageInterface::ShowMessage
    (wxT("Target::Execute() entered, theSolver=<%p>'%s'\n"), (GmatBase*)theSolver,
     theSolver->GetName().c_str());
    MessageInterface::ShowMessage
    (wxT("maxIter=%d\n"),
     theSolver->GetIntegerParameter(theSolver->GetParameterID(wxT("MaximumIterations"))));
    MessageInterface::ShowMessage
    (wxT("currentFunction=<%p>'%s'\n"),
     currentFunction, currentFunction ? ((GmatBase*)currentFunction)->GetName().c_str() : wxT("NULL"));
#endif

    // If targeting inside a function, we need to reinitialize since the local solver is
    // cloned in Initialize(). All objects including solvers are initialized in
    // assignment command which happens after Target::Initialize(). (LOJ: 2009.03.17)
    if (currentFunction != NULL && !targeterInFunctionInitialized)
    {
        Initialize();
        targeterInFunctionInitialized = true;
    }

    bool retval = true;

    // Drive through the state machine.
    Solver::SolverState state = theSolver->GetState();

#ifdef DEBUG_TARGET_COMMANDS
    MessageInterface::ShowMessage(wxT("TargetExecute(%c%c%c%d)\n"),
                                  (commandExecuting?wxT('Y'):wxT('N')),
                                  (commandComplete?wxT('Y'):wxT('N')),
                                  (branchExecuting?wxT('Y'):wxT('N')),
                                  state);
    MessageInterface::ShowMessage(wxT("   targeterConverged=%d\n"),
                                  targeterConverged);
#endif

    // Attempt to reset if recalled
    if (commandComplete)
    {
        commandComplete = false;
        commandExecuting = false;
        specialState = Solver::INITIALIZING;
    }

    if (!commandExecuting)
    {
#ifdef DEBUG_TARGET_COMMANDS
        MessageInterface::ShowMessage(
            wxT("Entered Targeter while command is not executing\n"));
#endif

        FreeLoopData();
        StoreLoopData();


        retval = SolverBranchCommand::Execute();

#ifdef DEBUG_TARGETER
        MessageInterface::ShowMessage(wxT("Resetting the Differential Corrector\n"));
#endif

        theSolver->TakeAction(wxT("Reset"));
        state = theSolver->GetState();
    }

    if (branchExecuting)
    {
        retval = ExecuteBranch();
        if (!branchExecuting)
        {
            if ((state == Solver::FINISHED) || (specialState == Solver::FINISHED))
            {
                PenDownSubscribers();
                LightenSubscribers(1);
                commandComplete = true;
            }
            else
            {
                PenUpSubscribers();
            }
        }
    }
    else
    {
        GmatCommand *currentCmd;

        publisher->SetRunState(Gmat::SOLVING);

        switch (startMode)
        {
        case RUN_INITIAL_GUESS:
#ifdef DEBUG_START_MODE
            MessageInterface::ShowMessage(
                wxT("Running as RUN_INITIAL_GUESS, specialState = %d, currentState = %d\n"),
                specialState, theSolver->GetState());
#endif
            switch (specialState)
            {
            case Solver::INITIALIZING:
                // Finalize initialization of the targeter data
                currentCmd = branch[0];
                targeterConverged = false;
                while (currentCmd != this)
                {
                    wxString type = currentCmd->GetTypeName();
                    if ((type == wxT("Target")) || (type == wxT("Vary")) ||
                            (type == wxT("Achieve")))
                        currentCmd->Execute();
                    currentCmd = currentCmd->GetNext();
                }
                StoreLoopData();
                specialState = Solver::NOMINAL;
                break;

            case Solver::NOMINAL:
                // Execute the nominal sequence
                if (!commandComplete)
                {
                    branchExecuting = true;
                    ResetLoopData();
                }
                specialState = Solver::RUNSPECIAL;
                break;

            case Solver::RUNSPECIAL:
                // Run once more to publish the data from the converged state
                if (!commandComplete)
                {
                    ResetLoopData();
                    branchExecuting = true;
                    publisher->SetRunState(Gmat::SOLVEDPASS);
                }
                theSolver->Finalize();
                specialState = Solver::FINISHED;

                // Final clean-up
                targeterConverged = true;
                break;

            case Solver::FINISHED:
                specialState = Solver::INITIALIZING;
                break;

            default:
                break;
            }
            break;

        case RUN_SOLUTION:
#ifdef DEBUG_START_MODE
            MessageInterface::ShowMessage(
                wxT("Running as RUN_SOLUTION, state = %d\n"), state);
#endif
            throw SolverException(
                wxT("Run Solution is not yet implemented for the Target ")
                wxT("command\n"));
            break;

        case RUN_AND_SOLVE:
        default:
#ifdef DEBUG_START_MODE
            MessageInterface::ShowMessage(
                wxT("Running as RUN_AND_SOLVE or default, state = %d\n"),
                state);
#endif
            switch (state)
            {
            case Solver::INITIALIZING:
                // Finalize initialization of the targeter data
                currentCmd = branch[0];
                targeterConverged = false;
                while (currentCmd != this)
                {
                    wxString type = currentCmd->GetTypeName();
                    if ((type == wxT("Target")) || (type == wxT("Vary")) ||
                            (type == wxT("Achieve")))
                    {
                        currentCmd->Execute();
                        if ((type == wxT("Vary")) && (targeterRunOnce))
                            currentCmd->TakeAction(wxT("SolverReset"));
                    }
                    currentCmd = currentCmd->GetNext();
                }
                StoreLoopData();
                GetActiveSubscribers();
                SetSubscriberBreakpoint();
                break;

            case Solver::NOMINAL:
                // Execute the nominal sequence
                if (!commandComplete)
                {
                    branchExecuting = true;
                    ApplySubscriberBreakpoint();
                    PenDownSubscribers();
                    LightenSubscribers(1);
                    ResetLoopData();
                }
                break;

            case Solver::CHECKINGRUN:
                // Check for convergence; this is done in the targeter state
                // machine, so this case is a NoOp for the Target command
                break;

            case Solver::PERTURBING:
                branchExecuting = true;
                ApplySubscriberBreakpoint();
                PenDownSubscribers();
                LightenSubscribers(4);
                ResetLoopData();
                break;

            case Solver::CALCULATING:
                // Calculate the next set of variables to use; this is
                // performed in the targeter -- nothing to be done here
                break;

            case Solver::FINISHED:
                // Final clean-up
                targeterConverged = true;
                targeterRunOnce = true;

                // Run once more to publish the data from the converged state
                if (!commandComplete)
                {
                    ResetLoopData();
                    branchExecuting = true;
                    ApplySubscriberBreakpoint();
                    PenDownSubscribers();
                    LightenSubscribers(1);
                    publisher->SetRunState(Gmat::SOLVEDPASS);
                }
                break;

            case Solver::ITERATING:     // Intentional fall-through
            default:
                throw CommandException(
                    wxT("Invalid state in the Targeter state machine"));
            }
            break;
        }
    }

    if (!branchExecuting)
    {
        theSolver->AdvanceState();

        if (theSolver->GetState() == Solver::FINISHED)
        {
            publisher->FlushBuffers();
            targeterConverged = true;
        }
    }

    // Pass spacecraft data to the targeter for reporting in debug mode
    if (targeterInDebugMode)
    {
        wxString dbgData = wxT("");
        for (ObjectArray::iterator i = localStore.begin(); i < localStore.end();
                ++i)
        {
            dbgData += (*i)->GetGeneratingString() + wxT("\n---\n");
        }
        theSolver->SetDebugString(dbgData);
    }
    BuildCommandSummary(true);

#ifdef DEBUG_TARGET_EXEC
    MessageInterface::ShowMessage
    (wxT("Target::Execute() returning %d, theSolver=<%p>'%s'\n"), retval,
     theSolver, theSolver->GetName().c_str());
#endif

    return retval;
}
コード例 #25
0
//------------------------------------------------------------------------------
// bool Initialize()
//------------------------------------------------------------------------------
bool GmatFunction::Initialize()
{
   #ifdef DEBUG_TRACE
   static Integer callCount = 0;
   callCount++;      
   clock_t t1 = clock();
   ShowTrace(callCount, t1, wxT("GmatFunction::Initialize() entered"));
   #endif
   
   #ifdef DEBUG_FUNCTION_INIT
      MessageInterface::ShowMessage
         (wxT("======================================================================\n")
          wxT("GmatFunction::Initialize() entered for function '%s'\n"), functionName.c_str());
      MessageInterface::ShowMessage(wxT("   and FCS is %s set.\n"), (fcs? wxT("correctly") : wxT("NOT")));
      MessageInterface::ShowMessage(wxT("   Pointer for FCS is %p\n"), fcs);
      MessageInterface::ShowMessage(wxT("   First command in fcs is %s\n"),
            (fcs->GetTypeName()).c_str());
      MessageInterface::ShowMessage(wxT("   internalCS is %p\n"), internalCoordSys);
   #endif
   if (!fcs) return false;
   
   Function::Initialize();
   
   // Initialize the Validator - I think I need to do this each time - or do I?
   validator->SetFunction(this);
   validator->SetSolarSystem(solarSys);
   std::map<wxString, GmatBase *>::iterator omi;
   
   // add automatic objects such as sat.X to the FOS (well, actually, clones of them)
   for (omi = automaticObjectMap.begin(); omi != automaticObjectMap.end(); ++omi)
   {
      wxString autoObjName = omi->first;
      
      // if name not found, clone it and add to map (loj: 2008.12.15)
      if (objectStore->find(autoObjName) == objectStore->end())
      {
         GmatBase *autoObj = (omi->second)->Clone();
         #ifdef DEBUG_MEMORY
         MemoryTracker::Instance()->Add
            (autoObj, autoObjName, wxT("GmatFunction::Initialize()"),
             wxT("autoObj = (omi->second)->Clone()"));
         #endif
         
         #ifdef DEBUG_FUNCTION_INIT
         try
         {
            MessageInterface::ShowMessage
               (wxT("   autoObj->EvaluateReal() = %f\n"), autoObj->GetRealParameter(wxT("Value")));
         }
         catch (BaseException &e)
         {
            MessageInterface::ShowMessage(e.GetFullMessage());             
         }
         #endif
         
         autoObj->SetIsLocal(true);
         objectStore->insert(std::make_pair(autoObjName, autoObj));
      }
   }
   
   // first, send all the commands the object store, solar system, etc
   GmatCommand *current = fcs;
   
   while (current)
   {
      #ifdef DEBUG_FUNCTION_INIT
         if (!current)  MessageInterface::ShowMessage(wxT("Current is NULL!!!\n"));
         else MessageInterface::ShowMessage(wxT("   =====> Current command is %s <%s>\n"),
                 (current->GetTypeName()).c_str(),
                 current->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
      #endif
      current->SetObjectMap(objectStore);
      current->SetGlobalObjectMap(globalObjectStore);
      current->SetSolarSystem(solarSys);
      current->SetInternalCoordSystem(internalCoordSys);
      current->SetTransientForces(forces);
      #ifdef DEBUG_FUNCTION_INIT
         MessageInterface::ShowMessage
            (wxT("   Now about to set object map of type %s to Validator\n"),
             (current->GetTypeName()).c_str());      
      #endif
      // (Re)set object map on Validator (necessary because objects may have been added to the 
      // Local Object Store or Global Object Store during initialization of previous commands)
      validatorStore.clear();
      for (omi = objectStore->begin(); omi != objectStore->end(); ++omi)
         validatorStore.insert(std::make_pair(omi->first, omi->second));
      for (omi = globalObjectStore->begin(); omi != globalObjectStore->end(); ++omi)
         validatorStore.insert(std::make_pair(omi->first, omi->second));
      validator->SetObjectMap(&validatorStore);
      
      #ifdef DEBUG_FUNCTION_INIT
      MessageInterface::ShowMessage
         (wxT("   Now about to call Validator->ValidateCommand() of type %s\n"),
          current->GetTypeName().c_str());
      #endif
      
      // Let's try to ValidateCommand here, this will validate the command
      // and create wrappers also
      if (!validator->ValidateCommand(current, false, 2))
      {
         // get error message (loj: 2008.06.04)
         StringArray errList = validator->GetErrorList();
         wxString msg; // Check for empty errList (loj: 2009.03.17)
         if (errList.empty())
            msg = wxT("Error occurred");
         else
            msg = errList[0];
         
         throw FunctionException(msg + wxT(" in the function \"") + functionPath + wxT("\""));
      }
      
      #ifdef DEBUG_FUNCTION_INIT
      MessageInterface::ShowMessage
         (wxT("   Now about to initialize command of type %s\n"), current->GetTypeName().c_str());
      #endif
      
      // catch exception and add function name to message (loj: 2008.09.23)
      try
      {
         if (!(current->Initialize()))
         {
            #ifdef DEBUG_FUNCTION_INIT
            MessageInterface::ShowMessage
               (wxT("Exiting  GmatFunction::Initialize for function '%s' with false\n"),
                functionName.c_str());
            #endif
            return false;
         }
      }
      catch (BaseException &e)
      {
         throw FunctionException(wxT("Cannot continue due to ") + e.GetFullMessage() +
                                 wxT(" in the function \"") + functionPath + wxT("\""));
      }
      
      // Check to see if the command needs a server startup (loj: 2008.07.25)
      if (current->NeedsServerStartup())
         if (validator->StartMatlabServer(current) == false)
            throw FunctionException(wxT("Unable to start the server needed by the ") +
                                   (current->GetTypeName()) + wxT(" command"));
      
      current = current->GetNext();
   }
   
   // Get automatic global object list and check if they are used in the function
   // command sequence so that when any global object is declared in the main script
   // but not used in the function, they can be ignored during function local object
   // initialization. (LOJ: 2009.12.18)
   BuildUnusedGlobalObjectList();
   
   fcsFinalized = false;
   #ifdef DEBUG_FUNCTION_INIT
   MessageInterface::ShowMessage
      (wxT("GmatFunction::Initialize() exiting for function '%s' with true\n"),
       functionName.c_str());
   #endif
   
   #ifdef DEBUG_TRACE
   ShowTrace(callCount, t1, wxT("GmatFunction::Initialize() exiting"), true);
   #endif
   
   return true;
}