The SRT Editor

A textual state machine is stored in a text file with the extension .srt, and you can edit it using any text editor. However, Model RealTime provides a dedicated text editor for .srt files called the "StatemachineRT Editor" (or SRT editor for short). It provides several features which increase your productivity when working with textual state machines.

Opening the SRT Editor

To open the SRT editor simply double-click on a state machine in the Project Explorer that is saved in an .srt file. You can also open it from the context menu by choosing one of the commands Open or Open With - StateMachineRT Editor.

Content Assist

Content assist helps you in editing an .srt file by automatically inserting small pieces of SRT code. Invoke it by placing your cursor somewhere in the .srt file and press Ctrl+Space. Depending on where the cursor is located different suggestions will appear in a popup menu. Not only does this feature reduce the typing effort, but it also is a great help when learning the SRT language.

For example, if the cursor is placed at the top inside a state machine, the content assist popup looks like this:

First comes model element proposals which will insert SRT code for a complete model element. At this place in an .srt file initial transitions, states and triggered transitions can be defined, and the yellow popup to the left shows the SRT code that will be inserted. After the model element proposals come individual keywords and other tokens from the SRT grammar, which are valid at this place in the .srt file. Finally, at the end, comes user-defined template proposals.

Often when you insert a model element proposal, there will be parts of the inserted text that need to be replaced. Such parts are called variables and you move between them using the Tab key. For example, if you invoke "New Triggered Transition" shown in the screen shot above, the inserted text looks like this:

statemachine 'State Machine' {
    fromState -> toState;
};

where the text "fromState" is selected. Type the name of the source state and press Tab to move the selection so that "toState" gets selected instead. Then type the name of the target state and press Tab again (or Enter) to finish.

Depending on context the content assist popup menu can sometimes contain names of elements that can be referenced at the current location. For example, if you invoke it after the on keyword in a transition the ports that can be referenced by a trigger for that transition will be suggested:

In the same way, invoking it after the dot (.) in the trigger will propose events that can be received by the selected port. Only in-events or out-events are proposed depending on the conjugation of the port.

User-defined Templates

You can extend content assist with your own user-defined templates. They are defined in the preference page StatemachineRT - Templates. Give your template a name and description and decide in which context is should appear. The context corresponds to where in the .srt file the cursor is placed. In the Pattern field type the text that should be inserted. The text can contain variables on the form ${name}, and the Insert Variable button can help you suggest appropriate variables depending on context.

User-defined templates appear last in the content assist popup. Therefore you can quickly get to them by pressing Arrow-Up in the content assist popup menu.

The inserted text will look like this:

Hover Tooltip

When you hover the mouse over names in the .srt file a tooltip will sometimes appear showing additional information about the named element. Typically the tooltip will contain the type of element, and any comment given for it. For example:

To make hover tooltips more useful it's good practise to write comments just before element names.

When you hold down the Ctrl key and hover the mouse over reference names, hyperlinks appear in the .srt file. For example:

You can click such hyperlinks to navigate to the referenced element. This works both for elements defined inside the .srt file (they will be highlighted in the SRT editor) and for elements defined outside of it (they will be highlighted in the Project Explorer).

Another useful navigation feature is to double-click elements shown in the Outline view for quickly jumping to a particular element in the .srt file. If you prefer to not have the Outline view open you can instead use the editor context menu command Quick Outline which brings up the outline in a popup window instead.

Formatting

After a while a textual state machine may get inconsistent formatting. For example, different users that have edited it over time may have used different indentation, different placement of curly brackets, different placement of code snippets etc. You can improve the readability of such an .srt file by running the editor context menu command Source - Format. If you only want to format a part of the .srt file, you can select that part before invoking the command.