Click or drag to resize
StaMaUsing 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.

StaMa provides a document Template and a set of shapes for Microsoft Visio that support drawing state diagrams and generate code from them.

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.

Caution note Caution

The visual representation of regions, states and transitions created with StaMa Visio Shapes is partially different from the description of OMG UML Specification.

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.

Caution note Caution

The code generator requires the Microsoft Visio 32-bit version.

If StaMa Visio Shapes based diagrams are openend with the 64-bit version of Microsoft Visio, one or more of the message boxes as below will be shown.

Shape Types

The below set of Microsoft Visio shapes allows to assemble state diagrams of any complexity as explained in Programming State Machines

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.

HowTo Sections
Limitation to Visio 32-bit version

The code generator requires the Microsoft Visio 32-bit version.

If StaMa Visio Shapes based diagrams are openend with the 64-bit version of Microsoft Visio, one or more of the following message boxes will be shown:

Visio64WarningMsComCtlOcx
Visio64WarningStaMaCodegen
Visio64WarningVbaCompileError

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.

See also 64-bit versions of Office and Choose the 32-bit or 64-bit version of Office regarding provider recommendations about Office versions.