Creating and Editing Enumeration Types

You can create and edit enumeration types.

In this scenario you create and edit an enumeration type.

This task shows you how to:

Create Empty Enumeration Types

You can create empty enumeration types, to later add elements.

To create an empty enumeration type, create a new class with certain selections:

For full information about creating a class, see Create a New Class or Extend from an Existing Class Using the New Class Command.

  1. From the Behavior Authoring section of the action bar, click New Modelica Class .
  2. In the New Class dialog box:

    • In the Name box, enter the name of the enumeration type, in this scenario enter MyEnumeration.
    • From the Class type list, select the Type type.
    • Make sure that Partial is not activated.
    • Make sure that no class is selected for Extends.
    • Click OK.

A new class MyEnumeration is created and appears in the Package Browser.
Tip: You can also use Modelica Editor in the model and create the enumeration type by typing type MyEnumeration = enumeration(:); in the declaration part of the code, that is, where you declare parameters and variables. For more about the Modelica Editor, see Displaying and Editing Modelica Text.

Add Enumeration Elements

You can add elements in an enumeration type.

Before you begin: You have created an empty enumeration MyEnumeration by performing the subtask above.

In this scenario you add elements to this enumeration.

  1. In the Package Browser, double-click the enumeration MyEnumeration to open it.
  2. From the Behavior Authoring section of the action bar, click Modelica Editor .
    The Modelica Editor dialog box appears, containing the enumeration type.
  3. In the Modelica Editor, right-click the enumeration type and select Enumeration > New Element
    The Enumeration Element dialog box appears.
    Tip: If you want to add several enumeration elements and be able to directly sort them by moving them in the list, you can instead use the command Enumeration > Edit Enumeration to display the Enumeration dialog box. Here you can use Add to display the Enumeration Element dialog box.
  4. In the Enumeration Element dialog box:
    1. In the Name box, type a name.

      In this scenario, type Small.

    2. Optional: In the Description box, enter a description.
    3. Click OK.
    A new element is created in the enumeration.
  5. For this scenario, also create the elements Normal and Large.
  6. Click OK.
    The enumeration is now, in the Modelica Editor:
    type MyEnumeration = enumeration(
                 Small,
                 Normal,
                 Large);
    Note: You can also use the Modelica Editor to type the text directly.

Edit Enumeration Elements

You can edit enumeration elements in an enumeration. This includes deleting elements and sorting elements.

Before you begin: You have created an empty enumeration MyEnumeration and added elements by performing the subtasks above.

In this scenario you edit elements in this enumeration.

  1. If not displayed, display the enumeration type in the Modelica Editor by performing Step 1 and Step 2 in the task above.
  2. In the Modelica Editor, right-click the enumeration type and select Enumeration > Edit Enumeration
    The Enumeration dialog box appears.
  3. To edit an enumeration element:
    1. In the enumeration dialog box, select the element and click Edit.
      The Enumeration Element dialog box for the element appears.
      Tip: To edit a certain element directly, for example the element Small, you can jump Step 2 and instead in the Modelica Editor right-click the enumeration type and select Enumeration > Small.
    2. Edit the Name and Description, and click OK.
      The element is changed.
      Note: The original name is displayed in the enumeration dialog.
  4. To delete an element, in the enumeration dialog box, select the element and click Delete.
  5. To sort an element, in the enumeration dialog box, select the element and click any of the Up or Down arrows.
  6. Click OK to validate the changes.

Note: You can use also use the Modelica Editor to edit directly by typing text.