Controlling Graphical Annotations of Icons by Parameters

You can control the values of graphical annotations (coordinates, color, text, etc) of the icon of a class by parameters.

The control is implemented by the DynamicSelect expression. It has two arguments, the second one specifies the value of the annotation in simulate mode, and in edit mode if the expression can be evaluated. It can contain references to parameters (also from submodels). The first argument must be a literal expression and is used if evaluation of the second argument fails.

In this scenario you create a library with two models, one with an icon where the graphics is partly controlled by parameters, and one model to test what you have done.

See Also
About Analyzing Variable Dependencies and Equation Incidence
  1. Create a new library and give it the name MyLib.

    For information on how to create a library, see Creating a Modelica Library or Dymola Behavior Library.

  2. In that library, create two new empty models, MyTankModel and TestModel.

    For information on how to create models, see Create a New Class or Extend from an Existing Class Using the New Class Command.



  3. Open MyTankModel and define two parameters:

    For information on how to define parameters, see Defining Parameters and Editing Properties of Parameters.

    1. A Real parameter Level for the tank level
    2. A Boolean parameter PhError to indicate if the PH value in the tank is too high
    For result see the figure below.
  4. From the Diagram section of the action bar, click Icon Layer .

    Note: Actually graphics in the diagram layer can be controlled as well, but mostly the icon layer is the relevant layer to use.

  5. Draw a large rectangle to symbolize the tank level. Start drawing from lower left corner.
    For more information on drawing, see Drawing Primitives.
  6. From the Behavior Authoring section of the action bar, click Modelica Editor .
  7. In the Modelica Editor, click the green a to expand the annotations of the rectangle.
    The code is displayed:

  8. Edit the extent to be like above; that uses the entire icon space and simplifies the handling of the level value in the next step.
  9. To animate the level of the tank, and to change the color of it if the PhError is true, apply DynamicSelect by editing the text:
    The resulting code (after some formatting) is:

  10. To test, do the following:, open the model and drag into it
    1. Open the model TestModel.
    2. Drag MyTankModel into it to instantiate it.

      For information on how to instantiate, see Instantiating a Component.

    3. Double-click the instantiated component and change the parameter values.
      The level and color of the component should vary accordingly.
    Note: This is just a simple example of control of graphical annotations, a real tank needs more work.