forked from modelica/ModelicaSpecification
-
Notifications
You must be signed in to change notification settings - Fork 2
/
annotations.tex
2178 lines (1854 loc) · 95.4 KB
/
annotations.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\chapter{Annotations}\doublelabel{annotations}
Annotations are intended for storing extra information about a model,
such as graphics, documentation or versioning, etc. A Modelica tool is
free to define and use other annotations, in addition to those defined
here, according to \autoref{vendor-specific-annotations}. The only requirement is that any tool
shall save files with all annotations from this chapter and all
vendor-specific annotations intact. To ensure this, annotations must be
represented with constructs according to the Modelica grammar (for
replaceable class declarations with a constraining-clause also refer to
\autoref{constraining-clause-annotations}). The specification in this document defines the
semantic meaning if a tool implements any of these annotations.
\section{Vendor-Specific Annotations}\doublelabel{vendor-specific-annotations}
A vendor may -- anywhere inside an annotation -- add specific, possibly
undocumented, annotations which are not intended to be interpreted by
other tools. Two variants of vendor-specific annotations exist; one
simple and one hierarchical. Double underscore concatenated with a
vendor name as initial characters of the identifier are used to identify
vendor-specific annotations.
\begin{example}
\begin{lstlisting}[language=modelica]
annotation (
Icon(coordinateSystem(extent={{-100,-100}, {100,100}}),
graphics={__NameOfVendor(Circle(center={0,0}, radius=10))}) );
\end{lstlisting}
This introduces a new graphical primitive \lstinline!Circle! using the
hierarchical variant of vendor-specific annotations.
\begin{lstlisting}[language=modelica]
annotation (
Icon(coordinateSystem(extent={{-100,-100}, {100,100}}),
graphics={Rectangle(extent={{-5,-5},{7,7}}, __NameOfVendor_shadow=2)}) );
\end{lstlisting}
This introduces a new attribute \lstinline!__NameOfVendor_shadow!
for the \lstinline!Rectangle! primitive using the simple variant of
vendor-specific annotations.
\end{example}
\section{Annotations for Documentation}\doublelabel{annotations-for-documentation}
\begin{lstlisting}[language=grammar]
documentation-annotation:
annotation "(" Documentation "(" [ "info" "=" STRING ]
[ "," "revisions" "=" STRING ]
[ "," "figures" "=" figure-annotations ] ")" ")"
\end{lstlisting}
The ``\lstinline!Documentation!'' annotation can contain the ``\lstinline!info!'' annotation
giving a textual description, the ``\lstinline!revisions!'' annotation giving a list
of revisions {[}\emph{The
``revisions'' documentation may be omitted in printed documentation}{]}, and the
``\lstinline!figures!'' annotation giving a list of \lstinline!Figure! annotations as
described in \autoref{annotations-for-figures}.
How the tool interprets the information in ``\lstinline!Documentation!'' is
unspecified. Within the ``\lstinline!info!'' and `\lstinline!revisions!'' strings of the ``\lstinline!Documentation!'' annotation, the
tags \lstinline!<HTML>! and \lstinline!</HTML>! or
\lstinline!<html>! and \lstinline!</html>! define
optionally begin and end of content that is HTML encoded. For external
links see \autoref{external-resources}. Links to Modelica classes may be defined with
the HTML link command using scheme ``\lstinline!Modelica!'', e.g.,
\begin{lstlisting}[language=modelica]
<a href="Modelica://MultiBody.Tutorial">MultiBody.Tutorial</a>
\end{lstlisting}
Together with scheme ``\lstinline!Modelica!'' the (URI) fragment specifiers
\lstinline!#diagram!, \lstinline!#info!, \lstinline!#text!, \lstinline!#icon! may be used to reference different
layers. Example:
\begin{lstlisting}[language=modelica]
<a href="Modelica://MultiBody.Joints.Revolute#info">Revolute</a>
\end{lstlisting}
\subsection{Annotations for Figures\doublelabel{annotations-for-figures}}
The \lstinline!figure-annotations! is list of \lstinline!Figure! annotations given by:
\begin{lstlisting}[language=modelica]
record Figure
String title "Title meant for display";
String identifier "Identifier meant for programmatic access";
String group = "" "Name of plot group";
Boolean preferred = false "Automatically display figure after simulation";
Plot[:] plots "Plots";
String caption "Figure caption";
end Figure;
\end{lstlisting}
A \lstinline!Figure! is a graphical container that can contain several
\lstinline!plots! described by \lstinline!Plot! annotations:
\begin{lstlisting}[language=modelica]
record Plot
String title "Title meant for display";
String identifier "Identifier meant for programmatic access";
Curve[:] curves "Plot curves";
Axis x "X axis properties";
Axis y "Y axis properties";
end Plot;
\end{lstlisting}
A \lstinline!Plot! can contain several \lstinline!curves!, see
\autoref{plot-curves}, that all share a common x and y axis with properties
described in \autoref{axis-properties}.
The \lstinline!title! of a \lstinline!Figure! shall be non-empty and is
mandatory, as every figure needs a title for presentation in contexts such as a
list of figures, and as it is generally hard for tools to automatically generate
a meaningful title. On the other hand, when the \lstinline!title! of a
\lstinline!Plot! isn't provided, the tool produces a default, but the default is
allowed to be empty. Providing the empty string as \lstinline!title! of a
\lstinline!Plot! means that no title should be shown. The plot title is not to
be confused with the plot \emph{label} which is never empty, see below. Variable
replacements, as described in \autoref{variable-replacements}, can be used in the
\lstinline!title! of \lstinline!Figure! and \lstinline!Plot!.
The \lstinline!identifier! in \lstinline!Figure! and \lstinline!Plot! is
optional, and is intended for programmatic access. An \lstinline!identifier!
must be unique within the class containing the \lstinline!figures! annotation,
without considering whether it belongs to \lstinline!Figure! or
\lstinline!Plot!. {[}\emph{For \lstinline!Figure!, this makes it possible to
reference the plot from a tool-specific scripting environment. For \lstinline!Plot!, this makes it possible to reference
the plot in the figure caption, which becomes useful when the \lstinline!Figure!
contains more than one \lstinline!Plot!.}{]}
Every \lstinline!Plot! has an automatically generated \emph{label} which is
required to be shown as soon as at least one \lstinline!Plot! in the
\lstinline!Figure! has an \lstinline!identifier!. A tool is free to choose both
labeling scheme (such as \emph{a}, \emph{b}, \dots, or \emph{i}, \emph{ii}, \dots) placement in the plot,
and styling in the plot itself as well as in other contexts.
When a \lstinline!Figure! defines a non-empty \lstinline!group!, it is used to
organize figures similar to how \lstinline!group! is used in the
\lstinline!Dialog! annotation (see \autoref{annotations-for-the-graphical-user-interface}). However, leaving \lstinline!group! at
the default of an empty string does not mean that a group will be created
automatically, but that the figure resides outside of any group. The
\lstinline!group! is both the key used for grouping, and the name of the group
for diaplay purposes.
If the \lstinline!preferred! attribute of \lstinline!Figure! is \lstinline!true!
tools should should show the figure automatically when the class is simulated. A
class may define multiple \lstinline!preferred! figures.
The \lstinline!caption! attribute of \lstinline!Figure! can use the restricted
form of text markup described in \autoref{text-markup-in-captions} as well as
the variable replacements described in \autoref{variable-replacements}.
\subsubsection{Plot Curves}\doublelabel{plot-curves}
The actual data to plot is specified in the \lstinline!curves! of a \lstinline!Plot!:
\begin{lstlisting}[language=modelica]
record Curve
expression x = time "X coordinate values";
expression y "Y coordinate values";
String legend "Legend";
end Curve;
\end{lstlisting}
The mandatory \lstinline!x! and \lstinline!y! expressions are restricted to be
component references refering to a scalar variable or \lstinline!time!.
When \lstinline!legend! isn't provided, the tool produces a default based on
\lstinline!x! and/or \lstinline!y!. Providing the empty string as
\lstinline!legend! means that the curve shall be omitted from the plot legend.
Variable replacements, as described in \autoref{variable-replacements}, can be
used in the \lstinline!legend! of \lstinline!Curve!
\subsubsection{Axis Properties}\doublelabel{axis-properties}
Properties may be defined for each \lstinline!Plot! axis:
\begin{lstlisting}[language=modelica]
record Axis
Real min "Axis lower bound";
Real max "Axis upper bound";
String unit "Unit of min and max";
String label "Axis label";
end Axis;
\end{lstlisting}
When an axis bound isn't provided, the tool computes one automatically.
The Modelica tool is responsible for showing the unit used for values at the
axis tick marks, so the axis \lstinline!label! shall not be used to convey this
information.
When an axis label isn't provided, the tool produces a default label. Providing
the empty string as axis label means that no label should be shown. Variable
replacements, as described in \autoref{variable-replacements}, can be used in
the \lstinline!label! of \lstinline!Axis!
\subsubsection{Variable Replacements}\doublelabel{variable-replacements}
In most places where text is displayed (\lstinline!title!, \lstinline!caption!, \lstinline!legend!, \lstinline!label!),
the final value of a result variable can be embedded by refering to the variable
as \lstinline!%{inertia1.w}!. This is similar to the \lstinline!Text! graphical in \autoref{text}.
Note that expansion to the final value means that expansion is not restricted to
parameters and constants, so that values to be shown in a caption can be
determined during simulation.
The percent character is encoded \lstinline!%%!. Neither \lstinline!%class! nor
\lstinline!%name! is supported in this context, as this information is expected
to already be easily accessible (when applicable) in tool-specific ways. (Titles
making use of \lstinline!%class! or \lstinline!%name! would then only lead to
ugly duplication of this information.)
\subsubsection{Text Markup in Captions}\doublelabel{text-markup-in-captions}
In addition to variable replacements, a very restricted form of text markup is
used for the \lstinline!caption!.
Links take the form \lstinline!%[<text>](<link>)!, where the
\lstinline![<text>]! part is optional. The \lstinline!<link>! can be in either
of the following forms: - A URI, such as
\lstinline!https://github.com/modelica/ModelicaSpecification! or
\lstinline!modelica:///Modelica.Blocks!. - A \lstinline!variable:<id>!, where
\lstinline!<id>! is a component reference such as \lstinline!inertia1.w!. - A
\lstinline!plot:<id>!, where \lstinline!<id>! is the identifier of a
\lstinline!Plot! in the current \lstinline!Figure!.
When \lstinline![<text>]! is omitted, a Modelica tool is free to derive a default based on
the \lstinline!<link>!.
The styling of the link text and the link action is left for each Modelica tool
to decide.
{[}\emph{For example,} \lstinline!%(inertia1.w)! \emph{could be displayed as the text
\lstinline!inertia1.w! formatted with upright monospaced font, and have a pop-up
menu attached with menu items for plotting the variable, setting its start
value, or investigating the equation system from which it is solved. On the
other hand,} \lstinline!%[angular velocity](inertia1.w)! \emph{could be formatted in
the same style as the surrounding text, except some non-intrusive visual clue
about it being linked.}{]}
A sequence of one or more newlines (encoded either literally or using the \lstinline!\n!
escape sequence) means a paragraph break. (A line break within a paragraph is
not supported.)
\section{Annotations for Code Generation}\doublelabel{annotations-for-code-generation}
\begin{lstlisting}[language=grammar]
code-annotation:
annotation"(" codeGenerationFlag "=" ( false | true ) ")"
codeGenerationFlag :
"Evaluate" | "HideResult" | "Inline" | "LateInline" | "GenerateEvents"
\end{lstlisting}
These annotations can influence the code generation. The details are
defined in the next table:
\begin{longtable}[]{|p{4.2cm}|p{10cm}|}
\hline \endhead
\lstinline!Evaluate!&
The annotation Evaluate can occur in the component declaration, its type
declaration, or a base-class of the type-declaration. In the case of
multiple conflicting annotations it is handled similarly to modifiers
(e.g., an Evaluate-annotation on the component declaration takes
precedence). The annotation Evaluate only has effect for a component
declared with the prefix \lstinline!parameter!.
If \lstinline!Evaluate = true!, the model developer proposes to utilize the value
for the symbolic processing. In that case, it is not possible to change
the parameter value after symbolic pre-processing.
If \lstinline!Evaluate = false!, the model developer proposes to not utilize the
value of the corresponding parameter for the symbolic processing.
{[}\lstinline!Evaluate! \emph{is for example used for axis of rotation parameters in
the} \lstinline!Modelica.Mechanics.MultiBody! \emph{library in order to improve the
efficiency of the generated code}{]}\\ \hline
\lstinline!HideResult! &
\lstinline!HideResult = true! defines that the model developer proposes to not show
the simulator results of the corresponding component {[}\emph{e.g., it
will not be possible to plot this variable}{]}.
\lstinline!HideResult = false! defines that the developer proposes to show the
corresponding component {[}\emph{if a variable is declared in a
protected section, a tool might not include it in a simulation result.
By setting} HideResult = false\emph{, the modeler would like to have the
variable in the simulation result, even if in the protected section}{]}.
{[}\lstinline!HideResult! \emph{is for example used in the connectors of the}
\lstinline!Modelica.StateGraph! \emph{library to not show variables to the modeler
that are of no interest to him and would confuse him}{]}\\ \hline
\lstinline!Inline! &
Has only an effect within a function declaration.
If ``\lstinline!Inline = true!'', the model developer proposes to inline the
function. This means, that the body of the function is included at all
places where the function is called.
If ``\lstinline!Inline = true!'', the model developer proposes to not inline the
function.
% Added "The annotation" to avoid bad formatting.
{[}The annotation \lstinline!Inline = true! \emph{is for example used in}
Modelica\allowbreak{}.Mechanics\allowbreak{}.MultiBody\allowbreak{}.Frames \emph{and in functions of}
Modelica\allowbreak{}.Media \emph{to have no overhead for function calls such as
resolving a vector in a different coordinate system and at the same time
the function can be analytically differentiated, e.g., for index
reduction needed for mechanical systems.}{]}\\ \hline
\lstinline!LateInline!
&
Has only an effect within a function declaration.
If ``\lstinline!LateInline = true!'', the model developer proposes to inline the
function after all symbolic transformations have been performed
\emph{{[}especially differentiation and inversion of functions; for
efficiency reasons it is then useful to replace all function calls with
identical input arguments by one function call, before the inlining{]}}.
If ``\lstinline!LateInline = false!'', the model developer proposes to not inline
the function after symbolic transformations have been performed.
``\lstinline!Inline=true, LateInline=false!'' is identical to ``\lstinline!Inline=true!''
``\lstinline!Inline=true, LateInline=true!'' is identical to ``\lstinline!LateInline=true!''
``\lstinline!Inline=false, LateInline=true!'' is identical to ``\lstinline!LateInline=true!''
{[}\emph{This annotation is for example used in
Modelica\allowbreak{}.Media\allowbreak{}.}Water\allowbreak{}.IF97\_Utilities\allowbreak{}.T\_props\_ph \emph{to provide in
combination with common subexpression elimination the automatic caching
of function calls. Furthermore, it is used in order that a tool is able
to propagate specific enthalpy over connectors in the Modelica\_Fluid
library.}{]}\\ \hline
\lstinline!InlineAfterIndexReduction!\strut
&
Has only an effect within a function declaration.
If \lstinline!true!, the model developer proposes to inline the function after the
function is differentiated for index reduction, and before any other
symbolic transformations are performed. This annotation cannot be
combined with annotations \lstinline!Inline! and \lstinline!LateInline!.
\\ \hline
\lstinline!GenerateEvents!\strut
&
Has only an effect within a function declaration
If ``\lstinline!GenerateEvents = true!'', the model developer proposes that crossing
functions in the function should generate events (one possibility of
doing this is to inline the function and generate events for the inlined
function).
{[}\emph{This annotation is for example used in}
Modelica\allowbreak{}.Media\allowbreak{}.Water\allowbreak{}.IF97\_Utilities.phase\_dT \emph{to indicate that
the output should generate an event when it changes.}{]}\\ \hline
\end{longtable}
\begin{lstlisting}[language=grammar]
smoothOrder-annotation:
annotation"(" smoothOrder "=" UNSIGNED-NUMBER ")" |
annotation"(" smoothOrder "(" normallyConstant "=" NAME
["," normallyConstant "=" NAME] ")"
"=" UNSIGNED-NUMBER ")"
\end{lstlisting}
This annotation has only an effect within a function declaration.
\lstinline!smoothOrder! defines the number of differentiations of the function, in
order that all of the differentiated outputs are continuous provided all
input arguments and their derivatives up to order \lstinline!smoothOrder! are
continuous {[}\emph{This means that the function is at least}
C\textsuperscript{smoothOrder}. \lstinline!smoothOrder = 1! \emph{means that the
function can be differentiated at least once in order that all output
arguments are still continuous, provided the input arguments are
continuous. If a tool needs the derivative of a function, e.g. for index
reduction or to compute an analytic Jacobian, the function can be
differentiated analytically at least smoothOrder times}{]}.
The optional argument \lstinline!normallyConstant! of \lstinline!smoothOrder! defines that the
function argument \lstinline!NAME! is usually constant {[}\emph{A tool might check
whether the actual argument to} \lstinline!NAME! \emph{is a parameter expression at the
place where the function is called. If this is the case, the derivative
of the function might be constructed under the assumption that the
corresponding argument is constant, to enhance efficiency. Typically, a
tool would generate at most two different derivative functions of a
function: One, under the assumption that all} \lstinline!normallyConstant! \emph{arguments
are actually constant. And one, under the assumption that all input
arguments are time varying. Based on the actual arguments of the
function call either of the two derivative functions is used.}
\emph{This annotation is used by many functions of the} \lstinline!Modelica.Fluid!
\emph{library, such as}\\
\lstinline!Modelica.Fluid.Dissipation.PressureLoss.StraightPipe.dp_laminar_DP!\emph{,
since geometric arguments to these functions are usually constant}{]}
\section{Annotations for Simulation Experiments}\doublelabel{annotations-for-simulation-experiments}
\begin{lstlisting}[language=grammar]
experiment-annotation:
annotation "(" "experiment" [ "(" [experimentOption
{"," experimentOption}] ")" ] ")"
experimentOption:
StartTime "=" [ "+" | "-" ] UNSIGNED-NUMBER |
StopTime "=" [ "+" | "-"] UNSIGNED-NUMBER |
Interval "=" UNSIGNED-NUMBER |
Tolerance "=" UNSIGNED-NUMBER
\end{lstlisting}
The experiment annotation defines the default start time (StartTime) in
{[}s{]}, the default stop time (StopTime) in {[}s{]}, the suitable time
resolution for the result grid (Interval) in {[}s{]}, and the default
relative integration tolerance (Tolerance) for simulation experiments to
be carried out with the model or block at hand. If StartTime is not specified it is assumed to be \lstinline!0.0!.
\section{Annotation for single use of class}\doublelabel{annotation-for-single-use-of-class}
For state machines it is useful to have single instances of local
classes. This can be done using:
\begin{lstlisting}[language=modelica]
annotation(singleInstance=true)
\end{lstlisting}
The annotation singleInstance in a class indicates that there should
only be one component instance of the class, and it should be in the
same scope as the class is defined. The intent is to remove the class
when the component is removed and to prevent duplication of the
component.
\section{Annotations for Graphical Objects}\doublelabel{annotations-for-graphical-objects}
A graphical representation of a class consists of two abstraction
layers, icon layer and diagram layer showing graphical objects,
component icons, connectors and connection lines. The icon
representation typically visualizes the component by hiding hierarchical
details. The hierarchical decomposition is described in the diagram
layer showing icons of subcomponents and connections between these.
Graphical annotations described in this chapter ties into the Modelica
grammar as follows.
\begin{lstlisting}[language=grammar]
graphical-annotations :
annotation "(" [ layer-annotations ] ")"
layer-annotations :
( icon\_layer | diagram\_layer ) [ "," layer-annotations ]
\end{lstlisting}
Layer descriptions (start of syntactic description):
\begin{lstlisting}[language=grammar]
icon-layer :
"Icon" "(" [ coordsys-specification "," ] graphics ")"
diagram-layer :
"Diagram" "(" [ coordsys-specification "," ] graphics ")"
\end{lstlisting}
{[}\emph{Example}:
\begin{lstlisting}[language=modelica]
annotation (
Icon(coordinateSystem(extent={{-100,-100}, {100,100}}),
graphics={Rectangle(extent={{-100,-100}, {100,100}}),
Text(extent={{-100,-100}, {100,100}}, textString="Icon")}));
\end{lstlisting}
{]}
The graphics is specified as an ordered sequence of graphical
primitives, which are described below. First base-class contents is
drawn according to the order of the extends-clauses, and then graphical
primitives are drawn according to the order such that later objects can
cover earlier ones. {[}\emph{Note that the ordered sequence is
syntactically a valid Modelica annotation, although there is no
mechanism for defining an array of heterogeneous objects in
Modelica.}{]}
These Icon, Diagram, and Documentation annotations are only allowed
directly in classes (e.g. not on components or connections). The allowed
annotations for a short class definition is the union of the allowed
annotations in classes and on extends-clauses.
\subsection{Common Definitions}\doublelabel{common-definitions}
The following common definitions are used to define graphical
annotations in the later sections.
\begin{lstlisting}[language=modelica]
type DrawingUnit = Real(final unit="mm");
type Point = DrawingUnit[2] "{x, y}";
type Extent = Point[2] "Defines a rectangular area {{x1, y1}, {x2, y2}}";
\end{lstlisting}
The interpretation of "\lstinline!unit!" is with respect to printer output in
natural size (not zoomed).
All graphical entities have a visible attribute which indicates if the
entity should be shown.
\begin{lstlisting}[language=modelica]
partial record GraphicItem
Boolean visible = true;
Point origin = {0, 0};
Real rotation(quantity="angle", unit="deg")=0;
end GraphicItem;
\end{lstlisting}
The \lstinline!origin! attribute specifies the origin of the graphical item in the
coordinate system of the layer in which it is defined. The origin is
used to define the geometric information of the item and for all
transformations applied to the item. All geometric information is given
relative the \lstinline!origin! attribute, which by default is \{0, 0\}.
The \lstinline!rotation! attribute specifies the rotation of the graphical item
counter-clockwise around the point defined by the \lstinline!origin! attribute.
\subsubsection{Coordinate Systems}\doublelabel{coordinate-systems}
Each of the layers has its own coordinate system. A coordinate system is
defined by the coordinates of two points, the left (x1) lower (y1)
corner and the right (x2) upper (y2) corner, where the coordinates of
the first point shall be less than the coordinates of the second point
{[}\emph{a first quadrant coordinate system}{]}.
The attribute \lstinline!preserveAspectRatio! specifies a hint for the shape of
components of the class, but does not actually influence the rendering of the component.
If \lstinline!preserveAspectRatio! is true, changing the
extent of components should preserve the current aspect ratio of the coordinate
system of the class.
The attribute \lstinline!initialScale! specifies the default component size as
\lstinline!initialScale! times the size of the coordinate system of the class. An
application may use a different default value of \lstinline!initialScale!.
The attribute grid specifies the spacing between grid points which can
be used by tools for alignment of points in the coordinate system
{[}\emph{e.g. ``snap-to-grid''}{]}. Its use and default value is
tool-dependent.
\begin{lstlisting}[language=modelica]
record CoordinateSystem
Extent extent;
Boolean preserveAspectRatio=true;
Real initialScale = 0.1;
DrawingUnit grid[2];
end CoordinateSystem;
\end{lstlisting}
{[}\emph{Example}: \emph{A coordinate system for an icon could for
example be defined as:}
\begin{lstlisting}[language=modelica]
CoordinateSystem(extent = {{-10, -10}, {10, 10}});
\end{lstlisting}
\emph{i.e. a coordinate system with width 20 units and height 20
units.}{]}
The coordinate systems for the icon and diagram layers are by default
defined as follows; where the array of \lstinline!GraphicsItem! represents an
ordered list of graphical primitives.
\begin{lstlisting}[language=modelica]
record Icon "Representation of the icon layer"
CoordinateSystem coordinateSystem(extent = {{-100, -100}, {100, 100}});
GraphicItem[:] graphics;
end Icon;
record Diagram "Representation of the diagram layer"
CoordinateSystem coordinateSystem(extent = {{-100, -100}, {100, 100}});
GraphicItem[:] graphics;
end Diagram;
\end{lstlisting}
The coordinate system (including preserveAspectRatio) of a class is
defined by the following priority:
\begin{enumerate}
\item
The coordinate system annotation given in the class (if specified).
\item
The coordinate systems of the first base-class where the extent on the
extends-clause specifies a null-region (if any). Note that null-region
is the default for base-classes, see \autoref{extends-clause}.
\item
The default coordinate system CoordinateSystem(extent=\{\{-100,
-100\}, \{100, 100\}\}).
\end{enumerate}
\subsubsection{Graphical Properties}\doublelabel{graphical-properties}
Properties of graphical objects and connection lines are described using
the following attribute types.
\begin{lstlisting}[language=modelica]
type Color = Integer[3](min=0, max=255) "RGB representation";
constant Color Black = zeros(3);
type LinePattern = enumeration(None, Solid, Dash, Dot, DashDot, DashDotDot);
type FillPattern = enumeration(None, Solid, Horizontal, Vertical,
Cross, Forward, Backward, CrossDiag, HorizontalCylinder, VerticalCylinder, Sphere);
type BorderPattern = enumeration(None, Raised, Sunken, Engraved);
type Smooth = enumeration(None, Bezier);
type EllipseClosure = enumeration(None, Chord, Radial);
\end{lstlisting}
The \lstinline!LinePattern! attribute \lstinline!Solid! indicates a normal line, \lstinline!None! an
invisible line, and the other attributes various forms of dashed/dotted
lines.
The \lstinline!FillPattern! attributes \lstinline!Horizontal!, \lstinline!Vertical!,
\lstinline!Cross!, \lstinline!Forward!,
\lstinline!Backward! and \lstinline!CrossDiag! specify fill patterns drawn with the line color
over the fill color.
The attributes \lstinline!HorizontalCylinder!, \lstinline!VerticalCylinder! and \lstinline!Sphere! specify
gradients that represent a horizontal cylinder, a vertical cylinder and
a sphere, respectively. The gradient goes from line color to fill color.
\includegraphics[width=2.08333in,height=1.66667in]{bezierpoints}
The border pattern attributes \lstinline!Raised!, \lstinline!Sunken! and \lstinline!Engraved! represent frames
which are rendered in a tool-dependent way -- inside the extent of the
filled shape.
The \lstinline!smooth! attribute specifies that a line can be drawn as straight line
segments (\lstinline!None!) or using a spline (\lstinline!Bezier!), where the line's points
specify control points of a quadratic Bezier curve.
For lines with only two points, the \lstinline!smooth! attribute has no effect.
For lines with three or more points (P\textsubscript{1},
P\textsubscript{2}, \ldots{}, P\textsubscript{n}), the middle point of
each line segment (P\textsubscript{12}, P\textsubscript{23}, \ldots{},
P\textsubscript{(n-1)n}) becomes the starting point and ending points of
each quadratic Bezier curve. For each quadratic Bezier curve, the common
point of the two line segment becomes the control point. For instance,
point P\textsubscript{2} becomes the control point for the Bezier curve
starting at P\textsubscript{12} and ending at P\textsubscript{23}. A
straight line is drawn between the starting point of the line and the
starting point of the first quadratic Bezier curve, as well as between
the ending point of the line and the ending point of the last quadratic
Bezier curve.
In the illustration above, the square points (P\textsubscript{1},
P\textsubscript{2}, P\textsubscript{3,} and P\textsubscript{4})
represent the points that define the line, and the circle points
(P\textsubscript{12}, P\textsubscript{23}, and P\textsubscript{34}) are
the calculated middle points of each line segment. Points
P\textsubscript{12}, P\textsubscript{2}, and P\textsubscript{23} define
the first quadratic Bezier curve, and the points P\textsubscript{23},
P\textsubscript{3}, and P\textsubscript{34} define the second quadratic
Bezier curve. Finally a straight line is drawn between points
P\textsubscript{1} and P\textsubscript{12} as well as between
P\textsubscript{34} and P\textsubscript{4}.
The values of the \lstinline!EllipseClosure! enumeration specify if and how the
endpoints of an elliptical arc are to be joined (see \autoref{ellipse} Ellipse).
\begin{lstlisting}[language=modelica]
type Arrow = enumeration(None, Open, Filled, Half);
type TextStyle = enumeration(Bold, Italic, UnderLine);
type TextAlignment = enumeration(Left, Center, Right);
\end{lstlisting}
Filled shapes have the following attributes for the border and interior.
\begin{lstlisting}[language=modelica]
record FilledShape "Style attributes for filled shapes"
Color lineColor = Black "Color of border line";
Color fillColor = Black "Interior fill color";
LinePattern pattern = LinePattern.Solid "Border line pattern";
FillPattern fillPattern = FillPattern.None "Interior fill pattern";
DrawingUnit lineThickness = 0.25 "Line thickness";
end FilledShape;
\end{lstlisting}
The extent/points of the filled shape describe the theoretical
zero-thickness filled shape, and the actual rendered border is then half
inside and half outside the extent.
\subsection{Component Instance}\doublelabel{component-instance}
A component instance can be placed within a diagram or icon layer. It
has an annotation with a \lstinline!Placement! modifier to describe the placement.
Placements are defined in term of coordinate systems transformations:
\begin{lstlisting}[language=modelica]
record Transformation
Point origin = {0, 0};
Extent extent;
Real rotation(quantity="angle", unit="deg")=0;
end Transformation;
\end{lstlisting}
The origin attribute defines the position of the component in the
coordinate system of the enclosing class. The \lstinline!extent! defines the
position, size and flipping of the component, relative to the \lstinline!origin!
attribute. The \lstinline!extent! is defined relative to the \lstinline!origin! attribute of the
component instance. Given an extent \{\{x1, y1\}, \{x2, y2\}\},
x2\textless{}x1 defines horizontal flipping and y2\textless{}y1 defines
vertical flipping around the center of the object.
The \lstinline!rotation! attribute specifies rotation of the extent around the point
defined by the \lstinline!origin! attribute.
The graphical operations are applied in the order: scaling, flipping and
rotation.
\begin{lstlisting}[language=modelica]
record Placement
Boolean visible = true;
Transformation transformation "Placement in the diagram layer";
Boolean iconVisible "Visible in icon layer; for public connector";
Transformation iconTransformation "Placement in the icon layer; for public connector";
end Placement;
\end{lstlisting}
If no \lstinline!iconTransformation! is given the \lstinline!transformation! is also used for
placement in the icon layer. If no \lstinline!iconVisible! is given for a public connector the
\lstinline!visible! is also used for visibility in the icon layer.
{[}\emph{A connector can be shown in both an icon layer and a diagram
layer of a class. Since the coordinate systems typically are different,
placement information needs to be given using two different coordinate
systems. More flexibility than just using scaling and translation is
needed since the abstraction views might need different visual placement
of the connectors. The attribute} \lstinline!transformation! \emph{gives the placement in
the diagram layer and} \lstinline!iconTransformation! \emph{gives the placement in the icon
layer. When a connector is shown in a diagram layer, its diagram layer
is shown to facilitate opening up a hierarchical connector to allow
connections to its internal subconnectors.}{]}
For connectors, the icon layer is used to represent a connector when it
is shown in the icon layer of the enclosing model. The diagram layer of
the connector is used to represent it when shown in the diagram layer of
the enclosing model. Protected connectors are only shown in the diagram
layer. Public connectors are shown in both the diagram layer and the
icon layer. Non-connector components are only shown in the diagram
layer.
\subsection{Extends clause}\doublelabel{extends-clause}
Each extends-clause (and short-class-definition, as stated in \autoref{annotations-for-graphical-objects})
may have layer specific annotations which describe
the rendering of the base class' icon and diagram layers in the
subclass.
\begin{lstlisting}[language=modelica]
record IconMap
Extent extent = {{0, 0}, {0, 0}};
Boolean primitivesVisible = true;
end IconMap;
record DiagramMap
Extent extent = {{0, 0}, {0, 0}};
Boolean primitivesVisible = true;
end DiagramMap;
\end{lstlisting}
All graphical objects are by default inherited from a base class. If the
\lstinline!primitivesVisible! attribute is false, components and connections are
visible but graphical primitives are not.
\begin{itemize}
\item
If the extent of the extends-clause defines a null region (the
default), the base class contents is mapped to the same coordinates in
the derived class, and the coordinate system (including
preserveAspectRatio) can be inherited as described in
\autoref{coordinate-systems}.
\item
If the extent of the extends-clause defines a non-null region, the
base class coordinate system is mapped to the region specified by the
attribute extent, if preserveAspectRatio is true for the base class
the mapping shall preserve the aspect ratio. The base class coordinate
system (and preserveAspectRatio) is not inherited.
\end{itemize}
{[}\emph{Example}:
\begin{lstlisting}[language=modelica]
model A
extends B annotation(
IconMap(extent={{-100,-100}, {100,100}},primitivesVisible=false),
DiagramMap(extent={{-50,-50}, {0,0}},primitivesVisible=true)
);
end A;
model B
extends C annotation(DiagramMap(primitivesVisible=false));
...
end B;
\end{lstlisting}
\emph{In this example the diagram of A contains the graphical primitives
from A and B (but not from C since they were hidden in B) -- the ones
from B are rescaled, and the icon of A contains the graphical primitives
from A (but neither from B nor from C).}
{]}
\subsection{Connections}\doublelabel{connections1}
A connection is specified with an annotation containing a \lstinline!Line! primitive
and optionally a Text-primitive, as specified below. {[}\emph{Example:}
\begin{lstlisting}[language=modelica]
connect(a.x, b.x)
annotation(Line(points={{-25,30}, {10,30}, {10, -20}, {40,-20}}));
\end{lstlisting}
{]}
The optional Text-primitive defines a text that will be written on the
connection line. It has the following definition (\emph{it is not equal
to the Text-primitive as part of graphics -- the differences are marked as bold lines}):
% NOTE: Technically just the names - not the entire lines are marked in bold
\begin{lstlisting}[language=modelica,escapechar=!,emph={horizontalAlignment,string,index}, emphstyle=\textbf]
record Text
extends GraphicItem;
extends FilledShape;
Extent extent;
String string;
Real fontSize = 0 "unit pt";
String fontName;
TextStyle textStyle[:];
Color textColor=lineColor;
TextAlignment horizontalAlignment = if index<0 then TextAlignment.Right else TextAligment.Left;
Integer index;
end Text;
\end{lstlisting}
The \lstinline!index! is one of the points of Line (numbered 1, 2, 3, \ldots{} where
negative numbers count from the end, thus -1 indicate the last one). The \lstinline!string!
may use the special
symbols ``\%first'' and ``\%second'' to indicate the connectors in the
connect-equation.
The \lstinline!extent! and \lstinline!rotation! are relative to the \lstinline!origin! (default \lstinline!{0,0}!)
and the \lstinline!origin! is relative to the point on the Line.
The textColor attribute defines the color of the text. The text is drawn
with transparent background and no border around the text (and without
outline). The contents inherited from FilledShape is deprecated, but kept for compatibility reasons.
The default value for \lstinline!horizontalAlignment! is deprecated.
Having a zero size for the extent is deprecated and is handled as if upper part is moved up an appropriate amount.
{[}\emph{Example:}
\begin{lstlisting}[language=modelica]
connect(controlBus.axisControlBus1, axis1.axisControlBus) annotation (
Text(string="%first", index=-1, extent=[-6,3; -6,7]),
Line(points={{-80,-10},{-80,-14.5},{-79,-14.5},{-79,-17},{-65,-17},{-65,-65},
{-25,-65}}));
\end{lstlisting}
\emph{Draws a connection line and adds the text ''axisControlBus1''
ending at \{-6, 3\}+\{-25, -65\} and 4 vertical units of space for the text.
Using a height of zero, such as \lstinline!extent=[-6,3; -6,3]! is deprecated, but gives similar result.}
{]}
\subsection{Graphical primitives}\doublelabel{graphical-primitives}
This section describes the graphical primitives that can be used to
define the graphical objects in an annotation.
\subsubsection{Line}\doublelabel{line}
A line is specified as follows:
\begin{lstlisting}[language=modelica]
record Line
extends GraphicItem;
Point points[:];
Color color = Black;
LinePattern pattern = LinePattern.Solid;
DrawingUnit thickness = 0.25;
Arrow arrow[2] = {Arrow.None, Arrow.None} "{start arrow, end arrow}";
DrawingUnit arrowSize=3;
Smooth smooth = Smooth.None "Spline";
end Line;
\end{lstlisting}
Note that the \lstinline!Line! primitive is also used to specify the graphical
representation of a connection.
For arrows:
\begin{itemize}
\item
The arrow is drawn with an aspect ratio of 1/3 for each arrow part.
\item
The arrowSize gives the width of the arrow (including the imagined
other half for Half) so that lineThickness=10 and arrowSize=10 will
touch at the outer parts.
\item
All arrow variants overlap for overlapping lines.
\item
The lines for the Open and Half variants are drawn with lineThickness.
\end{itemize}
\subsubsection{Polygon}\doublelabel{polygon}
A polygon is specified as follows:
\begin{lstlisting}[language=modelica]
record Polygon
extends GraphicItem;
extends FilledShape;
Point points[:];
Smooth smooth = Smooth.None "Spline outline";
end Polygon;
\end{lstlisting}
The polygon is automatically closed, if the first and the last points
are not identical.
\subsubsection{Rectangle}\doublelabel{rectangle}
A rectangle is specified as follows:
\begin{lstlisting}[language=modelica]
record Rectangle
extends GraphicItem;
extends FilledShape;
BorderPattern borderPattern = BorderPattern.None;
Extent extent;
DrawingUnit radius = 0 "Corner radius";
end Rectangle;
\end{lstlisting}
The \lstinline!extent! attribute specifies the bounding box of the rectangle. If the
\lstinline!radius! attribute is specified, the rectangle is drawn with rounded
corners of the given radius.
\subsubsection{Ellipse}\doublelabel{ellipse}
An ellipse is specified as follows:
\begin{lstlisting}[language=modelica]
record Ellipse
extends GraphicItem;
extends FilledShape;
Extent extent;
Real startAngle(quantity="angle", unit="deg")=0;
Real endAngle(quantity="angle", unit="deg")=360;
EllipseClosure closure = if startAngle == 0 and endAngle == 360
then EllipseClosure.Chord
else EllipseClosure.Radial;
end Ellipse;
\end{lstlisting}
The \lstinline!extent! attribute specifies the bounding box of the ellipse.
Partial ellipses can be drawn using the \lstinline!startAngle! and \lstinline!endAngle!
attributes. These specify the endpoints of the arc prior to the stretch
and rotate operations. The arc is drawn counter-clockwise from
\lstinline!startAngle! to \lstinline!endAngle!, where startAngle and endAngle are defined
counter-clockwise from 3 o'clock (the positive x-axis).
The closure attribute specifies whether the endpoints specified by
\lstinline!startAngle! and \lstinline!endAngle! are to be joined by lines to the centre of the
extent (\lstinline!closure=EllipseClosure.Radial!), joined by a single straight line
between the end points (\lstinline!closure=EllipseClosure.Chord!), or left
unconnected (\lstinline!closure=EllipseClosure.None!). In the latter case, the
ellipse is treated as an open curve instead of a closed shape, and the
\lstinline!fillPattern! and \lstinline!fillColor! are not applied (if present, they are
ignored).
The default closure is \lstinline!EllipseClosure.Chord! when \lstinline!startAngle! is 0 and
\lstinline!endAngle! is 360, or \lstinline!EllipseClosure.Radial! otherwise.
\emph{{[}The
default for a closed ellipse is not} \lstinline!EllipseClosure.None!\emph{, since that
would result in} \lstinline!fillColor! and \lstinline!fillPattern! \emph{being ignored, making it
impossible to draw a filled ellipse.} \lstinline!EllipseClosure.Chord! \emph{is equivalent
in this case, since the chord will be of zero length.{]}}
\subsubsection{Text}\doublelabel{text}
A text string is specified as follows:
\begin{lstlisting}[language=modelica]
record Text
extends GraphicItem;
extends FilledShape;
Extent extent;
String textString;
Real fontSize = 0 "unit pt";
String fontName;
TextStyle textStyle[:];
Color textColor=lineColor;
TextAlignment horizontalAlignment = TextAlignment.Center;
end Text;
\end{lstlisting}
The \lstinline!textColor! attribute defines the color of the text. The text is drawn
with transparent background and no border around the text (and without
outline). The contents inherited from \lstinline!FilledShape! is deprecated, but kept for compatibility reasons.
There are a number of common macros that can be used in the text, and
they should be replaced when displaying the text as follows:
\begin{itemize}
\item
\%\emph{par} and \%\{\emph{par\}} replaced by the value of the
parameter \emph{par}.
If the value is numeric, tools shall display the value with displayUnit, formatted according to bipm-specification.
E.g., for \lstinline!parameter Real t(unit="s",displayUnit="ms")=0.1! tools shall display \lstinline!100 ms!.
The intent is that the text is easily readable,
thus if par is of an enumeration type, replace \%par by the item name,
not by the full name.\\
\emph{{[}Example: if par="Modelica.Blocks.Types.Enumeration.Periodic",
then \%par should be displayed as "Periodic"{]}} The form
\%\{\emph{par\}} allows component-references, and can be directly
followed by a letter. Thus \lstinline!%{w}x%{h}! gives the value of w
directly followed by x and the value of h -- and \lstinline!%wxh! gives the value of the
parameter wxh. If the parameter does not exist it is an error.
\item
\%\% replaced by \%
\item
\%name replaced by the name of the component (i.e. the identifier for
it in in the enclosing class).
\item
\%class replaced by the name of the class (only the last part of the hierarchical name).
\end{itemize}
The style attribute \lstinline!fontSize! specifies the font size. If the \lstinline!fontSize!
attribute is 0 the text is scaled to fit its extent. Otherwise, the size
specifies the absolute size. The text is vertically centered in the
extent.
If the extent specifies a box with zero width and positive height the
height is used as height for the text (unless \lstinline!fontSize! attribute is
non-zero -- which specifies the absolute size), and the text is not
truncated (the horizontalAlignment is still used in this case).
\emph{{[}This is convenient for handling texts where the width is
unknown.{]}}