Debian Codegraph @

texmf-dist/source/latex/flowchart/flowchart.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Flowchart 3.3
4 % 19 March 2015
5 %
6 % flowchart.dtx
7 %
8 % Documented LaTeX file for the flowchart package.
9 %
10 % Run LaTeX on flowchart.ini to make the package's
11 % flowchart.sty file.
12 %
13 % Run LaTeX on this file to produce the package
14 % documentation.
15 %
16 % The flowchart package is an outcome of the Fluxion
17 % project.
18 %
19 % Copyright (C) 2015 by Adrian P Robson
20 % [email protected]
21 %
22 % This work may be distributed and/or modified under the
23 % conditions of the LaTeX Project Public License, either
24 % version 1.3c of this license or (at your option) any later
25 % version. The latest version of this license is in
26 % http://www.latex-project.org/lppl.txt
27 %
28 % This work has the LPPL maintenance status `maintained'.
29 %
30 % The Current Maintainer of this work is Adrian Robson.
31 %
32 % This work consists of the files flowchart.dtx and
33 % flowchart.ins
34 % and the derived files flowchart.sty and
35 % flowchart.pdf
36 % -----------------------------------------------------------
37 % \fi
38 %
39 % \iffalse
40 %<package>\NeedsTeXFormat{LaTeX2e}[2011/06/27]
41 %<package>\ProvidesPackage{flowchart}
42 %<package>[2015/03/19 3.3 Flowchart shapes for TikZ]
43 %<*driver>
44 \documentclass[10pt,a4paper]{ltxdoc}
45
46 \usepackage{flowchart}
47 \usetikzlibrary{arrows}
48
49 \usepackage[T1]{fontenc}
50 \usepackage{lmodern}
51 \usepackage{textcomp}
52
53 \usepackage{fancyvrb}
54 \usepackage{enumitem}
55 \usepackage{url}
56 \usepackage{array}
57
58 \EnableCrossrefs
59 \CodelineIndex
60 \RecordChanges
61 %\OnlyDescription % comment out for code implementation
62
63 \newcommand{\mnote}[1]
64 {\marginpar{\scriptsize \raggedright #1 }}
65
66 \def\tikzname{Ti\emph{k}Z}
67
68 \begin{document}
69 \DocInput{flowchart.dtx}
70 \end{document}
71 %</driver>
72 % \fi
73 %
74 %^^A-------------------------------------------------------------------
75 %^^A Change log...
76 %^^A-------------------------------------------------------------------
77 %^^A
78 %^^A 27 January 2013
79 %^^A Original
80 % \changes{v3.1}{2014/01/27}{
81 % Installation has been converted to dtx format,
82 % and the {\tt flowchart.sty} is generated by the
83 % {\tt flowchart.ins} file.
84 % It replaces version 2.4 of the package, and
85 % uses version 2.1 of the makeshape package.
86 % }
87 %^^A
88 %^^A 28 January 2013
89 %^^A Original
90 % \changes{v3.2}{2014/01/28}{
91 % The decision shape has been improved. }
92 %^^A
93 %^^A 19 March 2015
94 %^^A Original
95 % \changes{v3.3}{2015/03/19}{
96 % An error in the documentation's sample code has been corrected.
97 % }
98 %^^A
99 %^^A-------------------------------------------------------------------
100 %
101 % \CheckSum{0} ^^A no checksum for development
102 %^^A \CheckSum{59}
103 % \CharacterTable
104 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
105 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
106 % Digits \0\1\2\3\4\5\6\7\8\9
107 % Exclamation \! Double quote \" Hash (number) \#
108 % Dollar \$ Percent \% Ampersand \&
109 % Acute accent \' Left paren \( Right paren \)
110 % Asterisk \* Plus \+ Comma \,
111 % Minus \- Point \. Solidus \/
112 % Colon \: Semicolon \; Less than \<
113 % Equals \= Greater than \> Question mark \?
114 % Commercial at \@ Left bracket \[ Backslash \\
115 % Right bracket \] Circumflex \^ Underscore \_
116 % Grave accent \` Left brace \{ Vertical bar \|
117 % Right brace \} Tilde \~}
118 %
119 % \GetFileInfo{flowchart.sty}
120 %
121 % \title{The {\tt flowchart} package\thanks{
122 % This document corresponds to \textsf{flowchart}~\fileversion,
123 % dated~\filedate.}\\[0.5ex]
124 % Flowchart Shapes for \tikzname}
125 %
126 % \author{Adrian P. Robson\thanks{\texttt{[email protected]}}}
127 % \date{19 March 2015}
128 %
129 % \maketitle
130 %
131 %^^A \tableofcontents
132 %
133 %^^A-------------------------------------------------------------------
134 %^^A Start report body
135 %^^A-------------------------------------------------------------------
136 %
137 % \section{Introduction}
138 %
139 % This package provides shapes for drawing program flowcharts.
140 % They are based on the classic \emph{IBM Flowcharting Template},
141 % which conforms to ISO~1028:1973, with some IBM extensions.
142 % (this has since been revised by ISO 5807:1985).
143 %
144 % At the moment, there is only a limited selection of the standard symbols,
145 % but other symbols might be added in the future.
146 %
147 % This package requires that |makeshape| \cite{makeshape} and of course
148 % PGF/\tikzname{} \cite{pgfMan} are also installed .
149 %
150 % \section{The Symbols}\label{symbols}
151 %
152 % The package provides the following symbols as defined in the ISO standard:
153 %
154 % \def\colA{3.2cm}
155 % \def\colB{8cm}
156 %
157 % \def\swide{2.8cm}
158 % \def\pht{1.3cm}
159 % \def\dht{1.8cm}
160 % \def\ppht{\pht}
161 % \def\sht{\pht}
162 % \def\tht{0.75cm}
163 %
164 %^^A - process symbol
165 % \vspace{3mm}
166 % \noindent
167 % \begin{tabular}{m{\colA} m{\colB}}
168 % \begin{tikzpicture}[>=latex',font={\sf \small}]
169 % \node (process1) at (0,0) [draw, process,
170 % minimum width=\swide,
171 % minimum height=\pht] {PROCESS}; %PROCESS
172 % \end{tikzpicture}
173 % &
174 % {\bf Process} -- Any processing function; or defined operations causing change in value,
175 % form or location of information.\\
176 % \end{tabular}
177 %
178 %^^A - decision symbol
179 % \vspace{3mm}
180 % \noindent
181 % \begin{tabular}{m{\colA} m{\colB}}
182 % \begin{tikzpicture}[>=latex',font={\sf \small}]
183 % \node at (0,0) [draw, decision, %aspect=1.5,
184 % minimum width=\swide,
185 % minimum height=\dht] {DECISION};
186 % \end{tikzpicture}
187 % &
188 % {\bf Decision} -- A decision or switching-type operation that determines
189 % which of a number of alternative paths are followed.\\
190 % \end{tabular}
191 %
192 %^^A - predefined process symbol
193 % \vspace{5mm}
194 % \noindent
195 % \begin{tabular}{m{\colA} m{\colB}}
196 % \begin{tikzpicture}[>=latex',font={\sf \small}]
197 % \node at (0,0) [draw, predproc, align=left,
198 % minimum width=\swide,
199 % minimum height=\ppht] {Predefined\\
200 % Process};
201 % \end{tikzpicture}
202 % &
203 % {\bf Predefined Process} -- One or more named operations or program steps specified
204 % in a subroutine or another set of flowcharts.\\
205 % \end{tabular}
206 %
207 %^^A - storage symbol
208 % \vspace{5mm}
209 % \noindent
210 % \begin{tabular}{m{\colA} m{\colB}}
211 % \hspace*{-1.85mm}
212 % \begin{tikzpicture}[>=latex',font={\sf \small}]
213 % \node at (0,0) [draw, storage,
214 % minimum width=\swide,
215 % minimum height=\sht] {STORAGE};
216 % \end{tikzpicture}
217 % &
218 % {\bf Storage} -- Input or output using any kind of online storage.\\
219 %
220 % \end{tabular}
221 %
222 %^^A - terminal symbol
223 % \vspace{4mm}
224 % \noindent
225 % \begin{tabular}{m{\colA} m{\colB}}
226 % \begin{tikzpicture}[>=latex',font={\sf \small}]
227 % \node at (0,0) [ draw, terminal,
228 % minimum width=\swide,
229 % minimum height=\tht] {TERMINAL};
230 % \end{tikzpicture}
231 % &
232 % {\bf Terminal} -- A terminal point in a flowchart: start, stop, halt delay or interrupt.
233 % It may show exit from a closed subroutine.\\
234 % \end{tabular}
235 %
236 % \section{Usage}
237 %
238 % The example below uses all of the symbols given in \S\ref{symbols},
239 % and shows how they can be laid out and connected with \tikzname:
240 %
241 % \begin{center}
242 % \begin{tikzpicture}[>=latex',font={\sf \small}]
243 %
244 % \def\smbwd{2cm}
245 %
246 % \node (terminal1) at (0,0) [draw, terminal,
247 % minimum width=\smbwd,
248 % minimum height=0.5cm] {START};
249 %
250 % \node (predproc1) at (0,-1.5) [draw, predproc, align=left,
251 % minimum width=\smbwd,
252 % minimum height=1cm] {GET\\ DATA};
253 %
254 % \node (decide1) at (0,-3.5) [draw, decision,
255 % minimum width=\smbwd,
256 % minimum height=1cm] {C$<$3};
257 %
258 % \node (storage1) at (0,-5.5) [draw, storage,
259 % minimum width=\smbwd,
260 % minimum height=1cm] {STORE};
261 %
262 % \node (process1) at (3,-5.5) [draw, process,
263 % minimum width=\smbwd,
264 % minimum height=1cm] {PROCESS};
265 %
266 % \coordinate (point1) at (0,-6.75);
267 %
268 % \node (terminal2) at (0,-7.75) [draw, terminal,
269 % minimum width=\smbwd,
270 % minimum height=0.5cm] {END};
271 %
272 % \draw[->] (terminal1) -- (predproc1);
273 % \draw[->] (predproc1) -- (decide1);
274 % \draw[->] (decide1) -| node[above]{YES} (process1);
275 % \draw[->] (decide1) -- (storage1);
276 % \draw[->] (process1) |- (point1);
277 % \draw[->] (storage1) -- (point1) -- (terminal2);
278 %
279 % \end{tikzpicture}
280 % \end{center}
281 %
282 % It needs the following in the document's preamble:
283 %
284 % \begin{VerbatimOut}[gobble=5]{\jobname.tmp}
285 % \usepackage{flowchart}
286 % \usetikzlibrary{arrows}
287 % \end{VerbatimOut}
288 % \VerbatimInput[]{\jobname.tmp}
289 %
290 % \noindent
291 % The \tikzname{} package is included in |flowchart|, so it does not have to be explicitly loaded.
292 % However, any |\usetikzlibrary| commands that are needed must be placed after
293 % |\loadpackage{flowchart}|.
294 %
295 % The flowchart above is produced by the following |tikzpicture| environment:
296 %
297 % \begin{VerbatimOut}[gobble=1]{\jobname.tmp}
298 % \begin{tikzpicture}[>=latex',font={\sf \small}]
299 %
300 % \def\smbwd{2cm}
301 %
302 % \node (terminal1) at (0,0) [draw, terminal,
303 % minimum width=\smbwd,
304 % minimum height=0.5cm] {START};
305 %
306 % \node (predproc1) at (0,-1.5) [draw, predproc, align=left,
307 % minimum width=\smbwd,
308 % minimum height=1cm] {GET\\ DATA};
309 %
310 % \node (decide1) at (0,-3.5) [draw, decision,
311 % minimum width=\smbwd,
312 % minimum height=1cm] {C$<$3};
313 %
314 % \node (storage1) at (0,-5.5) [draw, storage,
315 % minimum width=\smbwd,
316 % minimum height=1cm] {STORE};
317 %
318 % \node (process1) at (3,-5.5) [draw, process,
319 % minimum width=\smbwd,
320 % minimum height=1cm] {PROCESS};
321 %
322 % \coordinate (point1) at (0,-6.75);
323 %
324 % \node (terminal2) at (0,-7.75) [draw, terminal,
325 % minimum width=\smbwd,
326 % minimum height=0.5cm] {END};
327 %
328 % \draw[->] (terminal1) -- (predproc1);
329 % \draw[->] (predproc1) -- (decide1);
330 % \draw[->] (decide1) -| node[above]{YES} (process1);
331 % \draw[->] (decide1) -- (storage1);
332 % \draw[->] (process1) |- (point1);
333 % \draw[->] (storage1) -- (point1) -- (terminal2);
334 %
335 % \end{tikzpicture}
336 % \end{VerbatimOut}
337 % \VerbatimInput[numbers=left]{\jobname.tmp}
338 %
339 % \subsection{Symbols}
340 %
341 % The flow chart symbols are created as nodes, as shown in lines 5-7,
342 % which defines a |terminal| shape.
343 % The minimum dimension keys should be used to create consistently sized symbols.
344 % In particular, a defined value should be used for the width in all symbols.
345 % So |\smbwd| is defined on line 3, and used in lines 6, 10, 14, 18, 22, and 28.
346 %
347 % \subsection{Layout}
348 %
349 % In this example, we have used absolute coordinates to position the diagram's nodes.
350 % This works well for small flowcharts, but relative positioning might be better for larger diagrams.
351 %
352 % \subsection{Connectors}
353 %
354 % The shapes are connected by drawing lines between them as shown in lines 31-36 of the example.
355 % Here, unqualified node names are used,
356 % but explicit anchor names such as |(nodename.north east)| could be used instead.
357 %
358 % It can sometimes be convenient to place a connector at an arbitrary point on a shape.
359 % The |(nodename.45)| notation achieves this, where the number gives the angle from the centre of the
360 % shape to the connecting point on its boundary.
361 %
362 % Right angled connections are traditionally used in flowcharts, and these are created with
363 % the \verb+-|+ and \verb+|-+ notations shown in lines 33 and 35 of the example.
364 %
365 % Joining connectors is best done by declaring a named coordinate, and using it as the meeting point.
366 % In the example, a coordinate called |point1| is declared on line 25,
367 % and then used in line 35 and 36 % to connect |process1| and |storage1| to |terminal2|.
368 %
369 %^^A-------------------------------------------------------------------
370 %^^A References
371 %^^A-------------------------------------------------------------------
372 %
373 % \def\mybib{
374 % \begin{thebibliography}{9}
375 % \raggedright
376 % \bibitem{makeshape}
377 % Adrian P. Robson,
378 % \emph{The makeshape package
379 % and a method for creating custom shapes in PGF}, 2013.
380 % Available as {\tt makeshape.pdf} from \url{ctan.org}.
381 % \bibitem{pgfMan}
382 % Till Tantau,
383 % \emph{The TikZ and PGF Packages, Manual for version 2.10},
384 % 2010.
385 % Available as {\tt pgfmanual.pdf} from \url{ctan.org}.
386 % \end{thebibliography}
387 % }
388 %
389 %^^A-------------------------------------------------------------------
390 %^^A Start code implementation
391 %^^A-------------------------------------------------------------------
392 %
393 % \StopEventually{\mybib}
394 %^^A \StopEventually{\mybib \PrintChanges}
395 %^^A -> Run pdfLaTeX flowchart.dtx
396 %^^A makeindex -s gglo.ist -o flowchart.gls flowchart.glo
397 %^^A pdfLaTeX flowchart.dtx
398 %
399 % \section{Implementation}
400 %
401 % The implementation of |flowchart.sty| uses the |makeshape| package,
402 % which provides support for custom PGF shapes.
403 % With this, we have only have to create boundary and anchor path macros,
404 % and anchor points for each shape.
405 %
406 % There are three pairs of keys that have to be accommodated by PGF shapes:
407 % inner and outer separation, and minimum dimensions.
408 % The |makeshape| package has corrected text box macros |\ctbnex| and |\ctbney|,
409 % which automatically handle inner separation;
410 % and the PGF keys |\pgfshapeouterxsep|, |\pgfshapeouterysep|, |\pgfshapeminheight| and
411 % |\pgfshapeminwidth|, which give the outer separation and minimum dimensions of the shape.
412 %
413 % \subsection{Preamble}
414 % The |makeshape| package provides the |tikz| package. However, the |shapes| library is also needed:
415 %
416 % \begin{macrocode}
417 \RequirePackage{makeshape}
418 \RequirePackage{tikz}
419 \usetikzlibrary{shapes}
420 % \end{macrocode}
421 %
422 %^^A ************************************************************
423 %^^A * Predefined Process shape starts
424 %^^A ************************************************************
425 % \subsection{Predproc Shape}
426 %
427 % This is the Predefined Process symbol.
428 %
429 % \subsubsection{Anchor and background paths}\label{predprocpaths}
430 %
431 %
432 % These macros define the paths that are used by the |makeshape| |setpaths| command in
433 % the shape's |\pgfdeclareshape| macro, which is described in \S\ref{predprocShape}.
434 %
435 % \begin{macro}{\band}
436 % The shape's side band size is an internal constant:
437 % \begin{macrocode}
438 \def\band{10pt}
439 % \end{macrocode}
440 % \end{macro}
441 %
442 % \begin{macro}{\predprocAnchorpath}
443 % The |\predprocAnchorpath| macro defines the shape's \emph{anchor path}.
444 % It `draws' the path on which the shape's calculated anchor points lay.
445 % It is very similar to first part of |\predproc@shape| that draws the outer path,
446 % but it corrects for outer separation and does not draw any side bands.
447 % \begin{macrocode}
448 \def\predprocAnchorpath{
449 % \end{macrocode}
450 %
451 % First, get the corrected text box's NE corner using |\ctbnex| and |\ctbney|,
452 % then make room for the side band.
453 % \begin{macrocode}
454 \pgf@xa=\ctbnex
455 \pgf@ya=\ctbney
456 \advance\pgf@xa by \band
457 % \end{macrocode}
458 % Correct for minimum dimensions and outer separation:
459 % \begin{macrocode}
460 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
461 \advance\pgf@xa\pgfshapeouterxsep
462 \mincorrect{\pgf@ya}{\pgfshapeminheight}
463 \advance\pgf@ya\pgfshapeouterysep
464 % \end{macrocode}
465 %
466 % Finally, draw the anchor path, which is a rectangle,
467 % using the values in |\pgf@xa| and |\pgf@ya| that were calculated above:
468 % \begin{macrocode}
469 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
470 \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
471 \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
472 \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
473 \pgfpathclose
474 }
475 % \end{macrocode}
476 % \end{macro}
477 %
478 % \begin{macro}{\predprocBackground}
479 % The |\predprocBackground| macro draws the shape's path, including its side band.
480 % It is used in the shape's |\backgroundpath| macro.
481 % \begin{macrocode}
482 \def\predprocBackground{
483 % \end{macrocode}
484 %
485 % First, get the corrected text box's NE corner using |\ctbnex| and |\ctbney|,
486 % then make room for the side band.
487 % \begin{macrocode}
488 \pgf@xa=\ctbnex
489 \pgf@ya=\ctbney
490 \advance\pgf@xa by \band
491 % \end{macrocode}
492 % Correct for minimum dimensions but \emph{do not add} outer separation:
493 % \begin{macrocode}
494 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
495 \mincorrect{\pgf@ya}{\pgfshapeminheight}
496 % \end{macrocode}
497 %
498 % Finally, draw the outer shape, which is a rectangle,
499 % using the values in |\pgf@xa| and |\pgf@ya| that were calculated above:
500 % \begin{macrocode}
501 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
502 \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
503 \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
504 \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
505 \pgfpathclose
506 % \end{macrocode}
507 %
508 % Finally, we draw the inner shape, which completes the shape with its side bands.
509 % The x-coordinate is aligned on the right side band position, then the side bands are drawn:
510 % \begin{macrocode}
511 \advance\pgf@xa by -\band
512 \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
513 \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
514 \pgfpathmoveto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
515 \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
516 }
517 % \end{macrocode}
518 % \end{macro}
519 %
520 %
521 % \subsubsection{Predproc shape declaration}\label{predprocShape}
522 %
523 % \begin{macro}{\pgfdeclareshape}
524 % \begin{macro}{predproc}
525 % This is the |\pgfdeclareshape| declaration for the |predproc| shape.
526 % \begin{macrocode}
527 \pgfdeclareshape{predproc}{
528 % \end{macrocode}
529 % The path macros defined in \S\ref{predprocpaths} are used as follows
530 % with the |setpaths| command provided by the |makeshape| package to draw the
531 % shape and make boundary intersection calculations.
532 % \begin{macrocode}
533 \setpaths{\predprocAnchorpath}{\predprocBackground}
534 % \end{macrocode}
535 %
536 % \begin{macro}{\savedanchor}
537 % \begin{macro}{\northeast}
538 % The |\northeast| saved anchor is used to define the position of the NE corner of the shape.
539 % The calculation is similar that used in the anchor path described in \S\ref{predprocpaths},
540 % and corrects for inner and outer separation, and minimum dimensions.
541 % It returns the coordinates of the point in |\pgf@x| and |\pgf@y|.
542 % \begin{macrocode}
543 \savedanchor{\northeast}{
544 \pgf@x = \ctbnex
545 \advance\pgf@x by \band
546 \mincorrect{\pgf@x}{\pgfshapeminwidth}
547 \advance\pgf@x\pgfshapeouterxsep
548 \pgf@y = \ctbney
549 \mincorrect{\pgf@y}{\pgfshapeminheight}
550 \advance\pgf@y\pgfshapeouterysep
551 }
552 % \end{macrocode}
553 % \end{macro}
554 % \end{macro}
555 %
556 % \begin{macro}{\anchor}
557 % \begin{macro}{north}
558 % \begin{macro}{north east}
559 % \begin{macro}{east}
560 % \begin{macro}{south east}
561 % \begin{macro}{south}
562 % \begin{macro}{south west}
563 % \begin{macro}{west}
564 % \begin{macro}{north west}
565 % There are some standard anchors, which
566 % are all based on the |\northeast| saved anchor:
567 % \begin{macrocode}
568 \anchor{north}{ \northeast \pgf@x=0pt }
569 \anchor{north east}{ \northeast }
570 \anchor{east}{ \northeast \pgf@y=0pt }
571 \anchor{south east}{ \northeast \pgf@y=-\pgf@y }
572 \anchor{south}{ \northeast \pgf@x=0pt \pgf@y=-\pgf@y }
573 \anchor{south west}{ \northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
574 \anchor{west}{ \northeast \pgf@x=-\pgf@x \pgf@y=0pt }
575 \anchor{north west}{ \northeast \pgf@x=-\pgf@x }
576 % \end{macrocode}
577 % \end{macro}
578 % \end{macro}
579 % \end{macro}
580 % \end{macro}
581 % \end{macro}
582 % \end{macro}
583 % \end{macro}
584 % \end{macro}
585 % \end{macro}
586 % \begin{macrocode}
587 }
588 % \end{macrocode}
589 % \end{macro} ^^A end predproc
590 % \end{macro} ^^A end \pgfdeclareshape
591 %
592 %^^A ************************************************************
593 %^^A * Predefined Process shape ends
594 %^^A ************************************************************
595 %
596 %^^A ************************************************************
597 %^^A * Storage shape starts
598 %^^A ************************************************************
599 % \subsection{Storage Shape}
600 %
601 % \subsubsection{Support Macros}
602 %
603 % \begin{macro}{\storagepath}
604 % The |storage| shape's background path is defined in |\storagepath|.
605 % It requires the following register to be set:
606 %
607 % \begin{tabular}{ll}
608 % |\pgf@x| & x coordinate of NE corner excluding outer separation\\
609 % |\pgf@y| & y coordinate of NE corner excluding outer separation\\
610 % |\pgf@xc| & arc offset for y coordinate
611 % \end{tabular}
612 %
613 %\medskip
614 % The NE corner is stored in |\pgf@xa| and |\pgf@ya| and
615 % and the SW corner is put in |\pgf@xb| and |\pgf@yb|.
616 % The SW x-coordinate has to be moved right by the arc offset to compensate for the
617 % curve of the shapes west side.
618 % \begin{macrocode}
619 \def\storagepath{
620 \pgf@xa=\pgf@x \pgf@ya=\pgf@y
621 \pgf@xb=-\pgf@xa \pgf@yb=-\pgf@ya
622 \advance\pgf@xb by \pgf@xc
623 % \end{macrocode}
624 % The shape is drawn from its SW corner moving counter clockwise.
625 % The radius for the arcs is the height.
626 % \begin{macrocode}
627 \pgfpathmoveto{\pgfpoint{\pgf@xb}{\pgf@yb}}
628 \pgfpatharc{210}{150}{2*\pgf@ya}
629 \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
630 \pgfpatharc{150}{210}{2*\pgf@ya}
631 \pgfpathclose
632 }
633 % \end{macrocode}
634 % \end{macro}
635 %
636 % \begin{macro}{\arcoffset}
637 % The |storage| shape's arc offset is calculated by the |\arcoffset| macro.
638 % The required arc offset is $b$, and the shape's height is $h$ in the diagram below.
639 % \medskip
640 %
641 % \begin{tabular}{cc}
642 % \begin{tikzpicture}
643 % \def\sht{4cm}
644 % \def\oset{0.536cm}
645 % \def\a{\sht+\oset}
646 % \draw[] (0,0) -- (-\sht,0);
647 % \draw[] (-\sht,0) arc (0:40:-\sht);
648 % \draw[] (-\sht,0) arc (180:140:\sht);
649 % \draw[] (-\a,-\sht*0.5) -- (-\a,\sht*0.5);
650 % \draw[] (-\a,\sht*0.5) -- (0,0);
651 % \draw[] (-\a,\sht*0.5) -- ++(-1,0);
652 % \draw[] (-\a,-\sht*0.5) -- ++(-1,0);
653 % \node at (-2cm,1.5cm) [] {$h$};
654 % \node at (-3.1cm,0.7cm) [] {$h/2$};
655 % \node at (-2cm,-0.2cm) [] {$a$};
656 % \node at (-3.7cm,-0.2cm) [] {$b$};
657 % \end{tikzpicture}
658 % &
659 % \begin{minipage}[b]{6.5cm}
660 % \begin{eqnarray}
661 % h^2 &=& a^2 + \left(\frac{h}{2}\right)^2 \nonumber\\[3pt]
662 % a^2 &=& h^2 - \frac{h^2}{4} = \frac{3h^2}{4} \nonumber\\[2pt]
663 % a &=& h \sqrt{3/4}\\[2ex]
664 % b &=& h - a = h - h \sqrt{3/4} \nonumber\\[2pt]
665 % &=& h(1 - \sqrt{3/4}) \approx 0.134h \label{equoffset} \\\nonumber
666 % \end{eqnarray}
667 % \end{minipage}
668 % \end{tabular}
669 %
670 % \bigskip
671 % \noindent
672 % The macro's parameters are:
673 %
674 % \begin{tabular}{ll}
675 % |#1| & the calculated arc offset\\
676 % |#2| & half the height\\
677 % \end{tabular}
678 %
679 % \medskip\noindent
680 % Equation \ref{equoffset} given above is implemented as follows:
681 % \begin{macrocode}
682 \def\arcoffset#1#2{
683 \pgfmathsetlength#1{0.134*2*#2}
684 }
685 % \end{macrocode}
686 % \end{macro}
687 %
688 % \begin{macro}{\storageParams}
689 % The |\storageParams| macro calculates reference values for the shape
690 % with no outer separation.
691 % The following have values assigned after it is called:
692 %
693 % \begin{tabular}{ll}
694 % |\pgf@x| & x-coordinate of NE corner excluding outer separation\\
695 % |\pgf@y| & y-coordinate of NE corner excluding outer separation\\
696 % |\pgf@xc| & arc offset for y-coordinate
697 % \end{tabular}
698 %
699 % \medskip
700 % First get the shape's corrected text box:
701 % \begin{macrocode}
702 \def\storageParams{
703 \pgf@xa=\ctbnex
704 \pgf@ya=\ctbney
705 % \end{macrocode}
706 % Correct for minimum height but not for outer separation.
707 % \begin{macrocode}
708 \mincorrect{\pgf@ya}{\pgfshapeminheight}
709 % \end{macrocode}
710 % Calculate the room needed for the side arc, which is one of the macro's outputs,
711 % and use it to change the x-coordinate:
712 % \begin{macrocode}
713 \arcoffset{\pgf@xc}{\pgf@ya}
714 \advance\pgf@xa by \pgf@xc
715 % \end{macrocode}
716 % Finally, correct for minimum width and set the output registers:
717 % \begin{macrocode}
718 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
719 \pgf@x=\pgf@xa
720 \pgf@y=\pgf@ya
721 }
722 % \end{macrocode}
723 % \end{macro}
724 %
725 % \begin{macro}{\storageParamsOuter}
726 % The |\storageParamsOuter| macro calculates reference values for the shape
727 % with its outer separation included.
728 % The following have values assigned after it is called:
729 % \begin{tabular}{ll}
730 % |\pgf@x| & x coordinate of NE corner including outer separation\\
731 % |\pgf@y| & y coordinate of NE corner including outer separation\\
732 % |\pgf@xc| & arc offset for y coordinate
733 % \end{tabular}
734 %
735 % \medskip
736 % Its implementation has a lot in common with |\storageParams|.
737 % First, get the NE corner of the corrected text box:
738 % \begin{macrocode}
739 \def\storageParamsOuter{
740 \pgf@xa=\ctbnex
741 \pgf@ya=\ctbney
742 % \end{macrocode}
743 % Correct for minimum height and outer separation:
744 % \begin{macrocode}
745 \mincorrect{\pgf@ya}{\pgfshapeminheight}
746 \advance\pgf@ya\pgfshapeouterysep
747 % \end{macrocode}
748 % Calculate the arc offset, which is an output, and make room for the side curve:
749 % \begin{macrocode}
750 \arcoffset{\pgf@xc}{\pgf@ya}
751 \advance\pgf@xa by \pgf@xc
752 % \end{macrocode}
753 % Finally, correct for minimum width and outer separation. Then set the output registers:
754 % \begin{macrocode}
755 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
756 \advance\pgf@xa\pgfshapeouterxsep
757 \pgf@x=\pgf@xa
758 \pgf@y=\pgf@ya
759 }
760 % \end{macrocode}
761 % \end{macro}
762 %
763 % \subsubsection{Anchor and background paths}\label{storagepaths}
764 %
765 % The anchor and background path macros both use |\storagepath|, but with with different parameters.
766 % The output registers of the macros |\storageParams| and |\storageParamsOuter|
767 % are compatible with the inputs of |\storagepath|.
768 %
769 % \begin{macro}{\storageAnchorpath}
770 % The |\storageAnchorpath| macro defines the shape's \emph{anchor path}.
771 % It `draws' the path on which the shape's calculated anchor points lay.
772 % This is similar to the background path but it is corrected for outer separation
773 % and minimum dimensions.
774 % \begin{macrocode}
775 \def\storageAnchorpath{
776 \storageParamsOuter
777 \storagepath
778 }
779 % \end{macrocode}
780 % \end{macro}
781 %
782 % \begin{macro}{\storageBackground}
783 % The |\storageBackground| macro draws the path that is the outer boundary of the
784 % |storage| shape. This excludes outer separation but corrects for minimum height and width.
785 % \begin{macrocode}
786 \def\storageBackground{
787 \storageParams
788 \storagepath
789 }
790 % \end{macrocode}
791 % \end{macro}
792 %
793 % \subsubsection{Storage shape declaration}
794 %
795 % \begin{macro}{\pgfdeclareshape}
796 % \begin{macro}{storage}
797 % This is the |\pgfdeclareshape| declaration for the |storage| shape.
798 % \begin{macrocode}
799 \pgfdeclareshape{storage}{
800 % \end{macrocode}
801 % The path macros defined in \S\ref{storagepaths} are used
802 % with the |setpaths| command provided by the |makeshape| package to draw the
803 % shape and make boundary intersection calculations:
804 % \begin{macrocode}
805 \setpaths{\storageAnchorpath}{\storageBackground}
806 % \end{macrocode}
807 %
808 % \begin{macro}{\savedanchor}
809 % \begin{macro}{\northeast}
810 % There are two saved anchors defined for the |storage| shape.
811 % The |\northeast| saved anchor is used to define the position of the NE corner of the shape.
812 % The calculation is similar that used in the anchor path described in \S\ref{storagepaths},
813 % and corrects for inner and outer separation, and minimum dimensions.
814 % It returns the coordinates of the point in |\pgf@x| and |\pgf@y|,
815 % and its implementation is trivial since |\storageParamsOuter| does the required work.
816 % \begin{macrocode}
817 \savedanchor{\northeast}{
818 \storageParamsOuter
819 }
820 % \end{macrocode}
821 % \end{macro}
822 % \end{macro}
823 %
824 % \begin{macro}{\savedanchor}
825 % \begin{macro}{\northeast}
826 % The |\northeastArc| saved anchor is similar, but corrects for the arc offset.
827 %
828 % \begin{macrocode}
829 \savedanchor{\northeastArc}{
830 \storageParamsOuter
831 \advance\pgf@x by -\pgf@xc
832 }
833 % \end{macrocode}
834 % \end{macro}
835 % \end{macro}
836 %
837 % \begin{macro}{\anchor}
838 % \begin{macro}{north}
839 % \begin{macro}{north east}
840 % \begin{macro}{east}
841 % \begin{macro}{south east}
842 % \begin{macro}{south}
843 % \begin{macro}{south west}
844 % \begin{macro}{west}
845 % \begin{macro}{north west}
846 % The standard anchors are defined.
847 % These are based on the |\northeast| and |\northeastArc| saved anchors:
848 % \begin{macrocode}
849 \anchor{north}{ \northeast \pgf@x=0pt }
850 \anchor{north east}{ \northeast }
851 \anchor{east}{ \northeastArc \pgf@y=0pt }
852 \anchor{south east}{ \northeast \pgf@y=-\pgf@y }
853 \anchor{south}{ \northeast \pgf@x=0pt \pgf@y=-\pgf@y }
854 \anchor{south west}{ \northeastArc \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
855 \anchor{west}{ \northeast \pgf@x=-\pgf@x \pgf@y=0pt }
856 \anchor{north west}{ \northeastArc \pgf@x=-\pgf@x }
857 % \end{macrocode}
858 % \end{macro}
859 % \end{macro}
860 % \end{macro}
861 % \end{macro}
862 % \end{macro}
863 % \end{macro}
864 % \end{macro}
865 % \end{macro}
866 % \end{macro}
867 %
868 % \begin{macro}{\anchor}
869 % \begin{macro}{north}
870 % \begin{macro}{north east}
871 % \begin{macro}{east}
872 % Three additional anchors are defined that follow the shape's bounding rectangle.
873 % \begin{macrocode}
874 \anchor{east r}{ \northeast \pgf@y=0pt }
875 \anchor{north west r}{ \northeast \pgf@x=-\pgf@x }
876 \anchor{south west r}{ \northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
877 % \end{macrocode}
878 % \end{macro}
879 % \end{macro}
880 % \end{macro}
881 % \end{macro}
882 %
883 % \begin{macrocode}
884 }
885 % \end{macrocode}
886 % \end{macro} ^^A end storage
887 % \end{macro} ^^A end \pgfdeclareshape
888 %
889 %^^A ************************************************************
890 %^^A * Storage shape ends
891 %^^A ************************************************************
892 %
893 %^^A ************************************************************
894 %^^A * Process shape starts
895 %^^A ************************************************************
896 % \subsection{Process Shape}
897 %
898 % \begin{macro}{\pgfdeclareshape}
899 % \begin{macro}{process}
900 % The {\tt process} shape is simply implemented
901 % by inheriting relevant anchors and paths from the standard |rectangle| shape
902 % without any changes:
903 % \begin{macrocode}
904 \pgfdeclareshape{process}{
905 \inheritsavedanchors[from=rectangle]
906 \inheritanchor[from=rectangle]{center}
907 \inheritanchor[from=rectangle]{text}
908 \inheritanchor[from=rectangle]{north}
909 \inheritanchor[from=rectangle]{north east}
910 \inheritanchor[from=rectangle]{east}
911 \inheritanchor[from=rectangle]{south east}
912 \inheritanchor[from=rectangle]{south}
913 \inheritanchor[from=rectangle]{south west}
914 \inheritanchor[from=rectangle]{west}
915 \inheritanchor[from=rectangle]{north west}
916 \inheritbackgroundpath[from=rectangle]
917 \inheritanchorborder[from=rectangle]
918 }
919 % \end{macrocode}
920 % \end{macro}
921 % \end{macro}
922 %
923 %^^A ************************************************************
924 %^^A * Process shape ends
925 %^^A ************************************************************
926 %
927 %^^A ************************************************************
928 %^^A * Decision shape starts
929 %^^A ************************************************************
930 % \subsection{Decision Shape}
931 %
932 % \subsubsection{Support Macros}
933 %
934 % Two macros |\decisionref| and |\decisionrefout| give a reference point for the |decision| shape.
935 % The default shape is a rotated square which touches the corrected text box.
936 % The location and calculation of the default reference point is illustrated below:
937 %
938 % \begin{center}
939 % \begin{tikzpicture}
940 %
941 % ^^A - Axis
942 % \draw [dotted] (0,0) -- +(3cm,0) -- +(-3cm,0) +(0,3cm) -- +(0,-1cm);
943 %
944 % ^^A - draw line
945 % \draw [] (0,2.5cm) -- (2.5cm,0);
946 %
947 % ^^A East point
948 % \node at (3.4cm,-0.3cm) [] {$(0,x_t + y_t)$};
949 % \draw [] (2.5cm,0) circle (2pt);
950 %
951 % ^^A North point
952 % \node at (-1cm,2.5cm) [] {$(y_t + x_t,0)$};
953 % \draw [] (0,2.5cm) circle (2pt);
954 % \node at (-0.6cm,1.8cm) [outer sep=-2pt] (angletxt) {$45^\circ$};
955 % \node at (0.15cm,2.1cm) [coordinate] (anglepnt) {};
956 % \draw [->] (angletxt) -- (anglepnt);
957 %
958 % ^^A Reference point
959 % \draw [dotted] (0,2.5cm) -- +(3,0);
960 % \draw [dotted] (2.5cm,0) -- +(0,3);
961 % \node at (3.7cm,2.7cm) [] {\sf \small reference point};
962 % \node at (3.9cm,2.2cm) [] {$(y_t+x_t,x_t+y_t)$};
963 % \draw (2.5cm,2.5cm) circle (2pt);
964 % \draw (2.5cm,2.5cm) -- +(4pt,0) -- +(-4pt,0) +(0,4pt) -- +(0,-4pt);
965 %
966 % ^^A - Corrected text box
967 % \node at (-1.5cm,0.7cm) [] {\sf \small corrected text box};
968 % \node at (2.5cm,0.7cm) [rectangle,draw,fill,white,minimum height=12pt] {};
969 % \node at (2.6cm,0.7cm) [] {$(x_t,y_t)$};
970 % \draw [] (2cm,0.5cm) circle (2pt);
971 % \node at (0,0)
972 % [rectangle, draw,
973 % minimum width=4cm,
974 % minimum height=1cm,
975 % ] (ctb) {};
976 %
977 % \end{tikzpicture}
978 % \end{center}
979 % \vspace{-2ex}
980 %
981 % \begin{macro}{\decisionrefout}
982 % The |\decisionrefout| macro gives a reference point on the bounding rectangle of
983 % the |decision| shape.
984 % Inner and outer separation are included, and it is corrected for the shape's minimum dimensions.
985 % On completion, the coordinates of the point are in |\pgf@xa| and |\pgf@ya|.
986 %
987 % First, the coordinates of the corrected text box are put into some registers:
988 % \begin{macrocode}
989 \def\decisionrefout{
990 \pgf@xa=\ctbnex
991 \pgf@ya=\ctbney
992 \pgf@xb=\ctbnex
993 \pgf@yb=\ctbney
994 % \end{macrocode}
995 % The reference point's x-coordinates is calculated and corrected for minimum width,
996 % and outer x-separation:
997 % \begin{macrocode}
998 \advance\pgf@xa by \pgf@yb
999 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
1000 \advance\pgf@xa by \pgfshapeouterxsep
1001 % \end{macrocode}
1002 % Then the calculation and correction is repeated for the y-coordinate:
1003 % \begin{macrocode}
1004 \advance\pgf@ya by \pgf@xb
1005 \mincorrect{\pgf@ya}{\pgfshapeminheight}
1006 \advance\pgf@ya by \pgfshapeouterysep
1007 }
1008 % \end{macrocode}
1009 % \end{macro}
1010 %
1011 % \begin{macro}{\decisionref}
1012 % The |\decisionref| macro is almost the same as |\decisionrefout|
1013 % but has no correction for outer separation.
1014 % Again, the coordinates of the point are in |\pgf@xa| and |\pgf@ya| on completion:
1015 % \begin{macrocode}
1016 \def\decisionref{
1017 \pgf@xa=\ctbnex
1018 \pgf@ya=\ctbney
1019 \pgf@xb=\ctbnex
1020 \pgf@yb=\ctbney
1021 \advance\pgf@xa by \pgf@yb
1022 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
1023 \advance\pgf@ya by \pgf@xb
1024 \mincorrect{\pgf@ya}{\pgfshapeminheight}
1025 }
1026 % \end{macrocode}
1027 % \end{macro}
1028 %
1029 % \begin{macro}{\decisionpath}
1030 % The |\decisionpath| macro draws the |\decision| shape's path.
1031 % It expects the reference point coordinates to be in |\pgf@xa| and |\pgf@ya|.
1032 % The path is drawn clockwise starting at the top:
1033 % \begin{macrocode}
1034 \def\decisionpath{
1035 \def\refx{\pgf@xa}
1036 \def\refy{\pgf@ya}
1037 \pgfpathmoveto{\pgfpoint{0}{\refy}}
1038 \pgfpathlineto{\pgfpoint{\refx}{0}}
1039 \pgfpathlineto{\pgfpoint{0}{-\refy}}
1040 \pgfpathlineto{\pgfpoint{-\refx}{0}}
1041 \pgfpathclose
1042 }
1043 % \end{macrocode}
1044 % \end{macro}
1045 %
1046 %\subsubsection{Anchor and background paths}\label{decisionpaths}
1047 %
1048 % \begin{macro}{\decisionanchor}
1049 % The |\decisionanchor| macro is the anchor path for the shape's |setpath|:
1050 % \begin{macrocode}
1051 \def\decisionanchor{
1052 \decisionrefout
1053 \decisionpath
1054 }
1055 % \end{macrocode}
1056 % \end{macro}
1057 %
1058 % \begin{macro}{\decisionborder}
1059 % The |\decisionborder| macro is the border path for the shape's |setpath|:
1060 % \begin{macrocode}
1061 \def\decisionborder{
1062 \decisionref
1063 \decisionpath
1064 }
1065 % \end{macrocode}
1066 % \end{macro}
1067 %
1068 % \subsubsection{Decision shape declaration}
1069 %
1070 % \begin{macro}{\pgfdeclareshape}
1071 % \begin{macro}{decision}
1072 % This is the |\pgfdeclareshape| declaration for the |decision| shape.
1073 % \begin{macrocode}
1074 \pgfdeclareshape{decision}{
1075 % \end{macrocode}
1076 % The path macros defined in \S\ref{terminalpaths} are used
1077 % with the |setpaths| command provided by the |makeshape| package to draw the
1078 % shape and make boundary intersection calculations:
1079 % \begin{macrocode}
1080 \setpaths{\decisionanchor}{\decisionborder}
1081 % \end{macrocode}
1082 %
1083 % There are three saved anchors defined for the |decision| shape.
1084 % They have to correct for inner and outer separation, and minimum dimensions;
1085 % and return the coordinates of the point in |\pgf@x| and |\pgf@y|.
1086 % However, this is simplified because |\decisionrefout| does the required work.
1087 % \begin{macro}{\savedanchor}
1088 % \begin{macro}{\north}
1089 % The |\north| saved anchor uses the y-coordinate of the reference point:
1090 % \begin{macrocode}
1091 \savedanchor{\north}{
1092 \decisionrefout
1093 \pgf@x = 0pt
1094 \pgf@y = \pgf@ya
1095 }
1096 % \end{macrocode}
1097 % \end{macro}
1098 % \end{macro}
1099 % \begin{macro}{\savedanchor}
1100 % \begin{macro}{\north}
1101 % The |\east| saved anchor uses the x-coordinate of the reference point:
1102 % \begin{macrocode}
1103 \savedanchor{\east}{
1104 \decisionrefout
1105 \pgf@x = \pgf@xa
1106 \pgf@y = 0pt
1107 }
1108 % \end{macrocode}
1109 % \end{macro}
1110 % \end{macro}
1111 % \begin{macro}{\savedanchor}
1112 % \begin{macro}{\northeast}
1113 % The |\northeast| saved anchor uses the both coordinates of the reference point to
1114 % calculate the required point:
1115 % \begin{macrocode}
1116 \savedanchor{\northeast}{
1117 \decisionrefout
1118 \divide\pgf@xa by 2
1119 \divide\pgf@ya by 2
1120 \pgf@x = \pgf@xa
1121 \pgf@y = \pgf@ya
1122 }
1123 % \end{macrocode}
1124 % \end{macro}
1125 % \end{macro}
1126 %
1127 % \begin{macro}{\anchor}
1128 % \begin{macro}{north}
1129 % \begin{macro}{north east}
1130 % \begin{macro}{east}
1131 % \begin{macro}{south east}
1132 % \begin{macro}{south}
1133 % \begin{macro}{south west}
1134 % \begin{macro}{west}
1135 % \begin{macro}{north west}
1136 % The standard anchors are defined.
1137 % These are based on the |\north| |\east| and |\northeast| saved anchors:
1138 % \begin{macrocode}
1139 \anchor{north}{ \north }
1140 \anchor{north east}{ \northeast }
1141 \anchor{east}{ \east }
1142 \anchor{south east}{ \northeast \pgf@y=-\pgf@y }
1143 \anchor{south}{ \north \pgf@y=-\pgf@y }
1144 \anchor{south west}{ \northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
1145 \anchor{west}{ \east \pgf@x=-\pgf@x }
1146 \anchor{north west}{ \northeast \pgf@x=-\pgf@x }
1147 % \end{macrocode}
1148 % \end{macro}
1149 % \end{macro}
1150 % \end{macro}
1151 % \end{macro}
1152 % \end{macro}
1153 % \end{macro}
1154 % \end{macro}
1155 % \end{macro}
1156 % \end{macro}
1157 %
1158 % \begin{macrocode}
1159 }
1160 % \end{macrocode}
1161 % \end{macro} ^^A end decision
1162 % \end{macro} ^^A end \pgfdeclareshape
1163 %
1164 %^^A ************************************************************
1165 %^^A * Decision shape ends
1166 %^^A ************************************************************
1167 %
1168 %^^A ************************************************************
1169 %^^A * Terminal shape starts
1170 %^^A ************************************************************
1171 % \subsection{Terminal Shape}
1172 %
1173 % \subsubsection{Support Macros}
1174 %
1175 % Two macros |\terminalrefneout| and |\terminalrefne| give a reference point on the
1176 % boundary surface of the |terminal| shape.
1177 %
1178 % \begin{center}
1179 % \begin{tikzpicture}
1180 % ^^A - Axis
1181 % \draw [dotted] (0,0) -- +(2cm,0) -- +(-2cm,0) +(0,1cm) -- +(0,-1cm);
1182 % ^^A - Terminal shape
1183 % \node (terminal) at (0,0) [draw,terminal,minimum height=1cm, minimum width=3cm] {};
1184 % ^^ A - Reference point
1185 % \draw (terminal.north east) circle (2pt);
1186 % \node at (1.7cm,0.8cm) [] {\sf \small reference point};
1187 % \draw [dotted] (terminal.north east) -- +(0,-1.5cm) -- +(0,0.2cm);
1188 % \end{tikzpicture}
1189 % \end{center}
1190 % \vspace{-2ex}
1191 %
1192 % \begin{macro}{\terminalrefneout}
1193 % The |\terminalrefneout| macro gives a reference point on the boundary surface of
1194 % the |terminal| shape.
1195 % Inner and outer separation are included, and it is corrected for the shape's minimum dimensions.
1196 % On completion, the coordinates of the point are in |\pgf@xa| and |\pgf@ya|.
1197 %
1198 % First, the coordinates of the corrected text box are obtained,
1199 % and then the width of the rounded end is add to the x-coordinate to get the bounding
1200 % dimensions:
1201 % \begin{macrocode}
1202 \def\terminalrefneout{
1203 \pgf@xa=\ctbnex
1204 \pgf@ya=\ctbney
1205 \advance\pgf@xa by \pgf@ya
1206 % \end{macrocode}
1207 % Then these bounding coordinates are corrected for minimum dimensions, and outer separation:
1208 % \begin{macrocode}
1209 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
1210 \advance\pgf@xa\pgfshapeouterxsep
1211 \mincorrect{\pgf@ya}{\pgfshapeminheight}
1212 \advance\pgf@ya\pgfshapeouterysep
1213 % \end{macrocode}
1214 % Finally, the corrected x-coordinate is reduced by the width of the rounded end to give
1215 % the required reference point:
1216 % \begin{macrocode}
1217 \advance\pgf@xa by -\pgf@ya
1218 }
1219 % \end{macrocode}
1220 % \end{macro}
1221 %
1222 % \begin{macro}{\terminalrefne}
1223 % The |\terminalrefne| macro is almost the same as |\terminalrefneout|
1224 % but has no correction for outer separation.
1225 % Again, the coordinates of the point are in |\pgf@xa| and |\pgf@ya| on completion:
1226 % \begin{macrocode}
1227 \def\terminalrefne{
1228 \pgf@xa=\ctbnex
1229 \pgf@ya=\ctbney
1230 \advance\pgf@xa by \pgf@ya
1231 \mincorrect{\pgf@xa}{\pgfshapeminwidth}
1232 \mincorrect{\pgf@ya}{\pgfshapeminheight}
1233 \advance\pgf@xa by -\pgf@ya
1234 }
1235 % \end{macrocode}
1236 % \end{macro}
1237 %
1238 % \begin{macro}{\terminalpath}
1239 % The |\terminalpath| macro draws the |terminal| shape's path.
1240 % It expects the reference point coordinates to be in |\pgf@xa| and |\pgf@ya|.
1241 % The path is drawn anticlockwise:
1242 % \begin{macrocode}
1243 \def\terminalpath{
1244 \def\refx{\pgf@xa}
1245 \def\refy{\pgf@ya}
1246 \def\radius{\refy}
1247 \pgfpathmoveto{\pgfpoint{\refx}{\refy}}
1248 \pgfpathlineto{\pgfpoint{-\refx}{\refy}}
1249 \pgfpatharc{90}{270}{\radius}
1250 \pgfpathlineto{\pgfpoint{\refx}{-\refy}}
1251 \pgfpatharc{270}{360}{\radius}
1252 \pgfpatharc{0}{90}{\radius}
1253 \pgfpathclose
1254 }
1255 % \end{macrocode}
1256 % \end{macro}
1257 %
1258 %\subsubsection{Anchor and background paths}\label{terminalpaths}
1259 %
1260 % \begin{macro}{\terminalanchor}
1261 % The |\terminalanchor| macro is the anchor path for the shape's |setpath|:
1262 % \begin{macrocode}
1263 \def\terminalanchor{
1264 \terminalrefneout
1265 \terminalpath
1266 }
1267 % \end{macrocode}
1268 % \end{macro}
1269 %
1270 % \begin{macro}{\terminalborder}
1271 % The |\terminalborder| macro is the border path for the shape's |setpath|:
1272 % \begin{macrocode}
1273 \def\terminalborder{
1274 \terminalrefne
1275 \terminalpath
1276 }
1277 % \end{macrocode}
1278 % \end{macro}
1279 %
1280 % \subsubsection{Terminal shape declaration}
1281 %
1282 % \begin{macro}{\pgfdeclareshape}
1283 % \begin{macro}{terminal}
1284 % This is the |\pgfdeclareshape| declaration for the |terminal| shape.
1285 % \begin{macrocode}
1286 \pgfdeclareshape{terminal}{
1287 % \end{macrocode}
1288 % The path macros defined in \S\ref{terminalpaths} are used
1289 % with the |setpaths| command provided by the |makeshape| package to draw the
1290 % shape and make boundary intersection calculations:
1291 % \begin{macrocode}
1292 \setpaths{\terminalanchor}{\terminalborder}
1293 % \end{macrocode}
1294 %
1295 % \begin{macro}{\savedanchor}
1296 % \begin{macro}{\northeast}
1297 % There are two saved anchors defined for the |terminal| shape.
1298 % The |\northeast| saved anchor gives the position of the shape's `reference point' used above.
1299 % It corrects for inner and outer separation, and minimum dimensions.
1300 % It returns the coordinates of the point in |\pgf@x| and |\pgf@y|,
1301 % and its implementation is simple since |\terminalrefneout| does the required work.
1302 % \begin{macrocode}
1303 \savedanchor{\northeast}{
1304 \terminalrefneout
1305 \pgf@x = \pgf@xa
1306 \pgf@y = \pgf@ya
1307 }
1308 % \end{macrocode}
1309 % \end{macro}
1310 % \end{macro}
1311 %
1312 % \begin{macro}{\savedanchor}
1313 % \begin{macro}{\northeastBB}
1314 % The |\northeastBB| macro gives the coordinates of the NE corner of the shape's
1315 % bounding rectangle in |\pgf@x| and |\pgf@y|.
1316 % It corrects for inner and outer separation, and minimum dimensions.
1317 % It is obtain by adding the width of the shape's round end to the x-coordinate of the
1318 % reference point:
1319 % \begin{macrocode}
1320 \savedanchor{\northeastBB}{
1321 \terminalrefneout
1322 \advance \pgf@xa by \pgf@ya
1323 \pgf@x = \pgf@xa
1324 \pgf@y = \pgf@ya
1325 }
1326 % \end{macrocode}
1327 % \end{macro}
1328 % \end{macro}
1329 %
1330 % \begin{macro}{\anchor}
1331 % \begin{macro}{north}
1332 % \begin{macro}{north east}
1333 % \begin{macro}{east}
1334 % \begin{macro}{south east}
1335 % \begin{macro}{south}
1336 % \begin{macro}{south west}
1337 % \begin{macro}{west}
1338 % \begin{macro}{north west}
1339 % The standard anchors are defined.
1340 % These are based on the |\northeast| and |\northeastBB| saved anchors:
1341 % \begin{macrocode}
1342 \anchor{north}{ \northeast \pgf@x=0pt }
1343 \anchor{north east}{ \northeast }
1344 \anchor{east}{ \northeastBB \pgf@y=0pt }
1345 \anchor{south east}{ \northeast \pgf@y=-\pgf@y }
1346 \anchor{south}{ \northeast \pgf@x=0pt \pgf@y=-\pgf@y }
1347 \anchor{south west}{ \northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
1348 \anchor{west}{ \northeastBB \pgf@x=-\pgf@x \pgf@y=0pt }
1349 \anchor{north west}{ \northeast \pgf@x=-\pgf@x }
1350 % \end{macrocode}
1351 % \end{macro}
1352 % \end{macro}
1353 % \end{macro}
1354 % \end{macro}
1355 % \end{macro}
1356 % \end{macro}
1357 % \end{macro}
1358 % \end{macro}
1359 % \end{macro}
1360 %
1361 % \begin{macro}{\anchor}
1362 % \begin{macro}{north east r}
1363 % \begin{macro}{south east r}
1364 % \begin{macro}{south west r}
1365 % \begin{macro}{north west r}
1366 % Four additional anchors are defined that follow the shape's bounding rectangle.
1367 % \begin{macrocode}
1368 \anchor{north east r}{\northeastBB}
1369 \anchor{south east r}{\northeastBB \pgf@y=-\pgf@y}
1370 \anchor{south west r}{\northeastBB \pgf@x=-\pgf@x \pgf@y=-\pgf@y}
1371 \anchor{north west r}{\northeastBB \pgf@x=-\pgf@x}
1372 % \end{macrocode}
1373 % \end{macro}
1374 % \end{macro}
1375 % \end{macro}
1376 % \end{macro}
1377 % \end{macro}
1378 %
1379 % \begin{macrocode}
1380 }
1381 % \end{macrocode}
1382 % \end{macro} ^^A end terminal
1383 % \end{macro} ^^A end \pgfdeclareshape
1384 %
1385 %^^A ************************************************************
1386 %^^A * Terminal shape ends
1387 %^^A ************************************************************
1388 %
1389 % \Finale
1390 \endinput