Create a New Class or Extend from an Existing Class Using the New
Class Command
You can create a new class, either by creating an empty class or by extending
an existing class.
Before you begin: You have to be in a library to create a new
class. Note:
As an exception, you can create free-standing models to, for example,
test features.
In this scenario, you create a model in a behavior
library. You can reuse such classes.
-
From the
Behavior Authoring section of the
action bar,
click
New Modelica Class
.
The
New Class dialog box appears.
-
From the
Name box, enter a valid Modelica name for
this new class, in this example enter
MyModel .
-
From the Class type list, select the class type. By
default, this Model type is selected.
You have the following alternatives:
- Block
- Connector
- Expandable Connector
- Function
- Model
- Package
- Record
- Type
For this scenario, keep the default selection
Model.
-
Click the
Insert in box, then select a library from
the
Package Browser.
To create a class as top-level class, do not enter a class name
in the box.
-
If you need to create a partial class, select the
Partial option.
-
If you need to create an extended class:
-
Click the
Extends box.
-
Select a class from the Package Browser or
click Switch between class and basic type
selection
to select a basic type or one of the recent classes from the
list.
-
Click
OK to close the
New Class dialog box and create your new
class.
From the
Package Browser, a new class is created under
the library node.
In the new class, you can, for example:
Extend from the Present Class
You can create a new class by extending from the present
class.
-
Right-click the class you want to extend from, in the
Package Browser, in the
Preferred Classes Browser, or in the
Classes for Force Elements browser.
-
From the context menu, select Extend
from...
.
The New Class dialog box appears, the boxes
corresponding to extending the present class are filled in.
-
From the
Name box, enter a valid Modelica name for
this new class.
- Optional:
For expert users, you can change the class type: From the
Class type list, select the type.
For information about changing class type when extending, see
Modelica Language Specification. This document is available on
http://www.modelica.org.
- Optional:
You can change where to insert the new class: Click the
Insert in box, then select a library from
the
Package Browser.
To create the class as top-level class, do not enter a class
name in the box.
-
If you need to create a partial class, select the
Partial option.
-
Click
OK to close the
New Class dialog box and create your new
class.
From the
Package Browser, a new class is created under
the library node.
Extend from a Replaceable Component
You can select a replaceable component and create a new class
by extending the extending clause class of the replaceable component.
-
Right-click the replaceable component and select
Extend from...
.
The New Class dialog box appears, with some boxes prefilled by
default. Comparing with the result of step 1 in the first task above, the
Extends: box is prefilled with the
constraining clause class of the replaceable component, and the
Insert in: box is prefilled with the present
active class.
-
See step 3-7 in the previous task.
|