Model Center—Modelica Text View
|Zooming In and Out||Toggling Word Wrap|
|Code Management||Finding and Replacing Text|
|Expanding or Collapsing Annotations||Customizing the Modelica Text View|
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.
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+Return.
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.
Both single-line and multiline comments are supported in the text view in System Modeler. 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 following).
An example of multiline and single-line comments.
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 and text styles 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.
Expanding or Collapsing Annotations
To increase readability, each annotation is by default collapsed to a single character, », in the text editor. An annotation can be expanded by clicking the » character, or collapsed by clicking the annotation word. To expand or collapse all annotations, right-click anywhere within the Modelica Text View and choose 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.
Toggling Word Wrap
By default, lines with text are allowed to extend beyond the right edge of the editor. The behavior can be changed by enabling word wrapping. If enabled, any portion of a line that does not fit the viewable editor area is automatically displayed on the next line, enabling the text to be read without any horizontal scrolling. To enable word wrapping, right-click anywhere within the Modelica Text View and choose Word Wrap. Whether word wrapping should be enabled or disabled 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.
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 Return 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 "controlBus" has automatically highlighted all other occurrences of the word.
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. Choose Options from the Tools menu and select Model Center ▶ Modelica Text View in the left column of the dialog box.
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 here.
- 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.
- 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 appearance. 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 and text style of the item selected in Display items.
- Expand annotations. If checked, annotations are expanded in the Modelica Text View. If not checked, annotations are collapsed into the » character.
- 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.