Debian Codegraph @

texmf-dist/metapost/metauml/metauml_state.mp

raw
1 % Copyright 2005 2015 Ovidiu Gheorghies
2 % Licensed under the Apache License, Version 2.0.
3
4 if known _metauml_state_mp:
5 expandafter endinput
6 fi;
7 _metauml_state_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 StateInfo@#=
25 attributes(@#);
26 var(color) foreColor, borderColor;
27 var(numeric) round;
28
29 FontInfo.@#iFont(metauml_defaultFont, defaultscale);
30 @#iFont.ignoreNegativeBase := 1;
31
32 PictureInfo.@#iText (2, 2, 2, 2)(@#iFont);
33 PictureStackInfo.@#iStack (2, 2, 2, 2)(9)(@#iText);
34
35 @#iStack.iPict.ignoreNegativeBase := 1;
36
37 Margins.@#(2,2,0,6);
38
39 GroupInfo.@#iGroupSubstates(2, 2, 4, 2);
40
41 @#round := 5;
42 @#drawNameLine := 0;
43
44 ShadeInfo.@#iShade;
45 @#foreColor := .9white;
46 @#borderColor := black;
47 enddef;
48
49 vardef StateInfoCopy@#(text src)=
50 log "StateInfoCopy: Copying state info";
51 attributes(@#);
52 var(color) foreColor, borderColor;
53 var(numeric) round;
54
55 PictureStackInfoCopy.@#iStack (src.iStack);
56 MarginsCopy.@#(src);
57 @#round := src.round;
58 @#drawNameLine := src.drawNameLine;
59
60 GroupInfoCopy.@#iGroupSubstates(src.iGroupSubstates);
61
62 ShadeInfoCopy.@#iShade(src.iShade);
63 @#foreColor := src.foreColor;
64 @#borderColor := src.borderColor;
65 enddef;
66
67 StateInfo.iState;
68
69 vardef State@#(text contents)(text _substates)=
70 EState.@#(iState)(contents)(_substates);
71 enddef;
72
73 vardef EState@#(text _info)(text contents)(text _substates)=
74 ObjectEquations(@#);
75 @#className := "State";
76
77 StateInfoCopy.@#info(_info);
78
79 numeric @#nLines; @#nLines := 0;
80 string @#lines[];
81
82 numeric @#nInternalTransitions; @#nInternalTransitions := 0;
83 string @#internalTransitions[];
84
85 for l=contents:
86 @#lines[@#nLines] := l;
87 @#nLines := @#nLines + 1;
88 endfor;
89
90 EGroup.@#substates(@#info.iGroupSubstates)(_substates);
91 %@#substates.info.boxed := 1;
92
93 EPictureStack.@#stack(@#info.iStack)(scantokens listArray(@#lines)(@#nLines))("vcenterbase");
94 enddef;
95
96 vardef stateTransitions@#(text transitions)=
97 State_internalTransitions@#(transitions);
98 enddef;
99
100 vardef State_internalTransitions@#(text transitions)=
101 for transition=transitions:
102 @#internalTransitions[@#nInternalTransitions] := transition;
103 @#nInternalTransitions := @#nInternalTransitions + 1;
104 endfor;
105 enddef;
106
107 vardef State_layout@#=
108 if @#laidout = 1:
109 log "State '" & (str @#) & "' has already been layed out";
110 else:
111 @#laidout := 1;
112 log "State layout: '" & (str @#) & "'";
113
114 EPictureStack.@#internalTransitionsStack(@#info.iStack)
115 (scantokens listArray(@#internalTransitions)(@#nInternalTransitions))("vleftbase");
116
117 log "State name layout '" & (str @#) & "'...";
118 PictureStack_layout.@#stack;
119 log "Internal transitions layout '" & (str @#) & "'...";
120 PictureStack_layout.@#internalTransitionsStack;
121 log "Substates layout '" & (str @#) & "'...";
122 Group_layout.@#substates;
123
124 log "All elements in state '" & (str @#) & "' successfully layed out, integrating...";
125
126 % @#internalTransitionsStack.info.boxed := 1;
127
128 @#contentWidth = lmax(@#stack.width, @#internalTransitionsStack.width, @#substates.width);
129
130 @#width = @#contentWidth + @#info.left + @#info.right + 2 * @#info.round;
131 @#height = @#stack.height + @#info.top + @#info.bottom +
132 @#internalTransitionsStack.height + @#substates.height;
133
134 @#stack.n = @#n + (0, -@#info.top);
135 @#substates.n = @#stack.s;
136
137 @#internalTransitionsStack.sw = @#sw + (@#info.round, @#info.round);
138
139 attributes(@#);
140 var(pair) urt, lrt, ulft, llft;
141 var(pair) urta, lrta, ulfta, llfta;
142 var(pair) urtb, lrtb, ulftb, llftb;
143
144 @#urta := @#ne - (@#info.round, 0);
145 @#urtb := @#ne - (0, @#info.round);
146
147 @#lrta := @#se + (0, @#info.round);
148 @#lrtb := @#se - (@#info.round, 0);
149
150 @#ulfta := @#nw - (0, @#info.round);
151 @#ulftb := @#nw + (@#info.round, 0);
152
153 @#llfta := @#sw + (@#info.round, 0);
154 @#llftb := @#sw + (0, @#info.round);
155
156 @#urt := @#ne - (@#info.round, @#info.round) + @#info.round * (sind(45),cosd(45));
157 @#lrt := @#se + (-@#info.round, @#info.round) + @#info.round * (sind(135),cosd(135));
158 @#llft := @#sw + (@#info.round, @#info.round) + @#info.round * (sind(225),cosd(225));
159 @#ulft := @#nw + (@#info.round, -@#info.round) + @#info.round * (sind(315),cosd(315));
160
161 var(pair) nameLineLeft, nameLineRight;
162 ypart @#nameLineLeft = ypart @#nameLineRight = @#stack.bottom;
163 xpart @#nameLineLeft = xpart @#nw;
164 xpart @#nameLineRight = xpart @#ne;
165
166 log "State layout for " & (str @#) & " ended.";
167 fi;
168 enddef;
169
170 vardef State_draw@#=
171 State_layout.@#;
172 objectEnsurePositioning.@#;
173
174 attributes(@#);
175 var(path) border;
176
177 @#border := @#urta .. @#urt .. @#urtb -- %
178 @#lrta .. @#lrt .. @#lrtb -- %
179 @#llfta .. @#llft .. @#llftb -- %
180 @#ulfta .. @#ulft .. @#ulftb -- cycle;
181
182 %fill @#border shifted (@#info.shade, -@#info.shade) withcolor .7white;
183 drawObjectShade(@#);
184
185 fill @#border withcolor @#info.foreColor;
186 draw @#border withcolor @#info.borderColor;
187
188
189 drawObject(@#internalTransitionsStack);
190 drawObject(@#stack);
191 drawObject(@#substates);
192
193 if @#info.drawNameLine = 1:
194 draw @#nameLineLeft -- @#nameLineRight;
195 fi;
196 enddef;
197
198 vardef State_border@#=
199 @#border
200 enddef;
201