The SteereoCommand class is the base class for all commands, which determine the steering functionality of a simulation.
An example is already given in the Howto. Here I will explain more detailed what you can do in your commands:
This functions from SteereoCommand can be used to configure your own command:
void setCommandName (std::string name)
With this you determine the name of your command. This can be quite important as this will be the name a client has to use to call this command, when you decide to automatically load the commands into your simulation.
void setUndoable (bool flag = true)
per default a command is not undoable. But with this function you can declare it as such. You also have to override the undo function then. With this the command will get into an execution history queue after execution and can be “undone” (it calls the undo function), if the client requests it.
void* getData ()
int getDataSize ()
Get the data pointer and the size of the data given to the command in the simulation. Especially with Fortran simulations the simulation data will only be available this way.
SteereoStream* getAdditionalData ()
Access data which the client transferred additionaly to the parameters.
SteereoCommunicator* getCommunicator ()
SteereoConnection* getConnection ()
Gives you the communicator respectively the connection to the client, that requested this command. Will be very helpful for sending results to the client.
The first two can be set as the second (name), respectively first parameter (undoable flag) of the SteereoCommand constructor.
You shape the main characteristics of your command by overriding the following functions:
static SteereoCommand* generateNewInstance ()
In this function you should specify how to generate a new instance of your command. In most cases a return new myCommand; should suffice.
void setParameters (std::list<std::string> params)
The command receives the parameters with which the client requests it. If your command is parameterized, you have to implement this function.
ReturnType execute ()
The core of your command. Here you should specify what your command does. At the end you should return one of the following values:
ReturnType undo ()
Only needed, when you set the undoable flag to true. Then you have to specify here how the command can be undone. The return value is of the same type as for the execute function.
bool condition ()
Before a command is executed the function condition is called. If the result is true (the default implementation just returns that) the command is executed, otherwise it is left in the queue. For example you can achieve, that the command is only executed, when the current step number is divisible by 5 or every 5 steps, when your execute function returns REPETITION_REQUESTED.