Debian Codegraph @

texmf-dist/source/latex/wargame/chit/shape.dtx

raw
1 % \iffalse
2 % --------------------------------------------------------------------
3 % <*chit>
4 % \fi
5 %
6 % \subsubsection{The \texttt{chit} key namespace}
7 %
8 % Some stuff to consider wrt.~line widths. Setting the line width in
9 % the \texttt{chit} scope overrides frame settings. The frame stroke
10 % can be larger but not smaller. Setting the stroke width in the
11 % symbol scope sets it for the symbol only. Thus, to get a thin
12 % border, we need to
13 % \begin{itemize}
14 % \item Set a small line width in the top chit scope.
15 % \item Possible set a larger line width in the frame sub-scope.
16 % \item Set a larger line width in the symbol sub-scope.
17 % \end{itemize}
18 % I do not know why this is.
19 %
20 % \begin{TikzKey}{/chit/full,
21 % /chit/symbol,
22 % /chit/left,
23 % /chit/right,
24 % /chit/upper left,
25 % /chit/upper right,
26 % /chit/lower left,
27 % /chit/lower right,
28 % /chit/factors,
29 % /chit/extra,
30 % /chit/setup,
31 % /chit/bevel,
32 % /chit/id}
33 %
34 % The parts of a chit
35 %
36 % \begin{macrocode}
37 \newif\ifchit@clip\chit@cliptrue
38 \tikzset{%
39 /chit/.search also={/tikz},
40 /chit/.cd,
41 full/.store in=\chit@full, full/.initial=,%
42 symbol/.store in=\chit@symbol, symbol/.initial=,%
43 left/.store in=\chit@left, left/.initial=,%
44 unique/.style={/chit/left={#1}},%
45 right/.store in=\chit@right, right/.initial=,%
46 parent/.style={/chit/right={#1}},%
47 upper left/.store in=\chit@upper@left, upper left/.initial=,%
48 upper right/.store in=\chit@upper@right, upper right/.initial=,%
49 lower left/.store in=\chit@lower@left, lower left/.initial=,%
50 lower right/.store in=\chit@lower@right, lower right/.initial=,%
51 factors/.store in=\chit@factors, factors/.initial=,%
52 setup/.store in=\chit@setup, setup/.initial=,%
53 id/.store in=\chit@id, id/.initial=,%
54 frame/.store in=\chit@frame, frame/.initial=,%
55 extra/.store in=\chit@extra, extra/.initial=,%
56 bev/.store in=\chit@bevel, bev/.initial=,
57 bevel fraction/.store in=\chit@bevel@frac,bevel fraction/.initial=10,
58 bevel/.is choice,
59 bevel/none/.style = {/chit/bev=},
60 bevel/north west/.style = {/chit/bev=1},
61 bevel/north east/.style = {/chit/bev=2},
62 bevel/south west/.style = {/chit/bev=3},
63 bevel/south east/.style = {/chit/bev=4},
64 bevel/NW/.style = {/chit/bev=1},
65 bevel/NE/.style = {/chit/bev=2},
66 bevel/SW/.style = {/chit/bev=3},
67 bevel/SE/.style = {/chit/bev=4},
68 bevel/.default = north west,
69 clip/.is if=chit@clip,%
70 nato shape/.store in=\chit@n@to@shape,
71 }
72 % \end{macrocode}
73 % \end{TikzKey}
74 %
75 % \begin{TikzKey}{/tikz/chit/full,
76 % /tikz/chit/symbol,
77 % /tikz/chit/left,
78 % /tikz/chit/right,
79 % /tikz/chit/upper left,
80 % /tikz/chit/upper right,
81 % /tikz/chit/lower left,
82 % /tikz/chit/lower right,
83 % /tikz/chit/factors,
84 % /tikz/chit/setup,
85 % /tikz/chit/id}
86 %
87 % Styles of each element in a chit. Users may override these at their
88 % own peril. That is, it is OK to override them, but the user should
89 % be careful.
90 %
91 % \begin{macrocode}
92 \def\chit@sym@sc@le{.4}
93 \tikzset{
94 chit/symbol/.style={scale=\chit@sym@sc@le,transform shape},
95 chit/parts/.style={shape=rectangle,transform shape},
96 chit/factors/.style={chit/parts,anchor=south},
97 chit/left/.style={chit/parts,anchor=base,rotate=90},%Anchor was south
98 chit/right/.style={chit/parts,anchor=north,rotate=90},
99 chit/upper left/.style={chit/parts,anchor=north west},
100 chit/upper right/.style={chit/parts,anchor=north east},
101 chit/lower left/.style={chit/parts,anchor=south west},
102 chit/lower right/.style={chit/parts,anchor=south east},
103 chit/setup/.style={chit/parts},
104 chit/full/.style={chit/parts},
105 chit/frame/.try={draw=pgfstrokecolor},
106 chit/bevel highlight/.style={fill=white,opacity=.25},
107 chit/bevel shadow/.style={fill=black,opacity=.25},
108 }
109 \def\chit@bevel@frac{10}
110 \newif\ifchit@draw@frame\chit@draw@frametrue
111 \tikzset{
112 chit/frame style/.search also={/tikz},
113 chit/frame style/.cd,
114 none/.code={\chit@draw@framefalse},
115 draw/.code={%
116 \chit@dbg{2}{Frame draw option `#1'}
117 \edef\tikz@temp{#1}%
118 \ifx\tikz@temp\tikz@nonetext%
119 \chit@draw@framefalse%
120 \else%
121 \chit@draw@frametrue%
122 \tikzset{/tikz/draw=#1}
123 \fi
124 }
125 }
126
127 % \end{macrocode}
128 % \end{TikzKey}
129 %
130 % \iffalse
131 % --------------------------------------------------------------------
132 % \fi
133 %
134 % \subsubsection{The \texttt{chit} styles}
135 %
136 % \begin{TikzKey}{/tikz/chit}
137 % This key sets up a node to make a chit. The key takes a single
138 % argument which in turn must contain key--value pairs in the
139 % \texttt{/chit} (or \texttt{/tikz}) namespace(s). We set the
140 % \texttt{shape} parameter of the node, and calls the passed keys in
141 % the \texttt{/chit} namespace to set-up elements of the chit.
142 %
143 % \begin{macrocode}
144 \tikzset{%
145 chit/.code={%
146 \chit@dbg{2}{chit arguments are `#1'}%
147 \pgfkeys{/tikz/transform shape,/tikz/shape=chit}%
148 \pgfkeys{/chit/.cd,nato shape=natoapp6c,#1}}}
149 % \end{macrocode}
150 % \end{TikzKey}
151 %
152 % We define a counter to set-up unique names for chit nodes.
153 %
154 % \begin{macrocode}
155 \newcounter{chit@id}\setcounter{chit@id}{0}
156 % \end{macrocode}
157 %
158 % \iffalse
159 % --------------------------------------------------------------------
160 % \fi
161 % \subsubsection{The \cs{chit} shape}
162 %
163 % \begin{Macro}{\chit@n@to,\@chit@n@to,\@@chit@n@to,\@chit@n@to@}
164 %
165 % These macros puts the NATO App6(c) symbol into a chit. The first
166 % macro takes the identifier and position of the symbol, and then
167 % scans for options. If no options are given, then we go directly
168 % to the rendering (\cs{@chit@n@to@}). Otherwise, we may also need
169 % to scan for an offset given as \parg{delta-x,delta-y}.
170 %
171 % \begin{macrocode}
172 \def\chit@n@to#1#2{%
173 %% Without a following start square bracket '[' by-pass to final
174 \chit@dbg{1}{Chit NATO App6(c) first step `#1' `#2'}
175 \@ifnextchar[{%
176 %\message{^^JStart square bracket}%
177 \@chit@n@to{#1}{#2}}{%
178 %\message{^^JNo start square bracket}%
179 \@chit@n@to@{#1}{#2}}%]]
180 }
181 % \end{macrocode}
182 %
183 % The following macro is called if we had no options.
184 %
185 % \begin{macrocode}
186 \def\chit@n@to@shape{natoapp6c}
187 \def\@chit@n@to@#1#2#3\@end@chit@n@to{%
188 \chit@dbg{1}{Chit NATO App6(c) w/o offset:
189 ^^J Options: `#3'
190 ^^J ID: `#1'
191 ^^J Position: `#2'
192 ^^J Style: `\chit@n@to@shape'
193 }
194 \chit@dbg{2}{NATO shape: `\chit@n@to@shape'}
195 \node[chit/symbol,\chit@n@to@shape={#3,id=#1}] (#1) at (#2) {};
196 \chit@dbg{4}{Chit NATO App6(c) ended}%
197 }
198 % \end{macrocode}
199 %
200 % This is called if we had an option-like argument. Check if we have
201 % an offset
202 %
203 % \begin{macrocode}
204 \def\@chit@n@to#1#2[#3]{%
205 \chit@dbg{1}{Chit NATO App6(c) second step `#1' `#2' `#3'}
206 \@ifnextchar({\@@chit@n@to{#1}{#2}{#3}}{\@@chit@n@to{#1}{#2}{#3}(0,0)}%)
207 }
208 % \end{macrocode}
209 %
210 % This called if we had option-like argument.
211 %
212 % \begin{macrocode}
213 \def\@@chit@n@to#1#2#3(#4)\@end@chit@n@to{%
214 \chit@dbg{1}{Chit NATO App6(c) w/offset:
215 ^^J Options: #3
216 ^^J ID: #1
217 ^^J Position: #2
218 ^^J Offset: #4}
219 \chit@dbg{10}{==== NATO shape: `\chit@n@to@shape' ====}
220 \node[chit/symbol,\chit@n@to@shape={#3,id=#1}] (#1) at ($(#2)+(#4)$) {};}
221 % \end{macrocode}
222 % \end{Macro}
223 %
224 % \begin{Macro}{\chit@tr@ns@nchor,\chit@nchor}
225 %
226 % Get anchor of sub-symbol element in chit. We need to do this,
227 % because the symbol is translated and scaled.
228 %
229 % \begin{macrocode}
230 \def\chit@tr@ns@nchor{%
231 \chit@dbg{10}{Translating anchor `\the\pgf@x',`\the\pgf@y'}
232 \wg@tmpa=\pgf@x%
233 \wg@tmpb=\pgf@y%
234 \symbol%
235 \chit@dbg{10}{Symbol origin `\the\pgf@x',`\the\pgf@y'}
236 \wg@tmpc=\pgf@x%
237 \wg@tmpd=\pgf@y%
238 \pgf@x=\chit@sym@sc@le\wg@tmpa%
239 \pgf@y=\chit@sym@sc@le\wg@tmpb%
240 \chit@dbg{10}{Scaled anchor `\the\pgf@x',`\the\pgf@y'}
241 \advance\pgf@x\wg@tmpc%
242 \advance\pgf@y\wg@tmpd%
243 \chit@dbg{10}{Offset anchor `\the\pgf@x',`\the\pgf@y'}
244 }
245 % \end{macrocode}
246 %
247 % \begin{macrocode}
248 \def\chit@nchor#1#2{%
249 \chit@dbg{10}{Get chit sub anchor of `#1' `#2'}%
250 \wg@sub@nchor{#1}{#2}%
251 \chit@tr@ns@nchor%
252 \chit@dbg{10}{Got chit sub anchor of `\the\pgf@x `\the\pgf@y}%
253 }
254 \def\chit@sym@nchor#1{%
255 \chit@dbg{10}{Get chit symbol `#1'}%
256 \edef\tmpid{\id symbol}%
257 \chit@nchor{\tmpid}{#1}}
258 \def\chit@report{}
259 \tikzset{
260 zone turn/.style={},
261 zone mult/.style={}
262 }
263 \def\chit@bkg@p@th{%
264 \northeast%
265 \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
266 \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
267 \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
268 \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
269 \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
270 \pgfclosepath%
271 }
272 % \end{macrocode}
273 % \end{Macro}
274 %
275 % Now follows the actual \text{chit} shape. This is rather long, so
276 % we will break it up a bit
277 % \begin{macrocode}
278 \def\chit@bevel@path#1{
279 \scope[#1]
280 \wg@tmpc=\wg@tmpa%
281 \wg@tmpd=\wg@tmpb%
282 %% Absolute values
283 \ifdim\wg@tmpa<0pt\multiply\wg@tmpc by -1\fi%
284 \ifdim\wg@tmpb<0pt\multiply\wg@tmpd by -1\fi%
285 % Why the hell do I need this?
286 \chit@dbg{10}{`\the\wg@tmpa' `\the\wg@tmpb'}%
287 %% Smallest dimension
288 \ifdim\wg@tmpc>\wg@tmpd \wg@tmpc=\wg@tmpd\fi%
289 \ifdim\wg@tmpc<\wg@tmpd \wg@tmpd=\wg@tmpc\fi%
290 %% Restore sign
291 \ifdim\wg@tmpa<0pt\multiply\wg@tmpc by -1\fi%
292 \ifdim\wg@tmpb<0pt\multiply\wg@tmpd by -1\fi%
293 %% Take the fraction
294 \multiply\wg@tmpc by \chit@bevel@frac%
295 \multiply\wg@tmpd by \chit@bevel@frac%
296 \divide\wg@tmpc100%
297 \divide\wg@tmpd100%
298 \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
299 % Move down along edge
300 \wg@tmpb=-\wg@tmpb%
301 \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
302 % Move left along edge
303 \wg@tmpa=-\wg@tmpa%
304 \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
305 % Move in and up
306 \advance\wg@tmpa\wg@tmpc%
307 \advance\wg@tmpb\wg@tmpd%
308 \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
309 % Move right, but in
310 \advance\wg@tmpa-\wg@tmpc\wg@tmpa=-\wg@tmpa%
311 \advance\wg@tmpa-\wg@tmpc%
312 \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
313 % Move up but down
314 \advance\wg@tmpb-\wg@tmpd\wg@tmpb=-\wg@tmpb%
315 \advance\wg@tmpb-\wg@tmpd%
316 \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
317 \pgfclosepath%
318 \pgfusepath{fill}%
319 \endscope%
320 }
321 % \end{macrocode}
322 %
323 % The first thing is we declare some saved anchors. These are
324 % computed (and defined as internal macros) when the shape is
325 % instantised. The anchors give the centre and north east corner of
326 % the node, the place to put the NATO App6(c) symbol and factors. We
327 % also set a dimension for the margins (corner and factors elements).
328 %
329 % \begin{macrocode}
330 \pgfdeclareshape{chit}{
331 \savedanchor\center{\pgf@x=0cm\pgf@y=0cm}
332 \savedanchor\northeast{\pgf@x=0.6cm\pgf@y=\pgf@x}
333 \savedanchor\symbol{\pgf@x=0cm\pgf@y=0.1cm}
334 \savedanchor\factors{\pgf@x=0cm\pgf@y=-0.5cm}
335 \saveddimen\margin{\pgf@x=0.04cm}
336 % \end{macrocode}
337 %
338 % Next, we define some saved macros. These are called (and declares
339 % internal macros) when the shape is instantised. We define macros
340 % for the identifier,
341 %
342 %
343 % \begin{macrocode}
344 \savedmacro\id{%
345 \chit@dbg{4}{Chit ID: \meaning\chit@id}%
346 \@ifundefined{chit@id}{\let\chit@id\pgfutil@empty}{}%
347 \ifx\chit@id\pgfutil@empty%
348 \wg@r@ndom@id%
349 \edef\id{chit\wg@uuid}%
350 \else%
351 \edef\id{\chit@id}%
352 \fi%
353 \chit@dbg{4}{Chit ID stored: \meaning\chit@id}
354 }
355 \savedmacro\chitframeopt{%
356 \let\chitframeopt\pgfutil@empty%
357 \@ifundefined{chit@frame}{}{%
358 \edef\chitframeopt{\chit@frame}}
359 \chit@dbg{3}{Chit Frame options: \meaning\chitframeopt}%
360 }
361 \savedmacro\thisname{\def\thisname{chit}}
362 % \end{macrocode}
363 %
364 % We define the regular anchors of the shape. That is, the centre,
365 % corners, and edges.
366 %
367 % \begin{macrocode}
368 \anchor{center}{\center}
369 \anchor{north east}{\northeast}
370 \anchor{north west}{\northeast\pgf@x=-\pgf@x}
371 \anchor{south west}{\northeast\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
372 \anchor{south east}{\northeast\pgf@y=-\pgf@y}
373 \anchor{north} {\northeast\pgf@x=0cm}
374 \anchor{south} {\northeast\pgf@x=0cm\pgf@y=-\pgf@y}
375 \anchor{east} {\northeast\pgf@y=0cm}
376 \anchor{west} {\northeast\pgf@x=-\pgf@x\pgf@y=0cm}
377 % \end{macrocode}
378 %
379 % Next, we want to be able to reference the symbol anchors too. So we
380 % define these anchors from the embedded node anchors. Note, these
381 % anchors will not exist if the chit is made with
382 % \texttt{full=}\meta{args}.
383 %
384 % \begin{macrocode}
385 \anchor{symbol north east}{\chit@sym@nchor{north east}}
386 \anchor{symbol north west}{\chit@sym@nchor{north west}}
387 \anchor{symbol south east}{\chit@sym@nchor{south east}}
388 \anchor{symbol south west}{\chit@sym@nchor{south west}}
389 \anchor{symbol north} {\chit@sym@nchor{north}}
390 \anchor{symbol west} {\chit@sym@nchor{west}}
391 \anchor{symbol south} {\chit@sym@nchor{south}}
392 \anchor{symbol east} {\chit@sym@nchor{east}}
393 \anchor{symbol upper} {\chit@sym@nchor{upper}}
394 \anchor{symbol lower} {\chit@sym@nchor{lower}}
395 \anchor{symbol left} {\chit@sym@nchor{left}}
396 \anchor{symbol right} {\chit@sym@nchor{right}}
397 \anchor{symbol echelon} {\chit@sym@nchor{echelon}}
398 \anchor{symbol below} {\chit@sym@nchor{below}}
399 % \end{macrocode}
400 %
401 % Some anchors to sub-elements. Some of them only exists if we have
402 % NATO App6(c) symbol in the chit.
403 %
404 % \begin{macrocode}
405 \anchor{symbol} {\symbol}
406 \anchor{factors} {\factors}
407 \anchor{left} {\chit@sym@nchor{west}\advance\pgf@x-\margin}
408 \anchor{right}{\chit@sym@nchor{east}\advance\pgf@x+\margin}
409 \anchor{upper right} {%
410 \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin%
411 }
412 \anchor{upper left}{
413 \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin \pgf@x=-\pgf@x%
414 }
415 \anchor{lower right} {%
416 \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin \pgf@y=-\pgf@y%
417 }
418 \anchor{lower left}{
419 \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin%
420 \pgf@x=-\pgf@x \pgf@y=-\pgf@y%
421 }
422 % \end{macrocode}
423 %
424 % Now for the actual path. For the background path, we simply specify
425 % the frame. This is so that this will get drawn (and possibly
426 % filled) using the appropriate options.
427 %
428 % \begin{macrocode}
429 \backgroundpath{%
430 %% This is the outline of the chit only. The rest of the chit is
431 %% made on the foreground "path".
432 \chit@dbg{1}{Chit drawing background path}
433 \chit@bkg@p@th%
434 % \northeast%
435 % \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
436 % \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
437 % \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
438 % \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
439 % \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
440 % \pgfclosepath
441 }
442 % \end{macrocode}
443 %
444 % Finally, we make the foreground rendered path. This is where we do
445 % the most stuff. We do it in the \emph{behind} foreground path so
446 % that we can ensure things are drawn the way we want it.
447 %
448 % The first thing is to set-up the clipping to the chit frame.
449 %
450 % \begin{macrocode}
451 \behindforegroundpath{%
452 \chit@dbg{1}{Chit drawing foreground path}
453 % \chit@dbg{4}{%
454 % Chit foreground: \meaning\id
455 % ^^J ID (set): \meaning\chit@id
456 % ^^J Symbol: \meaning\chit@symbol
457 % ^^J Full: \meaning\chit@full
458 % ^^J Factors: \meaning\chit@factors
459 % ^^J Left: \meaning\chit@left
460 % ^^J Right: \meaning\chit@right
461 % ^^J Upper left: \meaning\chit@upper@left
462 % ^^J Lower left: \meaning\chit@lower@left
463 % ^^J Upper right: \meaning\chit@upper@right
464 % ^^J Lower right: \meaning\chit@lower@right
465 % ^^J Extra: \meaning\chit@extra
466 % ^^J Bevel: \meaning\chit@bevel
467 % ^^J Frame: \meaning\chit@frame}
468 \chit@dbg{1}{Chit report}
469 \chit@report{}
470 \chit@dbg{1}{Chit start scope}
471 \pgfscope
472 %
473 \ifchit@clip%
474 \chit@dbg{1}{Chit clip path}
475 \chit@bkg@p@th%
476 % \northeast%
477 % \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
478 % \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
479 % \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
480 % \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
481 % \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
482 % \pgfclosepath%
483 \pgfusepath{clip}%
484 \fi%
485 % \end{macrocode}
486 %
487 % If we do not have the \texttt{symbol} key set, then we set the
488 % \texttt{full} key as a picture.
489 %
490 % \begin{macrocode}
491 \@ifundefined{chit@symbol}{%
492 %% Draw full stuff
493 \@ifundefined{chit@full}{}{%
494 \chit@dbg{1}{Chit draw full image: `\meaning\chit@full'}
495 \center\wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
496 \wg@pic@all{\chit@full}{}{\the\wg@tmpa,\the\wg@tmpb}{chit/full}}%
497 }{% With NATO symbol
498 % \end{macrocode}
499 %
500 % Otherwise, we put in a node with shape \texttt{natoapp6c} and pass
501 % the \texttt{symbol} key--value pairs as options.
502 %
503 % \begin{macrocode}
504 \chit@dbg{1}{Chit draw symbol image}
505 \edef\symid{\id symbol}%
506 \symbol%
507 \edef\args{{\symid}{\the\pgf@x,\the\pgf@y}\chit@symbol}%
508 \chit@dbg{6}{Arguments to chit NATO symbol: \meaning\args}%
509 \chit@dbg{1}{Chit draw nato image `\symid'}
510 \expandafter\chit@n@to\args\@end@chit@n@to%
511 \chit@dbg{6}{After making NATO symbol in chit}%
512 % \end{macrocode}
513 %
514 % Having made the NATO App6(c) symbol, which we gave the node name
515 % \meta{id}\texttt{symbol} where \meta{id} is the ID of this chit, we
516 % can make the rest of the chit elements. These are the left and
517 % right elements, which are set west and east of the symbol,
518 % respectively; the factors; and the four corner elements.
519 %
520 % If the respective elements have not been specified, we do not make
521 % them.
522 %
523 % First the left and right elements. Note that these uses the anchors
524 % of the embedded \texttt{natoapp6c} node for placement.
525 %
526 % \begin{macrocode}
527 % Put in left of symbol
528 \@ifundefined{chit@left}{}{%
529 \chit@dbg{2}{Chit draw left: `\meaning\chit@left'}
530 \wg@nchor{\thisname}{left}
531 \begin{scope}[]
532 \wg@pic@all{\chit@left}{}{\pgf@x,\pgf@y}{chit/left}%
533 \end{scope}}%
534 % Put in right of symbol
535 \@ifundefined{chit@right}{}{%
536 \chit@dbg{2}{Chit draw right: `\meaning\chit@right'}
537 \wg@nchor{\thisname}{right}
538 \begin{scope}[]
539 \wg@pic@all{\chit@right}{}{\pgf@x,\pgf@y}{chit/right}%
540 \end{scope}}%
541 % \end{macrocode}
542 %
543 % Next, we want to put in the corner elements. But before we do
544 % that, we use our saved anchors and dimensions to calculate the
545 % coordinates. Note that the corner elements are anchored to the
546 % corners (plus margin) of the chit frame.
547 %
548 % \begin{macrocode}
549 % Get coordinates
550 \northeast%
551 \wg@tmpa=\pgf@x%
552 \wg@tmpb=\pgf@y%
553 \advance\wg@tmpa-\margin%
554 \advance\wg@tmpb-\margin%
555 % \end{macrocode}
556 %
557 % With the coordinates extracted, we set the four corner
558 % elements. Note, for the anchoring to work, we should specify
559 % pictures that have anchors (e.g., nodes). If not, we must take care
560 % to give offsets or the like.
561 %
562 % \begin{macrocode}
563 % Put in upper left corner
564 \@ifundefined{chit@upper@left}{}{%
565 \chit@dbg{1}{Chit draw upper left: `\meaning\chit@upper@left'}%
566 \wg@nchor{\thisname}{upper left}
567 \begin{scope}[]
568 \wg@pic@all{\chit@upper@left}{}{\pgf@x,\pgf@y}{chit/upper left}%
569 \end{scope}}
570 % Put in upper right corner
571 \@ifundefined{chit@upper@right}{}{%
572 \chit@dbg{1}{Chit draw upper right: `\meaning\chit@upper@right'}
573 \wg@nchor{\thisname}{upper right}%
574 \begin{scope}[]
575 \wg@pic@all{\chit@upper@right}{}{\pgf@x,\pgf@y}{chit/upper right}%
576 \end{scope}}
577 % Put in lower left corner
578 \@ifundefined{chit@lower@left}{}{%
579 \chit@dbg{1}{Chit draw lower left: `\meaning\chit@lower@left'}
580 \wg@nchor{\thisname}{lower left}%
581 \begin{scope}[]
582 \wg@pic@all{\chit@lower@left}{}{\pgf@x,\pgf@y}{chit/lower left}%
583 \end{scope}}
584 % Put in lower right corner
585 \@ifundefined{chit@lower@right}{}{%
586 \chit@dbg{1}{Chit draw lower right: `\meaning\chit@lower@right'}
587 \wg@nchor{\thisname}{lower right}%
588 \begin{scope}[]
589 \wg@pic@all{\chit@lower@right}{}{\pgf@x,\pgf@y}{chit/lower right}%
590 \end{scope}}
591 % \end{macrocode}
592 %
593 % Finally, we put in the unit factors. They are put at the bottom of
594 % the chit frame (plus margin) and are typically anchored to the south
595 % anchor of the element. Note, we can put in several factors if need
596 % be.
597 %
598 % \begin{macrocode}
599 % Put in factors
600 \@ifundefined{chit@factors}{}{%
601 \chit@dbg{1}{Chit draw factors: `\meaning\chit@factors'}
602 \advance\wg@tmpb-\margin%
603 \begin{scope}[]
604 \wg@pic@all{\chit@factors}{}{0,-\the\wg@tmpb}{chit/factors}%
605 \end{scope}}%
606 % Put in extra
607 \@ifundefined{chit@extra}{}{%
608 \chit@dbg{1}{Chit draw extra: `\meaning\chit@extra'}
609 \begin{scope}[]
610 \wg@pic@all{\chit@extra}{}{0,0}{chit/factors}%
611 \end{scope}}%
612 }% End of full or symbol
613 \endpgfscope%
614 % Make bevel?
615 \@ifundefined{chit@bevel}{\let\chit@bevel\empty}{}
616 \ifx\chit@bevel\empty\else%
617 \chit@dbg{1}{Chit draw bevel}
618 %% South east bevel
619 \northeast%
620 \wg@tmpa=-\pgf@x\wg@tmpb=-\pgf@y%
621 \ifcase\chit@bevel\relax%
622 \or% 1
623 \or\wg@tmpa=-\wg@tmpa% 2
624 \or\wg@tmpb=-\wg@tmpb% 3
625 \or\wg@tmpa=-\wg@tmpa\wg@tmpb=-\wg@tmpb%4
626 \fi
627 \chit@bevel@path{chit/bevel highlight}
628 %% North west bevel
629 \northeast%
630 \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
631 \ifcase\chit@bevel\relax%
632 \or% 1
633 \or\wg@tmpa=-\wg@tmpa% 2
634 \or\wg@tmpb=-\wg@tmpb% 3
635 \or\wg@tmpa=-\wg@tmpa\wg@tmpb=-\wg@tmpb%4
636 \fi
637 \chit@bevel@path{chit/bevel shadow}
638 \fi
639 % Draw frame?
640 \chit@dbg{1}{Chit draw frame: `\meaning\chitframeopt'}
641 \edef\tmp@opt{[chit/frame style/.cd,chit/frame/.try,\chitframeopt]}
642 \chit@dbg{1}{Chit draw frame: `\meaning\tmp@opt}
643 \expandafter\scope\tmp@opt
644 \northeast%
645 \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y%
646 \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
647 \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
648 \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
649 \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}%
650 \pgfclosepath%
651 \chit@dbg{3}{Line width for frame: `\the\pgflinewidth'}
652 \ifchit@draw@frame\pgfusepath{stroke}\fi%
653 \chit@draw@frametrue%
654 %\iftikz@mode@fill\pgfusepath{fill}\fi%
655 \endscope%
656 \chit@dbg{1}{Chit end of shape}
657 }
658 }
659 % \end{macrocode}
660 %
661 % \iffalse
662 % --------------------------------------------------------------------
663 % \fi
664 % \subsubsection{The \cs{chit} wrapper macro}
665 %
666 % \begin{Macro}{\chit,\chit@,\chit@@}
667 %
668 % The macro to make the chits. This is a wrapper around a
669 % \texttt{node} with shape \texttt{chit}. The syntax of this macro
670 % is
671 %
672 % \begin{Syntax}
673 % \cs{chit}\oarg{chit options}\parg{position}\parg{identifier};
674 % \end{Syntax}
675 %
676 % Note that the trailing semi-colon is optional. Here \meta{chit
677 % options} are any key-value pairs in the \texttt{/chit} (and
678 % \texttt{/tikz}) namespace.
679 %
680 % The first macro parses for options.
681 %
682 % \begin{macrocode}
683 \def\chit{%
684 \chit@dbg{5}{Chit}
685 \@ifnextchar[{\chit@}{\chit@[]}%]
686 }
687 % \end{macrocode}
688 %
689 % Parse for coordinates.
690 %
691 % \begin{macrocode}
692 \def\chit@[#1]{%
693 \chit@dbg{5}{Chit second: `#1'}
694 \@ifnextchar({\chit@@{#1}}{\chit@@{#1}(0,0)}%)
695 }
696 % \end{macrocode}
697 %
698 % Parse for name.
699 %
700 % \begin{macrocode}
701 \def\chit@@#1(#2){%
702 \@ifnextchar({\chit@@@{#1}{#2}}{\chit@@@{#1}{#2}()}%)
703 }
704 % \end{macrocode}
705 %
706 % The work horse. This simply makes a \cs{node} with the shape
707 % \texttt{chit}. Note, we allow for a trailing semi-colon
708 % (\texttt{;}) to have a similar feel to other \TikZ{} macros.
709 %
710 % The macro will execute the style \texttt{/tikz/every chit} if
711 % defined. Note that this will be executed \emph{before} the usual
712 % \texttt{every chip node} style.
713 %
714 % \begin{macrocode}
715 \def\chit@@@#1#2(#3){%
716 \chit@dbg{5}{Chit final:
717 ^^J Options: #1
718 ^^J Position: #2
719 ^^J Name: `#3'}
720 \let\name\pgfutil@empty%
721 \chit@dbg{1}{=== Before chit node}%
722 \node[chit={/tikz/every chit/.try,id=#3,#1}] (tmp) at (#2) {};
723 \chit@dbg{2}{=== After chit node}%
724 \ifx|#3|\relax%
725 \else%
726 \chit@dbg{3}{=== Renaming chit to user defined name `#3'}%
727 \pgfnoderename{#3}{tmp}%
728 \fi%
729 \@ifnextchar;{\@gobble}{}%
730 }
731 % \end{macrocode}
732 % \end{Macro}
733 %
734 % \iffalse
735 % --------------------------------------------------------------------
736 % \fi
737 % \subsubsection{The Kriegspiel option for chits}
738 %
739 % This will select a Kriegspiel-like chit layout. That is, if we pass
740 % \texttt{kriegspiel} as a keyword to the \texttt{chit} style, then we
741 % will make a Kriegspiel-like chit (oblong, other symbols).
742 %
743 % \begin{macrocode}
744 \tikzset{
745 /chit/kriegspiel/.code={
746 \pgfkeys{%
747 /tikz/shape=kriegspiel,%
748 /chit/nato shape=kriegspiel symbol}
749 }
750 }
751 % \end{macrocode}
752 %
753 % Shape of a Kriegspiel like chit. This mainly inherits from the
754 % \texttt{chit} shape but overrides a number of anchors.
755 %
756 % \begin{macrocode}
757 \pgfdeclareshape{kriegspiel}{
758 \inheritsavedanchors[from=chit]
759 \savedanchor\northeast{\pgf@x=0.8cm\pgf@y=0.4cm}
760 \savedanchor\symbol{\pgf@x=0cm\pgf@y=0.15cm}
761 \savedanchor\factors{\pgf@x=.2cm\pgf@y=-.4cm}
762 \savedmacro\thisname{\def\thisname{kriegspiel}}
763 \saveddimen\margin{\pgf@x=0.03cm}
764 \inheritanchor[from=chit]{center}
765 \inheritanchor[from=chit]{north east}
766 \inheritanchor[from=chit]{north west}
767 \inheritanchor[from=chit]{south west}
768 \inheritanchor[from=chit]{south east}
769 \inheritanchor[from=chit]{north}
770 \inheritanchor[from=chit]{south}
771 \inheritanchor[from=chit]{east}
772 \inheritanchor[from=chit]{west}
773 \inheritanchor[from=chit]{symbol north east}
774 \inheritanchor[from=chit]{symbol north west}
775 \inheritanchor[from=chit]{symbol south east}
776 \inheritanchor[from=chit]{symbol south west}
777 \inheritanchor[from=chit]{symbol north}
778 \inheritanchor[from=chit]{symbol west}
779 \inheritanchor[from=chit]{symbol south}
780 \inheritanchor[from=chit]{symbol east}
781 \inheritanchor[from=chit]{symbol upper}
782 \inheritanchor[from=chit]{symbol lower}
783 \inheritanchor[from=chit]{symbol left}
784 \inheritanchor[from=chit]{symbol right}
785 \inheritanchor[from=chit]{symbol echelon}
786 \inheritanchor[from=chit]{symbol below}
787 \inheritanchor[from=chit]{symbol}
788 \inheritanchor[from=chit]{factors}
789 \inheritanchor[from=chit]{left}
790 \inheritanchor[from=chit]{right}
791 \inheritanchor[from=chit]{upper right}
792 \inheritanchor[from=chit]{upper left}
793 \inheritanchor[from=chit]{lower right}
794 \inheritanchor[from=chit]{lower left}
795 % \anchor{upper right} {%
796 % \northeast%
797 % \advance\pgf@x-\margin%
798 % \advance\pgf@y-\margin%
799 % \pgf@y=-\pgf@y%
800 % \advance\pgf@y5pt%
801 % }
802 % \anchor{upper left}{
803 % \northeast%
804 % \advance\pgf@x-\margin%
805 % \advance\pgf@y-\margin%
806 % \pgf@x=-\pgf@x%
807 % \pgf@y=-\pgf@y%
808 % \advance\pgf@y5pt%
809 % }
810 %%
811 \inheritbackgroundpath[from=chit]
812 \inheritbehindforegroundpath[from=chit]
813 }
814 % \end{macrocode}
815 %
816 % \begin{macrocode}
817 % \end{macrocode}
818 %
819 % \iffalse
820 % </chit>
821 % --------------------------------------------------------------------
822 % \fi