Objective Views : Chapter 12 Commands : Command Classes
Command Classes
This section outlines the various command classes available in Objective Views.
CODCommand
This is the base class of all the command objects in Objective Views. It monitors the model on which the command is executing. It also monitors a set of the CODComponent objects that it affects. Each command object has an ID associated with it so the code can distinguish among commands without using run-time type information.
CODMoveCommand
The move command moves a set of components. This command enables the end-user to move not only the component, but also its horizontal and vertical offsets. It applies a new offset to change the component's position. To undo the action, CODMoveCommand uses the negative of the offsets. When a macro command is executed, the class searches through the commands sequentially and then executes it. To undo an action, it searches through the commands in reverse order and then unexecutes it.
CODRotateCommand
The rotate command rotates a set of components. The only parameter it needs is the angle at which to rotate. Components always rotate from their centers. When you undo a rotate action, CODMoveCommand rotates the component by the negative of the former angle.
CODScaleCommand
The scale command scales a component to a different size. To scale, the horizontal and vertical scaling factors are needed, as well as the point of reference to use for scaling. To undo the action, the application calculates the inverses of the scaling factors as well as the point to use as a reference for the inverse scaling.
CODInsertVertexCommand
The insert vertex command adds a vertex to a primitive component. It needs the coordinates of the new vertex and the array index to insert the vertex. When you undo the action, a CODDeleteVertexCommand is created and executed.
CODDeleteVertexCommand
The delete vertex command removes a vertex from a primitive component. To delete, the index of the vertex is used. When you undo an action, a CODInsertVertexCommand is created and executed.
CODMoveVertexCommand
The move vertex command moves a single vertex of a component. It uses the index of the vertex, as well as the horizontal and vertical offsets, to move it. When you undo the action, the negatives of the offsets are used.
CODMovePortCommand
This command moves a port belonging to a symbol. Only one port can be moved at a time with this command. This command can also be used to connect the port being moved to another port.
CODSpacingCommand Class
The spacing command allows you to evenly space a set of components horizontally, vertically, or both. Objective Views supports two types of spacing values: fixed values specified by the caller and values that are automatically calculated so that the components are spread evenly across the current range. The SetHorizontalSpacing() and SetVerticalSpacing() functions set the spacing mode and optional spacing value.
The command saves the position of each component in a map prior to execution, so that CODComponent::SetPosition() can be used by CODSizeCommand::Unexecute() to restore the position and size of the components.
CODSizeCommand Class
The size command sets the size of one or more components. You can use the size command to set a component’s width, height, or both. Sizing occurs about a fixed control point on the components. The command saves the position of each component in a map prior to execution so that CODComponent::SetPosition() can be used by Unexecute() to restore the position and size of the component.
CODNameCommand
The name command sets the name of a component. When you execute this command, it stores the former name in the model and then applies the new name to the component. When you undo the action, the former name is retrieved from storage and then set for the component.
CODTextCommand
The text command sets the string for a text component. The old text is stored and then the new text is set for the component. When you undo the action, the old text is retrieved from storage and then set for the component.
CODTransparencyCommand
The transparency command sets a color to transparent in a bitmap component. It stores previous transparency values for the bitmaps and then sets in the new ones. When you undo this action, the previous transparency settings are retrieved and set in the bitmap components.
CODLinkCommand
The link command inserts a link object that defines a relationship between two symbols. It needs two ports to form the link. It can also use a set of points that define how the link lines are laid out. When you undo this action, a CODDeleteCommand is created and executed, which unhooks and deletes the link.
CODUpdateCommand
This command is used by the model to report changes to its observers. CODUpdateCommand is not logged in the transaction model. Instead, it is passed to the viewport’s OnUpdate() method. The viewport determines which pieces of the screen to invalidate based on the components in the update command.
CODIndexedCommand
There are several commands, like deleting and inserting, that affect the z-order, or stacking order, of the components. When the end-user undoes a command or redoes an undone command, the symbol is placed at the top of the stack unless the command is derived from CODIndexedCommand. CODIndexedCommand encapsulates the code so you can save and restore the z-order of the components affected by the command.
CODInsertCommand
Use this command to insert a new component into the model. When you execute this command, the components in its set are added to the model. When you undo the action, a CODDeleteCommand is created and executed.
CODDeleteCommand
The delete command removes components from the model. When you execute this command, the components in its set are removed from the model. When you undo the action, a CODInsertCommand is created and executed.
CODGroupCommand
The group command combines a set of components into one composite. The components are removed from the model and then replaced by the group. When you undo the action, the components are removed from the composite and inserted into the model.
CODUngroupCommand
The ungroup command takes a set of composite components and then divides them into individual child components. It removes the composites from the model and replaces them with the first level children. When you undo the action, the child components are grouped back into composites.
CODOrderCommand
The order command changes the z-order of a set of components. You can change the order in four ways: move the component back one, move the component forward one, move the component to the back of the stack, move the components to the front of the stack.
The original order of the components is saved and then the components are moved within the stacking order. When you undo the action, the original orders are retrieved from memory and the components are moved back to their original positions.
CODMacroCommand
This macro command is a collection of CODCommands. It groups many commands into a single unit for execution. Organizing your commands into a single unit gives the end-user the ability to undo and redo multiple actions at once. This functionality is used frequently in the component property sheet to change many properties at once.
CODAlignCommand
The alignment command aligns a set of components in relation to an anchor component. The anchor component is the last one in a set of components. There are six different ways to align a component: top, middle, bottom, left, center, and right.
The alignment command comprises many different move commands—which is why it is derived from CODMacroCommand. Each component in the set of selected components has a corresponding move command that moves it by the proper offsets to align it with the anchor. When you undo the action, the negative offsets of the move commands are used.
CODPropertyCommand
The property command sets a property for each component in its set. When this object executes, it caches the previous property of the components, and then passes its CODProperty object to the components. When you undo this action, it retrieves the old properties from memory and sends them to the components.
CODFontCommand
The font command is a special case of the property command. Because the font is being changed, the box surrounding the text may be changed as well. To undo this type of command, the old position of the box must be saved. The font command handles storing this information. The rest of the information is handled by CODPropertyCommand.
Commands are essential to the undo/redo capabilities of Objective Views. Each command encapsulates an action performed on the model as well as the ability to reverse that action. When executed, the commands are logged in the model’s transaction model. The transaction model has the ability to unexecute the commands.