modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
481 stars 169 forks source link

replaceable data records #4494

Open AHaumer opened 3 weeks ago

AHaumer commented 3 weeks ago

I’m using replaceable data records to parametrize models: see enclosed Test-library. It is desired to display the name of the used/redeclared data record or a string parameter of the used/redeclared data record on the icon of the model to help the user.

Update: I tried 6 different annotations (Thanks for your hint, @maltelenz):

Dymola 2024x displays:

OpenModelica v1.24.0 displays:

I have choosen redeclare Test.DataRecords.Data1 data, therefore I would expect a display of “Data1”.

Only Dymola no. 4 (DynamicSelect) is correct. I see now that no. 3 can’t be correct, it either displays the instance name of the model or the instance name of the data record. It seems that Dymola and OpenModelica interpret differently “editing state” and “non.editing state”. 18.6.6 “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. The second argument may contain references to variables to enable a dynamic behavior.“

I would be interested in the behavior of other tools (@maltelenz ), and what’s correct in terms of the specification (@HansOlsson ?). I think one of the options should work, @casella what’s your opinion? Test.zip

maltelenz commented 3 weeks ago

Without having looked at tool behavior or your library yet (will do tomorrow), are you aware of the new (not really anymore) syntax %{data.Type}?

maltelenz commented 3 weeks ago

System Modeler displays:

It is currently unclear (to me) in the specification if a.b references are allowed, and if so, if they are allowed in the form %a.b, or only in %{a.b}. It seems OpenModelica also assumed only local parameters. It should be clarified what should be allowed.

For DynamicSelect, this has also come up in https://github.com/modelica/ModelicaSpecification/issues/3376 and mentioned in https://github.com/modelica/ModelicaSpecification/issues/3464 . My interpretation of the spec is that it is for animation (Dynamic!), so it shouldn't be used (or work) for a case like this.

AHaumer commented 3 weeks ago

Thanks a lot @maltelenz ! So I have no solution for displaying a string parameter of the used/redeclared data record on the icon of the model, and the spec is not clear enough. @HansOlsson how could we solve that?

HansOlsson commented 3 weeks ago

Dymola 2025x will display:

I haven't checked Dymola 2024x Refresh 1.

And as far as I understand the Text(textString="%{data.Type}") seems like the good solution for this. If that is unclear we should clarify it.

The issue with Text(textString="%Type") is that it is difficult to know how far things should be evaluated.

maltelenz commented 3 weeks ago

And as far as I understand the Text(textString="%{data.Type}") seems like the good solution for this. If that is unclear we should clarify it.

Agreed! We should clarify this is OK in the spec.

I'm leaning towards saying %data.Type is not OK, similar to how %'quoted' is not OK.

casella commented 1 week ago

@AHaumer sorry, no time for this until we finalize MSL 4.1.0. Will look at it ASAP.