Per the documentation for OpenModelica , DynamicSelect,
Any value (coordinates, color, text, etc.) in graphical annotations can be dependent on class variables using the DynamicSelect expression. DynamicSelect has the syntax of a function call with two arguments, where the first argument specifies the value of the editing state and the second argument the value of the non-editing state. The first argument must be a literal expression and this value is used for the annotation when editing and/or browsing the diagram layer. The second argument may contain references to variables to enable a dynamic behavior and the actual value is used for the annotation for schematic animation of the diagram layer, e.g., after a simulation.
To test, a model with DynamicSelect was created to change colors and coordinates during a simulation.
model BarGraph_v001
Modelica.Blocks.Interfaces.RealInput u annotation(
Placement(visible = true, transformation(origin = {-104, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-62, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
annotation(
Icon(graphics = {
Rectangle(lineThickness = 2, extent = DynamicSelect({{-40, 100}, {40, -100}},{{-40, 100}, {u, -100}})),
Rectangle(visible=true, origin = DynamicSelect({0, 27},{0,u}), fillColor=DynamicSelect({192,192,192}, {125+u*5,125-u*5,125+u*5}), fillPattern = FillPattern.Solid, extent = {{-40, 13}, {40, -13}})}));
end BarGraph_v001;
Note that DynamicSelect is used to change the coordinates of the origin and the color of the rectangle in the icon.
The static icon for this model is:
Then this was integrated into a model with a stimulus and several other animated Modelica library elements.
model BarGraph_test_001
Anim.BarGraph_v001 barGraph_v001 annotation(
Placement(visible = true, transformation(origin = {22, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.Sine sine(f = 4) annotation(
Placement(visible = true, transformation(origin = {-54, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Math.Gain gain(k = 25) annotation(
Placement(visible = true, transformation(origin = {-14, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interaction.Show.RealValue realValue annotation(
Placement(visible = true, transformation(origin = {28, 24}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interaction.Show.BooleanValue booleanValue annotation(
Placement(visible = true, transformation(origin = {56, -36}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Logical.GreaterThreshold greaterThreshold annotation(
Placement(visible = true, transformation(origin = {18, -36}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(gain.y, barGraph_v001.u) annotation(
Line(points = {{-2, 0}, {16, 0}}, color = {0, 0, 127}));
connect(sine.y, gain.u) annotation(
Line(points = {{-42, 0}, {-26, 0}}, color = {0, 0, 127}));
connect(realValue.numberPort, gain.y) annotation(
Line(points = {{16, 24}, {8, 24}, {8, 0}, {-2, 0}}, color = {0, 0, 127}));
connect(greaterThreshold.y, booleanValue.activePort) annotation(
Line(points = {{30, -36}, {44, -36}}, color = {255, 0, 255}));
connect(greaterThreshold.u, gain.y) annotation(
Line(points = {{6, -36}, {-2, -36}, {-2, -12}, {10, -12}, {10, 0}, {-2, 0}}, color = {0, 0, 127}));
end BarGraph_test_001;
The model looks like this in the editor:
And after simulation, it is animated like this. Note that colors change, the library parts are animated, but the DynamicSelect used to change coordinates is not working.
Questions:
Changing the size of the rectangle works in Dymola:
But it seems like the current version of OMEdit (v1.19.2) does not fully support DynamicSelect.
There is an issue on github about DynamicSelect support in OpenModelica: #3675: Add interactive simulation support (e.g., DynamicSelect display)