Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expressions in annotations with instance api #9453

Closed
adeas31 opened this issue Sep 30, 2022 · 2 comments · Fixed by #9730
Closed

Expressions in annotations with instance api #9453

adeas31 opened this issue Sep 30, 2022 · 2 comments · Fixed by #9730
Assignees
Labels
COMP/GUI/InstBased Interface Issues with new instantiation-based OMEdit feature COMP/OMC/Interactive Environment
Milestone

Comments

@adeas31
Copy link
Member

adeas31 commented Sep 30, 2022

Description

Right now the instance api just dumps the expressions in the annotation.

Steps to Reproduce

model IconVisible
parameter Boolean show=true;
annotation(
    Icon(graphics = {
    Rectangle(visible=not show, origin = {-40, 0}, extent = {{-20, 20}, {20, -20}}),
    Rectangle(visible=show,origin = {40, 0}, fillPattern = FillPattern.Solid, extent = {{-20, 20}, {20, -20}})}));
end IconVisible;

Calling getModelInstance(IconVisible) outputs,

Click to expand output
"{
  \"name\": \"IconVisible\",
  \"restriction\": \"model\",
  \"annotation\": {
    \"Icon\": {
      \"graphics\": [
        {
          \"$kind\": \"record\",
          \"name\": \"Rectangle\",
          \"elements\": [
            {
              \"$kind\": \"unary_op\",
              \"op\": \" not \",
              \"exp\": {
                \"$kind\": \"cref\",
                \"parts\": [
                  {
                    \"name\": \"show\"
                  }
                ]
              }
            },
            [
              -40,
              0
            ],
            0,
            [
              0,
              0,
              0
            ],
            [
              0,
              0,
              0
            ],
            {
              \"$kind\": \"enum\",
              \"name\": \"LinePattern.Solid\",
              \"index\": 2
            },
            {
              \"$kind\": \"enum\",
              \"name\": \"FillPattern.None\",
              \"index\": 1
            },
            0.25,
            {
              \"$kind\": \"enum\",
              \"name\": \"BorderPattern.None\",
              \"index\": 1
            },
            [
              [
                -20,
                20
              ],
              [
                20,
                -20
              ]
            ],
            0
          ]
        },
        {
          \"$kind\": \"record\",
          \"name\": \"Rectangle\",
          \"elements\": [
            {
              \"$kind\": \"cref\",
              \"parts\": [
                {
                  \"name\": \"show\"
                }
              ]
            },
            [
              40,
              0
            ],
            0,
            [
              0,
              0,
              0
            ],
            [
              0,
              0,
              0
            ],
            {
              \"$kind\": \"enum\",
              \"name\": \"LinePattern.Solid\",
              \"index\": 2
            },
            {
              \"$kind\": \"enum\",
              \"name\": \"FillPattern.Solid\",
              \"index\": 2
            },
            0.25,
            {
              \"$kind\": \"enum\",
              \"name\": \"BorderPattern.None\",
              \"index\": 1
            },
            [
              [
                -20,
                20
              ],
              [
                20,
                -20
              ]
            ],
            0
          ]
        }
      ]
    }
  },
  \"components\": [
    {
      \"name\": \"show\",
      \"type\": \"Boolean\",
      \"modifiers\": \"true\",
      \"value\": {
        \"binding\": true
      },
      \"prefixes\": {
        \"variability\": \"parameter\"
      }
    }
  ],
  \"source\": {
    \"filename\": \"C:/Users/adeas31/Desktop/ModelInstance/issue-6111.mo\",
    \"lineStart\": 1,
    \"columnStart\": 1,
    \"lineEnd\": 7,
    \"columnEnd\": 16
  }
}"

Expected Behavior

Output both the original expression and the evaluated value.

Additional Context

One idea is to improve the Expression class in OMEdit to evaluate such expressions. I am not sure about this but @perost knows more since he implemented it. Not sure if we can handle all cases with Expression class. For example, if the above model is used like this in another model,

model M
  IconVisible iconVisible(show=false)
    annotation (Placement(transformation(extent={{-74,-8},{-54,12}})));
  annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
        coordinateSystem(preserveAspectRatio=false)));
end M;

Then we need to apply the modifiers.

@perost
Copy link
Member

perost commented Sep 30, 2022

For example, if the above model is used like this in another model,

model M
  IconVisible iconVisible(show=false)
    annotation (Placement(transformation(extent={{-74,-8},{-54,12}})));
  annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
        coordinateSystem(preserveAspectRatio=false)));
end M;

Then we need to apply the modifiers.

I'm not sure what the problem with that is, getModelInstance of M will apply the modifiers so as long as variable bindings are just changed it should be fine. But if modifiers are added or removed then we'll probably need to call getModelInstance again.

@adeas31
Copy link
Member Author

adeas31 commented Oct 5, 2022

We (me, @perost and @adrpo) had a meeting today and discussed how to solve this.

We will use the Expression class (as suggested by @perost) to evaluate using the value binding of the variable.

@adeas31 adeas31 added the COMP/GUI/InstBased Interface Issues with new instantiation-based OMEdit feature label Oct 20, 2022
@adeas31 adeas31 added this to To do in Improvements for BR Oct 21, 2022
adeas31 added a commit to adeas31/OpenModelica that referenced this issue Nov 22, 2022
@adeas31 adeas31 moved this from To do to In progress in Improvements for BR Nov 22, 2022
adeas31 added a commit that referenced this issue Nov 22, 2022
* Evaluate expressions in the annotation

Fixes #6111, fixes #9453

* Fix build

* Fix ExpressionTest

* Catch exception

Print space only for not operator

* Look for the variable binding value in components and in extends
Improvements for BR automation moved this from In progress to Done Nov 22, 2022
@casella casella added this to the 1.21.0 milestone Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP/GUI/InstBased Interface Issues with new instantiation-based OMEdit feature COMP/OMC/Interactive Environment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants