Displaying and Editing Modelica Text

You can display and edit the Modelica text of a class using the Modelica Editor.

Note: If you only want to do basic editing of an existing equation part, you can use the Equation Editor.

See Also
About Displaying and Editing Modelica Text
  1. Select and activate the class to edit.
  2. From the Behavior Authoring section of the action bar, click Modelica Editor .

    Tip: You can also access this command from the Action Pad panel. To access the Action Pad panel, from the Tools section of the action bar, click Action Pad , or right-click an empty area and select Display > Action Pad.

    The Modelica text of the class appears in a new tab in the Modelica Editor.

    Note: If a Modelica Editor is already open, the new tab appears in that editor, otherwise a new Modelica Editor appears, containing the new tab.
  3. Optional: For the tab, you can right-click the tab header and do any of:
    • Close to close the tab.
    • Detach in New Window to open a new Modelica Editor and display the tab in that editor.
  4. Select your display mode:
    • Edit Modelica : displays and allows editing of editable Modelica text in an expandable/collapsed code format.

      By default, this mode is selected.

    • Show Formatted Modelica : displays the full Modelica text with mathematical notation and hyperlinks for easy navigation. No editing can be done in this mode.
    • Show Used Classes : displays the used classes. While you are in this read-only mode, you cannot view the formatted text, and other options are disabled.
    • Show Flat Modelica : displays Modelica text after evaluation of component structure and inheritance. No editing can be done in this mode.

      Displaying a class as Flat Modelica text is useful, for example, when investigating a model where the concept of replaceable classes is heavily used (like large models using replaceable classes for many media calculations).

      Flat Modelica is available for:

      • Models
      • Blocks
      • Media packages
      • Connectors
      • Partial models
      • Functions
      • Type and other short class definitions
      • Attributes of inherited classes (for example buses).

      If the class selected is not supported, Used Classes is displayed.

      If the evaluation to Flat Modelica is not successful, an error message is displayed.

  5. Select if the Modelica Editor should change content depending on selections other than opening another class.

    This command works in Toggle mode.

    • To select that the content should only change when you open another class, from the header of the Modelica Editor, click Ignore Selection to activate this selection.

      The icon is changed to to indicating pinning, that is, that other selections than opening another class are ignored.

      This is the default selection.

    • To select that the content should change also when you, for example, select a variable in the Variable Browser or a component in the Component Browser, click Ignore Selection to activate this selection.

      The icon is changed to to indicating unpinned state, that is, other selections than opening another class also changes the content of the Modelica Editor.

  6. In the Edit Modelica mode, edit the Modelica text.

    If the padlock after the class path is red and closed the class is either not active or write-protected. Click the padlock. If it turns green and open , you can now edit the class.

    Tips:
    • White background of the editor indicates the text being editable, light gray background indicates the text being non-editable.
    • An icon indicates an element that contains subelements. Select the icon to display the subelements.
    • To decide what should be displayed, from the context menu, select Expand to access the following commands:
      • Hide all annotations
      • Show components and connections: to expand all components and connections
      • Show entire text: to expand also annotations.
    • If you select a class with the cursor, you can right-click and use any of the following commands to explore that class:
      • Selected Class > Open Class to open the class in the current tab.
      • Selected Class > Open Class in New Tab to open the class in a new tab.
      • Selected Class > Info to display the documentation layer for that class.
    • A number of features are available for editing:
      • You can use code completion when typing; by Ctrl+Shift you get possible alternatives to select from, including new defined variables not yet syntactically checked.
      • You can insert new function calls, and edit existing ones, by dedicated commands.
      • You can cut, copy, paste, find and replace, and go to a certain line using context menu commands.
      • You can auto-format a selection of the code:select it, right-click and select Auto-format.
      • You can comment out a section of the code: select it, right-click and select Comment Selection - now it is not executed. To activate the code again, select it, right-click and select Uncomment Selection.
      • You can insert types and insert statements, the latter helps you to get the proper structure of statements like if ... then ... else.
      • You can insert a name of a component from the model by right-clicking and selecting from the alternatives in Insert Component Reference.
      • You can insert a reference to a class defined locally by right-clicking and selecting from the alternatives in Insert Local Class Reference.
      • Automatic indenting.
      • You can, for each Modelica Editor dialog box, specify the maximum text length by pressing Shift and dragging the dotted line located to the right in the dialog box (the line is only visible when you can see positions larger than the maximum text length). The default value of this maximum line length can be changed by the flag Advanced.MaxLineLength. A value less than 50 cannot be specified.

    Changed unsaved text is indicated by a star in the tab header.
  7. Click Apply All to add this information to the active class without closing the Modelica Editor.

    Important: You do this for all unsaved tabs in the editor.

    If you click OK, you also close the Modelica Editor.

  8. Optional: In a Show Formatted Display mode, navigate through Modelica paths using hyperlinks.
  9. Optional: In a Show Used Classes mode, right-click and select Settings to access a number of additional, temporary, options. To switch back to the text editor, click Show Modelica Text .
  10. To display another class in the active tab in the Modelica Editor:

    • In the Modelica Editor, expand the list to select a class previously displayed, or a subclass then click Display .
    • Type the path of a class as text in the box then click Display .
    • Use the blue arrows to navigate through the previous and next class.

    Notes:
    • A red padlock appears after the class path to indicate that the displayed class is not the active class, so it cannot be edited.
    • To open a new tab with a new class, perform Step 1 and Step 2 above.

  11. Click to activate the class.

    Note: A green open padlock indicates that the class is editable. However, the class can only be edited in the Edit Modelica mode.

    If the class is not write-protected, the symbol turns green and open , you can now edit the Modelica text of this class.
  12. Click OK to save the changes and close the Modelica Editor.

    Important: You save the changes for all unsaved tabs in the editor.