WOLFRAM SYSTEMMODELER TUTORIAL

Model CenterModelica Text View

Introduction | Class Browser | Class Window | Graphical Views | Modelica Text View | Component Browser | Variable Views | Reliability View | Messages View | Kernel Command View | Documentation Center | Functional Mock-up Interface | Keyboard Shortcuts | Kernel Commands

The Modelica Text View is a text editor where the textual representation (Modelica definition) of the class can be viewed and edited. The Modelica Text View allows you to access and edit all attributes of a class. In most situations, the graphical views are easier to work with and provide a better overview of the class. However, the graphical views do not let you edit all aspects of a class. For instance, to edit the equations of a class, the Modelica Text View is used.

1.gif

The textual representation of the ForceAndTorque model in Modelica.Mechanics.MultiBody.Forces.

Any changes made to the class in the Modelica Text View are applied when saving the class or when switching to a view that accesses the Modelica definition of the class. The changes can also be applied manually by pressing Shift+Enter.

The Modelica class definition is checked for syntax errors when applying changes in the Modelica Text View. Syntax errors will appear as clickable links in the Messages view. Clicking a link will highlight the row where the error originates. It is important that the syntax errors are corrected before editing the class (or any other class) in any other view, or you risk losing the parts of the class definition with syntax errors.

The position (line and column) of the text cursor is visible in the status bar when the Modelica Text View is active.

Zooming In and Out

The Modelica text view has zoom in and out capabilities. To zoom in or out, either use the drop-down menu located in the toolbar or press Ctrl and rotate the mouse scroll wheel forward or backward.

Code Management

Both single-line and multiline comments are supported in the text view in SystemModeler. The multiline comments, /*comment*/, are most often used to comment out larger sections that cover several lines, whereas the single-line comments, //comment, only comment out the line in which the double slash is inserted (see example below).

An example of multiline and single-line comments.

Syntax Highlighting

To make Modelica code easier to read and write, the text editor highlights elements of the Modelica language in different colors. The highlighting is performed in real time while typing or modifying text in the text editor. The colors used by the highlighter can be customized in the Options dialog box; see how to customize the Modelica Text View.

To further assist you in reading and writing Modelica code, the editor will highlight matching parentheses, braces, and brackets. Whenever you type one of these parentheses, or place the text cursor next to an existing parenthesis, the editor will attempt to match it. If a matching parenthesis is found, the parenthesis, as well as the text in between, will be highlighted.

Toggling Annotation Visibility

To increase readability, each annotation is by default collapsed to a single character, ¤, in the text editor. Annotations can be expanded or collapsed by right-clicking anywhere within the Modelica Text View and choosing Expand Annotations or Collapse Annotations from the popup menu. The default behavior can be specified in the Options dialog box; see how to customize the Modelica Text View.

Finding and Replacing Text

The find and replace toolbar allows you to search in the Modelica Text View of a class window and to make text substitutions if you wish. To open the find and replace toolbar, choose Edit Find.

3.gif

Searching for parameters in the Modelica Text View.

Enter the text you intend to search for in the Find what text field. The search is performed while you are typing, and if the text is found, it will be selected in the document and all matches become highlighted. Click the Find Next button or press Enter to find the next occurrence of the text. The search automatically continues past the end or start of the document into the unsearched portion. If the text is not found at all, the background color of the text field will turn red.

Clicking the Replace button will substitute the first occurrence of the text you search for with the text entered in the Replace with text field. To replace all occurrences of the text, click the Replace All button.

By default, the search is performed from the insertion point and forward in the document. To search backward from the insertion point, select the Search up checkbox. Check the Match case checkbox to restrict the search to look only for occurrences that match the uppercase and lowercase characters you enter. You can also choose to search only for whole words, rather than matching the text as it occurs within words, by checking the Match whole words only box.

Close the find and replace toolbar by clicking the close button or pressing the Esc key.

To get a quick overview of all occurrences of a particular word or a piece of text without using the Find function, simply mark the text, and all other matches will be highlighted automatically.

Marking the word "input" has automatically highlighted all other occurrences of the word.

Printing

You can print the contents of the currently active Modelica Text View by choosing File Print. By default, a page header including the name of the printed class and the page number is inserted on every page. Also, to the left of each line of code, a line number is inserted. To turn off the header or line numbers, choose File Page Setup and open the Page Setup dialog box. In the Print Setup tab, clear the checked boxes in the Paper Decorations section.

The Print Setup view of the Page Setup dialog box.

Customizing the Modelica Text View

The text editor of the Modelica Text View may be customized in the Options dialog box. To open the dialog box, choose Options from the Tools menu.

Editing the options of the Modelica Text View.

All settings in the dialog box are automatically saved when closing the dialog box and restored the next time the model editor is started.

The sections of the Modelica Text View options are described in detail below.

  • Font and Colors The Font and Colors settings allow you to establish a custom font and color scheme for various display items in the Modelica Text View.
  • Font. The font style to use in the Modelica Text View. Changing the font affects all Display items.
  • Size. Specifies the point size of the font to use in the Modelica Text View. A point is a traditional measure used by typesetters and is equal to 1/72 of an inch. Changing the font size affects all Display items.
  • Display items. Lists the items for which you can modify the foreground color. Text is the default display item. As such, properties assigned to Text will be overridden by properties assigned to other display items. For example, if you assign the color blue to Text and the color green to Identifier, all identifiers will appear in green. In this example, Identifier properties override Text properties.
  • Item foreground. Specifies the foreground color of the item selected in Display items.
  • Sample. Displays a sample of the font and color scheme for the Modelica Text View. You can use this box to preview the results as you experiment with different formatting options.
  • Options These options allow you to customize some aspects of the Modelica Text View.
  • Collapse annotations. If checked, annotations in class definitions are by default collapsed into a ¤ character in the Modelica Text View.
  • Show a warning message before deleting collapsed annotations. Specifies whether or not a warning message is shown when a collapsed annotation is deleted in the Modelica Text View.

Introduction | Class Browser | Class Window | Graphical Views | Modelica Text View | Component Browser | Variable Views | Reliability View | Messages View | Kernel Command View | Documentation Center | Functional Mock-up Interface | Keyboard Shortcuts | Kernel Commands