Search code examples
modelicaopenmodelicagraphical-interaction

How to give an option of icon color at time of configuration?


I try to make Modelica library code that works for different platforms and prefer to use general annotation-commands for handling of icons etc.

i have a component with an icon of a standard fill-colour. In some usage of the the component in a configuration I would like to have a different fill-colour from the standard, just to facilitate the understanding of the configuration. The functionality of the component is identical in the two use cases so no point to make two different components.

So far I have not found any examples of this kind in the documentation I have looked at. The closest I come is the use of "choice" in Modelica spec section 7.3.4 but the section covers not really what I want. https://specification.modelica.org/master/inheritance-modification-and-redeclaration.html#annotation-choices-for-suggested-redeclarations-and-modifications

annotation(choices(
   choice(Icon(graphics.... RGB-triplet-standard...), Text(), Diagram() "standard"),
   choice(Icon(graphics.... RGB-triplet-special...), Text(), Diagram() "special"));

But difficult to get it to work in OpenModelica, and also sort of "clumsy code". Is this the right track?

Appreciate some guidance, or reference to some example/text.


Solution

  • I have played with the function DynamicSelect() and read the material provided by Imke Kreuger and also read in MLS_3.7-dev section 18.6.6, and what I understand the function does not address the current problem. It is stated that the function has two arguments and the first is for editing state and the other for non-editing state, and the first argument can only have literals. For me editing mode refers to what I would call the "time of configurations using the GUI" and it is in this mode I want user interaction to select colour of the icon.

    Short answer: Make a duplicate icons for different colours. Then drag in the icon with the colour you want. This solution creates duplicate code, and when maintained you must be sure you update all the duplicate models. Not ideal, but works. (One could perhaps make a partial model that covers everything but the colour of the icon and have that defined in an appropriate extension, but I have not tried).

    Longer answer: Can the annotation code at least in principle solve the problem. I think so. When I play with the MSL CombiTimeTable and connect the output signal to another component I get automatically an interactive dialog and I choose to connect output=1. After the connection is made (as well as all others) then the configured system can be translated and we can get results from simulation.

    In this interactive dialog "run by the annotation code", the fact that output had not been chosen was detected and brought to my attention, and I gave it a value. Thus, annotation code could both read a parameter in the Modelica code and after interaction set a new value to the parameter in the Modelica code. However, in this example the icon for output is not changed, and perhaps a key observation.

    It is the primitives of this kind of interaction I think I would like to use when choosing colour of my icon.

    Understanding the code for CombiTimeTable and the part responsible for the user dialogue described is difficult. Here is annotation using Dialog and reference to Blocks.Interfaces.MO but I do not get any idea for a solution of my problem this way.

    Here could very well be a Modelica language design choice not to allow this kind of flexibility in a more general way that I am looking for. Would be good if someone could confirm that.