You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 18 Next »

Introduction

A Command represents sets of instruction(s) to perform a certain task in GMAT. A Command is associated with one or more Resources and describes how associated Resources will be utilized and evolved over time. Commands are sequential and they run in sequential order, which is called the Mission Control Sequence. Commands in GMAT are created in order, via script or GUI, for running a mission.
The following shows sample scripting of mission sequence:

BeginMissionSequence;
Propagate 'Prop To Periapsis' DefaultProp(DefaultSC) {DefaultSC.Earth.Periapsis};
Target 'Hohmann Transfer' DC1 {SolveMode = Solve, ExitMode = SaveAndContinue};
   Vary 'Vary TOI' DC1(TOI.Element1 = 1, {Perturbation = 0.0001, Lower = 0.0, Upper = 3.14159, MaxStep = 0.5});
   Maneuver 'Perform TOI' TOI(DefaultSC);
   Propagate 'Prop To Apoapsis' DefaultProp(DefaultSC) {DefaultSC.Earth.Apoapsis};
   Achieve 'Achieve RMAG = 42165' DC1(DefaultSC.Earth.RMAG = 42164.169, {Tolerance = 0.1});
   Vary 'Vary GOI' DC1(GOI.Element1 = 1, {Perturbation = 0.0001, Lower = 0.0, Upper = 3.14159, MaxStep = 0.2});
   Maneuver 'Perform GOI' GOI(DefaultSC);
   Achieve 'Achieve ECC = 0.005' DC1(DefaultSC.Earth.ECC = 0.005, {Tolerance = 0.0001});
EndTarget;  % For targeter DC1
Propagate 'Prop One Day' DefaultProp(DefaultSC) {DefaultSC.ElapsedSecs = 86400};


The following shows the mission sequence of the above script in GUI mode.


There are many types of built-in Commands for use in spacecraft missions. However, new Commands can be created to extend GMAT and perform a new desired task. This document will describe a general procedure how to add a new Command to the baseline GMAT code. If you would prefer to add your new Command as a plugin, please see instead the document "Building a GMAT Plug-in: A Walkthrough Using Visual Studio 2010".

Overview

All configurable Command types must be derived from GmatCommand. The GmatCommand class is derived from the base GMAT class, GmatBase. There are often intermediate classes as well, to encapsulate common data and methods for the Command type. For example, there is a PlotCommand class, which derives from GmatCommand, and from which ClearPlot, MarkPoint, PenDown, and PenUp Commands are derived. Data and method implementations that are common to all of these subclasses are placed in the PlotCommand class, and only those that need specific modifications are added or overridden in the subclasses. Only leaf Commands can be created and used in GMAT mission sequence.

Most Commands have one or more associated Resources and options. Though not shown in the above diagram, the associated Resource type of the PlotCommand is the Subscriber/XYPlot, and there are no command options. The example script syntax is

ClearPlot DefaultXYPlot; 

A more complicated command is shown below.

Propagate DefaultProp(DefaultSC) {DefaultSC.ElapsedSecs = 12000.0}; 

The associated Resource type is the Propagator type named "DefaultProp" and the Spacecraft type named "DefaultSC." The command option is "DefaultSC.ElapsedSecs = 12000.0." This script tells the Propagate command to propagate the Spacecraft object "DefaultSC" for 12000 seconds using the Propagator object "DefaultProp."

A maneuver command example is shown below.

Maneuver DefaultIB(DefaultSC);

The associated Resource type is the ImpulsiveBurn type named "DefaultIB" and the Spacecraft type named "DefaultSC." This script snippet tells the Maneuver Command to maneuver the Spacecraft object "DefaultSC" using the ImpulsiveBurn object "DefaultIB."


Commands in GMAT are executed in order, whether created via script or GUI, when running a mission. When a Command is created via GUI, it is set to use its default Resource and options. When a Command is created via script, the associated Resource must be created before the Commands are created, otherwise errors will occur during script parsing.  GMAT uses a late binding scheme to provide interconnection between Resource objects and Commands. Therefore, Commands store names of associated Resource objects during script parsing. Actual object instances are connected before the execution of Commands when the Sandbox is initialized. See the "GMAT Architectural Specification" document for more details on late binding scheme.

Required First Steps

In order to add a new Command to GMAT, some preliminary steps must be taken to set up your build environment:

  1. Download the configured GMAT source
  2. Download, or refer to, the GMAT C++ Code Style Guide from the GMAT Wiki – standard GMAT coding style must be followed for any new/modified code
  3. Build GMAT on your platform with no code changes (see instructions on building the source on the GMAT Wiki) [NOTE: to maintain cross-platform compatibility, code must build successfully using the GCC compiler in order to be considered for inclusion into GMAT]
  4. Run Sample Missions (or SmokeTests* and possibly a subset of relevant system test folders, if you have access to those) before code modification, to
    1. Confirm successful execution of the unmodified GMAT, and
    2. Obtain an initial set of 'truth' data for later testing

Once these steps have been completed and GMAT runs successfully as-is, you can start the work to create a new Command.

General Requirements

Though GMAT is a modular system, adding a new Command is not as simple as just compiling and linking a new class. There are requirements that must be met regarding, among other things:

  • Deriving from base classes (either an existing Command class, or GmatCommand)
  • Implementing, at a minimum, specific methods
  • Adding a new type to the appropriate factory (or creating a new factory)
  • Updating base type lists and related enumerated types
  • Modification of types and addition of methods in GUI management classes
  • Optionally, creating GUI components to edit your new Command

Required Methods

Among other generic methods provided by the GmatBase class, the following list details methods that should usually be implemented for a new Command. Note that InterpretAction() and Execute() methods are specific to the Command class and must be implemented.

  • InterpretAction(): Parses the command string and builds the corresponding command structures. During the script interpretation, this method is called to parse the string and to set Resource object names and options.
  • GetWrapperObjectNameArray(), SetElementWrapper(), ClearWrappers(): If a Command access configured Parameters or other Resource properties, these methods should be implemented.
  • RenameRefObject(): If a Command access configured Resource, this method should be implemented.
  • Initialize(): Initializes the internal command data. During the Sandbox initialization, this method is called to set Resource object pointers to the objects in the Sandbox.
  • Execute(): Performs actions on associated Resource objects or just performs actions without associated Resource objects. During the Sandbox execution, this method is called to perform actions.
  • TakeAction(): Performs an action specific to a Command. This method is usually called from other Commands.
  • GetGeneratingString(): Generates a command string as it appears in the script. This method is called when saving GUI resources and commands to script file or showing scripts from the individual resource panel.

Recommended Practices

There are practices and/or strategies that may be helpful to a developer in creating a new Command, e.g., sometimes it is helpful to:

  • First, determine scripting of the new component
  • Next, modify/add the minimal set of code for the new Command until the script parses
  • Then, add validation of the input data
  • Then, begin to add functionality (may be done in steps)

Adding a New Command

Base Code modifications:

  1. Decide which GMAT Command base class will be the parent of your new class. Most Commands derive from the GmatCommand class located in src/base/command.
  2. Add additional data or methods to the new class as needed.
  3. Implement the pure virtual methods of the parent class, and other public methods whose base/default implementation are not correct or sufficient for your new class. The only pure virtual method for Command is Execute() and must be implemented. For example, you may need to add some validation to the Initialize() method, so you would include new code in your Initialize() method and (almost certainly) call the parent Initialize() method as well.
  4. If your class is a leaf class, implement the Clone() and Copy()methods. Implement RenameRefobjects() method to handle renaming Resource names from the GUI. If your command does not reference any objects, add the macro "DEFAULT_TO_NO_REFOBJECTS" in the public part of your header file. This macro is replaced by RenameRefobjects() returning true during compilation time.
  5. If your class has cloned objects, implement cloning of objects in the copy constructor and the assignment operator appropriately. The assignment operator should delete owned cloned objects first before creating new owned cloned objects. If your class does not own any cloned objects, add the macro "DEFAULT_TO_NO_CLONES" in the public part of your header file. This macro is replaced by HasLocalClones() returning false.
  6. Update /src/base/factory/CommandFactory.cpp to add your new Command type. Add a new Command type to the data member "creatables" list in the CommandFactory constructor so that new Command type is recognized from the Interpreter. Update CreateCommand() method to return an instance of a new Command type when new Command instance is requested.
  7. Add your new class(es) to the MakeBase.eclipse file to make sure it is compiled.
  8. Add new Command class to Microsoft Visual C++ 2010 Express libGmatBase project if you prefer to build GMAT using MS Visual Studio.

GUI Code modifications:

  1. If you want to show customized icon for a new Command from the Mission tree, insert your new Command type to MissionIconType in /src/gui/app/GuiTreeItem.hpp. The new Command type must to be inserted between MISSION_ICON_OPENFOLDER and MISSION_ICON_DEFAULT. Add a statement to load the new Command icon file at the same position where new Type was inserted to MissionIconType in MissionTree.cpp in /src/gui/mission/MissionTree::AddIcons() since bitmaps index should match with the position in MissionIconType.
  2. If you want to specially handle the new Command type, for example creating different popup menu, add your new type in ItemType in /src/gui/app/GuiTreeItem.hpp and implement appropriately in MissionTree.cpp.
  3. Check CreateNewCommand() in /src/gui/app/GmatMainFrame.cpp to see if you need to add or modify the list (i.e. look in the switch statement), to match the modifications to GmatTreeItemData.
  4. Decide whether you can use the GmatCommandPanel which is a generic panel for a Command, or if you will need a custom GUI panel for your new Command. See "How to Create GMAT panels" for further instructions on creating a new GUI panel.
  5. Add your new class(es) to the MakeGui.eclipse file to make sure it is compiled
  6. Add your new Command class(es) to Microsoft Visual C++ 2010 Express GMAT_wxGui project if you prefer to build GMAT using MS Visual Studio.

System Test Readiness Criteria

Once you have completed your code modifications and additions, there are several criteria that must be met before the GMAT team will allow the code to be included into the GMAT base. Note that meeting these criteria does not guarantee that your commands will be added to GMAT.

  1. Update your code base with the latest configured GMAT code, merging the configured code into your code base when necessary.
  2. Build with the gcc compiler to make sure that it builds on other platforms. If you prefer, build with Visual Studio C++ Compiler.

Then, for those with code modification and system test privileges:

  1. Run SmokeTests and the applicable Command and/or command system test folder(s) successfully
  2. Inform testers of changes to GUI components, when applicable

Or, for those without code modification and system test privileges:

  1. Run unit-tests with the new code – these unit-tests must be thorough and should use input test data obtained from GMAT engineers when available
  2. Coordinate with GMAT team members to deliver code modifications

Step-By-Step Tutorial

This section shows an example how to create a new Command. The actual code for the command we are going to create is in Appendix B.

  1. Come up with Command syntax and actions.

For this example, we are going to add a new Display command. The Display command will display GMAT Parameters (Calculated Parameters, Array, Variable, and String) in the Message Window. The script syntax will be:
"Display ParameterName"
Where ParameterName is a configured Parameter object name.

  1. There are a couple of ways to create a new Command class. You can create it from scratch or copying existing class and modify it. To copy an existing class and modify it, look through built-in Commands in /src/base/command and see if you can find a similar Command that you will use for the new Command. If you don't see any similar Commands, just copy SaveMission class which provides basic methods and is simple enough to modify for a new Command. The SaveMission command writes the whole mission to a file.

Our Display class will be pretty similar to the Report class except it will write data to the Message Window instead of to a file. So Report.hpp and Report.cpp would be a good choice to copy and modify for our Display class. However, for this example, we will copy and modify SaveMission for Display command class to illustrate the steps needed to create the new Command. Copy the SaveMission.cpp and SaveMission.hpp files as Display.cpp and Display.hpp and save them in the /src/base/command directory.

  1. After copying the SaveMission C++ files, globally replace SaveMission with Display. Update only the author, date, description from the file prolog. Then, globally replace FILE_NAME with PARAM_NAME and fileName with paramName.
  2. In the Display.cpp file, change "Filename" to "Parameter" in PARAMETER_TEXT. This informs the GMAT code that the Display command has one associated object type of PARAMETER. Change FILENAME_TYPE to OBJECT_TYPE since "Parameter" is an object type. See /base/include/gmatdefs.hpp for the kinds of object types defined.
  3. Next, go to InterpretAction() method. This method parses the script line that was read from the Interpreter and does some syntax checking. In the InterpretAction() method, update the function prolog to match the script syntax which is "Display ParameterName". This method parses generatingString which is set from the Interpreter and builds command dataWhat does this mean?. Basically the Interpreter reads a script line and creates an instance of Display command and then calls Display::InterpretAction() to build the command data. The Display command expects two chunks, "Display" and "ParameterName", so add a check for the correct number of chunks. We can remove the code for removing single quotes since ParameterName does not require single quotes.
  4. Next, go to the GetGeneratingString() method. This method generates a syntactically-correct command string as it would be read from the script file. This method is called when saving a mission to a script file or showing a script from the GUI panel. The single quote is not needed around paramName, so remove it.
  5. Next, the Initialize() method needs to be implemented. The SaveMission class did not need additional code for Initialize(), but our Display class needs to add additional code to set Parameter object pointers. In order to handle various types of optional inputs to Commands in a generic way, Commands use ElementWrapper classes. For detailed description on how ElementWrapper classes are used in Command, see "Data Elements in Commands" section in "GMAT Architectural Specification." Since a Parameter type is required to be wrapped with ElementWrapper, include "ElementWrapper.hpp" and add ElementWrapper *paramWrapper to header. ElementWrapper access methods are also needed to set paramWrapper. These are the GetWrapperObjectNameArray(), SetElementWrapper(), and ClearWrappers() methods. When the Interpreter parses a command script line, it creates a wrapper for paramName and calls SetElementWrapper(). In the Initialize() method, call parent GmatCommand::SetWrapperReferences() to set wrapper references which is Parameter object. See Appendix B for actual code.
  6. Next, go to the Execute() method. In the Execute() method, we need to evaluate the paramWrapper and write a string value to MessageWindow using MessageInterface::ShowMessage().
  7. Next, we need to add our new command to factory class so that GMAT can properly create it. Open the /src/base/factory/CommandFactory.cpp to add the Display command. Modify the CreateCommand() method so that it can return a new instance of Display class. Modify the CommandFactory() constructor to add "Display" to the creatable command list.
  8. All of our code updates are now done. Assuming you are using Microsoft Visual Studio C++ 2010 Express to build GMAT, open the solution file for GMAT located at /build/windows-VS2010/GmatVS2010.sln. Add the new Display class to the project. Expand the libGmatBase -> Source Files -> command, and then add existing item Display.hpp and Display.cpp from /src/base/command folder. Build the project and fix any compilation errors.
  9. For gcc build, open /src/base/MakeBase.eclipse and add "command/Display.o" in OBJECTS section.

The next step is testing. Our Display command does not use any math algorithms, so we will just test it using a script. Create the following script.

Create Spacecraft sat1;
Create Variable var1
Create Array arr[2,2];
Create String str1

BeginMissionSequence

var1 = 123.456
arr(1,1) = 11
arr(1,2) = 12
arr(2,1) = 21
arr(2,2) = 22
str1 = 'This is my string'

Display sat1.X
Display var1
Display arr22
Display str1

Open GMAT and open the script. If you click on Mission tab, the Mission Sequence will look like this:

Press the Run button, then you will see the following text in the MessageWindow.
You can also add a new Display Command via the GUI. Append a Display Command to MissionSequence and double click on the new Display Command and you will see the following dialog opens. This dialog is the default dialog for the new Commands. If you want you can create a customized Command dialog and connect it to GMAT main menu item. See "How to Create GMAT Panels" for detail instructions.



Congratulations! You have created your first GMAT command.

Tutorial Sample Code

Display.hpp

 

//$Id$
 //------------------------------------------------------------------------------
 // Display
 //------------------------------------------------------------------------------
 // GMAT: General Mission Analysis Tool.
 //
 // Copyright (c) 2002-2014 United States Government as represented by the
 // Administrator of The National Aeronautics and Space Administration.
 // All Other Rights Reserved.
 //
 // Author: Linda Jun (NASA/GSFC)
 // Created: 2014/10/16
 //
 // Developed jointly by NASA/GSFC and Thinking Systems, Inc. under contract
 // number S-67573-G
 //
 /**Class declaration for the Display command
 */
 //------------------------------------------------------------------------------
 #ifndef Display_hpp
 #define Display_hpp 
 #include "GmatCommand.hpp"
 #include "ElementWrapper.hpp" 
 /**
Command used to write data to Message Window.
 */
 class GMAT_API Display : public GmatCommand
 {
 public:
 Display();
 virtual ~Display();
 Display(const Display& display);
 Display& operator=(const Display& display); 
 // inherited from GmatCommand
 virtual bool Execute();
 virtual bool InterpretAction();
 virtual bool SetElementWrapper(ElementWrapper* toWrapper,
 const std::string &withName);
 virtual void ClearWrappers(); 
 // inherited from GmatBase
 virtual bool Initialize();
 virtual GmatBase* Clone(void) const;
 virtual bool RenameRefObject(const Gmat::ObjectType type,
 const std::string &oldName,
 const std::string &newName);
 virtual const StringArray&
 GetWrapperObjectNameArray(bool completeSet = false); 
 // Parameter accessors
 virtual std::string GetParameterText(const Integer id) const;
 virtual Integer GetParameterID(const std::string &str) const;
 virtual Gmat::ParameterType
 GetParameterType(const Integer id) const;
 virtual std::string GetParameterTypeString(const Integer id) const; 
 virtual std::string GetStringParameter(const Integer id) const;
 virtual std::string GetStringParameter(const std::string &label) const;
 virtual bool SetStringParameter(const Integer id, 
 const std::string &value);
 virtual bool SetStringParameter(const std::string &label, 
 const std::string &value); 
 // for generating string
 virtual const std::string&
 GetGeneratingString(
 Gmat::WriteMode mode = Gmat::SCRIPTING,
 const std::string &prefix = "",
 const std::string &useName = ""); 
 DEFAULT_TO_NO_CLONES 
 protected:
 // Parameter IDs
 enum 
 {
 PARAM_NAME = GmatCommandParamCount,
 DisplayParamCount
 }; 
 std::string paramName;
 ElementWrapper *paramWrapper; 
 static const std::string
 PARAMETER_TEXT[DisplayParamCount - GmatCommandParamCount];
 static const Gmat::ParameterType
 PARAMETER_TYPE[DisplayParamCount - GmatCommandParamCount];
 }; 
 #endif // Display_hpp 
 

Display.cpp

//$Id$
 //------------------------------------------------------------------------------
 // Display
 //------------------------------------------------------------------------------
 // GMAT: General Mission Analysis Tool.
 //
 // Copyright (c) 2002-2014 United States Government as represented by the
 // Administrator of The National Aeronautics and Space Administration.
 // All Other Rights Reserved.
 //
 // Author: Linda Jun (NASA/GSFC)
 // Created: 2014/10/16
 //
 // Developed jointly by NASA/GSFC and Thinking Systems, Inc. under contract
 // number S-67573-G
 //
 /**

Class implementation for the Display command
 */
 //------------------------------------------------------------------------------ 
 #include "Display.hpp"
 #include "CommandException.hpp"
 #include "StringUtil.hpp" // for ToString()
 #include "MessageInterface.hpp" // for ShowMessage() 
 //#define DEBUG_DISPLAY_IA
 //#define DEBUG_DISPLAY_INIT
 //#define DEBUG_DISPLAY_EXE 
 //---------------------------------
 // static data
 //---------------------------------
 const std::string
 Display::PARAMETER_TEXT[DisplayParamCount - GmatCommandParamCount] = 
 {
 "Parameter",
 }; 
 const Gmat::ParameterType
 Display::PARAMETER_TYPE[DisplayParamCount - GmatCommandParamCount] =
 {
 Gmat::OBJECT_TYPE, // "Parameter",
 }; 
 
 //------------------------------------------------------------------------------
 // Display()
 //------------------------------------------------------------------------------
 /**
Constructs the Display command (default constructor).
 */
 //------------------------------------------------------------------------------
 Display::Display() :
 GmatCommand("Display"),
 paramWrapper(NULL)
 {
 parameterCount = DisplayParamCount;
 } 
 
 //------------------------------------------------------------------------------
 // ~Display()
 //------------------------------------------------------------------------------
 /**
Destroys the Display command (default constructor).
 */
 //------------------------------------------------------------------------------
 Display::~Display()
 {
 } 
 
 //------------------------------------------------------------------------------
 // Display(const Display& display)
 //------------------------------------------------------------------------------
 /**
Makes a copy of the Display command (copy constructor).
 *
@param display The original used to set parameters for this one.
 */
 //------------------------------------------------------------------------------
 Display::Display(const Display& display) :
 GmatCommand (display),
 paramName(display.paramName),
 paramWrapper(NULL)
 {
 } 
 
 //------------------------------------------------------------------------------
 // Display& operator=(const Display& display)
 //------------------------------------------------------------------------------
 /**
Sets this Display to match another one (assignment operator).
@param display The original used to set parameters for this one.
 *
@return this instance.
 */
 //------------------------------------------------------------------------------
 Display& Display::operator=(const Display& display)
 {
 if (this != &display)
 {
 paramName = display.paramName;
 paramWrapper = NULL;
 } 
 return *this;
 } 
 
 //------------------------------------------------------------------------------
 // bool Execute()
 //------------------------------------------------------------------------------
 /**
Executes the Display command
@return true always.
 */
 //------------------------------------------------------------------------------
 bool Display::Execute()
 {
 Gmat::WrapperDataType wrapperType = paramWrapper->GetWrapperType();
 std::string result = "Unknown";
 Integer precision = 16;
 bool zeroFill = false; 
 switch (wrapperType)
 {
 case Gmat::VARIABLE_WT:
 case Gmat::ARRAY_ELEMENT_WT:
 case Gmat::OBJECT_PROPERTY_WT:
 {
 Real rval = paramWrapper->EvaluateReal();
 result = GmatStringUtil::ToString(rval, precision, zeroFill);
 break;
 }
 case Gmat::PARAMETER_WT:
 {
 Gmat::ParameterType dataType = paramWrapper->GetDataType();
 switch (dataType)
 {
 case Gmat::REAL_TYPE:
 {
 Real rval = paramWrapper->EvaluateReal();
 result = GmatStringUtil::ToString(rval, precision, zeroFill);
 break;
 }
 case Gmat::RMATRIX_TYPE:
 {
 Rmatrix rmat = paramWrapper->EvaluateArray();
 result = rmat.ToString();
 break;
 }
 case Gmat::RVECTOR_TYPE:
 {
 Rvector rvec = paramWrapper->EvaluateRvector();
 result = rvec.ToString();
 break;
 }
 case Gmat::STRING_TYPE:
 {
 result = paramWrapper->EvaluateString();
 break;
 }
 default:
 throw CommandException
 ("Display cannot write \"" + paramName + "\" due to unimplemented "
 "Parameter data type");
 }
 break;
 }
 case Gmat::ARRAY_WT:
 {
 Rmatrix rmat = paramWrapper->EvaluateArray();
 result = rmat.ToString(precision, 1, false, "", false);
 break;
 }
 case Gmat::STRING_OBJECT_WT:
 {
 result = paramWrapper->EvaluateString();
 break;
 }
 default:
 break;
 } 
 MessageInterface::ShowMessage("%s = \n%s\n\n", paramName.c_str(), result.c_str()); 
 BuildCommandSummary(true); 
 return true;
 } 
 
 //------------------------------------------------------------------------------
 // void InterpretAction()
 //------------------------------------------------------------------------------
 /**
Parses the command string and builds the corresponding command structures.
 *
The Display command has the following syntax:
 *
Display ParameterName
 */
 //------------------------------------------------------------------------------
 bool Display::InterpretAction()
 {
 StringArray chunks = InterpretPreface(); 
 if (chunks.size() < 2)
 throw CommandException("Missing information for MissionSave command.\n"); 
 paramName = chunks[1]; 
 return true;
 } 
 
 //------------------------------------------------------------------------------
 // bool SetElementWrapper(ElementWrapper *toWrapper, const std::string &withName)
 //------------------------------------------------------------------------------
 /**
Sets an element wrapper for a given object name
 */
 //------------------------------------------------------------------------------
 bool Display::SetElementWrapper(ElementWrapper *toWrapper,
 const std::string &withName)
 {
 if (toWrapper == NULL)
 return false; 
 bool retval = false;
 ElementWrapper *oldWrapper = paramWrapper; 
 if (paramName == withName)
 {
 paramWrapper = toWrapper;
 retval = true;
 } 
 if (oldWrapper)
 delete oldWrapper; 
 return retval;
 } 
 
 //------------------------------------------------------------------------------
 // const StringArray& GetWrapperObjectNameArray(bool completeSet = false)
 //------------------------------------------------------------------------------
 const StringArray& Display::GetWrapperObjectNameArray(bool completeSet)
 {
 wrapperObjectNames.clear();
 wrapperObjectNames.push_back(paramName);
 return wrapperObjectNames;
 } 
 //------------------------------------------------------------------------------
 // void ClearWrappers()
 //------------------------------------------------------------------------------
 /**
Clears wrappers and set to NULL.
 */
 //------------------------------------------------------------------------------
 void Display::ClearWrappers()
 {
 ElementWrapper *wrapper = paramWrapper;
 paramWrapper = NULL; 
 if (wrapper)
 delete wrapper;
 } 
 //------------------------------------------------------------------------------
 // bool Initialize()
 //------------------------------------------------------------------------------
 /**
Performs the initialization needed to run the Display command.
 *
@return true if the Display is initialized, false if an error occurs.
 */
 //------------------------------------------------------------------------------
 bool Display::Initialize()
 { 
 bool retval = true; 
 if (GmatCommand::Initialize() == false)
 retval = false; 
 if (retval)
 {
 // Set wrapper reference
 if (SetWrapperReferences(*paramWrapper) == false)
 retval = false; 
 } 
 return retval;
 } 
 
 //------------------------------------------------------------------------------
 // GmatBase* Clone(void) const
 //------------------------------------------------------------------------------
 /**
This method returns a clone of the Display.
 *
@return clone of the Display.
 */
 //------------------------------------------------------------------------------
 GmatBase* Display::Clone() const
 {
 return (new Display(*this));
 } 
 
 //------------------------------------------------------------------------------
 // bool RenameRefObject(const Gmat::ObjectType type,
 // const std::string &oldName, const std::string &newName)
 //------------------------------------------------------------------------------
 /**
@see GmatBase
 */
 //------------------------------------------------------------------------------
 bool Display::RenameRefObject(const Gmat::ObjectType type,
 const std::string &oldName,
 const std::string &newName)
 {
 // Change Parameter name
 if (paramName.find(oldName) != oldName.npos)
 {
 paramName = GmatStringUtil::ReplaceName(paramName, oldName, newName);
 } 
 // Go through wrapper
 std::string desc = paramWrapper->GetDescription();
 if (desc.find(oldName) != oldName.npos)
 {
 paramWrapper->RenameObject(oldName, newName);
 } 
 // Go through generating string
 generatingString = GmatStringUtil::ReplaceName(generatingString, oldName, newName); 
 return true;
 } 
 
 //------------------------------------------------------------------------------
 // std::string GetParameterText(const Integer id) const
 //------------------------------------------------------------------------------
 std::string Display::GetParameterText(const Integer id) const
 {
 if (id >= GmatCommandParamCount && id < DisplayParamCount)
 return PARAMETER_TEXT[id - GmatCommandParamCount];
 else
 return GmatCommand::GetParameterText(id);
 } 
 
 //------------------------------------------------------------------------------
 // Integer GetParameterID(const std::string &str) const
 //------------------------------------------------------------------------------
 Integer Display::GetParameterID(const std::string &str) const
 {
 for (int i=GmatCommandParamCount; i<DisplayParamCount; i++)
 {
 if (str == PARAMETER_TEXT[i - GmatCommandParamCount])
 return i;
 } 
 return GmatCommand::GetParameterID(str);
 } 
 
 //------------------------------------------------------------------------------
 // Gmat::ParameterType GetParameterType(const Integer id) const
 //------------------------------------------------------------------------------
 Gmat::ParameterType Display::GetParameterType(const Integer id) const
 {
 if (id >= GmatCommandParamCount && id < DisplayParamCount)
 return PARAMETER_TYPE[id - GmatCommandParamCount];
 else
 return GmatCommand::GetParameterType(id);
 } 
 
 //------------------------------------------------------------------------------
 // std::string GetParameterTypeString(const Integer id) const
 //------------------------------------------------------------------------------
 std::string Display::GetParameterTypeString(const Integer id) const
 {
 if (id >= GmatCommandParamCount && id < DisplayParamCount)
 return GmatBase::PARAM_TYPE_STRING[GetParameterType(id)];
 else
 return GmatCommand::GetParameterTypeString(id);
 } 
 
 //------------------------------------------------------------------------------
 // std::string GetStringParameter(const Integer id) const
 //------------------------------------------------------------------------------
 std::string Display::GetStringParameter(const Integer id) const
 {
 switch (id)
 {
 case PARAM_NAME:
 return paramName;
 default:
 return GmatCommand::GetStringParameter(id);
 }
 } 
 
 //------------------------------------------------------------------------------
 // std::string GetStringParameter(const std::string &label) const
 //------------------------------------------------------------------------------
 std::string Display::GetStringParameter(const std::string &label) const
 {
 return GetStringParameter(GetParameterID(label));
 } 
 
 //------------------------------------------------------------------------------
 // bool SetStringParameter(const Integer id, const std::string value)
 //------------------------------------------------------------------------------
 bool Display::SetStringParameter(const Integer id, const std::string &value)
 {
 switch (id)
 {
 case PARAM_NAME:
 paramName = value;
 return true;
 default:
 return GmatCommand::SetStringParameter(id, value);
 }
 } 
 
 //------------------------------------------------------------------------------
 // bool SetStringParameter(const std::string &label, const std::string &value)
 //------------------------------------------------------------------------------
 bool Display::SetStringParameter(const std::string &label, const std::string &value)
 {
 return SetStringParameter(GetParameterID(label), value);
 } 
 
 //------------------------------------------------------------------------------
 // const std::string& GetGeneratingString(Gmat::WriteMode mode = Gmat::SCRIPTING,
 // const std::string &prefix = "",
 // const std::string &useName = "");
 //------------------------------------------------------------------------------
 const std::string& Display::GetGeneratingString(Gmat::WriteMode mode,
 const std::string &prefix,
 const std::string &useName)
 {
 // Build the local string
 generatingString = prefix + "Display ";
 generatingString += paramName; 
 // Then call the base class method for comments
 return GmatCommand::GetGeneratingString(mode, prefix, useName);
 }

  • No labels