A Class Element, which can be executed with Cameo Simulation Toolkit, must have its Classifier Behavior defined. The Classifier Behavior can be any kind of Behavior such as Activity, State Machine, and Interaction. This tutorial uses the State Machine Behavior to define the Behavior of the stopwatch.

To define the Classifier Behavior for the StopWatch Class, you have to create the Behavior on the StopWatch, which will be assigned later as the Classifier Behavior of the StopWatch automatically.

To define the Classifier Behavior for the StopWatch Class


  1. Right-click the StopWatch symbol on the Class diagram and select New Diagram > State-Machine Diagram.... A new State Machine Element will be created under the StopWatch Class with a new State Machine diagram.
  2. Name the State Machine diagram "StopWatch".
  3. Make sure that the StopWatch State machine is the Classifier Behavior of the StopWatch Class. To see the Classifier Behavior of the StopWatch Class, right-click the StopWatch symbol on the Class diagram and select Specification from the context menu. The Specification window will open.
  4. Select All from the Properties drop-down menu.

    All Attributes in the Properties Drop-down Menu of StopWatch Class in the Specification Dialog

  5. Scroll down to see the ClassifierBehavior row, and you will see that the Classifier Behavior of the StopWatch Class is defined by the StopWatch State Machine.

    Specification of transition

    Specification of class StopWatch

Next, we are going to create the StopWatch initial and final stages, and the four States (Ready, Running, Paused, and Stopped) in the initial stage as well.

To add an Initial stage to the StopWatch State Machine


  • Click Initial on the State Machine diagram toolbar, and then click any area on the State Machine diagram to place the Initial stage.

    Adding an Initial Stage to the StopWatch State Machine Diagram

 

To add the ready, running, paused, and stopped States


  1. Click State on the State Machine diagram toolbar, and then click any area on the diagram to place a State. Name the created State "ready".
  2. Repeat Step 1 to create the "running", "paused", and "stopped" States. 

    Four States Created on the StopWatch State Machine Diagram



To add a final stage to the State machine diagram


  • Click Final State on the State Machine diagram toolbar, and then click any area on the diagram to place the final stage. 

    The Final Stage Created on the StopWatch State Machine Diagram



Now that the initial and final stages have been created, you will need to add the transitions between them and among the four States in the initial stage.

To add a transition from the Initial stage to the ready State


  1. Click a stage (the Initial stage in this example) that will be the source of the transition to be created. The smart manipulator toolbar will open.
  2. Click the Transition icon on the smart manipulator toolbar. 

    The Transition Icon on the Smart Manipulator Toolbar

  3. Click a State (the ready State in this example) that will be the target of the transition. 

    The Transition between the Initial Stage and Ready State

  4. Repeat Steps 1 to 3 to create more transitions between the following States: 

    from the ready to running State 
    from the running to paused State 
    from the running to stopped State 
    from the paused to running State 
    from the paused to stopped State 
    from the stopped to ready State 
    from the stopped State to the Final stage

    Transitions Connecting the States of StopWatch State Machine

  5. Create a looping transition to the running State by clicking the Transitiontoself icon on the smart manipulator toolbar.
     The Transition to Self Icon on the Smart Manipulator Toolbar


  6. Now your StopWatch State machine will look similar to the one shown in the following figure

    The StopWatch State Machine with Its States and Transitions


You will see that some of the created transitions have the SignalEvent triggers. These triggers need signal Elements and a package that is required to store those signal Elements. You can add a package and create the signal Elements by using the browser context menu.

To add a new package for the signal Elements


  1. Right-click the Model node in the containment browser and select New Element > Package.
  2. Name the created package "signals"

    Creating the Signals Package in the Containment Browser



To create signal Elements


  1. Right-click the signals package and select New Element > Signal.
  2. Name the created signal "reset". The reset signal will be created and stored in the signals package.
  3. Repeat Steps 1 to 2 to create the split, start, stop, and unsplit signal Elements.

    Creating Signal Elements To Trigger StopWatch



To create signal Events for the transitions on the StopWatch State Machine diagram


  • Drag a signal Element from the containment browser to a transition on the State Machine diagram. The signal Event will later be specified as the trigger of the transition. 

    Dragging a Signal to a Transition to Create a Signal Event 


To create a signal Event for each transition


  1. Drag the start signal to the transition between the ready and running States.
  2. Drag the split signal to the transition between the running and paused States.
  3. Drag the stop signal to the transition between the running and stopped States.
  4. Drag the unsplit signal to the transition between the paused and running States.
  5. Drag the stop signal to the transition between the paused and stopped States.
  6. Drag the reset signal to the transition between the stopped and ready States.
  7. Drag the stop signal to the transition between the stopped and Final States. 

    StopWatch State Machine with Signal Events



Now each and every transition between the States has its own signal Event. Next, you will also need to create a signal Event for the transitiontoself of the running State. The signal Event that will be created as the trigger for the transitiontoself is called TimeEvent.

To create a signal Event for the transition to self of the running State


  1. Right-click the Transitiontoself of the running State and select Specification to open its Specification window.
  2. Click the Categorized View button to open the properties of the transition in the categorized view.
  3. Click the EventType row in the Trigger category and select TimeEvent from the drop-down menu.

    Specifying Time Event as the Signal Event for the Transition to Self of the Running State

  4. Click the When row in the Trigger category and type "1s" to specify that the trigger will send the time Event every second.

    Specifying the Value for the When Attribute in the Trigger Category

  5. Click Close. You will see all of the created stages, States, transitions, and signal Events are shown on the StopWatch State Machine diagram.

    The StopWatch State Machine with All of the Defined Stages,States, Transitions, and Signal Events