Debian Codegraph @

texmf-dist/metapost/metauml/metauml_links.mp

raw
1 % Copyright 2005 2015 Ovidiu Gheorghies
2 % Licensed under the Apache License, Version 2.0.
3
4 % A LinkStructure is used to compute the relevant elements
5 % of a link, such as what is the main path of the link and
6 % where the link ends are to be drawn.
7 %
8 % For example, for a unidirectional aggregation between points
9 % A and B one must reserve some space for one diamond to the left and one arrow
10 % to the right, and draw the continous line on a segment shorter than AB.
11 %
12
13 if known _metauml_links_mp:
14 expandafter endinput
15 fi;
16 _metauml_links_mp:=1;
17
18 vardef LinkStructure@#(expr my_path, widthA, widthB) =
19 pair @#pointA, @#pointB, @#pointAc, @#pointBc;
20 path @#circleA, @#circleB;
21 numeric @#timeA, @#timeB;
22 path @#actualPath;
23
24 @#pointA = point 0 of my_path;
25 @#pointB = point infinity of my_path;
26
27 @#circleA = fullcircle scaled widthA shifted @#pointA;
28 @#circleB = fullcircle scaled widthB shifted @#pointB;
29
30 @#timeA = xpart (my_path intersectiontimes @#circleA);
31 @#timeB = xpart (my_path intersectiontimes @#circleB);
32 @#pointAc = point @#timeA of my_path;
33 @#pointBc = point @#timeB of my_path;
34
35 @#actualPath = subpath (@#timeA, @#timeB) of my_path;
36 enddef;
37
38 % Used for visual debugging purposes
39 %
40 vardef describeLinkStructure(text linkStruct)=
41 %draw linkStruct.pointA -- linkStruct.pointB withpen pencircle scaled 2 withcolor green;
42
43 draw linkStruct.circleA;
44 draw linkStruct.circleB;
45
46 dotlabel.lft("A", linkStruct.pointA);
47 dotlabel.rt ("B", linkStruct.pointB);
48
49 dotlabel.urt("A1", linkStruct.pointAc);
50 dotlabel.ulft("B1", linkStruct.pointBc);
51
52 draw linkStruct.actualPath withcolor red;
53 enddef;
54
55 % Draws the path using graphical elements specified by iLink
56 % using the landmark points computed in the LinkStructure
57 % linkStruct.
58 %
59 vardef drawLinkStructure(text linkStruct)(text iLink) =
60 scantokens(iLink.drawMethod)(linkStruct.actualPath);
61
62 scantokens(iLink.drawMethodA)(linkStruct.pointAc)(linkStruct.pointA)(iLink.heightA);
63 scantokens(iLink.drawMethodB)(linkStruct.pointBc)(linkStruct.pointB)(iLink.heightB);
64 enddef;
65
66 vardef LinkInfo@# =
67 numeric @#widthA, @#heightA;
68 string @#drawMethodA;
69
70 numeric @#widthB, @#heightB;
71 string @#drawMethodB;
72
73 string @#drawMethod;
74 enddef;
75
76 % Draws a link using the given path as support.
77 %
78 vardef link(text iLink)(expr myPath)=
79 LinkStructure.ls(myPath, iLink.widthA, iLink.widthB);
80 drawLinkStructure(ls)(iLink);
81 enddef;
82
83 % Draws a direct link between the center of the objects.
84 vardef clink(text iLink)(suffix objectA, objectB)=
85 link(iLink)(pathCut(objectA, objectB)(objectA.c--objectB.c));
86 enddef;