Clarisse 5.0 SP8 SDK
5.0.5.8.0
|
This topic covers how to use the Clarisse commands system to use existing commands and create new ones.
Commands are Clarisse functionalities made available in a user friendly way, with additional services like undo and redo.
Commands declared in Clarisse are automatically exposed to Python.
A command is structured into a class which inherits from OfCommand. This new class must implement two pure virtual methods:
For example, let's say you create a command that modifies an object during the exec call. You have first to store its state to be able to restore it during the unexec call. For more information please refer to Command History section.
Once you created your command class it's time to register it in the command manager. The file app_command_manager.h in App library defines the class CommandRegistrar. This class is a helper which allows to quickly declare new commands.
Few parameters are required: Command name, command class info, parameters types and names.
To register the command 'MyTransformCommand' from the above example, we use the following line:
A few things there:
If you have to perform specific things before calling the command when its called (like modifying, checking or retrieving arguments), you can change the way its registered.
You can specify your own specific function as second parameter:
This is just an example of why you could need such declaration.
Finally, you may want to have multiple signatures for the same Command. It is possible by creating multiple constructors for the same command with different argument numbers. Then you just have to register several times, one for each constructor:
The following code calls a registered command:
Each time a new command is registered, it is automatically exposed in the Python namespace cmds. The previous registration example also defines the command in Python which can be called using:
You have to give the proper parameters types that the command expects, with some exceptions:
And, of course, you may want that a specific command is NOT available in python. You just have to specify it during registration:
The last argument false
specifies we don't want this signature to be exposed in Python. The 0
is a optional custom data (here empty).
When a user performs an action, a command should be systematically called as this is how Clarisse performs undo. Each time a command is called, it is appended to the command history. Undoing an action then becomes simply a call to the implementation of its unexec method.
In order to avoid creating a command each time an attribute is modified in a script, command history is automatically disabled before a Python script is run. However, sometimes, it can be useful to be able to undo a script.
To avoid filling the application command history, it's recommended to create a batch command. A batch command simply stacks commands in a local history. That local history then appears as a single named entry in the main history.
To create a bach command you must first make sure to activate the command history:
Then you just have to call:
and when completed.