OpenModelica / OpenModelica

OpenModelica is an open-source Modelica-based modeling and simulation environment intended for industrial and academic usage.
https://openmodelica.org
Other
851 stars 306 forks source link

Problems with Graphic annotations #11173

Open mpradovelasco opened 1 year ago

mpradovelasco commented 1 year ago

After trying to define a MWE to show a potential DynamicSelect from #11157), several details are observed. All of them refer to the following minimal example:

package DynamicSelectTest
  class DynamicIcon
    type FlipFlop = Integer(min=1, max=3) "Types of flip-flop";
    parameter FlipFlop gateType = 3 "Type of flip-flop (1=D, 2=T, 3=JK)"
      annotation(choices(choice = 1 "D flip-flop",
                       choice = 2 "T flip-flop",
                       choice = 3 "JK flip-flop"));
    annotation(
      defaultComponentName="DIcon1",
      Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,100}}), 
    graphics={Text(origin = {34, -54}, extent = {{-150, 150}, {150, 110}}, textString = "%name"),
    Text(origin = {-57, 36}, extent = {{-7, 12}, {7, -12}}, textString = 
      DynamicSelect("J",if (gateType == 3) then "J" else if (gateType == 2) then "D" else "T")),
    Text(origin = {-57, -36}, extent = {{-7, 12}, {7, -12}}, textString = 
      DynamicSelect("K",if (gateType == 3) then "K" else "")), 
    Line(origin = {-59.44, 1.01}, points = {{-8.56105, 8.99245}, {11.4389, -1.00755}, {-8.56105, -11.0076}}, color = {0, 85, 0}), 
    Line(origin = {-30, -1}, points = {{-16, -13}, {0, -13}, {0, 13}, {16, 13}}), Rectangle(origin = {2, 0}, extent = {{-70, 60}, {70, -60}})}));
  end DynamicIcon;

  class DynamicIcon2
    type FlipFlop = enumeration(D, T, J) "Types of flip-flop";
    parameter FlipFlop gateType = FlipFlop.J "Type of flip-flop (D, T, JK)"
      annotation(Evaluate = true, choicesAllMatching = true);
    parameter String strTest = "H";
    annotation(
      defaultComponentName="DIcon2",
      Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,100}}), 
    graphics={Text(origin = {34, -54}, extent = {{-150, 150}, {150, 110}}, textString = "%name"),
    Text(origin = {-57, 36}, extent = {{-7, 12}, {7, -12}}, textString = "%gateType"),
    Text(origin = {-57, -36}, extent = {{-7, 12}, {7, -12}}, textString = "K"),
    Line(origin = {-59.44, 1.01}, points = {{-8.56105, 8.99245}, {11.4389, -1.00755}, {-8.56105, -11.0076}}, color = {0, 85, 0}), 
    Line(origin = {-30, -1}, points = {{-16, -13}, {0, -13}, {0, 13}, {16, 13}}), Rectangle(origin = {2, 0}, extent = {{-70, 60}, {70, -60}})}));
  end DynamicIcon2;

  model View
    Modelica.Blocks.Interaction.Show.RealValue IconTest2(use_numberPort = false, number = 2.4) annotation(
        Placement(visible = true, transformation(origin = {-2, -16}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
    DynamicIcon DIcon1 annotation(
        Placement(visible = true, transformation(origin = {-4, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
    DynamicIcon2 DIcon2(gateType = DIcon2.FlipFlop.D)  annotation(
        Placement(visible = true, transformation(origin = {-4, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  end View;
end DynamicSelectTest;
  1. DynamicSelect behaviour Really the DynamicSelect clause operates properly. It presents the dynamic texts when the diagram is shown in the plotting view. The following figure shows the view model after removing the DIcon2 component in view. Pasted image 20230913141334 This way the dynamic field respect the if expression based on parameter conditions (class DynamicIcon). The second component is from MSL. I do not know why appears the tidy text below, but this is a minor doubt.

  2. Graphical primitives behaviour

However, I am interested in showing some graphic feedback in the diagram view of the model during GUI procedures. I have used the Text graphic primitive (annotation) in the DynamicIcon2 class, that it is now declared to the View model according the previous code. I reach the following results.

If I substitute the code:

textString = "%gateType"

by

textString = "%strTest"

the "H" is shown in the diagram (DIcon2 icon), as expected. Pasted image 20230913142247

But if I try to use a conditional expression for strTest like

parameter String strTest = if true then "J" else "Otro";

then textString = "%strTest" produces an empty field in the place of "H" of the DIcon2 icon as shown: Pasted image 20230913142502 I have tested other combinations and similar situations without success. This limitation difficults the feedback to the user of a selected value for a parameter.

Finally, if I used the initial code, with textString = "%gateType" for DynamicIcon2, the situation is more complex. When I drag and drop the icon DynamicIcon2, the place of H in DIcon2 remains empty as in previous figure. However, if I modify the gateType value using the dialog box as seen: Pasted image 20230913143127 now this is properly presented in the diagram (DIcon2 where I have selected the D value): Pasted image 20230913143252

However, OMEdit gives the warning: Parameter gateType has annotation(Evaluate=true) and no binding.

This seems not logical, since it has a binding equation and it is indeed accepted by the GUI API.

But worst, if I try now to simulate the View model, OMEdit gives an error: [Found component 'D' in composite name 'DIcon2.FlipFlop.D', expected class.]

But the value defined was fine, according to the choicesAllMatching = true, as shown: Pasted image 20230913143821

I suspect that it may be due to the fact that the modifier is using the name of the component where it is applied. That is:

DynamicIcon2 DIcon2(gateType = DIcon2.FlipFlop.D)

In summary, DynamicSelect seems fine, but the field Text in the Icon annotation does not, what makes difficult the cited user feedback.

System: OMEdit 1.22 - dev (10 september), Enable Instance API ON , Windows 11.

I apologize for the extension. Thanks!

adeas31 commented 12 months ago

See #11386.

mpradovelasco commented 12 months ago

Thank you for the information @adeas31 !

AustraleanPerson commented 9 months ago
  1. The second component is from MSL. I do not know why appears the tidy text below, but this is a minor doubt.

This is source expression text. The expected usage of 'Show.RealValue' is something like this:

model m1
  Modelica.Blocks.Sources.Sine sine(f=2) annotation (Placement(transformation(extent={{-10,50},{10,70}})));
  Modelica.Blocks.Interaction.Show.RealValue realValue(use_numberPort=false, number=sine.y) annotation (Placement(transformation(extent={{-20,14},{20,54}})));
  Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort=false, number=time) annotation (Placement(transformation(extent={{-20,-12},{20,28}})));
  annotation (uses(Modelica(version="4.0.0")));
end m1;

image