Debian Codegraph @

texmf-dist/metapost/metauml/metauml_component.mp

raw
1 % Copyright 2006 2015 Radu-George Radulescu, Ovidiu Gheorghies
2 % Licensed under the Apache License, Version 2.0.
3
4 if known _metauml_component_mp:
5 expandafter endinput
6 fi;
7 _metauml_component_mp:=1;
8
9 % Sadly, this copy of the macro is needed to prevent multiple file loads being shown by MetaPost.
10 % The guard values (such as _metauml_mp) do ensure that the file isn't loaded multiple times,
11 % but this macro makes sure that MetaPost won't try to load the file and display a message for that.
12 def inputonce text libraryFile=
13 if not known scantokens ("_" & str libraryFile & "_mp"):
14 %includeonce% show "Loading " & str libraryFile;
15 scantokens ("input " & str libraryFile);
16 else:
17 %includeonce% show str libraryFile & " already loaded.";
18 fi;
19 enddef;
20
21 inputonce metauml_defaults;
22 inputonce util_log;
23
24 vardef ComponentInfo@#=
25 attributes(@#);
26 var(color) foreColor, borderColor;
27 var(numeric) minimumNameContentsDifference;
28
29 FontInfo.@#iFont(metauml_defaultFont, defaultscale);
30 @#iFont.ignoreNegativeBase := 1;
31
32 PictureInfo.@#iText (2, 2, 2, 2)(@#iFont);
33 PictureStackInfo.@#iNameStack (2, 2, 2, 2)(9)(@#iText);
34 @#iNameStack.iPict.ignoreNegativeBase := 1;
35
36 Margins.@#(2,2,2,2);
37
38 ShadeInfo.@#iShade;
39 @#foreColor := .9white;
40 @#borderColor := black;
41
42 @#minimumNameContentsDifference := 20;
43
44 GroupInfo.@#iContentsGroup(2, 2, 10, 2);
45 enddef;
46
47 vardef ComponentInfoCopy@#(text src)=
48 log "ComponentInfoCopy: Copying component info";
49
50 attributes(@#);
51 var(color) foreColor, borderColor;
52 var(numeric) minimumNameContentsDifference;
53
54 PictureStackInfoCopy.@#iNameStack (src.iNameStack);
55 MarginsCopy.@#(src);
56
57 ShadeInfoCopy.@#iShade(src.iShade);
58 @#foreColor := src.foreColor;
59 @#borderColor := src.borderColor;
60
61 @#minimumNameContentsDifference := src.minimumNameContentsDifference;
62
63 GroupInfoCopy.@#iContentsGroup(src.iContentsGroup);
64 enddef;
65
66 ComponentInfo.iComponent;
67
68 vardef Component@#(text contents)(text _subItems)=
69 EComponent.@#(iComponent)(contents)(_subItems);
70 enddef;
71
72 vardef EComponent@#(text _info)(text contents)(text _subItems)=
73 ObjectEquations(@#);
74 @#className := "Component";
75
76 ComponentInfoCopy.@#info(_info);
77
78 numeric @#nLines; @#nLines := 0;
79 string @#lines[];
80 numeric @#nSubItems; @#nSubItems := 0;
81
82 for l=contents:
83 @#lines[@#nLines] := l;
84 @#nLines := @#nLines + 1;
85 endfor;
86
87 for s=_subItems:
88 @#nSubItems := @#nSubItems + 1;
89 endfor;
90
91 EGroup.@#subItems(@#info.iContentsGroup)(_subItems);
92
93 EPictureStack.@#nameStack(@#info.iNameStack)(scantokens listArray(@#lines)(@#nLines))("vcenterbase");
94 enddef;
95
96 vardef Component_layout@#=
97 if @#laidout = 1:
98 log "Component '" & (str @#) & "' has already been layed out";
99 else:
100 @#laidout := 1;
101 log "Component layout: '" & (str @#) & "'";
102
103 log "Component name layout '" & (str @#) & "'...";
104 PictureStack_layout.@#nameStack;
105 log "SubItems for component layout '" & (str @#) & "'...";
106 Group_layout.@#subItems;
107
108 log "All elements in component '" & (str @#) & "' successfully layed out, integrating...";
109
110
111 if @#subItems.width < @#nameStack.width + @#info.minimumNameContentsDifference:
112 @#contentWidth = @#nameStack.width + @#info.minimumNameContentsDifference;
113 else:
114 @#contentWidth = lmax(@#nameStack.width, @#subItems.width);
115 fi;
116
117 @#width = @#contentWidth + @#info.left + @#info.right + 15;
118
119 if @#nSubItems = 0:
120 @#height = @#info.top + @#info.bottom + @#subItems.height + 15;
121 @#nameStack.n = @#n - (0, 7);
122 else:
123 @#height = @#info.top + @#info.bottom + @#subItems.height + 30;
124 @#nameStack.n = @#n + (0, @#info.top) - (0, 5);
125 fi;
126
127 @#subItems.n = @#n + (0, -((@#height - @#subItems.height)/2)) - (0, 5);
128
129 log "Component layout for " & (str @#) & " ended.";
130 fi;
131 enddef;
132
133 vardef Component_draw@#=
134 Component_layout.@#;
135 objectEnsurePositioning.@#;
136
137 attributes(@#);
138 var(path) border;
139
140 @#border := @#ne -- @#nw -- @#sw -- @#se -- cycle;
141
142 drawObjectShade(@#);
143
144 fill @#border withcolor @#info.foreColor;
145 draw @#border withcolor @#info.borderColor;
146
147 drawComponentVisualStereotype(@#ne);
148
149 drawObject(@#nameStack);
150 drawObject(@#subItems);
151
152 enddef;
153
154 vardef drawComponentVisualStereotype(text ne)=
155 % lud = left-up-down of the top-right rectangle; luu = left-up-up of the top-right rectangle etc.
156 pair lud, luu, ru, rd, ldd, ldu, lmd, lmu;
157 % urectld = upper rectangle left-down, lrectru = lower rectangle right-up
158 pair urectld, urectlu, urectru, urectrd, lrectld, lrectlu, lrectru, lrectrd;
159 lud = ne - (14, 5 );
160 luu = lud + (0, 2 );
161 ru = luu + (8, 0 );
162 rd = ru - (0, 14);
163 ldd = rd - (8, 0 );
164 ldu = ldd + (0, 2 );
165 lmd = ldu + (0, 3 );
166 lmu = lud - (0, 3 );
167
168 urectld = lmu - (3, 0);
169 urectlu = lud - (3, 0);
170 urectru = lud + (3, 0);
171 urectrd = lmu + (3, 0);
172
173 lrectld = ldu - (3, 0);
174 lrectlu = lmd - (3, 0);
175 lrectru = lmd + (3, 0);
176 lrectrd = ldu + (3, 0);
177
178 draw lud -- luu -- ru -- rd -- ldd -- ldu;
179 draw lmd -- lmu;
180 draw urectld -- urectlu -- urectru -- urectrd -- urectld;
181 draw lrectld -- lrectlu -- lrectru -- lrectrd -- lrectld;
182 enddef;
183
184 vardef Component_border@#=
185 @#border
186 enddef;