MDT – The OpenModelica Development Tooling Eclipse Plugin¶
Introduction¶
The Modelica Development Tooling (MDT) Eclipse Plugin as part of OMDev – The OpenModelica Development Environment integrates the OpenModelica compiler with Eclipse. MDT, together with the OpenModelica compiler, provides an environment for working with Modelica and MetaModelica development projects. This plugin is primarily intended for tool developers rather than application Modelica modelers.
The following features are available:
- Browsing support for Modelica projects, packages, and classes
- Wizards for creating Modelica projects, packages, and classes
- Syntax color highlighting
- Syntax checking
- Browsing of the Modelica Standard Library or other libraries
- Code completion for class names and function argument lists
- Goto definition for classes, types, and functions
- Displaying type information when hovering the mouse over an identifier.
Installation¶
The installation of MDT is accomplished by following the below installation instructions. These instructions assume that you have successfully downloaded and installed Eclipse (http://www.eclipse.org).
The latest installation instructions are available through the OpenModelica Trac.
- Start Eclipse
- Select Help->Software Updates->Find and Install... from the menu
- Select ‘Search for new features to install’ and click ‘Next’
- Select ‘New Remote Site...’
- Enter ‘MDT’ as name and http://www.ida.liu.se/labs/pelab/modelica/OpenModelica/MDT as URL and click ‘OK’
- Make sure ‘MDT’ is selected and click ‘Finish’
- In the updates dialog select the ‘MDT’ feature and click ‘Next’
- Read through the license agreement, select ‘I accept...’ and click ‘Next’
- Click ‘Finish’ to install MDT
Getting Started¶
Configuring the OpenModelica Compiler¶
MDT needs to be able to locate the binary of the compiler. It uses the environment variable OPENMODELICAHOME to do so.
If you have problems using MDT, make sure that OPENMODELICAHOME is pointing to the folder where the OpenModelica Compiler is installed. In other words, OPENMODELICAHOME must point to the folder that contains the Open Modelica Compiler (OMC) binary. On the Windows platform it’s called omc.exe and on Unix platforms it’s called omc.
Using the Modelica Perspective¶
The most convenient way to work with Modelica projects is to use to the Modelica perspective. To switch to the Modelica perspective, choose the Window menu item, pick Open Perspective followed by Other... Select the Modelica option from the dialog presented and click OK..
Selecting a Workspace Folder¶
Eclipse stores your projects in a folder called a workspace. You need to choose a workspace folder for this session, see Figure 73.
Creating one or more Modelica Projects¶
To start a new project, use the New Modelica Project Wizard. It is accessible through File->New-> Modelica Project or by right-clicking in the Modelica Projects view and selecting New->Modelica Project.
You need to disable automatic build for the project(s) (Figure 75).
Repeat the procedure for all the projects you need, e.g. for the exercises described in the MetaModelica users guide: 01_experiment, 02a_exp1, 02b_exp2, 03_assignment, 04a_assigntwotype, etc.
NOTE: Leave open only the projects you are working on! Close all the others!
Building and Running a Project¶
After having created a project, you eventually need to build the project (Figure 76).
The build options are the same as the make targets: you can build,
build from scratch (clean), or run simulations depending on how the
project is setup. See Figure 77 for an example of how omc
can be compiled (make omc
builds OMC).
Switching to Another Perspective¶
If you need, you can (temporarily) switch to another perspective, e.g. to the Java perspective for working with an OpenModelica Java client as in Figure 79.
Creating a Package¶
To create a new package inside a Modelica project, select File->New->Modelica Package. Enter the desired name of the package and a description of what it contains. Note: for the exercises we already have existing packages.
Creating a Class¶
To create a new Modelica class, select where in the hierarchy that you want to add your new class and select File->New->Modelica Class. When creating a Modelica class you can add different restrictions on what the class can contain. These can for example be model, connector, block, record, or function. When you have selected your desired class type, you can select modifiers that add code blocks to the generated code. ‘Include initial code block’ will for example add the line ‘initial equation’ to the class.
Syntax Checking¶
Whenever a build command is given to the MDT environment, modified and saved Modelica (.mo) files are checked for syntactical errors. Any errors that are found are added to the Problems view and also marked in the source code editor. Errors are marked in the editor as a red circle with a white cross, a squiggly red line under the problematic construct, and as a red marker in the right-hand side of the editor. If you want to reach the problem, you can either click the item in the Problems view or select the red box in the right-hand side of the editor.
Automatic Indentation Support¶
MDT currently has support for automatic indentation. When typing the Return (Enter) key, the next line is indented correctly. You can also correct indentation of the current line or a range selection using CTRL+I or “Correct Indentation” action on the toolbar or in the Edit menu.
Code Completion¶
MDT supports Code Completion in two variants. The first variant, code completion when typing a dot after a class (package) name, shows alternatives in a menu. Besides the alternatives, Modelica documentation from comments is shown if is available. This makes the selection easyer.
The second variant is useful when typing a call to a function. It shows the function signature (formal parameter names and types) in a popup when typing the parenthesis after the function name, here the signature Real sin(SI.Angle u) of the sin function:
Code Assistance on Identifiers when Hovering¶
When hovering with the mouse over an identifier a popup with information about the identifier is displayed. If the text is too long, the user can press F2 to focus the popup dialog and scroll up and down to examine all the text. As one can see the information in the popup dialog is syntax-highlighted.
Go to Definition Support¶
Besides hovering information the user can press CTRL+click to go to the definition of the identifier. When pressing CTRL the identifier will be presented as a link and when pressing mouse click the editor will go to the definition of the identifier.
Code Assistance on Writing Records¶
When writing records, the same functionality as for function calls is used. This is useful especially in MetaModelica when writing cases in match constructs.