|Using Visio Shapes|
Explains how to use the accompanying Microsoft Visio template and shapes to create a state machine diagram and generate the state machine structure definition code from it.
Plain state diagrams are a common means to sketch the behavior of a component during its inception phase. Apparently the state machine design approach is inherently a visual design technique.
A state diagram is essential for communicating the state machine behavior to other stakeholders in the software development process. It should never go out of sync with the actual implementation, as it is a superior communication media compared to the source code.
Generating the code from the diagram ensures the visual representation of the component behavior is always up to date and in sync with the source code implementation.
The Microsoft Visio template and shapes can generate the StateMachineTemplate structure definition with the Region, EndRegion, State, EndState and Transition statements. Further the code generator can be adapted to emit lists of identifiers for states, transitions, events, actions and conditions.
Action and condition code is not defined within the diagram, instead it is suggested to encapsulate the action and condition code within methods and functions with speaking names. These methods and functions are referenced in the diagram as entry actions, exit actions, transition actions and guard conditions.
Generally there shouldn't be a problem to map diagrams created with StaMa Visio Shapes to the corresponding visual representations and semantic constructs of OMG UML Specification. However the collaboration with developers that expect a OMG UML Specification conformant visualization may be impaired.
The shapes must be arranged and connected in a specific way to form a valid state machine diagram. If they are not properly connected, the code generator emits incomplete code that usually doesn't compile.
Seen from a Microsoft Visio graphical object point of view the composition hierarchy of states and regions is provided through the Microsoft Visio grouping concept with an arbitrary depth nesting. Transitions are top level graphical objects that connect to the states. Each transition is composed of a transition knot that must be connected to the source state and a transition segment that must be connected to the targt state. In case of join and fork transitions the single transition knot must be extended with additional transition segments that connect to the multiple source and target states.
The following sections describe step by step how to use the shapes to create a particular state machine fragment.
The code generator requires the Microsoft Visio 32-bit version.
The code generator shapes use expressions written in Visual Basic Script to customize the generated code. Visual Basic Script is provided through the Microsoft Script Control (msscript.ocx) which is only available for 32-bit applications.