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

Can %par textString expressions be used as literal expressions in DynamicSelect? #3573

Open
casella opened this issue Sep 17, 2024 · 3 comments

Comments

@casella
Copy link
Collaborator

casella commented Sep 17, 2024

Section 18.6.5.5 defines the meaning of Text annotations including "%" in textString, in particular

%par and %{par} replaced by the value of the parameter par

while Section 18.6.6, which defines DynamicSelect, reads:

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.

Consider now the following annotation:

annotation(Icon(graphics = {Text(textString=DynamicSelect("%x_start", String(x))}));

where x_start is a parameter. On the one hand, "x_start" is a literal String expression. On the other hand, it clearly refers to a parameter value, so it's not really literal.

How should this case be interpreted?

@maltelenz
Copy link
Collaborator

Test model:

model M
  parameter Real x_start = 2;
  annotation(
    Icon(
      graphics = {
        Text(
          origin = {18.445, 40.975},
          extent = {{-38.445, -30.975}, {38.445, 30.975}},
          textString = DynamicSelect("%x_start", String(x))
        )
      }
    )
  );
end M;

I think it's allowed. (System Modeler supports this by showing the value of x_start in the icon).

@HansOlsson
Copy link
Collaborator

I also think this make sense.

@bilderbuchi
Copy link

bilderbuchi commented Sep 18, 2024

I think there is actually no contradiction here.
"%x_start" is a literal expression, so this works as a first argument of DynamicSelect.

At the same time, https://specification.modelica.org/maint/3.6/annotations.html#text explains the text macros (emphasis mine):

There are a number of common macros that can be used in the text, and they should be replaced when displaying the text

So, in my mind

  1. DynamicSelect is evaluated to produce (e.g.) the string "%x_start"
  2. This string put into a Text annotation
  3. When displaying the (literal) string it is processed for macros, at which point, %x_start is interpolated to 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants