3D PLM Enterprise Architecture

User Interface - Commands

Managing the State Dialog Command Lifecycle

Coding the command class constructor and destructor, and the methods Activate, Desactivate, and Cancel
Technical Article

Abstract

This article shows the roles of the command class constructor and destructor, and of the methods Activate, Desactivate, and Cancel in the command lifecycle.


Managing the State Dialog Command Lifecycle

The command lifecycle is managed using the constructor and the destructor, and using the three methods Activate, Desactivate, and Cancel.

[Top]

Constructor

The command constructor instantiates the command class. It should instantiate or retrieve the command class data members, or retrieve the pointers to the appropriate interfaces set as data members, that should be created once during the command lifecycle, and that are required at the beginning of the command.

Using the constructor, and using the CATStateCommand constructor, you can also manage the command running mode and possibly the argument passed to the command from the command header:

[Top]

Destructor

You should explicitly delete or release the data members created or retrieved once for the command, usually in the constructor or in the BuildGraph method, such as the dialog agents, compared to the data members created in the Activate method that should generally be deleted in the Cancel method.

Any state, transition, condition, or action created in BuildGraph using the methods proposed by the CATStateCommand class are automatically deleted. These methods are:

On the opposite, any state (CATDialogState), transition (CATDialogTransition), condition (CATStateCondition), or action (CATDiaAction) you explicitly instantiate using its constructor should be deleted in the command class destructor.

[Top]

Activate

Activate is called when the state dialog command takes the focus. This happen in two cases:

  1. The command is just selected by the end user. The command class is instantiated and the dialog starts from the beginning
  2. The command restarts at the state that was current when a shared command took the focus from it.

Activate can be used to create temporary objects that are needed from the beginning, either because they help the end user to perform the command, such as the outline of the created object, or a rubber band that follows the mouse, both known as interactive objects and added to the set of interactive objects (ISO), or construction objects that can be helpful.

[Top]

Desactivate

Desactivate is called when a shared command takes the focus. The active command becomes inactive, is frozen in its current state and put in the command stack. When the shared command will complete, the frozen command will be reactivated from its current state using the Activate method. Desactivate should hide temporary objects created by Activate, or by the action methods, such as a dialog box, or temporary interactive objects that should be removed from the ISO. Some objects should be deleted, such as the rubber band, that will never be restored as it were since it follows the mouse.

[Top]

Cancel

Cancel is called when the command completes, or when an exclusive command takes the focus and requests the command to be deleted. When the command completes, the focus is given to the default command (usually Select). If the command was set as a repeatable, the focus is given to it again. Cancel must delete or release temporary objects created by the command, possibly after having removed them from the sets of objects. It should also delete objects created in the action methods, or possibly in the condition methods, even if this code could be put in the destructor, except if the command were declared in repeat mode.

When the command is canceled, you can request the command undo when the command completes by calling the ExecuteUndoAtEnd method.

The following table summarizes the methods that go in pairs for creation/destruction of the command objects.

Creation/Destruction Destructor Desactivate Cancel Undo
Constructor X
BuildGraph X
Activate X
Action method X
Redo X

[Top]


In Short

A dialog state command is a dialog command designed as a state machine, each state enabling end user input, that enables the end user to pass from state to state using transitions between these states triggered when requested events happen and when requested guard conditions are satisfied, and that execute the declared actions. It is modeled using a class deriving from the CATStateCommand class.

The statechart diagram is implemented using the BuildGraph method, and the command life cycle is managed by the Activate, Desactivate, and Cancel methods in addition to the command class constructor and destructor.

[Top]


History

Version: 1 [Jan 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.