summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/metapost/metauml/metauml_manual/metauml_manual.tex
blob: 498960cf7611e1bbeef9aa5ee54ae7b51340c266 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
%    MetaUML: Tutorial, Reference and Test Suite
%
%    Copyright (c) 2005-2006 Ovidiu Gheorghies
%    Permission is granted to copy, distribute and/or modify this document
%    under the terms of the GNU Free Documentation License, Version 1.2
%    or any later version published by the Free Software Foundation;
%    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
%    A copy of the license is included in the section entitled "GNU
%    Free Documentation License".

\documentclass{article}

\usepackage[pdftex,colorlinks=true]{hyperref}
\usepackage{multicol}
\usepackage{multido}

\ifx\pdftexversion\undefined
  \usepackage[dvips]{graphicx}
\else
  \usepackage[pdftex]{graphicx}
   \DeclareGraphicsRule{*}{mps}{*}{}
\fi

\newcommand{\code}{\ttfamily}
\newcommand{\metauml}{MetaUML}

\setcounter{page}{1}

\begin{document}

\metauml: Tutorial, Reference and Test Suite

\begin{quote}
    Copyright \copyright 2005-2006 Ovidiu Gheorghie\c{s}.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.2
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU
    Free Documentation License".
\end{quote}

\pagebreak
This page is intentionally left blank.

\pagebreak
\title{\metauml: Tutorial, Reference and Test Suite}

\author{Ovidiu Gheorghie\c{s}}

\maketitle

\begin{abstract}
\metauml\ is a GNU GPL MetaPost library for typesetting UML diagrams, using a human-friendly textual notation. MetaUML offers a highly customizable, object-oriented API, designed with the ease of use in mind. Apart from being a reference, this manual is also a tutorial but, more importantly, a living example. You can look at its source code, getting direct accounts on ``how things are done''.
\end{abstract}

%\begin{keywords}
%MetaPost, TeX, LaTeX, UML, class diagram, state machine diagram,
%use case diagram, activity diagram
%\end{keywords}

\section{Introduction}

Here are a few diagrams created with MetaUML, just to give you a glimpse of its features:

\begin{multicols}{2}
\paragraph{A} Class Diagram\\
\includegraphics[scale=.55]{fig/appetizer.1}
\paragraph{B} Activity Diagram\\
\includegraphics[scale=.55]{fig/appetizer.2}
\paragraph{C} Notes\\
\includegraphics[scale=.55]{fig/appetizer.5}
\columnbreak
\paragraph{D} Use Case Diagram\\
\includegraphics[scale=.55]{fig/appetizer.3}
\paragraph{E} State Machine Diagram\\
\includegraphics[scale=.55]{fig/appetizer.4}
\paragraph{F} Package Diagram\\
\includegraphics[scale=.55]{fig/appetizer.6}
\end{multicols}

\pagebreak

The code which generates these diagrams is quite straightforward, combining a natural object-oriented parlance with the power of MetaPost equation solving; for more information on MetaPost see \cite {metapost}.

An UML class, for example, can be drawn as follows:

\begin{multicols}{2}
\begin{verbatim}
Class.A("MyClass")
  ("attr1: int", "attr2: int")
  ("method1(): void",
   "method2(): void");

A.nw = (0, 0); % optional, implied
drawObject(A);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/appetizer.7}
\end{multicols}

This piece of code creates an instance of {\code Class}, which will be afterward
identified as {\code A}. This object has the following content properties: a name
({\code MyClass}), a list of attributes ({\code attr1}, {\code attr2})
and a list of methods ({\code method1}, {\code method2}). The one thing remaining
before actually drawing {\code A} is to set its location.

\begin{figure}
\centering
\includegraphics{fig/properties.1}
\caption{Positioning properties of any MetaUML object (here a class object is depicted).}
\label{fig:properties}
\end{figure}

In {\code A.nw} we refer to the ``north-west'' of the class rectangle, that is
to its upper-left corner. In general, every MetaUML object has the positioning
properties given in figure \ref{fig:properties}. These properties are used to set
where to draw a given object, whether by assigning them absolute values, or by setting
them relatively to other objects. Suppose that we have defined two classes
{\code A} and {\code  B}. Then the following code would give a conceivable positioning:

\begin{multicols}{2}
\begin{verbatim}
A.nw = (0,0);
B.e = A.w + (-20, 0);
\end{verbatim}
\columnbreak
\includegraphics{fig/appetizer.8}
\end{multicols}

After the objects are drawn, one may draw links between them, such as inheritance
or association relations between classes in class diagrams, or transitions between states
in state machine diagrams. Whichever the purpose is, MetaUML provides a generic
way of drawing an edge in a diagram's graph:

\begin{verbatim}
link(how-to-draw-information)(path-to-draw);
\end{verbatim}

The ``how to draw information'' is actually an object which defines the style
of the line (e.g. solid, dashed) and the appearance of the heads (e.g. nothing, arrow, diamond).
One such object, called {\code inheritance}, defines a solid path ending in
a white triangle. The {\code path-to-draw} parameter is simply a MetaPost path.
For example, the following code can be used used to represent that class {\code B} is derived from {\code A}:

\begin{verbatim}
link(inheritance)(B.e -- A.w);
\end{verbatim}

Note that the direction of the path is important, and MetaUML uses it to determine the
type of adornment to attach at the link ends (if applicable). In our example, a white triangle,
denoting inheritance, points towards the end of the path, that is towards class {\code A}.

To sum up, we present a short code and the resulting diagram, typical for just about
everything else in MetaUML. The positioning of {\code A} does not need to be
explicitly set because ``floating'' objects are automatically positioned at {\code (0,0)} by their
draw method.

\begin{multicols}{2}

\begin{verbatim}
input metauml;
beginfig(1);
  Class.A("A")()();
  Class.B("B")()();
  B.e = A.w + (-20, 0);
  drawObjects(A, B);
  link(inheritance)(B.e -- A.w);
endfig;
end
\end{verbatim}
\columnbreak
\includegraphics{fig/appetizer.9}
\end{multicols}

From a user's perspective, this is all there is to MetaUML. With a reference describing how other
UML elements are created, one can set out to typeset arbitrary complex diagrams.

\section{Class Diagrams}

A class is created as follows:

\begin{verbatim}
Class.name(class-name)
  (list-of-attributes)
  (list-of-methods);
\end{verbatim}

The suffix {\code name} gives a name to the {\code Class} object (which, of course, represents an UML class).
The name of the UML class is a string given by {\code class-name};
the attributes are given as a comma separated list of strings, {\code list-of-attributes};
the methods are given as a comma separated list of strings, {\code list-of-attributes}.
The list of attributes and the list of methods may be void.

Each of the strings representing an attribute or a method may begin with a visibility marker: ``$+$'' for
public, ``\#'' for protected and ``$-$'' for private. MetaUML interprets this marker and renders a
graphic stereotype in form of a lock which may be opened, semi-closed and closed, respectively.

Here is an example:

\begin{multicols}{2}
\begin{verbatim}
Class.A("Point")
  ("#x:int", "#y:int")
  ("+set(x:int, y:int)",
   "+getX():int",
   "+getY():int",
   "-debug():void");
drawObject(A);
\end{verbatim}
\columnbreak
\includegraphics{fig/class.1}
\end{multicols}

\subsection{Stereotypes}

After a class is created, its stereotypes may be specified by using the macro {\code classStereotypes}:

\begin{verbatim}
classStereotypes.name(list-of-stereotypes);
\end{verbatim}

Here, {\code name} is the object name of a previously created class and {\code list-of-stereotypes}
is a comma separated list of strings. Here is an example:

\begin{multicols}{2}
\begin{verbatim}
Class.A("User")()();
classStereotypes.A("<<interface>>",
                   "<<home>>");

drawObject(A);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/class.2}
\end{multicols}

\subsection{Interfaces and Abstract Classes}

At times it is prefered to typeset the name of an interface in an oblique font, rather than using the ``interface'' stereotype. This can be easily achieved by using the macro:

\begin{verbatim}
Interface.name(class-name)
  (list-of-methods);
\end{verbatim}

Here is an example:

\begin{multicols}{2}
\begin{verbatim}
Interface.A("Observer")
    ("+update(src:Object)");

drawObject(A);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/class.11}
\end{multicols}

Note that {\code Interface} is a special kind of {\code Class}, the declaration code above being equivalent to:
\begin{verbatim}
EClass.A(iInterface)("Observer")()
      ("+update(src:Object)");
\end{verbatim}

Along the same line, here's how abstract classes can be drawn:

\begin{multicols}{2}
\begin{verbatim}
EClass.A(iAbstractClass)("Observable")
    ("observers: Observer[0..*]")
    ("+addObserver(o: Observer)",
     "+notify()");

drawObject(A);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/class.12}
\end{multicols}

If you prefer, you can use the syntactic sugar:

\begin{verbatim}
AbstractClass.A("Observable")
    ("observers: Observer[0..*]")
    ("+addObserver(o: Observer)",
     "+notify()");
\end{verbatim}

\subsection{Displaying Class Name Only}

If you want the empty methods and attributes compartments in a class not being displayed, one way is to set the spacing at their top and the bottom to {\code 0}:

\begin{multicols}{2}
\begin{verbatim}
Class.A("MyModel")()();
A.info.iAttributeStack.top := 0;
A.info.iAttributeStack.bottom := 0;
A.info.iMethodStack.top := 0;
A.info.iMethodStack.bottom := 0;

drawObject(A);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/class.13}
\end{multicols}

There are also specific formating macros defined for this usage scenarios, the formatting information object {\code iClassNameOnly} and the syntactic sugar macro {\code ClassName}:

\begin{multicols}{2}
\begin{verbatim}
EClass.A(iClassNameOnly)("MyModel")()();
ClassName.B("AnotherModel");
classStereotypes.B("<<smart>>");

topToBottom(20)(A, B);

drawObjects(A, B);
\end{verbatim}
\columnbreak
\hspace{2cm}\includegraphics{fig/class.14}
\end{multicols}

To customize the space around the class name globally, you can set the values of {\code iClassNameOnly.iName.top} and {\code iClassNameOnly.iName.bottom}. Individually, for a given object, say {\code B}, the attributes {\code B.info.iName.top} and {\code B.info.iName.bottom} can be used.

\subsection{Objects (or Class Instances)}

An UML object (or class instance) is created as follows:

\begin{verbatim}
Instance.name(object-name)
  (list-of-attributes);
\end{verbatim}

The suffix {\code name} gives a name to the {\code Instance} object. The name of the object (given by {\code object-name}) is typeset underlined. The attributes are given as a comma separated list of strings, {\code list-of-attributes}.

\begin{multicols}{2}
\begin{verbatim}
Instance.order("o: Order")
  ("name='book'", "{placed}", "{payed}");
drawObject(order);
\end{verbatim}
\columnbreak
\hspace{2cm}\includegraphics{fig/instance.1}
\end{multicols}


\subsection{Parametrized Classes (Templates)}

The most convenient way of typesetting a class template in \metauml\ is to use the macro {\code ClassTemplate}.
This macro creates a visual object which is appropriately positioned near the class object it adorns.

\begin{verbatim}
ClassTemplate.name(list-of-templates)
                  (class-object);
\end{verbatim}

The {\code name} is the name of the template object, {\code list-of-templates} is a comma separated list of strings and the {\code class-object} is the name of a class object.

Here is an example:

\begin{multicols}{2}
\begin{verbatim}
Class.A("Vector")()();
ClassTemplate.T("T", "size: int")(A);

drawObjects(A, T);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/class.3}
\end{multicols}

The macro {\code Template} can also be used to create a template object, but this time the resulting
object can be positioned freely.

\begin{verbatim}
Template.name(list-of-templates);
\end{verbatim}

Of course, one can specify both stereotypes and template parameters for a given class.

\subsection{Types of Links}

In this section we enumerate the relations that can be drawn between classes by means
of \metauml\ macros. Suppose that we have the declared two points, {\code A} (on the left)
and {\code B} (on the right):

\begin{verbatim}
pair A, B;
A = (0,0);
B = (50,0);
\end{verbatim}

\begin{tabular}{||l|c||}
\hline
{\code link(association)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.4} \\
\hline
{\code link(associationUni)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.5}  \\
\hline
{\code link(inheritance)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.6} \\
\hline
{\code link(realization)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.12} \\
\hline
{\code link(aggregation)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.7} \\
\hline
{\code link(aggregationUni)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.8} \\
\hline
{\code link(composition)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.9} \\
\hline
{\code link(compositionUni)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.10} \\
\hline
{\code link(dependency)(X.e -- Y.w)} & \includegraphics{fig/class_diagrams.11} \\
\hline
\end{tabular}

\subsection{Associations}
In UML an association typically has two of association ends and may have a name specified for it.
In turn, each association end may specify a multiplicity, a role, a visibility, an ordering.
These entities are treated in \metauml\ as pictures having specific drawing information
(spacings, font).

The first method of creating association ``items'' is by giving them explicit names.
Having a name for an association item comes in handy when referring to its properties
is later needed (see the non UML-compliant diagram below). Note that the last parameter of the macro {\code item} is an equation which uses the item name to perform positioning.

\begin{multicols}{2}
\begin{verbatim}
Class.P("Person")()();
Class.C("Company")()();
% drawing code ommited

item.aName(iAssoc)("works for")
          (aName.s = .5[P.w, C.w]);
draw aName.n -- (aName.n + (20,20));
label.urt("association name" infont "tyxtt",
          aName.n + (20,20));
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics[scale=.8]{fig/class_association.1}
\end{multicols}

However, giving names to every association item may become an annoying burden
(especially when there are many of them). Because of this, \metauml\ also allows for
``anonymous items''. In this case, the positioning is set by an equation
which refers to the anonymous item as {\code obj}.

\begin{multicols}{2}
\begin{verbatim}
% P and C defined as in the previous example

item(iAssoc)("employee")(obj.nw = P.s);
item(iAssoc)("1..*")(obj.ne = P.s);

% other items are drawn similarly
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/class_association.2}
\end{multicols}

\subsection{Dependencies and Stereotypes}

Stereotypes are frequently used with dependencies. Below is an example.
\pagebreak

\begin{multicols}{2}
\begin{verbatim}
Class.F("Factory")()();
Class.O("Object")()();

O.n = F.s - (0, 50);
drawObjects(F, O);

clink(dependency)(F, O);
item(iStereo)("<<creates>>")(obj.w = .5[F.s,O.n])
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/class_association.3}
\end{multicols}

\section{Notes}

A note is created as follows:

\begin{verbatim}
Note.name(list-of-lines);
\end{verbatim}

The suffix {\code name} is the name of the {\code Note} object. The comma separated list of strings, {\code list-of-lines}, gives the text contents of the note object, each string being drawn on its own line.
Here is an example:

\begin{multicols}{2}
\begin{verbatim}
Note.A("This note", "has two lines.");
drawObject(A);
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/note.1}
\end{multicols}

\subsection{Attaching notes to diagram elements}

Notes can be attached to diagram elements by using a link of type {\code dashedLink}.

\begin{multicols}{2}
\begin{verbatim}
Note.A("This is a class");
Class.C("Object")()();

A.sw = C.ne + (20, 20);

drawObject(A, C);

clink(dashedLink)(A, C);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/note.2}
\end{multicols}

Now let us see a more complex example, which demontrates the ability of accessing sub-elements in a \metauml\ diagram.
\pagebreak

\begin{multicols}{2}
\begin{verbatim}
Note.nA("This is the class name");
Note.nB("This is a key attribute");
Note.nC("This is a nice method");

Class.C("Object")("+id:int")
        ("+clone()", "+serialize()");

topToBottom.left(10)(nA, nB, nC);
leftToRight(10)(C, nB);

drawObjects(C, nA, nB, nC);

clink(dashedLink)(C.namePict, nA); 
clink(dashedLink)(C.attributeStack.pict[0], nB); 
clink(dashedLink)(C.methodStack.pict[1], nC);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/note.3}
\end{multicols}

Macros like {\code leftToRight} and {\code topToBottom} are presented in section \ref{section:positioning}.

\subsection{Using mathematical formulae}

MetaUML notes can contain mathematical formulae typeset in TeX (and {\bf not} LaTeX). This feature is considered experimental, as it is not always straightforward to use it. Below is a full-code example, note the import of MetaPost package {\code TEX}.

\begin{multicols}{2}
\begin{verbatim}
input metauml;
input TEX;

beginfig(1);
    Note.A("This class implements the formula:", 
           TEX("$\sum_1^n f(x) \cdot dx$"));
    drawObjects(A);
endfig;

end
\end{verbatim}
\columnbreak
\hspace{0.5cm}\includegraphics{fig/note.4}
\end{multicols}

If you have a taller formula, you must be prepared to do some advanced stunts. Remark: {\code "aaa" \& "bbb"} is MetaPost's way to concatenate the strings into {\code "aaabbb"}. The formula's string was split in two for space reasons.

\begin{multicols}{2}
\begin{verbatim}
Note.A("Can you do it?", 
        TEX("$\sum_1^n f(x) \cdot dx " &
            "\over \sum_1^m g(y) \cdot dy$"));
A.stack.info.spacing := 30;
A.stack.pict[1].info.ignoreNegativeBase := 0;

drawObject(A);
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/note.5}
\end{multicols}

Alas, this trick does not entirely solve the problem: a third line in the note would be badly aligned. Therefore, until MetaUML's {\code Note} class is upgraded to better support this scenario, you may want to limit yourself to two lines per note --- at least when tall formulae are involved.

\section{Packages}

MetaUML allows for the creation of packages in various forms. Firstly, we have the option of writing the package name in the middle of the main box. Secondly, we can write the name on the tiny box above the main box, leaving the main box empty. Lastly, we can write the package name as in the second case, but the main box can have an arbitrary contents: classes, other packages, or even other UML items. 

The macro that creates a package has the following synopsis:

\begin{verbatim}
Package.name(package-name)(subitems-list);
\end{verbatim}

The parameter {\code package-name} is a string or a list of comma separated strings representing the package's name. The {\code subitems-list} parameter is used to specify the subitems (tipically classes or packages) of this package; its form is as a comma separated list of objects, which can be void.

\begin{multicols}{2}
\begin{verbatim}
Package.P("java.lang")();
drawObject(P);
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/package.1}
\end{multicols}

Below is another example:

\begin{multicols}{2}
\begin{verbatim}
Package.P("An important", "package")();
drawObject(P);
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/package.2}
\end{multicols}

If you wish to leave the main box empty, you can use the following code:

\begin{multicols}{2}
\begin{verbatim}
Package.P("java.lang")();
P.info.forceEmptyContent := 1;
drawObject(P);
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/package.3}
\end{multicols}

The same effect as above can be achieved globally by doing:

\begin{verbatim}
iPackage.forceEmptyContent := 1;
\end{verbatim}

More information on MetaUML's way of managing global and per-object configuration data can be found in section \ref{section:infrastructure} and section \ref{section:customization}.

Here is an example involving items contained in a package.

\begin{multicols}{2}
\begin{verbatim}
Class.A("A")()();
Class.B("B")()();
Package.P("net.metauml")(A, B);

leftToRight(10)(A, B);

drawObject(P);
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/package.4}
\end{multicols}

\subsection{Types of Links}

The nesting relation between packages is created by using the {\code nest} link information.

\begin{tabular}{||l|c||}
\hline
{\code link(nest)(X.e -- Y.w)} & \includegraphics{fig/package.5} \\
\hline
\end{tabular}

\section{Component Diagrams}

A component is created by the macro {\code Component}:

\begin{verbatim}
Component.name(component-name)
  (subitems-list)
\end{verbatim}

The parameter {\code component-name} is a string representing the component's name. The {\code subitems-list} parameter is used to specify the subitems of this component (possibly classes, packages or other components); its form is as a comma separated list of objects, which can be void.

\begin{multicols}{2}
\begin{verbatim}
Component.C("Business Logic")();
drawObject(C);
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/component.1}
\end{multicols}

Here is an example involving subitems in a component:

\begin{multicols}{2}
\begin{verbatim}
Class.A("A")()();
Package.B("B")();
Component.C("C")();

Component.BigC("Big Component")(A, B, C);

leftToRight(10)(A, B);
topToBottom(10)(A, C);

drawObject(BigC);
\end{verbatim}
\columnbreak
\hspace{3cm}\includegraphics{fig/component.2}
\end{multicols}

\subsection{Types of Links}

\begin{tabular}{||l|c||}
\hline
{\code link(requiredInterface)( A.e -- .5[A.e, B.w] );} & \includegraphics{fig/component.3} \\
\hline
{\code link(providedInterface)( .5[A.e, B.w] -- B.w );} & \includegraphics{fig/component.4} \\
\hline
\end{tabular}

\vspace{0.5cm}

The {\code requiredInterface} and {\code providedInterface} visual constructs can be easily combined, as shown in the following example:

\begin{multicols}{2}
\begin{verbatim}
Component.A("A")();
Component.B("B")();

leftToRight(80)(A, B);

drawObjects(A, B);

link(providedInterface)( A.e -- .5[A.e, B.w] );
link(requiredInterface)( B.w -- .5[A.e, B.w] );
\end{verbatim}
\columnbreak
\hspace{-1cm}\includegraphics{fig/component.5}
\end{multicols}


\section{Use Case Diagrams}

\subsection{Use Cases}
An use case is created by the macro {\code Usecase}:

\begin{verbatim}
Usecase.name(list-of-lines);
\end{verbatim}

The {\code list-of-lines} is a comma separated list of strings. These strings are placed
on top of each other, centered and surrounded by the appropriate visual UML notation.

Here is an use case example:

\begin{multicols}{2}
\begin{verbatim}
Usecase.U("Authenticate user",
          "by name, password");
drawObject(U);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/usecase.1}
\end{multicols}

\subsection{Actors}

An actor is created by the macro {\code Actor}:

\begin{verbatim}
Actor.name(list-of-lines);
\end{verbatim}

Here, {\code list-of-lines} represents the actor's name. For convenience, the name may be
given as a list of strings which are placed on top of each other, to provide support for
the situations when the role is quite long. Otherwise, giving a single string
as an argument to the Actor constructor is perfectly fine.

Here is an actor example:

\begin{multicols}{2}
\begin{verbatim}
Actor.A("User");
drawObject(A);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/usecase.2}
\end{multicols}

Note that one may prefer to draw diagram relations positioned relatively to
the visual representation of an actor (the ``human'') rather than relatively to the whole
actor object (which also includes the text). Because of that, MetaUML provides access
to the ``human'' of every actor object {\code actor} by means of the sub-object {\code actor.human}.

\begin{multicols}{2}
\begin{verbatim}
Actor.A("Administrator");
drawObject(A);
draw objectBox(A);
draw objectBox(A.human);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/usecase.3}
\end{multicols}

Note that in \metauml\ {\code objectBox(X)} is equivalent to {\code X.nw -- X.ne -- X.se -- X.sw -- cycle} for every object {\code X}. {\code A.human} is considered a \metauml\ object, so you can use expressions like {\code A.human.n} or {\code A.human.midx}.

\subsection{Types of Links}

Some of the types of links defined for class diagrams (such as inheritance, association etc.) can be used with similar semantics within use case diagrams.

\section{Activity Diagrams}

\subsection{Begin, End and Flow End}

The begin and the end of an activity diagram can be marked by using the macros {\code Begin}
and {\code End} or {\code FlowFinal}, respectively. The constructors of these visual objects take no parameters:

\begin{verbatim}
Begin.beginName;
End.endName;
\end{verbatim}

Below is an example:

\begin{multicols}{2}
\begin{verbatim}
Begin.b;
End.e;
FlowFinal.f;

leftToRight(20)(b, e, f);

drawObjects(b, e, f);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/activity.1}
\end{multicols}

\subsection{Activity}

An activity is constructed as follows:
\begin{verbatim}
Activity.name(list-of-strings);
\end{verbatim}

The parameter {\code list-of-strings} is a comma separated list of strings. These strings are
centered on top of each other to allow for the accommodation of a longer activity description
within a reasonable space.

An example is given below:

\begin{multicols}{2}
\begin{verbatim}
Activity.A("Learn MetaUML -",
           "the MetaPost UML library");
drawObject(A);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/activity.2}
\end{multicols}

\subsection{Fork and Join}

A fork or join is created by the macro:

\begin{verbatim}
Fork.name(type, length);
\end{verbatim}

The parameter {\code type} is a string and can be either of {\code "h"}, {\code "horiz"}, {\code "horizontal"} for horizontal bars, and either of {\code "v"}, {\code "vert"}, {\code "vertical"} for vertical bars. The {\code length} gives the bar's length.

\begin{multicols}{2}
\begin{verbatim}
Fork.forkA("h", 100);
Fork.forkB("v", 20);

leftToRight(10)(forkA, forkB);

drawObject(forkA, forkB);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/activity.3}
\end{multicols}

\subsection{Branch}

A branch is created by the macro:

\begin{verbatim}
Branch.name;
\end{verbatim}

Here is an example:

\begin{multicols}{2}
\begin{verbatim}
Branch.testA;

drawObject(testA);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/activity.4}
\end{multicols}


\subsection{Types of Links}

In activity diagrams, transitions between activities are needed. They are typeset
as in the example below. In section \ref{composite-states} such a transition
is showed. This type of link is also used for state machine diagrams.

\begin{verbatim}
link(transition)( pointA -- pointB );
\end{verbatim}

\section{State Diagrams}

The constructor of a state allows for aggregated sub-states:

\begin{verbatim}
State.name(state-name)(substates-list);
\end{verbatim}

The parameter {\code state-name} is a string or a list of comma separated strings representing
the state's name or description. The {\code substates-list} parameter is used to specify
the substates of this state as a comma separated list of objects; this list may be void.

An example of a simple state:

\begin{multicols}{2}
\begin{verbatim}
State.s("Take order")();
drawObject(s);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/state.1}
\end{multicols}


\subsection{Composite States}
\label{composite-states}

A composite state is defined by enumerating at the end of its constructor the inner
states. Interestingly enough, the composite state takes care of drawing the sub-states it
contains. The transitions must be drawn after the composite state, as seen in the
next example:

\begin{multicols}{2}
\begin{verbatim}
Begin.b;
End.e;
State.c("Component")();
State.composite("Composite")(b, e, c);

b.midx = e.midx = c.midx;
c.top = b.bottom - 20;
e.top = c.bottom - 20;

composite.info.drawNameLine := 1;
drawObject(composite);

link(transition)(b.s -- c.n);
link(transition)(c.s -- e.n);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/state.2}
\end{multicols}

\subsection{Internal Transitions}

Internal transitions can be specified by using the macro:
\begin{verbatim}
stateTransitions.name(list-transitions);
\end{verbatim}

Identifier {\code name} gives the state object whose internal transitions are being set,
and parameter {\code list-transitions} is a comma separated string list.


An example is given below:

\begin{multicols}{2}
\begin{verbatim}
State.s("An interesting state",
        "which is worth mentioning")();
stateTransitions.s(
  "OnEntry / Open eyes",
  "OnExit  / Sleep well");
s.info.drawNameLine := 1;

drawObject(s);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/state.3}
\end{multicols}

\subsection{Special States}

Similarly to the usage of {\code Begin} and {\code End} macros, one can define history states,
exit/entry point states and terminate pseudo-states, by using the following constructors.

\begin{verbatim}
History.nameA;
ExitPoint.nameB;
EntryPoint.nameC;
Terminate.nameD;
\end{verbatim}

\section{Drawing Paths}

The {\code link} macro is powerful enough to draw relations following arbitrary paths:

\begin{multicols}{2}
\begin{verbatim}
path cool;
cool := A.e .. A.e+(20,10) ..
        B.s+(20,-40) .. B.s+(-10,-30)
        -- B.s;
link(inheritance)(cool);

link(aggregationUni)
    (A.n ..(30,30)..B.w);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/paths.1}
\end{multicols}

Regardless of how amusing this feature might be, it does become a bit of a nuisance to
use it in its bare form. When typesetting UML diagrams in good style, one generally
uses rectangular paths. It is for this kind of style that \metauml\ offers extensive
support, providing a ``syntactic sugar'' for constructs which can otherwise be
done by hand, but with some extra effort.

\subsection{Manhattan Paths}

The ``Manhattan'' path macros generate a path between two points consisting of one
horizontal and one vertical segment. The macro {\code pathManhattanX} generates first a
horizontal segment, while the macro {\code pathManhattanY} generates first a
vertical segment. In \metauml\ it also matters the direction of a path, so you
can choose to reverse it by using {\code rpathManhattanX} and {\code rpathManhattanY}
(note the prefix ``{\code r}''):

\begin{verbatim}
pathManhattanX(A, B)
pathManhattanY(A, B)

rpathManhattanX(A, B)
rpathManhattanY(A, B)
\end{verbatim}

\pagebreak
Here is an example:

\begin{multicols}{2}
\begin{verbatim}
Class.A("A")()();
Class.B("B")()();

B.sw = A.ne + (10,10);
drawObjects(A, B);

link(aggregationUni)
   (rpathManhattanX(A.e, B.s));
link(inheritance)
   (pathManhattanY(A.n, B.w));
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/paths.2}
\end{multicols}

\subsection{Stair Step Paths}

These path macros generate stair-like paths between two points.
The ``stair'' can ``rise'' first in the direction of $Ox$ axis ({\code pathStepX})
or in the direction of $Oy$ axis ({\code pathStepY}). How much should a step
rise is given by an additional parameter, {\code delta}. Again, the macros
prefixed with ``{\code r}'' reverse the direction of the path given by their
unprefixed counterparts.

\begin{verbatim}
pathStepX(A, B, delta)
pathStepY(A, B, delta)

rpathStepX(A, B, delta)
rpathStepY(A, B, delta)
\end{verbatim}

Here is an example:

\begin{multicols}{2}
\begin{verbatim}
stepX:=60;
link(aggregationUni)
   (pathStepX(A.e, B.e, stepX));

stepY:=20;
link(inheritance)
   (pathStepY(B.n, A.n, stepY));
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/paths.3}
\end{multicols}

\subsection{Horizontal and Vertical Paths}

There are times when drawing horizontal or vertical links is required,
even when the objects are not properly aligned. To this aim, the following macros
are useful:

\begin{verbatim}
pathHorizontal(pA, untilX)
pathVertical(pA, untilY)

rpathHorizontal(pA, untilX)
rpathVertical(pA, untilY)
\end{verbatim}

A path created by {\code pathHorizonal} starts from the point {\code pA}
and continues horizontally until coordinate {\code untilX} is reached. The macro
{\code pathVertical} constructs the path dually, working vertically.
The prefix ``{\code r}'' reverses the direction of the path.

Usage example:

\begin{multicols}{2}
\begin{verbatim}
untilX := B.left;
link(association)
   (pathHorizontal(A.e, untilX));

untilY:= C.bottom;
link(association)
   (pathVertical(A.n, untilY));
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/paths.4}
\end{multicols}

\subsection{Direct Paths}

A direct path can be created with {\code directPath}. The call {\code directPath(A, B)}
is equivalent to {\code A -{}-  B}.

\subsection{Paths between Objects}

Using the constructs presented above, it is clear that one can draw links between diagram
objects, using a code like:

\begin{verbatim}
link(transition)(directPath(objA.nw, objB.se));
\end{verbatim}

There are times however this may yield unsatisfactory visual results,
especially when the appearance of the object's corners is round. MetaUML provides the macro
{\code pathCut} whose aim is to limit a given path exactly to the region outside the actual
borders of the objects it connects. The macro's synopsis is:

\begin{verbatim}
pathCut(thePath)(objectA, objectB)
\end{verbatim}

Here, {\code thePath} is a given MetaPost path and {\code objectA} and {\code objectB}
are two \metauml\ objects. By contract, each \metauml\ object of type, say, {\code X}
defines a macro {\code X\_border} which returns the path that surrounds it. Because
of that, {\code pathCut} can make the appropriate modifications to {\code thePath}.

The following code demonstrates the benefits of the {\code pathCut} macro:

\begin{multicols}{2}
\begin{verbatim}
z = A.se + (30, -10);
link(transition)
   (pathCut(A, B)(A.c--z--B.c));
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/paths.5}
\end{multicols}

\subsubsection{Direct Paths between Centers}

At times is quicker to just draw direct paths between the center of two objects,
minding of course the object margins. The macro which does this is {\code clink}:

\begin{verbatim}
clink(how-to-draw-information)(objA, objB);
\end{verbatim}

The parameter {\code how-to-draw-information} is the same as for the macro {\code link};
{\code objA} and {\code objB} are two \metauml\ objects.

Below is an example which involves the inheritance relation:

\begin{multicols}{2}
\begin{verbatim}
clink(inheritance)(A, B);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/paths.6}
\end{multicols}

\section{Arranging Diagram Items}
\label{section:positioning}

Using equations involving cardinal points, such as {\code A.nw = B.ne + (10,0)}, is
good enough for achieving the desired results. However, programs are best to
be written for human audience, rather than for compilers. It does become a bit
tiresome to think all the time of cardinal points and figure out the
direction of positive or negative offsets. Because of that, \metauml\ offers
syntactic sugar which allows for an easier understanding of the intent behind
the positioning code.

Suppose that we have three classes, {\code A}, {\code B}, {\code C} and their base class
{\code Base}. We want the base class to be at the top, and the derived classes to be
on a line below. A code like the following will do:

\begin{verbatim}
A.ne = B.nw + (20,0);
B.ne = C.nw + (20,0);
Base.s = B.n + (0,-20);
\end{verbatim}

Now, look at the code again. What strikes you is that you cannot visualize what it is all about, unless you really try --- decoding the intent line by line. What this code lacks is a feature called self-documenting: the code is good only if you can read it as a story and understand its meaning.

Perhaps the following version of the code will make the point. All you need to know is that the numeric argument represents a distance.

\begin{multicols}{2}
\begin{verbatim}
leftToRight(20)(A, B, C);
topToBottom(20)(Base, B);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/positioning.2}
\end{multicols}

Below there are examples which show how these macros can be used. Suppose that we have the following definitions for objects {\code X}, {\code Y}, and {\code Z}; also, let's assume that {\code spacing} is a numeric variable set to {\code 5}.

\begin{verbatim}
Picture.X("a");
Picture.Y("...");
Picture.Z("Cyan");
\end{verbatim}

\begin{tabular}{||l|c||}
\hline
{\code leftToRight.top(spacing)(X, Y, Z);} & \includegraphics{fig/positioning.3} \\
\hline
{\code leftToRight.midy(spacing)(X, Y, Z);} & \includegraphics{fig/positioning.4} \\
\hline
{\code leftToRight.bottom(spacing)(X, Y, Z);} & \includegraphics{fig/positioning.5} \\
\hline
{\code topToBottom.left(spacing)(X, Y, Z);} & \includegraphics{fig/positioning.6} \\
\hline
{\code topToBottom.midx(spacing)(X, Y, Z);} & \includegraphics{fig/positioning.7} \\
\hline
{\code topToBottom.right(spacing)(X, Y, Z);} & \includegraphics{fig/positioning.8} \\
\hline
\end{tabular} \\

To make typesetting even quicker in frequent usage scenarios, the following equivalent contructs are also allowed:

\begin{verbatim}
leftToRight.midy(spacing)(X, Y, Z);
leftToRight(spacing)(X, Y, Z);
\end{verbatim}

\begin{verbatim}
topToBottom.midx(spacing)(X, Y, Z);
topToBottom(spacing)(X, Y, Z);
\end{verbatim}

If you want to specify that some objects have a given property equal, while the distance between them is given elsewhere, you can use the macro {\code same}.
This macro accepts a variable number of parameters, but at least two. The following table gives the interpretation of the macro for a simple example.

\begin{tabular}{||l|l||}
\hline
{\code same.top(X, Y, Z);} & {\code X.top = Y.top = Z.top;} \\
\hline
{\code same.midy(X, Y, Z);} & {\code X.midy = Y.midy = Z.midy;} \\
\hline
{\code same.bottom(X, Y, Z);} & {\code X.bottom = Y.bottom = Z.bottom;} \\
\hline
{\code same.left(X, Y, Z);} & {\code X.left = Y.left = Z.left;} \\
\hline
{\code same.midx(X, Y, Z);} & {\code X.midx = Y.midx = Z.midx;} \\
\hline
{\code same.right(X, Y, Z);} & {\code X.right = Y.right = Z.right;} \\
\hline
\end{tabular} \\


To specify the relative position of two points more easily, one can use the macros {\code below}, {\code above}, {\code atright}, {\code atleft}. Let us assume that {\code A} and {\code B} are two points (objects of type {\code pair} in MetaPost). The following constructs are equivalent:

\begin{tabular}{||l|l||}
\hline
{\code B = A + (5,0);} & {\code B = atright(A, 5);} \\
{\code B = A - (5,0);} & {\code B = atleft(A, 5);} \\
{\code B = A + (0,5);} & {\code B = above(A, 5);} \\
{\code B = A - (0,5);} & {\code B = below(A, 5);} \\
\hline
\end{tabular}


\section{The MetaUML Infrastructure}
\label{section:infrastructure}

MetaPost is a macro language based on equation solving. Using it may seem quite
tricky at first for a programmer accustomed to modern object-oriented languages.
However, the great power of MetaPost consists in its versatility. Indeed, it is possible to write
a system which mimics quite well object-oriented behavior. Along this line, METAOBJ
(\cite{metaobj}) is a library worth mentioning: it provides a high-level objects
infrastructure along with a battery of predefined objects.

Surprisingly enough, \metauml\ does not use METAOBJ. Instead, it uses a custom written,
lightweight object-oriented infrastructure, provisionally called ``{\code util}''.
METAOBJ's facilities, although impressive, were perceived by me as being a bit too much
for what was initially intented as a quick way of getting some UML diagrams layed out.
Inspired by METAOBJ, ``{\code util}'' was designed to fulfill with minimal effort
the specific tasks needed to confortably position, allign or group visual objects
which include text.

Another library having some object-oriented traits is the {\code boxes}
library, which comes with the standard MetaPost distribution. Early versions of
MetaUML did use {\code boxes} as an infrastructure, but this approach had to be abandoned eventually.
The main reason was that it was difficult to achieve good visual results when stacking texts
(more on that further on). Also, it had a degree of flexibility which became apparent to be
insufficient.

\subsection{Motivation}

Suppose that we want to typeset two texts with their bottom lines aligned, using {\code boxit}:

\begin{multicols}{2}
\begin{verbatim}
boxit.a ("yummy");
boxit.b ("cool");

a.nw = (0,0); b.sw = a.se + (10,0);

drawboxed (a, b); % or drawunboxed(a,b)
draw a.sw -- b.se dashed evenly
   withpen pencircle scaled 1.1;
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/boxes_vs_util.1}
\end{multicols}

Note that, despite supposedly having their bottoms alligned,
``yummy'' {\it looks} slightly higher than ``cool''. This would be unacceptable
in an UML class diagram, when roles are placed at the ends of a horizontal association.
Regardless of default spacing being smaller in the {\code util} library,
the very same unfortunate misalignment effect rears its ugly head:

\pagebreak

\begin{multicols}{2}
\begin{verbatim}
Picture.a("yummy");
Picture.b("cool");
% comment next line for unboxed
a.info.boxed := b.info.boxed := 1;

b.sw = a.se + (10,0);

drawObjects(a, b);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/boxes_vs_util.2}
\end{multicols}

However, the strong point of {\code util} is that we have a recourse to this problem:

\begin{multicols}{2}
\begin{verbatim}
iPict.ignoreNegativeBase := 1;

Picture.a("yummy");
Picture.b("cool");
% the rest the same as above
drawObjects(a, b);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/boxes_vs_util.3}
\end{multicols}

\subsection{The Picture Macro}

We have seen previously the line {\code iPict.ignoreNegativeBase := 1}.
Who is {\code iPict} and what is it doing in our program? \metauml\
aims at separating the ``business logic'' (what to draw) from the
``interface'' (how to draw). In order to achieve this, it records the ``how to draw''
information within the so-called {\code Info} structures. The object {\code iPict}
is an instance of {\code PictureInfo} structure, which has the following properties
(or attributes):
\begin{verbatim}
left, right, top, bottom
ignoreNegativeBase
boxed, borderColor
\end{verbatim}

The first four attributes specify how much space should be left around the
actual item to be drawn. The marvelous effect of {\code ignoreNegativeBase}
has just been shown (off), while the last two attributes control whether the border
should be drawn (when {\code boxed=1}) and if drawn, in which color.

There's one more thing: the font to typeset the text in. This is specified
in a {\code FontInfo} structure which has two attributes: the font name
and the font scale. This information is kept within the {\code PictureInfo} structure
as a contained attribute {\code iFont}. Both {\code FontInfo} and {\code PictureInfo}
have ``copy constructors'' which can be used to make copies. We have already
the effect of these copy constructors at work, when we used:

\begin{verbatim}
Picture.a("yummy");
a.info.boxed := 1;
\end{verbatim}

A copy of the default info for a picture, {\code iPict}, has been made within
the object {\code a} and can be accessed as {\code a.info}. Having a copy of the
info in each object may seem like an overkill, but it allows for a fine grained
control of the drawing mode of each individual object. This feature comes in very
handy when working with a large number of settings, as it is the case for \metauml.

Let us imagine for a moment that we have two types of text to write: one with a small font
and a small margin and one with a big font and a big margin. We could in theory
configure each individual object or set back and forth global parameters, but
this is far for convenient. It is preferable to have two sets of settings and specify
them explicitly when they are needed. The following code could be placed somewhere
in a configuration file and loaded before any {\code beginfig} macro:
\begin{verbatim}
PictureInfoCopy.iBig(iPict);
iBig.left := iBig.right := 20;
iBig.top := 10;
iBig.bottom := 1;
iBig.boxed := 1;
iBig.ignoreNegativeBase := 1;
iBig.iFont.name := defaultfont;
iBig.iFont.scale := 3;

PictureInfoCopy.iSmall(iPict);
iSmall.boxed := 1;
iSmall.borderColor := green;
\end{verbatim}

Below is an usage example of these definitions. Note the name of the macro: {\code EPicture}.
The prefix comes form ``explicit''  and it's used to acknowledge that the
``how to draw'' information is given explicitly --- as a parameter,
rather than defaulted to what's recorded in {\code iPict}, as with the {\code Picture} macro.
Having predefined configurations yields short, convenient code.

\begin{multicols}{2}
\begin{verbatim}
EPicture.a(iBig)("yummy");
EPicture.b(iSmall)("cool");
% you can still modify a.info, b.info

b.sw = a.se + (10,0);

drawObjects(a, b);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/picture_info.1}
\end{multicols}

\subsubsection{Fixed Sizes}

By default, the size of a {\code Picture} object is set by its contents. However,
it is possible to specify fixed dimensions both the width and the height, independently.
This can be done by setting the {\code info}'s attributes {\code fixedWidth} and {\code fixedHeight} to values
greater than 0. If any of these attributes is left to its default value, {\code -1}, then for the corresponding
axis the dimension is set according to the dimension of the content. Nevertheless, the fixed dimensions are enforced, even though the contained object would have needed additional space.

\begin{multicols}{2}
\begin{verbatim}
PictureInfoCopy.myFixed(iPict);
myFixed.ignoreNegativeBase := 1;
myFixed.fixedWidth  := 15;
myFixed.fixedHeight := 20;
myFixed.boxed := 1;

EPicture.a(myFixed)("a");
EPicture.b(myFixed)(".-.");
EPicture.c(myFixed)("toolong");

leftToRight.bottom(10)(a, b, c);

drawObjects(a, b, c);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/picture_info.2}
\end{multicols}

\subsubsection{Content alignment}

When fixed dimensions are used, one most likely would prefer a centered alignement of the contents in the 
{\code Picture} box. This option can be expressed independently for each of the axes, 
by setting the {\code info}'s attributes {\code valign} and {\code halign} to descriptive string values. 
For horizontal alignement, {\code halign} can be set to {\code "left"} or {\code "center"}, and for
vertical alignement, {\code valign} can be set to {\code "bottom} or {\code "center"}. The default
values for these attributes are {\code "left"} and {\code "bottom"}, respectively.

The next example uses horizontal centered alignement and a bottom alignement with a {\code 4.5} base offset, for
vertical alignement. This vertical alignement gives a better visual result than the centered one, at
least for the situations in which there are texts to be placed horizontally.

\begin{multicols}{2}
\begin{verbatim}
PictureInfoCopy.myFixed(iPict);
myFixed.ignoreNegativeBase := 1;
myFixed.bottom := 4.5;
myFixed.valign := "bottom";
myFixed.halign := "center";
myFixed.fixedWidth  := 25;
myFixed.fixedHeight := 15;
myFixed.boxed := 1;

EPicture.a(myFixed)("a");
EPicture.b(myFixed)("yum");
EPicture.c(myFixed)("b");

leftToRight.bottom(10)(a, b, c);

drawObjects(a, b, c);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/picture_info.3}
\end{multicols}

\subsection{Stacking Objects}

It is possible to stack objects, much in the style of {\code setboxjoin}
from {\code boxes} library.

\pagebreak

\begin{multicols}{2}
\begin{verbatim}
Picture.a0("yummy");
Picture.a1("cool");
Picture.a2("fool");

setObjectJoin(pa.sw = pb.nw);
joinObjects(scantokens listArray(a)(3));

drawObjects(scantokens listArray(a)(3));
% or drawObjects (a0, a1, a2);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/object_stack.1}
\end{multicols}

The {\code listArray} macro provides here a shortcut for writing
{\code a0, a1, a2}. This macro is particularly useful for generic
code which does not know beforehand the number of elements to be drawn.
Having to write the {\code scantokens} keyword is admittedly a nuisance, but
this is required.


\subsection{The Group Macro}

It is possible to group objects in \metauml. This feature is the cornerstone
of \metauml, allowing for the easy development of complex objects, such as
composite stats in state machine diagrams.

Similarly to the macro {\code Picture}, the structure {\code GroupInfo}
is used for specifying group properties; its default instantiation is
{\code iGroup}. Furthermore, the macro {\code EGroup} explicitely sets the
layout information.

Here is an example:

\begin{multicols}{2}
\begin{verbatim}
iGroup.left:=20;
iGroup.right:=15;
iGroup.boxed:=1;
iPicture.boxed:=1;

Picture.a("yummy");
Picture.b("cool");
Picture.c("fool");

b.nw = a.nw + (20,20);  % A
c.nw = a.nw + (15, 40); % B

Group.g(a, b, c);
g.nw = (10,10); % C

drawObject(g);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/group.1}
\end{multicols}

Note that after some objects are grouped, they can all be drawn
by invoking the {\code drawObject} macro solely on the group that aggregates them.
Another important remark is that it is necessary only to set the relative
positioning of objects within a group (line A and B); afterward, one can
simply ``move'' the group to a given position (line C), and all the contained
objects will move along.

\subsection{The PictureStack Macro}

The {\code PictureStack} macro is a syntactic sugar for a set of pictures,
stacked according to predefined equations and grouped together.

\begin{multicols}{2}
\begin{verbatim}
iStack.boxed := 1;
iStack.iPict.boxed := 1;
PictureStack.myStack("foo",
  "bar: int" infont "tyxtt",
  "nicely-centered" infont defaultfont,
  "nice")("vcenter");

drawObject(myStack);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/picture_stack.1}
\end{multicols}

Note the last parameter of the macro {\code PictureStack}, here {\code vcenter}.
It is used to generate appropriate equations based on a descriptive name.
The spacing between individual picture objects is set by the field
{\code iStack.spacing}. Currently, the following alignment names are
defined: {\code vleft}, {\code vright}, {\code vcenter},
{\code vleftbase}, {\code vrightbase}, {\code vcenterbase}. All these
names refer to vertical alignment (the prefix ``{\code v}''); alignment can
be at left, right or centered. The variants having the suffix ``{\code base}'' align
the pictures so that {\code iStack.spacing} refer to the distance between the
bottom lines of the pictures. The unsuffixed variants use {\code iStack.spacing} as
the distance between one's bottom line and the next's top line.

The ``{\code base}'' alignment is particularly useful for stacking text, since it
offers better visual appearance when {\code iPict.ignoreNegativeBase} is set to {\code 1}.

\section{Components Design}

Each MetaUML component (e.g. {\code Picture}, {\code PictureStack}, {\code Class}) is
designed according to an established pattern. This section gives more insight
on this.

In order to draw a component, one must know the following information:
\begin{itemize}
\item what to draw, or what are the elements of a component.
\item how to draw, or how are the elements positioned in relation to each other within the component
\item where to draw
\end{itemize}

For example, in order to draw a picture object we must know, respectively:
\begin{itemize}
\item what is the text or the native picture that needs to be drawn
\item what are the margins that should be left around the contents
\item where is the picture to be drawn
\end{itemize}

Why do we bother with these questions? Why don't we just simply draw the picture
component as soon as it was created and get it over with?
That is, why doesn't the following code just work?

\begin{verbatim}
Picture.pict("foo");
\end{verbatim}

Well, although we have the answer to question 1 (what to draw),
we still need to have question 3 answered. The code below becomes thus a
necessity (actually, you are not forced to specify the positioning of an object,
because its draw method positions it to {\code (0,0)} by default):

\begin{verbatim}
% question 1: what to draw
Picture.pict("foo");

% question 3: where to draw
pict.nw = (10,10);

% now we can draw
drawObject(pict);
\end{verbatim}

How about question 2, how to draw? By default, this problem is addressed behind the
scenes by the component. This means, for the Picture object, that a native picture is created
from the given string, and around that picture certain margins are placed, by means of MetaPost equations.
(The margins come in handy when one wants to quickly place Picture objects near others,
so that the result doesn't look too cluttered.)
If these equations were defined within the Picture constructor, then an
usability problem would have appeared, because it wouldn't have been possible to modify the margins,
as in the code below:

\begin{verbatim}
% question 1: what to draw
Picture.pict("foo");

% question 2: how to draw
pict.info.left := 10;
pict.info.boxed := 1;

% question 3: where to draw
pict.nw = (0,0);

% now we can draw
drawObject(pict);
\end{verbatim}

To allow for this type of code, the equations that define the layout of the {\code Picture} object (here, what the margins are)
must be defined somewhere after the constructor. This is done by a macro called {\code Picture\_layout}.
This macro defines all the equations which link the ``what to draw'' information to the ``how to draw''
information (which in our case is taken from the {\code info} member, a copy of {\code iPict}).
Nevertheless, notice that {\code Picture\_layouts} is not explicitly invoked. To the user's
great relief, this is taken care of automatically within the {\code Picture\_draw} macro.

There are times however, when explicitly invoking a macro like {\code Picture\_layout}
becomes a necessity. This is because, by contract, it is only after the {\code layout}
macro is invoked that the final dimensions (width, height) of an object are
definitely and permanently known. Imagine that we have a component whose job is to
surround in a red-filled rectangle some other objects. This component
needs to know what the dimensions of the contained objects are, in order to be able to set
its own dimensions. At drawing time, the contained objects must not have been drawn already,
because the red rectangle of the container would overwrite them.
Therefore, the whole pseudo-code would be:
\begin{verbatim}
Create objects o1, o2, ... ok;
Create container c(o1, o2, ..., ok);
Optional: modify info-s for o1, o2, ... ok;
Optional: modify info for c;

layout c, requiring layout of o1, o2, ... ok;
establish where to draw c;
draw red rectangle defined by c;
draw components o1, o2, ...ok within c
\end{verbatim}

Note that an object mustn't be laid out more than once, because otherwise
inconsistent or superfluous equations would arise. To enforce this, by contract,
any object must keep record of whether its layout method has already been invoked,
and if the answer is affirmative, subsequent invocations of the layout macro would
do nothing. It is very important to mention that after the {\code layout} macro is
invoked over an object, modifying the {\code info} member of that object has
no subsequent effect, since the layout equations are declared and interpreted only once.

\subsection{Notes on the Implementation of Links}

\metauml\ considers edges in diagram graphs as links. A link is composed of a path and the
heads (possible none, one or two). For example, an association has no heads, and one must simply
draw along the path with a solid pen. An unidirectional aggregation has a solid path and two
heads: one is an arrow and the other is a diamond. So the template algorithm for drawing a link
is:

\begin{verbatim}
0. Reserve space for heads
1. Draw the path (except for the heads)
2. Draw head 1
3. Draw head 2
\end{verbatim}

Each of the UML link types define how the drawing should be done, in each of the
cases (1, 2 and 3). Consider the link type of unidirectional composition.
Its ``class'' is declared as:

\begin{verbatim}
vardef CompositionUniInfo@# =
  LinkInfo@#;

  @#widthA      = defaultRelationHeadWidth;
  @#heightA     = defaultRelationHeadHeight;
  @#drawMethodA = "drawArrow";

  @#widthB      = defaultRelationHeadWidth;
  @#heightB     = defaultRelationHeadHeight;
  @#drawMethodB = "drawDiamondBlack";

  @#drawMethod = "drawLine";
enddef;
\end{verbatim}

Using this definition, the actual description is created like this:

\begin{verbatim}
CompositionUniInfo.compositionUni;
\end{verbatim}

As shown previously, is is the macro {\code link} which
performs the actual drawing, using the link description information
which is given as parameter (generally called {\code iLink}).
For example, we can use:

\begin{verbatim}
link(aggregationUni)((0,0)--(40,0));
\end{verbatim}

%\begin{figure}
%\centering
%\includegraphics{fig/how-links-work.1}
%\caption{An example of a picture stack.}
%\label{fig:hlw}
%\end{figure}

Let us see now the inner workings of macro {\code link}. Its definition is:

\begin{verbatim}
vardef link(text iLink)(expr myPath)=
   LinkStructure.ls(myPath,
                    iLink.widthA, iLink.widthB);
   drawLinkStructure(ls)(iLink);
enddef;
\end{verbatim}

\begin{figure}
\centering
\begin{tabular}{l|l}
$AB$ & the path specified by the user \\
$|AA'|$ & {\code iLink.widthA}\\
$|BB'|$ & {\code iLink.widthB}
\end{tabular}
\includegraphics{fig/how-links-work.2}
\caption{Details on how a link is drawn by \metauml.}
\label{fig:hlw2}
\end{figure}

First, space is reserved for heads, by ``shortening'' the given path {\code myPath}
by {\code iLink.widthA} at the beginning and by {\code iLink.widthB} at the end.
After that, the shortened path is drawn with the ``method''
given by {\code iLink.drawMethod} and the heads with the ``methods''
{\code iLink.drawMethodA} and {\code iLink.drawMethodB},
respectively (figure \ref{fig:hlw2}).

\subsection{Object Definitions: Easier {\code generic\_declare}}

In MetaPost, if somebody wants to define something resembling a class in an object-oriented language,
named, say, {\code Person}, he would do something like this:

\begin{verbatim}
vardef Person@#(expr _name, _age)=
  % @# prefix can be seen as `this` pointer
  string @#name;
  numeric @#age;

  @#name := _name;
  @#age := _age;
enddef;
\end{verbatim}

This allows for the creation of instances (or objects) of class {\code Person} by using
declarations like:

\begin{verbatim}
Person.personA;
Person.personB;
\end{verbatim}

 However, if one also wants to able able to create indexed arrays of persons, such as
{\code Person.student0}, {\code Person.student1} etc., the definition of class
{\code Person} must read:

\begin{verbatim}
vardef Person@#(expr _name, _age)=
  _n_ := str @#;
  generic_declare(string) _n.name;
  generic_declare(numeric) _n.age;

  @#name := _name;
  @#age := _age;
enddef;
\end{verbatim}

This construction is rather inelegant. MetaUML offers alternative macros to achieve
the same effect, uncluttering the code by removing the need for the unaesthetic {\code \_n\_} and
{\code \_n}.

\begin{verbatim}
vardef Person@#(expr _name, _age)=
  attributes(@#);
  var(string) name;
  var(numeric) age;

  @#name := _name;
  @#age := _age;
enddef;
\end{verbatim}

\section{Customization in MetaUML: Examples}
\label{section:customization}

We have seen that in MetaUML the ``how to draw'' information is memorized into the so-called
``{\code Info}'' structures. For example, the default way in which a {\code Picture} object is
to be drawn is recorded into an instance of {\code PictureInfo}, named {\code iPict}. In this section we
present a case study involving the customization of {\code Class} objects. The customization of
any other \metauml\ objects works similarly. Here we cannot possibly present all the customization
options for all kinds of \metauml\ objects: this would take too long. Nevertheless, an interested reader can refer
to the top of the appropriate \metauml\ library file, where {\code Info} structures are defined.
For example, class diagram related definitions are in {\code metauml\_class.mp}, activity diagram
definitions are in {\code metauml\_activity.mp} etc.

\subsection{Global settings}

Let us assume that we do not particularly like the default foreground color of all classes, and wish
to change it so something yellowish. In this scenario, one would most likely want to change
the appropriate field in {\code iClass}:

\begin{verbatim}
iClass.foreColor := (.9, .9, 0);
\end{verbatim}

After this, we can obtain the following result:

\begin{multicols}{2}
\begin{verbatim}
Class.A("A")()();
Class.B("B")()();
Class.C("C")()();

B.w = A.e + (20,0);
C.n = .5[A.se, B.sw] + (0, -10);

drawObjects(A, B, C);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/class_customization.1}
\end{multicols}

\subsection{Individual settings}

When one wants to make modifications to the settings of one particular
{\code Class} objects, another strategy is more appropriate. How about having class
{\code C} stand out with a light blue foreground color, a bigger font size for the class name and a blue border?

\pagebreak
\begin{multicols}{2}
\begin{verbatim}
iPict.foreColor := (.9, .9, 0);

Class.A("A")()();
Class.B("B")()();
Class.C("C")()();
C.info.foreColor := (.9, .7, .7);
C.info.borderColor := green;
C.info.iName.iFont.scale := 2;

% positioning code ommited
drawObjects(A, B, C);
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/class_customization.2}
\end{multicols}

As an aside, note that for each {\code Class} object its {\code info} member is created as
a copy of {\code iClass}: the actual drawing is performed using this copied
information. Because of that, one can modify the {\code info} member after the object
has been created and still get the desired results.

Another thing worth mentioning is that the {\code ClassInfo} structure contains
the {\code iName} member, which is an instance of {\code PictureInfo}. In our example we
do not want to modify the spacings around the {\code Picture} object,
but the characteristics of the font its contents is typeset into. To do that,
we modify the {\code iName.iFont} member, which by default is a copy of {\code iFont}
(an instance of {\code FontInfo}, defined in {\code util\_picture.mp}).
If, for example, we want to change the font the class name is rendered into, we would set
the attribute {\code iName.iFont.name} to a string representing a font name
on our system (as used with the MetaPost {\code infont} operator).


\subsection{Predefined settings}

This usage scenario is perhaps more interesting. Suppose that we have two
types of classes which we want to draw differently. Making the setting adjustments
for each individual class object would soon become a nuisance. \metauml's solution consists in the
ability of using predefined ``how to draw'' {\code Info} objects. Let us create such objects:

\begin{verbatim}
ClassInfoCopy.iHome(iClass);
iHome.foreColor := (0, .9, .9);

ClassInfo.iRemote;
iRemote.foreColor := (.9, .9, 0);
iRemote.borderColor := green;
\end{verbatim}

Object {\code iHome} is a copy of {\code iClass} (as it might have been set at
the time of the macro call). Object {\code iRemote} is created just as {\code iClass}
is originally created. We can now use these {\code Info} objects to easily set the
``how to draw'' information for classes. The result is depicted below,
please note the ``{\code E}'' prefix in {\code EClass}:

\begin{multicols}{2}
\begin{verbatim}
EClass.A(iHome)("UserHome")()();
EClass.B(iRemote)("UserRemote")()();
EClass.C(iHome)("CartHome")()();
EClass.D(iRemote)("CartRemote")()();
\end{verbatim}
\columnbreak
\hspace{1cm}\includegraphics{fig/class_customization.3}
\end{multicols}

\subsection{Extreme customization}

When another font (or font size) is used, one may also want to modify the spacings between the
attributes' and methods' baselines. Figure below is the result of the
(unlikely) code:

\begin{multicols}{2}
\begin{verbatim}
Class.A("Foo")
  ("a: int", "b: int")
  ("foo()", "bar()", "gar()");

A.info.iName.iFont.name := metauml_defaultFontBold;
A.info.iName.iFont.scale := 1.2;

A.info.iAttributeStack.iPict.iFont.scale := 0.8;
A.info.iAttributeStack.top := 10;
A.info.iAttributeStack.spacing := 11;

A.info.iMethodStack.iPict.iFont.scale := 2;
A.info.iMethodStack.spacing := 17;
A.info.iMethodStack.bottom := 10;

drawObject(A);
\end{verbatim}
\columnbreak
\hspace{4cm}\includegraphics{fig/class_customization.4}
\end{multicols}

\begin{verbatim}
\end{verbatim}

Both {\code iAttributeStack} and {\code iMethodStack} are instances of
{\code PictureStackInfo}, which is used to control the display of {\code PictureStack} objects.
%We can also customize the size and colors of the ``locks'' by setting {\code A.info.iLock}.

As font names, you can choose from the globally defined {\code metauml\_defaultFont}, {\code metauml\_defaultFontOblique}, {\code metauml\_defaultFontBold}, {\code metauml\_defaultFontBoldOblique}, or any other name of a font that is available on your system.

%\theendnotes

\bibliographystyle{apalike}

\begin{thebibliography}{1}
\bibitem[Roegel, 2002]{metaobj}
Roegel, D. (2002).
\newblock {The METAOBJ tutorial and reference manual}.
\newblock Available from {\code www.loria.fr/~roegel/TeX/momanual.pdf}.

\bibitem[Knuth, 1986]{knuth}
Knuth, D.~E. (1986).
\newblock {\em The {\TeX{}}book}.
\newblock Addison-Wesley Publishing Company.

\bibitem[Lamport, 1994]{lamport}
Lamport, L. (1994).
\newblock {\em {\LaTeX} a Document Preparation System}.
\newblock Addison-Wesley Publishing Company, 2nd edition.

%\bibitem[Gheorghies, 2005]{metaumlman}
%Gheorghies, O. (2005).
%\newblock {MetaUML: Tutorial, Reference and Test Suite}.
%\newblock Available from {\code http://metauml.sourceforge.net}.

\bibitem[Hobby, 1992]{metapost}
Hobby, J. (1992)
\newblock {A User's Manual for MetaPost}.
\newblock Available from {\code http://www.tug.org/tutorials/mp/}.

\bibitem[Gjelstad, 2001]{umlsty}
Gjelstad, E. (2001).
\newblock {uml.sty 0.09.09}.
\newblock Available from {\code http://heim.ifi.uio.no/\~{ }ellefg/uml.sty/}.

\bibitem[Diamantini, 1998]{pstumlsty}
Diamantini, M. (1998).
\newblock {Interface utilisateur du package pst-uml}.
\newblock Available from {\code http://perce.de/LaTeX/pst-uml/}.

\bibitem[Palmer, 1999]{umldoc}
Palmer, D. (1999).
\newblock {The umldoc UML Documentation Package}.
\newblock Available from {\code http://www.charvolant.org/\~{ }elements/}.

\bibitem[OMG, 2003]{XMI}
Object Management Group (2003).
\newblock {XML Metadata Interchange (XMI) Specification}.
\newblock Available from {\code http://www.omg.org/}.
\end{thebibliography}

\pagebreak
\pagebreak
\pagebreak
\input{test_suite}

\pagebreak
\section{GNU Free Documentation License}
\input{gnu-fdl}

\end{document}