next up previous contents
Next: Mouse Up: User interface objects Previous: Command   Contents

Subsections


CommandQueue

Files: CommandQueue.h, CommandQueue.C
Derived from: none
Global instance (if any): commandQueue
Used in optional component: Part of main VMD code

Description

CommandQueue maintains a queue of Command's, and will go through this queue and execute them when requested. The queue is first-in first-out. This object also has the ability to log commands to a file.

There is one global instance of this class in VMD, called commandQueue. It is used by all the user interface objects (UIObject classes). Each time a new action is requested by the user or some other part of VMD, a new Command instance is created and added to the CommandQueue. Within the main event loop of VMD, after each UIObject is checked for new events, the commands in the queue are all executed until the queue is empty (since the execution of one command may result in the queuing of a new command, this process continues until the queue is empty). Each time the queue is checked, the following occurs:

Constructors

Internal data structures

Nonvirtual member functions

Method of use

When objects other than UIObjects wish to execute a command, they should use the global object commandQueue, and append the command:
commandQueue->append(new CmdReshape());
This command will not actually be run until the main event loop in VMD is run. If a command needs to be executed immediately, use runcommand:
int success = commandQueue->runcommand(new CmdReshape());

When UIObjects are adding commands, there are special funcions in UIObject to make this faster, `addcommand' and `runcommand'. Each UIObject is given a pointer to a CommandQueue object, and so the `addcommand' routine will take a command and add it to that queue. For example, in UIText there might be:

addcommand(new TextEvent("text command", id()));
Most commands have as their last argument an id code for the UIObject which created them. This is that so UIObjects can tell, when they are told that the command has executed, who started it all.

Suggestions for future changes/additions

There should be a version of runcommand that allows for executing a command without 'new'ing it. At least, there should be an argument to runcommand to allow this possibility.


next up previous contents
Next: Mouse Up: User interface objects Previous: Command   Contents
vmd@ks.uiuc.edu