Using the Stateflow® Editor

Stateflow® Editor Window

You use the Stateflow® Editor to draw, zoom, modify, print, and save a chart displayed in the window. It has the following appearance:

The Stateflow Editor window includes the following elements:

Displaying the Context Menu for Objects

Every object that you create in a chart has a shortcut menu associated with it. To display the shortcut (context) menu, do the following:

  1. Move your pointer over the object.

  2. Right-click the object.

    A menu of operations that apply to the object appears.

To display the context menu for the chart object, do the following:

  1. Move your pointer to an unoccupied location in the chart.

  2. Right-click the location.

    A menu of operations that apply to the chart appears.

Specifying Colors and Fonts

You can specify the color and font for items in the Stateflow Editor, as described in the following topics:

Changing Fonts for an Individual Text Item

You can change the font for an individual text item as follows:

  1. Right-click the text item.

  2. In the context menu, select Font Size > size of font.

You can also specify the label font size of a particular object:

  1. Left-click an individual text item in the Stateflow Editor.

  2. Select Edit > Set Font Size.

  3. In the context menu, select the font size.

Using the Colors & Fonts Dialog

The Colors & Fonts dialog allows you to specify a color scheme for a chart as a whole, or colors and label fonts for different types of objects in a chart.

To display the Colors & Fonts dialog, select Edit > Style in the Stateflow Editor.

The drawing area of the dialog displays examples of the types of objects whose colors and font labels you can specify. The examples use the colors and label fonts specified by the current color scheme for the chart. To choose another color scheme, select the scheme from the dialog's Schemes menu. The dialog displays the selected color scheme. Click Apply to apply the selected scheme to the chart or OK to apply the scheme and dismiss the dialog.

To make the selected scheme the default scheme for all charts, select Make this the "Default" scheme from the dialog's Options menu.

To modify the current scheme, position your pointer over the example of the type of object whose color or label font you want to change. Then left-click to change the object's color or right-click to change the object's font. If you left-click, a color chooser dialog appears.

Use the dialog to select a new color for the selected object type.

If the selected object is a label and you right-click, a font selection dialog appears.

Use the font selector to choose a new font for the selected label.

To save changes to the default color scheme, select Save defaults to disk from the Colors & Fonts dialog's Options menu.

Differentiating Syntax Elements in the Stateflow® Action Language

This release gives you the option of using color highlighting to differentiate the following syntax elements in the Stateflow action language:

Default Syntax Highlighting

Syntax highlighting is enabled by default, assigning the following colors to syntax elements:

This Stateflow chart illustrates the default highlighting for each language element:

If the parser cannot resolve a syntax element, the Stateflow Editor displays the element in the default text color.

To modify color assignments, see Editing Syntax Highlighting. To disable syntax highlighting, see Enabling and Disabling Syntax Highlighting.

Editing Syntax Highlighting

To edit syntax highlighting, follow these steps:

  1. In the Stateflow Editor, select Edit > Highlighting Preferences.

    The Syntax Highlight Preferences dialog appears.

  2. Click the color you want to change, choose an alternative from the color palette, and click Apply.

  3. Click OK to close the Syntax Highlight Preferences dialog.

Enabling and Disabling Syntax Highlighting

You can toggle syntax highlighting from the Tools and Edit menus in the Stateflow Editor. From the Tools menu, select Syntax Highlighting. From the Edit menu, follow these steps:

  1. Select Highlighting Preferences to open the Syntax Highlight Preferences dialog.

  2. Check or uncheck Enable syntax highlighting and click OK.

Selecting and Deselecting Objects

Once an object is in the drawing area, you need to select it to make any changes or additions to that object.

Select objects in the Stateflow Editor as follows:

When an object is selected, it is highlighted in the color set as the selection color (blue by default; see Specifying Colors and Fonts for more information).

Cutting and Pasting Objects

You can cut objects from the drawing area or cut and then paste them as many times as you like. You can cut and paste objects from one Stateflow chart to another. The Stateflow Editor retains a selection list of the most recently cut objects. The objects are pasted in the drawing area location closest to the current pointer location.

To cut an object, select the object and choose Cut from one of the following:

To paste the most recently cut selection of objects, choose Paste from either of the following:

Copying Objects

To copy and paste an object in the drawing area, select the objects and right-click and drag them to the desired location in the drawing area. This operation also updates the Stateflow clipboard.

Alternatively, to copy from one Stateflow chart to another, choose the Copy and then Paste menu items from either of the following:

You can group together states that contain other states (superstates).

Editing Object Labels

Some Stateflow objects (for example, states and transitions) have labels. To change these labels, place your pointer anywhere in the label and click. Your pointer changes to an I-beam. You can then edit the text.

You can use the shortcut (context) menu to change a label's font size:

  1. Select the states whose label font size you want to change.

  2. Right-click to display the shortcut menu.

  3. Place your pointer over the Font Size menu item.

    A menu of font sizes appears.

  4. Select the desired font size from the menu.

    The Stateflow Editor changes the font size of all labels on all selected states to the selected size.

Viewing Stateflow® Objects in the Model Explorer

To view or modify Stateflow Editor objects in the Model Explorer, follow these steps:

  1. Position your pointer over the state.

  2. Right-click to display the context menu for the state.

  3. Select Explore from the context menu.

    The Model Explorer opens (if not already open) and highlights the state in the left hierarchy pane to show any data or events defined by the state.

To view data and events defined by the parent state of a transition or junction, select Explore from the transition or junction's context menu.

The Model Explorer is the only place where you can view and modify data and events. See Defining Data and Defining Events for more details on using the Model Explorer to view, add, delete, and modify data and events for Stateflow objects. See also Using the Model Explorer with Stateflow® Objects for more details on using the Model Explorer to view Stateflow objects.

Zooming a Chart

You can magnify or shrink a chart, using the following zoom controls:

Using the Zoom Factor Selector

The Zoom Factor Selector allows you to specify the zoom factor by

Zooming with Shortcut Keys

This table is a summary of the shortcut keys you can use to perform some of the zooming operations described above:

Key

Zoom Operation

F

Highlight (select) an object and press the F key to fit it to view.

space bar

Set to full view of chart.

R or +

Increase zoom factor.

V or -

Decrease zoom factor.

Moving in Zoomed Charts with Shortcut Keys

You can also use number keys to move in zoomed charts according to their layout in the number keypad:

You can enter numbers for moving from the number keys above the alphabetic keys at any time or from the number keypad if NumLock is engaged for the keyboard. The 5 key fits the currently selected object to full view. If no object is selected, the entire chart is fit to view.

Zooming a Chart Object Using the Stateflow® API

How to Zoom a Chart Object

Use the Stateflow API method fitToView to zoom in on a graphical object in the Stateflow Editor. (See Using the API in the Stateflow API documentation for information about obtaining object handles.)

Objects You Can Zoom

You can zoom these objects in the Stateflow Editor:

Example of Zooming States in a Chart

Follow these steps to zoom in on different states in the sf_car demo:

  1. At the MATLAB® command prompt, type:

    sf_car;

    The chart shift_logic appears in the Stateflow Editor.

  2. To define an object handle for the chart shift_logic, type:

    myChart = find(sfroot,'-isa','Stateflow.Chart','name', ...
    'shift_logic');
    
  3. To define an object handle for the state upshifting, type:

    myState = find(sfroot,'-isa','Stateflow.State','name', ...
    'upshifting');
    
  4. To zoom in on the state upshifting, type:

    myState.fitToView;

    The Stateflow Editor zooms in on the state and highlights it.

  5. To define an object handle for the state downshifting, type:

    myState = find(sfroot,'-isa','Stateflow.State','name', ...
    'downshifting');
    
  6. To zoom in on the state downshifting, type:

    myState.fitToView;

    The Stateflow Editor zooms in on the state and highlights it.

  7. To zoom back to the chart level in the Stateflow Editor, type:

    myChart.fitToView;

    The chart shift_logic reappears, as shown below.

  8. You can also zoom in on a state using the sfgco function. Follow these steps:

    1. Click any state in the chart.

    2. At the MATLAB command prompt, type:

      myState = sfgco;

      This command assigns the selected state to the object handle myState.

    3. To zoom in on the selected state, type:

      myState.fitToView;

      The Stateflow Editor zooms in on the state and highlights it.

Undoing and Redoing Editor Operations

You can undo and redo operations you perform in the Stateflow Editor. When you undo an operation in the Stateflow Editor, you reverse the last edit operation you performed. After you undo operations in the Stateflow Editor, you can also redo them one at a time.

To undo an operation in the Stateflow Editor, do one of the following:

To redo an operation in the Stateflow Editor, do one of the following:

Exceptions for Undo

You can undo or redo all Stateflow Editor operations, with the following exceptions:

Stateflow® Chart Notes Dialog Box

You can use the chart notes dialog box to edit note properties.

The Note dialog contains the following properties for a chart note:

Field

Description

Label

The label for the note. This includes the name of the note and its associated actions.

Description

Textual description/comment.

Use display text as click callback

Checking this option causes a Simulink® model to treat the text in the Text field as the note's click function. The specified text must be a valid MATLAB expression comprising symbols that are defined in the MATLAB workspace when the user clicks this annotation. Note that selecting this option disables the ClickFcn edit field.

ClickFcn

Specifies MATLAB code to be executed when a user single-clicks this annotation. The Simulink model stores the code entered in this field.

Document Link

Enter a URL address or a general MATLAB command. Examples are www.mathworks.com, mailto:email_address, and edit /spec/data/speed.txt.

See Annotation Callback Functions in the Simulink User's Guide for a description of the ClickFcn edit field.

Keyboard Shortcuts for Stateflow® Charts

This table gives a comprehensive list of keyboard shortcuts for the Stateflow Editor.

Task

Windows® platformUNIX® platform

Display the parent of the currently displayed chart or subchart. There is no limit on the time between the entry of each period.

.. (two periods).. (two periods)

Zoom in by an incremental amount.

+ or r or R

+ or r or R

Zoom out by an incremental amount.

- or v or V

- or v or V

Fit chart to screen.

0 or Space Bar

0 or Space Bar

Zoom to normal view.

1

1

Move the current Stateflow Editor view down within the full chart.

2

2

Move the current Stateflow Editor view down and right within the full chart.

3

3

Move the current Stateflow Editor view left within the full chart.

4

4

Fit the currently selected object to full view. If no object is selected, the chart is fit to full view.

5

5

Move the current Stateflow Editor view right within the full chart.

6

6

Move the current Stateflow Editor view up and left within the full chart.

7

7

Move the current Stateflow Editor view up within the full chart.

8

8

Move the current Stateflow Editor view up and right within the full chart.

9

9

Delete the selected objects.

Delete

Delete

Access the contents of the currently highlighted subchart or truth table.

Enter

Enter

Perform any of the following actions:

  • If you are editing the label of an object, the Esc key disables label editing but leaves the object selected.

  • If objects are selected, the Esc key deselects all objects in the current view.

  • If the current chart view is the contents of a subchart and no object is selected, the Esc key changes the view to the parent of the subchart.

  • If the current chart view is at the chart level and no object is selected, the Esc key displays the Simulink model window for that chart's block.

Esc

Esc

Fit the currently selected object to screen. If no object is selected, the chart is fit to screen.

f or F

f or F

Pan leftd or D or Ctrl+Left Arrowd or D or Ctrl+Left Arrow
Pan rightg or G or Ctrl+Right Arrowg or G or Ctrl+Right Arrow
Pan upe or E or Ctrl+Up Arrowe or E or Ctrl+Up Arrow
Pan downc or C or Ctrl+Down Arrowc or C or Ctrl+Down Arrow
Go back in pan/zoom historyb or Bb or B
Go forward in pan/zoom historyt or Tt or T

Select the first state, function, truth table, or box parented (contained) by the currently selected object in the same chart. Selection order of contained objects is top-down, left-right. See also u key.

j (jump) or J

j (jump) or J

Select the next state, function, truth table, or box at the same containment level. Selection order of objects is top-down, left-right.

n (next) or N

n (next) or N

Select the previous state, function, truth table, or box at the same containment level. Selection order of objects is top-down, left-right.

p (previous) or P

p (previous) or P

Select the parent object of the currently highlighted object in the same chart. See also j key.

u (up) or U

u (up) or U

Customizing the Stateflow® Editor

You can write M-code to customize the Stateflow Editor by

Adding Items to Stateflow® Editor Menus

You use the Simulink customization manager to add items, including submenus, to the end of menus in the Stateflow Editor. For example, you can add menu items that invoke your own M-code functions.

To add an item to the end of a Stateflow Editor menu, you must create the following functions in an sl_customization.m file on the MATLAB path:

For detailed descriptions of these procedures, see Adding Items to Model Editor Menus in the Simulink User's Guide.

Code Example: Adding a Custom Submenu to the Stateflow® Editor.   The following sl_customization.m file adds a submenu called Set Font Style to the Stateflow Editor's Edit menu. The submenu contains three menu options for font style: Arial, Courier New, and Times New Roman. Your sl_customization function should accept one argument, a handle to an object called the Simulink.CustomizationManager. For example, you can set cm = sl_customization_manager at the MATLAB command line.

function sl_customization(cm)

  %% Register custom menu function.
  cm.addCustomMenuFcn('Stateflow:EditMenu', @getMyMenuItems);
end

%% Define the custom submenu function.

function schemaFcns = getMyMenuItems(callbackInfo)
  schemaFcns = {@getItem4};
end

%% Define the schema function for first submenu item
function schema = getItem1(callbackInfo)
  schema = sl_action_schema;
  schema.label = 'Arial';
  schema.userdata = 'font style Arial';
  schema.callback = @myCallback1;
end

%% Define the schema function for second submenu item.
function schema = getItem2(callbackInfo)
  schema = sl_action_schema;
  schema.label = 'Courier New';
  schema.userdata = 'font style Courier New';
  schema.callback = @myCallback1;

%% Define the schema function for third submenu item.
function schema = getItem3(callbackInfo)
  schema = sl_action_schema;
  schema.label = "Times New Roman';
  schema.userdata = 'font style Times New Roman';
  schema.callback = @myCallback1;
end

function myCallback1(callbackInfo)
  disp(['Callback for 'callbackInfo.userdata' was called']);
end

function schema = getItem4(callbackInfo)
  % Make a submenu label 'Set Font Style'
  % with the font styles defined in menu items above.
  schema = sl_container_schema;
  schema.label = 'Set Font Style';
  schema.childrenFcns = {@getItem1, @getItem2, @getItem3};
end

Custom Menu Example: Set Font Style.   When you run sl_customization(cm) described in Code Example: Adding a Custom Submenu to the Stateflow® Editor, the following new submenu appears in the Stateflow Editor.

Disabling and Hiding Stateflow® Editor Menu Items

You can disable or hide items that appear on Stateflow Editor menus by

For detailed descriptions of these procedures, see Disabling and Hiding Model Editor Menu Items in the Simulink User's Guide.

Code Example: Disabling the Print Command in the Stateflow® Editor.   The following sl_customization.m file disables the Print command in the File menu of the Stateflow Editor. The example assumes you set cm = sl_customization_manager.

function sl_customization(cm)

  %%Register custom filter function.
  cm.addCustomFilterFcn('Stateflow:PrintMenuItem', @myFilter);

end

function state = myFilter(callbackInfo)
  state = 'Disabled';
end

Custom Menu Example: Disable Print Menu Item.   After you run sl_customization(cm) described in Code Example: Disabling the Print Command in the Stateflow® Editor, the Stateflow Editor's File menu looks like this:

Displaying Menu Tags

To determine the tags that identify the menus or menu items you wish to customize on the Stateflow Editor, set the Simulink customization manager's showWidgetIdAsToolTip property to true by entering the following commands at the MATLAB command line:

cm = sl_customization_manager;
cm.showWidgetIdAsToolTip = true;

After enabling this property, the tag of each menu or menu item appears next to its label in the Stateflow Editor:

To turn off tag display, enter the following command at the MATLAB command line:

cm.showWidgetIdAsToolTip = false;

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS