Debian Codegraph @

texmf-dist/metapost/metauml/metauml_usecase.mp

raw
1 % Copyright 2005 2015 Ovidiu Gheorghies
2 % Licensed under the Apache License, Version 2.0.
3
4 if known _metauml_usecase_mp:
5 expandafter endinput
6 fi;
7 _metauml_usecase_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 ActorInfo@#=
25 FontInfo.@#iFont(metauml_defaultFont, defaultscale);
26 @#iFont.ignoreNegativeBase := 1;
27
28 PictureInfo.@#iName (2, 2, 2, 2)(@#iFont);
29 PictureStackInfo.@#iNameStack (1pt, 1pt, 1pt, 1pt)(9)(@#iName);
30
31 @#iNameStack.iPict.ignoreNegativeBase := 1;
32
33 HumanInfo.@#iHuman(25, 35, .3, .35, .5, 1, 1);
34 enddef;
35
36 vardef ActorInfoCopy@#(text src)=
37 log "ActorInfoCopy: Copying actor info";
38
39 PictureStackInfoCopy.@#iNameStack (src.iNameStack);
40
41 HumanInfoCopy.@#iHuman(src.iHuman);
42 enddef;
43
44 ActorInfo.iActor;
45
46 vardef Actor@#(text contents)=
47 EActor.@#(iActor)(contents);
48 enddef;
49
50 vardef EActor@#(text _info)(text contents)=
51 ObjectEquations(@#);
52 @#className := "Actor";
53
54 ActorInfoCopy.@#info(_info);
55
56 numeric @#nLines; @#nLines := 0;
57 string @#lines[];
58 for l=contents:
59 @#lines[@#nLines] := l;
60 @#nLines := @#nLines + 1;
61 endfor;
62 EHuman.@#human(@#info.iHuman);
63 EPictureStack.@#nameStack(@#info.iNameStack)(scantokens listArray(@#lines)(@#nLines))("vcenterbase");
64 enddef;
65
66 vardef Actor_setDebugMode@#=
67 @#.nameStack.info.boxed := 1;
68 enddef;
69
70 vardef Actor_layout@#=
71 if @#laidout = 1:
72 log "Actor " & (str @#) & " has already been layed out";
73 else:
74 @#laidout := 1;
75 log "Actor layout: " & (str @#);
76 Human_layout.@#human;
77 PictureStack_layout.@#nameStack;
78
79 @#width = max(@#nameStack.width)(@#human.width);
80 @#height = @#nameStack.height + @#human.height;
81
82 @#n = @#human.n;
83 @#nameStack.n=@#human.s;
84 @#s = @#nameStack.s;
85 fi;
86 enddef;
87
88 vardef Actor_draw@#=
89 Actor_layout.@#;
90
91 objectEnsurePositioning.@#;
92
93 drawObjects(@#nameStack, @#human);
94 enddef;
95
96 vardef Actor_border@#=
97 objectBox(@#);
98 enddef;
99
100 vardef UsecaseInfo@#=
101 attributes(@#);
102 var(color) foreColor, borderColor;
103
104 FontInfo.@#iFont(metauml_defaultFont, defaultscale);
105 @#iFont.ignoreNegativeBase := 1;
106
107 PictureInfo.@#iName (2, 2, 2, 2)(@#iFont);
108 PictureStackInfo.@#iNameStack (0, 0, 0, 0)(9)(@#iName);
109
110 @#iNameStack.iPict.ignoreNegativeBase := 1;
111
112 Margins.@#(2,2,2,2);
113
114 @#hFatRatio := .1;
115 @#vFatRatio := .15;
116
117 ShadeInfo.@#iShade;
118 @#foreColor := .9white;
119 @#borderColor := black;
120 enddef;
121
122 vardef UsecaseInfoCopy@#(text src)=
123 log "UsecaseInfoCopy: Copying usecase info";
124 attributes(@#);
125 var(color) foreColor, borderColor;
126
127 PictureStackInfoCopy.@#iNameStack (src.iNameStack);
128 MarginsCopy.@#(src);
129 @#hFatRatio := src.hFatRatio;
130 @#vFatRatio := src.vFatRatio;
131
132 ShadeInfoCopy.@#iShade(src.iShade);
133 @#foreColor := src.foreColor;
134 @#borderColor := src.borderColor;
135 enddef;
136
137 UsecaseInfo.iUsecase;
138
139 vardef Usecase@#(text contents)=
140 EUsecase.@#(iUsecase)(contents);
141 enddef;
142
143 vardef EUsecase@#(text _info)(text contents)=
144 ObjectEquations(@#);
145 @#className := "Usecase";
146
147 UsecaseInfoCopy.@#info(_info);
148
149 attributes(@#);
150 var(numeric) nLines;
151 @#nLines := 0;
152
153 string @#lines[];
154 for l=contents:
155 @#lines[@#nLines] := l;
156 @#nLines := @#nLines + 1;
157 endfor;
158 enddef;
159
160 vardef Usecase_layout@#=
161 if @#laidout = 1:
162 log "Usecase " & (str @#) & " has already been layed out";
163 else:
164 @#laidout := 1;
165
166 EPictureStack.@#nameStack(@#info.iNameStack)(scantokens listArray(@#lines)(@#nLines))("vcenterbase");
167 PictureStack_layout.@#nameStack;
168
169 numeric @#vFat, @#hFat;
170
171 @#hFat = 0;
172 @#vFat = 10;
173
174 @#width = @#nameStack.width + @#info.left + @#info.right + 2 * @#hFat;
175 @#height = @#nameStack.height + @#info.top + @#info.bottom + 2 * @#vFat;
176
177 log "UC w,h";
178 log @#hFat;
179 log @#vFat;
180 log @#nameStack.width;
181 log @#nameStack.height;
182 log @#width;
183 log @#height;
184
185 @#c = @#nameStack.c;
186 fi;
187 enddef;
188
189 vardef Usecase_draw@#=
190 Usecase_layout@#;
191
192 pair @#urt, @#lrt, @#ulft, @#llft;
193
194 @#urt = @#nameStack.ne;
195 @#lrt = @#nameStack.se;
196 @#ulft = @#nameStack.nw;
197 @#llft = @#nameStack.sw;
198
199 objectEnsurePositioning.@#;
200
201 path @#border;
202 %@#border := @#w .. @#ulft .. @#n .. @#urt .. @#e .. @#lrt .. @#s .. @#llft .. cycle;
203 @#border := @#w .. @#n .. @#e .. @#s .. cycle;
204
205 drawObjectShade(@#);
206
207 fill Usecase_border.@# withcolor @#info.foreColor;
208 draw Usecase_border.@# withcolor @#info.borderColor;
209
210 drawObject(@#nameStack);
211 enddef;
212
213 vardef Usecase_border@#=
214 @#border
215 enddef;