Using the Model Explorer with Stateflow Objects

Viewing Stateflow Objects in the Model Explorer

Depending on what you edit, you can use one of these methods for opening the Model Explorer:

The Model Explorer appears similar to the following:

The main window has two panes: a Model Hierarchy pane on the left and a Contents pane on the right. When you open the Model Explorer, the Stateflow object you are editing (chart, truth table, or Embedded MATLAB function) is highlighted in the Model Hierarchy pane and its objects are displayed in the Contents pane. In the preceding example, the Model Explorer was opened from the Truth Table Editor for the truth table tt_func in the Stateflow chart myChart.

The Model Hierarchy pane displays the elements of all loaded Simulink models, which includes Stateflow charts, and their states, boxes, and functions. A preceding plus (+) character for an object indicates that you can expand the display of its child objects by double-clicking the entry or by clicking the plus (+). A preceding minus (-) character for an object indicates that it has no child objects.

Clicking an entry in the Model Hierarchy pane selects that entry and displays its child objects in the Contents pane. For convenience, a hypertext link to the currently selected object in the Model Hierarchy pane is included following the Contents of: label at the top of the Contents pane. Click this link to display that object in its native editor. In the preceding example, selecting the link

(Stateflow.TruthTable) myModel/myChart/myChart/tt_func

displays the truth table tt_func in the Truth Table Editor.

By default, the Model Explorer displays event and data child objects in the Contents pane for the selected object in the Model Hierarchy pane. To display additional or different child Stateflow objects in the Contents pane, do the following:

  1. From the Model Explorer, select View > List View Options.

  2. In the submenu, select any or all of the following individual options: States/Functions/Boxes/Etc., Transitions, Junctions, Events, or Data.

    To display all of the preceding Stateflow child objects, select All Stateflow Objects.

Each type of object, whether in the Object Hierarchy or Contents pane, appears with an adjacent icon. Objects that are subcharted (states, boxes, and graphical functions) have their appearance altered by shading.

Object

Icon

Icon for Subcharted Object

Chart

Not applicable

State

Box

Graphical function

Truth table function

Not applicable

Embedded MATLAB function

Not applicable

Simulink function

Not applicable

Data

Not applicable

Event

Not applicable

Target

Not applicable

The display of child objects in the Contents pane includes properties for each object, most of which are directly editable. You can also access the properties dialog box for an object from the Model Explorer. See Setting Properties for Stateflow Objects in the Model Explorer for more details.

Editing States or Charts in the Model Explorer

To edit a state or chart displayed in the Object Hierarchy pane of the Model Explorer, do the following:

  1. Right-click the object.

  2. Select Edit from the resulting menu.

    The selected object appears highlighted in the Stateflow Editor in the context of its parent.

Adding Data and Events in the Model Explorer

State, box, and function Stateflow objects can parent data and events. You can also add data and events to the Simulink model to make them globally available to all Stateflow objects in the model.

To add a data or an event to a Stateflow object or to the Simulink model, do the following:

  1. In the Model Hierarchy pane of the Model Explorer, select a Simulink model or a Stateflow object.

  2. From the Add menu, select Data or Event.

    A data or event is added to the Model Explorer Contents pane with the default name data or event. If you continue adding more data, each new data or event is named with an integer suffix (data1, event1, data2, event2, and so on).

    You can change the displayed properties for a data or event directly in the Model Explorer. You can also access the complete list of properties for a data or event from the Model Explorer. See Setting Properties for Stateflow Objects in the Model Explorer.

For more detailed examples of creating data and events in the Model Explorer, see Adding Events Using the Model Explorer and Adding Data Using the Model Explorer.

Adding Custom Targets in the Model Explorer

Custom targets are parented exclusively by a Simulink model. In the Model Explorer, you can add custom targets to a model as follows:

  1. In the Model Explorer, in the left Model Hierarchy pane, select the Simulink model to receive the custom target.

  2. In the Model Explorer, select Add > Stateflow Target.

    The Contents pane of the Model Explorer displays the new custom target with the default name untitled.

  3. In the Contents pane, right-click the row of the custom target and select Properties from the context menu.

    The Stateflow Custom Target dialog box appears.

  4. Enter the name of the custom target.

    You can use any string except the reserved names sfun and rtw.

  5. Specify other properties in the panes.

  6. Click Apply.

For more information, see How to Build a Stateflow Custom Target.

Renaming Objects in the Model Explorer

Follow these steps to rename a state, box, function, data, event, or target objects in the Model Explorer:

  1. Right-click the object row in the Contents pane of the Model Explorer.

    A pop-up menu appears.

  2. From the resulting pop-up menu, select Rename.

    The name of the selected object appears in a text edit box that overlays the Name property for the object row.

  3. Change the name of the target in the edit box and click outside the edit box.

You can also change the name of an object in the Model Explorer by changing the value of its Name property. See Setting Properties for Stateflow Objects in the Model Explorer for details.

Setting Properties for Stateflow Objects in the Model Explorer

To change one of the displayed properties of a displayed object in the Contents pane of the Model Explorer:

  1. In the Contents pane, click anywhere in the row of the displayed object.

    This highlights the row.

  2. Click an individual entry for a property column in the highlighted row.

To set all the properties for an object displayed in the Model Hierarchy or Contents pane of the Model Explorer:

  1. Right-click the object.

  2. Select Properties from the resulting menu.

    The properties dialog box for the object appears.

  3. Edit the appropriate properties and select Apply or OK to apply the changes.

To display the property dialog box dynamically for the selected object in the Model Hierarchy or Contents pane of the Model Explorer:

  1. Select View > Dialog View.

    The property dialog box for the selected object appears in the far right pane of the Model Explorer.

Moving and Copying Data, Events, and Targets in the Model Explorer

You can move data, event, or target objects to another parent by doing the following:

  1. Select the data, event, or target to move in the Contents pane of the Model Explorer.

    You can select a contiguous block of items by highlighting the first (or last) item in the block and then using Shift+click for highlighting the last (or first) item.

  2. Click and drag the highlighted objects from the Contents pane to a new location in the Model Hierarchy pane to change its parent.

    A shadow copy of the selected objects accompanies the mouse cursor during dragging. If no parent is chosen or the parent chosen is the current parent, the mouse cursor changes to an X enclosed in a circle, indicating an invalid choice.

You can accomplish the same outcome by cutting or copying the selected events, data, and targets as follows:

  1. Select the event, data, and targets to move in the Contents pane of the Model Explorer.

  2. In the Model Explorer, select Edit > Cut or Copy.

    If you select Cut, the selected items are deleted and are copied to the clipboard for copying elsewhere. If you select Copy, the selected items are left unchanged.

    You can also right-click a single selection and select Cut or Copy from the resulting menu. The Model Explorer also uses the keyboard equivalents of Ctrl+X (Cut) and Ctrl+C (Copy) on a computer running the UNIX or Windows operating system.

  3. Select a new parent machine, chart, or state in the Model Hierarchy pane of the Model Explorer.

  4. Select Edit > Paste. The cut items appear in the Contents pane of the Model Explorer.

    You can also paste the cut items by right-clicking an empty part of the Contents pane of the Model Explorer and selecting Paste from the resulting menu. The Model Explorer also uses the keyboard equivalent of Ctrl+V (Paste) on a computer running the UNIX or Windows operating system.

Changing the Port Order of Input and Output Data and Events

Input data, output data, input events, and output events each have numerical sequences of port index numbers. You can change the order of indexing for event or data objects with a scope of Input to Simulink or Output to Simulink in the Contents pane of the Model Explorer as follows:

  1. Select one of the input or output data or event objects.

  2. Click the Port property for the object.

  3. Enter a new value for the Port property for the object.

    The remaining objects in the affected sequence are automatically assigned a new value for their Port property.

Deleting Data, Events, and Targets in the Model Explorer

Delete event, data, and target objects in the Contents pane of the Model Explorer as follows:

  1. Select the object.

  2. Press the Delete key.

    You can also select Cut from the Edit menu or Ctrl+X from the keyboard to delete an object.

  


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