Debian Codegraph @

texmf-dist/metapost/metauml/util_picture_stack.mp

raw
1 % Copyright 2005 2015 Ovidiu Gheorghies
2 % Licensed under the Apache License, Version 2.0.
3
4 if known _util_picture_stack_mp:
5 expandafter endinput
6 fi;
7 _util_picture_stack_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 util_picture;
22 inputonce util_commons;
23 inputonce util_group;
24
25 inputonce util_log;
26
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 % %
29 % PICTURE STACK %
30 % %
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32
33 %% Style for a stack of child pictures with the given margins, spacing between children, and a common child style.
34 %% If child style supplier @#childStyleSupplier is set, it takes precedence over the common child style.
35 %% The child style supplier must be the name of a macro taking a child index as an argument and returning a child style.
36 vardef PictureStackInfo@#(expr marginLeft, marginRight, marginTop, marginBottom)(text _spacing)(text _childStyle)=
37 attributes(@#);
38 var(numeric) boxed;
39 var(color) borderColor;
40 var(numeric) spacing;
41 var(string) childStyleSupplier;
42
43 Margins@#(marginLeft, marginRight, marginTop, marginBottom);
44
45 @#spacing := _spacing;
46
47 @#boxed := 0;
48 @#borderColor := green;
49
50 @#childStyleSupplier := "";
51
52 PictureInfoCopy.@#iPict(_childStyle);
53 enddef;
54
55 vardef PictureStackInfoCopy@#(text src)=
56 PictureStackInfo@#(src.left, src.right, src.top, src.bottom)(src.spacing)(src.iPict);
57
58 @#childStyleSupplier := src.childStyleSupplier;
59 @#boxed := src.boxed;
60 @#borderColor := src.borderColor;
61 enddef;
62
63 PictureStackInfo.iStack(2, 2, 2, 2)(2)(iPict);
64
65 vardef EPictureStack@#(text pictStackInfo)(text thePictures)(text how)=
66 ObjectEquations(@#);
67 @#className := "PictureStack";
68
69 PictureStackInfoCopy.@#info(pictStackInfo);
70
71 attributes(@#);
72 var(numeric) nItems;
73 var(numeric) minx, miny, maxx, maxy;
74 var(string) picturesAsString;
75 %var(text) joinMethod;
76
77 string @#joinMethod;
78
79 %@#joinMethod := str how;
80 for l=how:
81 @#joinMethod := l;
82 endfor;
83
84 @#nItems := 0;
85 for p=thePictures:
86 if (@#info.childStyleSupplier <> ""):
87 EPicture.@#pict[@#nItems](scantokens (@#info.childStyleSupplier)(@#nItems))(p);
88 else:
89 EPicture.@#pict[@#nItems](@#info.iPict)(p);
90 fi;
91 @#nItems := @#nItems + 1;
92 endfor;
93
94 @#picturesAsString := listArray(@#pict)(@#nItems);
95
96 EGroup.@#group(@#info)(scantokens @#picturesAsString);
97
98 @#nw = @#group.nw;
99 @#se = @#group.se;
100 enddef;
101
102 vardef PictureStack@#(text thePictures)(text how)=
103 EPictureStack@#(iStack)(thePictures)(how);
104 enddef;
105
106 vardef PictureStack_layout@#=
107 if @#laidout = 1:
108 log "PictureStack " & (str @#) & " has already been layed out";
109 else:
110 @#laidout := 1;
111
112 layoutObjects(scantokens @#picturesAsString);
113
114 if @#joinMethod = "vleft":
115 setObjectJoin(pa.left=pb.left; pa.bottom = pb.top + @#info.spacing);
116 elseif @#joinMethod = "vcenter":
117 setObjectJoin(pa.midx=pb.midx; pa.bottom = pb.top + @#info.spacing);
118 elseif @#joinMethod = "vright":
119 setObjectJoin(pa.right=pb.right; pa.bottom = pb.top + @#info.spacing);
120 elseif @#joinMethod = "vleftbase":
121 setObjectJoin(pa.left=pb.left; pa.bottom = pb.bottom + @#info.spacing);
122 elseif @#joinMethod = "vcenterbase":
123 setObjectJoin(pa.midx=pb.midx; pa.bottom = pb.bottom + @#info.spacing);
124 elseif @#joinMethod = "vrightbase":
125 setObjectJoin(pa.right=pb.right; pa.bottom = pb.bottom + @#info.spacing);
126 else:
127 setObjectJoin(pa.c = pb.c); % By default, stack objects on top of each other.
128 scantokens @#joinMethod;
129 fi;
130
131 joinObjects(scantokens @#picturesAsString);
132
133 Group_layout.@#group;
134 fi;
135 enddef;
136
137 vardef PictureStack_draw@#=
138 PictureStack_layout.@#;
139 objectEnsurePositioning.@#;
140
141 for i=0 upto @#nItems-1:
142 Picture_draw.@#pict[i];
143 endfor;
144
145 if (@#info.boxed = 1):
146 draw objectBox(@#) withcolor @#info.borderColor;
147 fi;
148 enddef;
149
150 vardef PictureStack_border@#=
151 objectBox(@#)
152 enddef;
153