User Tools

Site Tools




The SteereoCommand class is the base class for all commands, which determine the steering functionality of a simulation.

Writing own commands

An example is already given in the Howto. Here I will explain more detailed what you can do in your commands:

Functions to use

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.

Functions to override

You shape the main characteristics of your command by overriding the following functions:

  • (mandatory)
     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.

  • (recommended)
     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.

  • (mandatory)
     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:

    • NOT_EXECUTED → the command couldn't be executed fully by some misfortune
    • REPETITION_REQUESTED → everything went fine, but the command shall be called again and thus be put into the command queue (again).
    • EXECUTED → everything went fine and the command will be removed from the command queue
  •  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.

steereo/classes/steereocommand.txt · Last modified: 2010/03/22 15:25 (external edit)