Debian Codegraph @

texmf-dist/metapost/metauml/metauml_instance.mp

raw
1 % Copyright 2005 2015 Radu-George Radulescu
2 % Licensed under the Apache License, Version 2.0.
3
4 if known _metauml_instance_mp:
5 expandafter endinput
6 fi;
7 _metauml_instance_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 inputonce util_picture;
25 inputonce util_picture_stack;
26 inputonce util_shade;
27
28 vardef InstanceInfo@#=
29 attributes(@#);
30 var(color) foreColor, borderColor;
31
32 FontInfo.@#nameFont(metauml_defaultFont, defaultscale);
33
34 FontInfo.@#attributeFont(metauml_defaultFont, defaultscale);
35
36 ShadeInfo.@#iShade;
37
38 @#foreColor := .9white;
39 @#borderColor := black;
40
41 PictureInfo.@#iName (2, 2, 1, 3)(@#nameFont);
42
43 PictureInfo.@#iAttribute (2, 2, 1.25, 0)(@#attributeFont);
44
45 PictureStackInfo.@#iAttributeStack (2, 2, 2.5, 2)(10.5)(@#iAttribute); % 8.5
46 @#iAttributeStack.iPict.bottom := 2;
47
48 @#iName.ignoreNegativeBase := 1;
49 @#iAttributeStack.iPict.ignoreNegativeBase := 1;
50 enddef;
51
52 vardef InstanceInfoCopy@#(text src)=
53 log "InstanceInfoCopy: Copying Instance";
54
55 attributes(@#);
56 var(color) foreColor, borderColor;
57
58 FontInfoCopy.@#nameFont(src.nameFont);
59
60 FontInfoCopy.@#attributeFont(src.attributeFont);
61
62 ShadeInfoCopy.@#iShade(src.iShade);
63
64 @#foreColor := src.foreColor;
65 @#borderColor := src.borderColor;
66
67 PictureInfoCopy.@#iName (src.iName);
68
69 PictureInfoCopy.@#iAttribute (src.iAttribute);
70 PictureStackInfoCopy.@#iAttributeStack (src.iAttributeStack);
71
72 enddef;
73
74 InstanceInfo.iInstance;
75
76 %
77 % Instance
78 %
79 vardef defInstance@#(expr pname) =
80 ObjectEquations(@#);
81 @#className := "Instance";
82
83 string @#name;
84 @#name = pname;
85
86 string @#attributes[];
87 numeric @#nAttrs;
88 @#nAttrs := 0;
89 enddef;
90
91 vardef Instance_addAttribute@#(expr pcontent) =
92
93 @#.attributes[@#.nAttrs] := pcontent;
94 @#.nAttrs := @#.nAttrs + 1;
95
96 enddef;
97
98 vardef EInstance@#(text _info)(expr name)(text attributes)=
99 log "EInstance begin";
100 defInstance@#(name);
101
102 log "Copying Instance info";
103 InstanceInfoCopy.@#info(_info);
104
105 for a = attributes:
106 log "Adding attribute ", a;
107 Instance_addAttribute@#(a);
108 endfor;
109 enddef;
110
111 vardef Instance@#(expr name)(text attributes)=
112 EInstance@#(iInstance)(name)(attributes);
113 enddef;
114
115 vardef Instance_border@#=
116 objectBox(@#)
117 enddef;
118
119 vardef Instance_layout@# =
120 if @#laidout = 1:
121 log "Instance " & (str @#) & " has already been layed out";
122 else:
123 @#laidout := 1;
124 log "Instance layout: " & (str @#);
125
126 @#maxFeatureWidth := 0;
127
128 EPicture.@#namePict(@#info.iName)(@#name);
129 EPictureStack.@#attributeStack(@#info.iAttributeStack)
130 (scantokens listArray(@#attributes)(@#nAttrs))("vleftbase");
131
132 layoutObjects(@#namePict, @#attributeStack);
133
134 @#maxFeatureWidth := lmax(@#namePict.width, @#attributeStack.width) + 1;
135
136 @#namePict.midx = @#midx;
137
138 @#namePict.top = @#top - 1;
139 @#attributeStack.top = @#namePict.bottom - 1;
140
141 @#attributeStack.left = @#left;
142
143 @#width = @#maxFeatureWidth;
144 @#bottom = @#attributeStack.bottom;
145
146 log "Layout done...";
147 fi;
148 enddef;
149
150 vardef Instance_drawFeatures@#=
151 log "Drawing name";
152 drawObject(@#namePict);
153 log "Underlining name";
154 pair A, B;
155 A := @#namePict.se + (-@#namePict.info.left, @#namePict.info.bottom-1);
156 B := @#namePict.sw + (@#namePict.info.right, @#namePict.info.bottom-1);
157 draw A--B;
158 log "Drawing attribute stack";
159 drawObject(@#attributeStack);
160
161 enddef;
162
163 vardef Instance_paintSkin@# =
164 log "Painting Instance skin...";
165
166 drawObjectShade(@#);
167
168 fill Instance_border.@# withcolor @#info.foreColor;
169 draw Instance_border.@# withcolor @#info.borderColor;
170
171 draw (xpart @#nw, @#attributeStack.top)--(xpart @#se, @#attributeStack.top) withcolor @#info.borderColor;
172 enddef;
173
174 vardef Instance_draw@#=
175 log "draw Instance begin...";
176 Instance_layout.@#;
177 objectEnsurePositioning.@#;
178 Instance_paintSkin.@#;
179 Instance_drawFeatures.@#;
180 enddef;
181
182 vardef Instance_setDebugMode@#=
183 @#.info.iName.boxed := 1;
184 @#.info.iAttributeStack.boxed := 1;
185 @#.info.iAttributeStack.iPict.boxed := 1;
186 enddef;