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

Ambiguities in macros of Text #2416

Closed
maltelenz opened this issue Sep 30, 2019 · 7 comments · Fixed by #2453
Closed

Ambiguities in macros of Text #2416

maltelenz opened this issue Sep 30, 2019 · 7 comments · Fixed by #2453
Labels
decided A decision has been made (label added before the spec is changed)

Comments

@maltelenz
Copy link
Collaborator

The way I read it, there still seem to be ambiguities in the specification of how to expand text macros (18.6.5.5 of the 3.5-dev specification).

  1. What should %{class}, %{name} and %{comment} be expanded to, if anything?
  2. In the event that there is a parameter called name, what does %name expand to? The component name or the parameter value?

There was a lot of discussion in #2148, but I haven't found a clear answer to the above.

@HansOlsson
Copy link
Collaborator

  1. I would say nothing special, as there seems less need for the special handling in these cases. That also allows %{name} to show the value of the parameter name.
  2. I would say fully qualified name for %class, so for
package P
  model M
    annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={
            Text(
            extent={{-62,62},{60,26}},
            lineColor={28,108,200},
            textString="%class"), Text(
            extent={{-66,-8},{56,-44}},
            lineColor={28,108,200},
            textString="%name")}), Diagram(coordinateSystem(preserveAspectRatio
            =false)));
  end M;

  model N
    
    P.M m annotation (Placement(transformation(extent={{-62,-46},{82,82}})));
  end N;
end P;

It should be P.M and m.

@maltelenz
Copy link
Collaborator Author

  1. I'm fine with the interpretation that %{name} means the parameter called name. It's my interpretation of the current spec text.
  2. I don't follow how this answers my question.
    %class always expands to only the last part of the hierarchical name (not the fully qualified) according to Ambiguities in definition of % parameters in Text annotations #2335, which is already incorporated in the spec.
    This model exemplifies all the alternatives I was wondering about:
package P2
  model M
    parameter Real name = 2;
    annotation(Diagram(coordinateSystem(extent = {{-150, -90}, {150, 90}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})), Icon(coordinateSystem(extent = {{-140, -150}, {320, 50}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Text(visible = true, origin = {0, 25}, extent = {{-100, -25}, {100, 25}}, textString = "%%name -> %name"), Text(visible = true, origin = {0, -25}, extent = {{-100, -25}, {100, 25}}, textString = "%%{name} -> %{name}"), Text(visible = true, origin = {0, -125}, extent = {{-100, -25}, {100, 25}}, textString = "%%class -> %class"), Text(visible = true, origin = {0, -75}, extent = {{-100, -25}, {100, 25}}, textString = "%%{class} -> %{class}"), Line(visible = true, origin = {120, -50}, points = {{0, 100}, {0, -100}}), Text(visible = true, origin = {224.158, 25}, extent = {{-75.842, -25}, {75.842, 25}}, textString = "m_component"), Text(visible = true, origin = {175, -25}, extent = {{-25, -25}, {25, 25}}, textString = "2"), Text(visible = true, origin = {225, -75}, extent = {{-75, -25}, {75, 25}}, textString = "<undefined>"), Text(visible = true, origin = {175, -125}, extent = {{-25, -25}, {25, 25}}, textString = "M")}));
  end M;

  model Example
    M m_component annotation(Placement(visible = true, transformation(origin = {-8, 20}, extent = {{-92, -40}, {92, 40}}, rotation = 0)));
    annotation(Diagram(coordinateSystem(extent = {{-115, -30}, {100, 68.101}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
  end Example;
  annotation(Diagram(coordinateSystem(extent = {{-150, -90}, {150, 90}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
end P2;

The text strings to the right of the line are the hard-coded strings I would expect.
This is my interpretation of a rendered version of P2.Example:

image

So to summarize:

  • %{name} and %{class} refer to the parameters called name and class (where class is an illegal identifier)
  • %name always refers to the name of the component, even if there is a parameter called name

I think the precedence of %name needs clarification in the spec.

@HansOlsson
Copy link
Collaborator

I would propose clarify as follows:
and they should be replaced when displaying the text as follows:
...
->
and they should be replaced when displaying the text as follows (in order so that the ones highest up has priority):
... (reorder so that %% and %name and %class are higher up in the list)

@maltelenz
Copy link
Collaborator Author

Sounds good to me.

@HansOlsson HansOlsson added the decided A decision has been made (label added before the spec is changed) label Oct 2, 2019
@HansOlsson
Copy link
Collaborator

Agreement by language group.

@HansOlsson
Copy link
Collaborator

And %name, %par means that they are not immediately followed by an identifier character (alpha-numeric and _).

@HansOlsson
Copy link
Collaborator

For quoted identifiers require the %{} form, agreement by acclamation.

We recommend to use %{par} or deprecate:
Recommend: 4
Deprecate: 4
(Delay, and possibly make separate ticket.)

HansOlsson added a commit to HansOlsson/ModelicaSpecification that referenced this issue Nov 6, 2019
HansOlsson added a commit to HansOlsson/ModelicaSpecification that referenced this issue Jul 10, 2020
Clarify macros for text
Closes modelica#2416
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decided A decision has been made (label added before the spec is changed)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants