diff options
Diffstat (limited to 'macros/latex/contrib/wargame/source/chit')
-rw-r--r-- | macros/latex/contrib/wargame/source/chit/core.dtx | 47 | ||||
-rw-r--r-- | macros/latex/contrib/wargame/source/chit/elements.dtx | 105 | ||||
-rw-r--r-- | macros/latex/contrib/wargame/source/chit/misc.dtx | 460 | ||||
-rw-r--r-- | macros/latex/contrib/wargame/source/chit/shape.dtx | 544 |
4 files changed, 1156 insertions, 0 deletions
diff --git a/macros/latex/contrib/wargame/source/chit/core.dtx b/macros/latex/contrib/wargame/source/chit/core.dtx new file mode 100644 index 0000000000..7a0189074e --- /dev/null +++ b/macros/latex/contrib/wargame/source/chit/core.dtx @@ -0,0 +1,47 @@ +% \iffalse +% ==================================================================== +% \fi +% +% \subsection{The \texttt{wargame.chit} \TikZ{} library} +% \label{sec:impl:natoapp6c} +% +% We define the library for making chits. We load the hex \TikZ{} +% \spec{wargame.natoapp6c} library and the \textsf{amsmath} and +% \textsf{amstext} packages as we need those. +% +% \iffalse +%<*chit> +% \fi +% +% \begin{macrocode} +\RequirePackage{amsmath} +\RequirePackage{amstext} +\usetikzlibrary{wargame.util,wargame.natoapp6c,math} +% \end{macrocode} +% +% \iffalse +% -------------------------------------------------------------------- +% \fi +% +% \subsubsection{Debugging} +% +% \begin{Macro}{\chitdbglvl,\chit@dbg} +% +% Some macros for debugging. Similar to what we have in +% \spec{wargame.hex} (see \sectionname~\ref{sec:impl:hex}. +% +% \begin{macrocode} +\newcount\chitdbglvl\chitdbglvl=\wargamedbglvl +\def\chit@dbg#1#2{% + \ifnum#1>\chitdbglvl\relax\else\message{^^J#2}\fi} +% \end{macrocode} +% \end{Macro} +% +% \input{chit/shape.dtx} +% \input{chit/elements.dtx} +% \input{chit/misc.dtx} +% +% \iffalse +%</chit> +% -------------------------------------------------------------------- +% \fi diff --git a/macros/latex/contrib/wargame/source/chit/elements.dtx b/macros/latex/contrib/wargame/source/chit/elements.dtx new file mode 100644 index 0000000000..8708ca2a15 --- /dev/null +++ b/macros/latex/contrib/wargame/source/chit/elements.dtx @@ -0,0 +1,105 @@ +% \iffalse +% -------------------------------------------------------------------- +%<*chit> +% \fi +% +% \subsubsection{Predefined \texttt{chit} element pictures} +% +% \begin{TikzKey}{/tikz/pics/chit/1 factor, +% /tikz/pics/chit/2 factors, +% /tikz/pics/chit/2 factors artillery, +% /tikz/pics/chit/3 factors, +% /tikz/pics/chit/4 factors, +% /tikz/pics/chit/identifier, +% /tikz/pics/chit/small identifier, +% /tikz/pics/chit/identifier macro} +% +% These pictures can be used as the value of \texttt{chit} keys. +% +% \begin{macrocode} +\tikzset{% + chit/1 factor/.pic={ + \chit@dbg{4}{ Chit 1 factor: #1}% + \node[chit/factor,chit/1 factor,pic actions]{#1};}, + pics/chit/2 factors/.style args={#1,#2}{% + code={% + \chit@dbg{4}{ Chit 2 factors: #1 and #2}% + \node[chit/factor,chit/2 factors,pic actions]{#1--#2};}}, + pics/chit/2 factors artillery/.style args={#1,#2,#3}{% + code={ + \chit@dbg{4}{ Chit 2 factors w/artillery: `#1' `#2' `#3'}% + \node[chit/factor,chit/2 factors,pic actions]{% + #1$\overset{\text{\scriptsize #3}}{\text{--}}$#2};}}, + pics/chit/3 factors/.style args={#1,#2,#3}{% + code={ + \chit@dbg{4}{ Chit 3 factors: `#1' `#2' `#3'}% + \node[chit/factor,chit/3 factors,pic actions]{#1-#2-#3};}}, + pics/chit/4 factors/.style args={#1,#2,#3,#4}{% + code={ + \chit@dbg{4}{ Chit 3 factors: `#1' `#2' `#3' `#4'}% + \node[chit/factor,chit/4 factors,pic actions]{#1-#2-#3-#4};}}, + chit/identifier/.pic={ + \chit@dbg{4}{ Chit identifier: `#1'}% + \node[chit/identifier,pic actions]{#1}; + }, + chit/small identifier/.pic={ + \chit@dbg{4}{ Chit small identifier: `#1'}% + \node[chit/small identifier,pic actions]{#1}; + }, + chit/identifier macro/.pic={% + \chit@dbg{4}{ Chit identifier macro: \meaning#1} + \edef\chit@i@tmp{#1} + \node[chit/identifier,pic actions]{\chit@i@tmp};}, +} +% \end{macrocode} +% \end{TikzKey} +% +% \begin{TikzKey}{/tikz/chit/factor, +% /tikz/chit/1 factor, +% /tikz/chit/2 factors, +% /tikz/chit/3 factors, +% /tikz/chit/4 factors, +% /tikz/chit/identifier, +% /tikz/chit/small identifier} +% +% Styles used by the above pictures. Users can change these as they +% see fit. +% +% \begin{macrocode} +\tikzset{% + chit/factor/.style={ + shape=rectangle, + font=\sffamily\bfseries\large, + anchor=base, + inner sep=0, + %text=pgfstrokecolor, + draw=none, + fill=none, + }, + chit/1 factor/.style={}, + chit/2 factors/.style={}, + chit/3 factors/.style={}, + chit/4 factors/.style={text/.append style=\small}, + chit/identifier/.style={ + shape=rectangle, + font=\sffamily\bfseries\scriptsize, + inner sep=0, + % text=pgfstrokecolor, + draw=none, + fill=none, + }, + chit/small identifier/.style={ + shape=rectangle, + font=\sffamily\bfseries\tiny, + inner sep=0, + % text=pgfstrokecolor, + draw=none, + fill=none, + }, +} +% \end{macrocode} +% \end{TikzKey} +% \iffalse +%</chit> +% -------------------------------------------------------------------- +% \fi diff --git a/macros/latex/contrib/wargame/source/chit/misc.dtx b/macros/latex/contrib/wargame/source/chit/misc.dtx new file mode 100644 index 0000000000..6c406af3f8 --- /dev/null +++ b/macros/latex/contrib/wargame/source/chit/misc.dtx @@ -0,0 +1,460 @@ +% \iffalse +% -------------------------------------------------------------------- +%<*chit> +% \fi +% \subsubsection{Other pictures} +% Pictures for frame, factors, left, right, and below. +% \begin{macrocode} +\tikzset{ + pics/chit/shade/.style={ + code={% + \path[fill=white,opacity=#1,pic actions] (-.6,-.6) rectangle(.6,.6);}}, + pics/chit/eliminate/.style={ + code={% + \path[fill=red,opacity=#1,pic actions] (-.6,-.6) rectangle(.6,.6);}}, + pics/chit/shade/.default=0.5, + pics/chit/eliminate/.default=0.25, +} +\def\shadechit(#1){% + \pic at (#1) {chit/shade};} +\def\eliminatechit(#1){% + \pic at (#1) {chit/eliminate};} +% \end{macrocode} +% +% +% \iffalse +% -------------------------------------------------------------------- +% \fi +% \subsubsection{Stacking of chits} +% +% Stacking of chits. The key \spec{chit/stack direction} sets the +% default direction to make the stack in. +% +% \begin{macrocode} +% offset, location, direction, list +\tikzset{% + chit/stack direction/.store in=\chit@stack@dir, + chit/stack direction/.initial={(.3,.3)}, +} +% \end{macrocode} +% +% Now the code +% +% \begin{macrocode} +\def\chit@stack@dir{(.3,.3)} +\def\stackchits(#1){% + \@ifnextchar({\st@ckchits{#1}}{\st@ckchits{#1}(.3,.3)}%) +} +\def\st@ckchits#1(#2)#3{ + \chit@dbg{2}{Stacking chits `#1', `#2', `#3'} + \edef\xy{#1} + \chit@dbg{4}{Stack start at \xy} + \foreach[count=\i from 0] \c/\o in {#3} {% + \ifx\c\empty\else% + \edef\ccc{\c} + \chit@dbg{2}{Adding \meaning\ccc\space to stack at (\xy)' `\o'} + \expandafter\ccc(\xy) + %% + \ifx\c\o\else + %\chit@dbg{0}{Option: \o} + \edef\ccc{\o} + \expandafter\ccc(\xy) + \fi + \expandafter\ccc(\xy) + \tikzmath{% + coordinate \cc; + \cc = (\xy) + (#2);} + \xdef\xy{\cc} + \fi + } +} +% \end{macrocode} +% +% \iffalse +% -------------------------------------------------------------------- +% \fi +% \subsubsection{Making order of battle charts} +% +% +% Macros for making OOBs +% +% Style for turns +% +% \begin{macrocode} +\tikzset{ + chit/oob turn/.pic={\node[pic actions]{#1};}} +% \end{macrocode} +% +% +% current c, current r, n-columns, cell size, y +% +% \begin{macrocode} +\def\chit@oob@cellupdate(#1,#2)#3#4#5{% + \edef\f{\ifwg@oob@inv-1\else1\fi}% + \chit@dbg{1}{ \space Cell update `c=|#1|' vs `#4'*(`#3'-1)} + \pgfmathparse{int(ifthenelse(abs(#1)>=#4*(#3-1),#5-1,#5))}% + \xdef#5{\pgfmathresult} + \pgfmathparse{ifthenelse(abs(#1)>=#4*(#3-1),#2-#4,#2)}% + \xdef#2{\pgfmathresult}% + \pgfmathparse{ifthenelse(abs(#1)>=#4*(#3-1),0,#1+\f*#4)}% + \xdef#1{\pgfmathresult}% + \chit@dbg{1}{ \space\space-> `\string#5'=#5 `\string#2'=#2 `\string#1'=#1} +} +% \end{macrocode} +% +% current c, current r, cell size, extra vertical spacing +% +% \begin{macrocode} +\def\chit@oob@rowupdate(#1,#2)#3#4{% + \chit@dbg{2}{ Row update c=`#1',r=`#2',s=`#3',e=`#4'} + %\pgfmathparse{ifthenelse(#1>0,#2-#3,#2)}% + \pgfmathparse{#2-#3)}% + \xdef#2{\pgfmathresult}% + %\xdef#1{0} + \chit@dbg{2}{ \space\space-> update `\string#2'=#2} +} +% \end{macrocode} +% current c, current r, cell size, extra spacing +% +% \begin{macrocode} +\def\chit@oob@turnupdate(#1,#2)#3#4{% + \chit@dbg{2}{ Turn update c=`#1',r=`#2',s=`#3',e=`#4'} + % \pgfmathparse{#2-ifthenelse(#1>0,#3,0)-#4}% + \pgfmathparse{#2-#4-ifthenelse(abs(#1)>0.0001,#3,0)} + \xdef#2{\pgfmathresult}% + \xdef#1{0}% + \chit@dbg{2}{ \space\space-> update `\string#1'=#1,`\string#2'=#2} +} +% \end{macrocode} +% chit list, n-colls, cell size, extra vertical spacing +% +% This expects a list of lists of chits, one list per turn; the +% maximum number of columns; the size of cells, extra spacing between +% turns. +% +% Note, the list of lists leaf elements should be styles for the +% chits. +% +% This depends on the Tikz pic \texttt{chit/oob~turn} which takes the +% number as argument. +% +% +% \begin{macrocode} +\newif\ifwg@oob@inv\wg@oob@invfalse +\def\wg@star@oob{\wg@oob@invtrue\wg@oob} +\def\wg@nostar@oob{\wg@oob@invfalse\wg@oob} +\def\oob{% + \@ifstar{\wg@star@oob% + }{\wg@nostar@oob% + }% +} +\def\wg@oob#1#2#3#4{ + \def\r{0} + \chit@dbg{1}{OOB: `#1'} + \foreach[count=\ti from 0] \t/\y in #1{ + \xdef\o{\r} + \def\c{0} + \ifx\t\y\def\y{0}\fi + \chit@dbg{1}{Turn \ti\space(\r,\t,y=\y):'} + \ifwg@oob@inv% + \pic at ( .5,\r) {chit/oob turn=\ti};% + \else + \pic at (-.5,\r) {chit/oob turn=\ti};% + \fi% + \ifx\t\empty\else% + \foreach \u/\m in \t{ + %% \chit@dbg{2}{ `\u'=`\m'} + \ifx\u\empty\else + \ifx\m\@empty\def\m{1}\fi + \ifx\u\m\def\m{1}\fi + \foreach \n in {1,...,\m}{% + \ifx\u\chit@blank\else + \chit[\u=\ti,zone point={\u}{\c}{\r}](\c,\r) + \fi + \chit@oob@cellupdate(\c,\r){#2}{#3}{\y} + } + \fi + } + \fi + \chit@dbg{1}{ End of chits in turn + \ti\space(c=`\c',r=`\r',o='\o',y='\y')} + % IF no units where given, then we force \c to be non-zero so that + % \chit@oob@turnupdate increments the row + \ifx\t\@empty + \def\c{#3} + \chit@dbg{2}{ Turn is empty, set c=`\c'} + \fi + %\ifnum\y<0% No explicit number of rows given + % \def\c{#3} + % \chit@dbg{2}{ No explicit number of rows given, set c=`\c'} + %\fi + % In case the user gave and explicit number of rows, add the rows + % that are missing. \y is initially set to the number of + % requested rows, and then decremented every time we go down one + % row. So if the number of rows we did so far is N, and the + % requested number of rows is M, then the loop below adds M-N + % rows. + \ifnum\y>0% + \chit@dbg{2}{ Looping rows from 2 to \y, break when row > \y}% + \foreach \rr in {2,...,\y}{ + %\ifnum\rr>\y% A little funny, but \y can be negative! + % \chit@dbg{2}{ \space Breaking loop \rr\space > \y}% + % \breakforeach% + %\else% + \chit@oob@rowupdate(\c,\r){#3}{#4} + %\fi + } + \fi + % This will zero \c. However, if on entry |\c|>0, then we also + % increment the row + \chit@oob@turnupdate(\c,\r){#3}{#4} + \chit@dbg{1}{End of turn \ti\space(c=`\c',r=`\r',o='\o',y='\y')} + } + \chit@dbg{2}{End of OOB (c=`\c',r=`\r',y=`\y')} +} +% \end{macrocode} +% +% \iffalse +% -------------------------------------------------------------------- +% \fi +% \subsubsection{Table of chits} +% +% \begin{macrocode} +\tikzset{ + chit/cell background/.style={fill=black}, + blank chit/.style={/chit/frame={draw=none,fill=none}}, +} +% \end{macrocode} +% +% These macros are used when we set tables of chits. This allows us +% to define blank spaces in the table by giving the element +% \texttt{blank~chit}. +% +% \begin{macrocode} +\def\chit@blank{blank chit} +\def\chit@cellbg(#1,#2)#3{% + \draw[chit/cell background](#1-#3/2,#2-#3/2) rectangle++(#3,#3); +} +% \end{macrocode} +% +% \begin{Macro}{\ifchits@reset} +% +% This `if' controls whether to reset the coordinates to the origin +% when \cs{chits} is called. If true, then reset for a new table. +% +% \begin{macrocode} +\newif\ifchits@reset\chits@resettrue +% \end{macrocode} +% \end{Macro} +% +% \begin{Macro}{\chits,\@chits,\chit@sng@cellupdate} +% \begin{macrocode} +\def\chit@sng@cellupdate(#1,#2)#3#4{% + \chit@dbg{2}{Current `#1' vs `#4'*(`#3'+1)} + \pgfmathparse{ifthenelse(#1>=#4*(#3-1),#2-#4,#2)}% + \xdef#2{\pgfmathresult}% + \pgfmathparse{ifthenelse(#1>=#4*(#3-1),0,#1+#4)}% + \xdef#1{\pgfmathresult}% +} +% \end{macrocode} +% +% The stared version (\cs{chits*}) of this macro continues the +% previously set chit table. +% +% \begin{macrocode} +\def\chits{% + \@ifstar{\chits@resetfalse\@chits}{\chits@resettrue\@chits}} +% \end{macrocode} +% +% \begin{macrocode} +\def\@chits#1#2#3{ + \ifchits@reset + \def\r{0}% + \def\c{0}% + \fi + \chit@dbg{1}{Chits to make: #1}% + \foreach[count=\ti from 0] \t/\x in #1{% + \chit@dbg{2}{Turn `\t' with option `\x'} + \ifx\t\empty\else% + \foreach \u/\m in \t{% + \ifx\u\empty\else% + \chit@dbg{2}{Next chit `\u' with possible multiplicity `\m'}% + \ifx\m\@empty\def\m{1}\fi% + \ifx\u\m\def\m{1}\fi% + \chit@dbg{2}{Next chit `\u' multiplicity `\m'}% + \foreach \n in {1,...,\m}{% + \ifx\u\chit@blank% + \chit@dbg{3}{Ignoring blank chit:\u}% + \else% + \chit@cellbg(\c,\r){#3}% + \chit[\u=\ti](\c,\r)% + \chit@sng@cellupdate(\c,\r){#2}{#3}% + \fi% + }% + \fi% + }% + \fi% + }% +} +% \end{macrocode} +% \end{Macro} +% +% \begin{Macro}{\doublechits, +% \@doublechits, +% \chit@dbl@cellupdate, +% \chit@dbl@flip} +% \begin{enumerate} +% \item coordinates +% \item coordinates +% \item cell-size +% \end{enumerate} +% +% \begin{macrocode} +\def\chit@dbl@flip(#1,#2)#3{% + \pgfmathparse{-#1}% + \xdef\mc{\pgfmathresult}% +} +% \end{macrocode} +% +% \begin{enumerate} +% \item coordinates +% \item coordinates +% \item Number of columns +% \item cell-size +% \end{enumerate} +% +% \begin{macrocode} +\def\chit@dbl@cellupdate(#1,#2)#3#4{% + \pgfmathparse{ifthenelse(#1<-#4/2,#2,#4+#2)}% + \xdef#2{\pgfmathresult}% + \pgfmathparse{ifthenelse(#1<-#4/2,#4+#1,-(#3-.5)*#4)}% + \xdef#1{\pgfmathresult}% +} +% \end{macrocode} +% +% \begin{enumerate} +% \item List of list of keys +% \item Number of columns +% \item size of each cell +% \end{enumerate} +% +% The stared version (\cs{doublechits*}) of this macro continues the +% previously set chit table. +% +% \begin{macrocode} +\def\doublechits{% + \@ifstar{\chits@resetfalse\@doublechits}{\chits@resettrue\@doublechits}} +% \end{macrocode} +% +% \begin{macrocode} +\def\@doublechits#1#2#3{% + \chit@dbg{1}{Setting double-sided chits: #1} + \ifchits@reset + \pgfmathparse{-(#2-.5)*#3} + \xdef\c{\pgfmathresult} + \def\r{0} + \fi + + \foreach[count=\ti from 0] \t/\x in #1{ + \ifx\t\empty\else% + \foreach \u/\m in \t{ + \ifx\u\empty\else + \ifx\m\@empty\def\m{1}\else% + \ifx\u\m\def\m{1}\fi\fi + \chit@dbg{2}{`\u'=`\m' (\c,\r)} + \foreach \n in {1,...,\m}{% + \ifx\u\chit@blank + \chit@dbg{3}{Ignoring blank chit:\u} + \else + \chit@cellbg(\c,\r){#3} + \chit[\u=\ti](\c,\r) + \chit@dbl@flip(\c,\r){#3} + \chit@cellbg(\mc,\r){#3} + \chit[\u\space flipped=\ti,zone turn=\t,zone mult=\n](\mc,\r) + \chit@dbl@cellupdate(\c,\r){#2}{#3} + \fi + } + \fi + } + \fi + } + \draw[dashed](0,-3*#3/4)--(0,\r-#3/4); + \draw[dashed,<-] (#3/5,-2*#3/3)--(#3/2,-2*#3/3) node[anchor=west]{Back}; + \draw[dashed,<-] (-#3/5,-2*#3/3)--(-#3/2,-2*#3/3) node[anchor=east]{Front}; +} +% \end{macrocode} +% \end{Macro} +% +% \iffalse +% -------------------------------------------------------------------- +% \fi +% \subsubsection{Some utilities} +% +% +% Game turn marker +% +% \begin{macrocode} +\tikzset{ + number chit/.pic={ + \node[shape=rectangle,font=\sffamily\bfseries\LARGE]{% + \begin{tabular}{c} #1\end{tabular}};}, + game turn/.pic={ + \node[shape=rectangle,font=\sffamily\bfseries]{% + \begin{tabular}{c} Game\\Turn\end{tabular}};}, + game turn/.style={ + /chit/full={game turn}, + color=black, + fill=white}, + game turn flipped/.style={game turn}, + dummy chit/.style={fill=white}, +} +% \end{macrocode} +% +% Marks of chits +% +% \begin{macrocode} +\providecommand\chitmark[2][]{\tikz[scale=.25,#1]{\chit[#2]}} +% \end{macrocode} +% +% Stacking mark +% +% \begin{macrocode} +\tikzset{ + wg stacking/.style={fill=white, + /chit/symbol={[faction=friendly,command=land]}}, +} +\DeclareRobustCommand\stackmark[1][]{% + \tikz[baseline=(current bounding box.center),scale=.3,#1]{ + \stackchits(0,0)(.3,-.3){% + \noexpand\chit[wg stacking], + \noexpand\chit[wg stacking], + \noexpand\chit[wg stacking]}}} +% \end{macrocode} +% +% ZOC mark +% +% \begin{macrocode} +\DeclareRobustCommand\zocmark[1][]{% + \tikz[baseline=(current bounding box.center),scale=.1,#1]{% + \begin{scope}[hex/first row and column are=0, + hex/row direction is=normal, + hex/column direction is=normal, + hex/short columns=none] + \hex[label=,fill=gray](c=1,r=1)% + \hex[label=,fill=white](c=1,r=2)% + \hex[label=,fill=white](c=1,r=0)% + \hex[label=,fill=white](c=0,r=0)% + \hex[label=,fill=white](c=0,r=1)% + \hex[label=,fill=white](c=2,r=1)% + \hex[label=,fill=white](c=2,r=0) + \end{scope}}} +% \end{macrocode} +% +% \begin{macrocode} +\tikzset{ + zone point/.code n args={3}{}} +% \end{macrocode} +% +% \iffalse +%</chit> +% \fi diff --git a/macros/latex/contrib/wargame/source/chit/shape.dtx b/macros/latex/contrib/wargame/source/chit/shape.dtx new file mode 100644 index 0000000000..8ad0614cb8 --- /dev/null +++ b/macros/latex/contrib/wargame/source/chit/shape.dtx @@ -0,0 +1,544 @@ +% \iffalse +% -------------------------------------------------------------------- +% <*chit> +% \fi +% +% \subsubsection{The \texttt{chit} key namespace} +% \begin{TikzKey}{/chit/full, +% /chit/symbol, +% /chit/left, +% /chit/right, +% /chit/upper left, +% /chit/upper right, +% /chit/lower left, +% /chit/lower right, +% /chit/factors, +% /chit/setup, +% /chit/id} +% +% The parts of a chit +% +% \begin{macrocode} +\tikzset{% + /chit/.search also={/tikz}, + /chit/.cd, + full/.store in=\chit@full, full/.initial=,% + symbol/.store in=\chit@symbol, symbol/.initial=,% + left/.store in=\chit@left, left/.initial=,% + unique/.style={/chit/left={#1}},% + right/.store in=\chit@right, right/.initial=,% + parent/.style={/chit/right={#1}},% + upper left/.store in=\chit@upper@left, upper left/.initial=,% + upper right/.store in=\chit@upper@right, upper right/.initial=,% + lower left/.store in=\chit@lower@left, lower left/.initial=,% + lower right/.store in=\chit@lower@right, lower right/.initial=,% + factors/.store in=\chit@factors, factors/.initial=,% + setup/.store in=\chit@setup, setup/.initial=,% + id/.store in=\chit@id, id/.initial=,% + frame/.store in=\chit@frame, frame/.initial=,% +} +% \end{macrocode} +% \end{TikzKey} +% +% \begin{TikzKey}{/tikz/chit/full, +% /tikz/chit/symbol, +% /tikz/chit/left, +% /tikz/chit/right, +% /tikz/chit/upper left, +% /tikz/chit/upper right, +% /tikz/chit/lower left, +% /tikz/chit/lower right, +% /tikz/chit/factors, +% /tikz/chit/setup, +% /tikz/chit/id} +% +% Styles of each element in a chit. Users may override these at their +% own peril. That is, it is OK to override them, but the user should +% be careful. +% +% \begin{macrocode} +\tikzset{ + chit/symbol/.style={scale=.4,transform shape}, + chit/parts/.style={shape=rectangle,transform shape}, + chit/factors/.style={chit/parts,anchor=south}, + chit/left/.style={chit/parts,anchor=south,rotate=90}, + chit/right/.style={chit/parts,anchor=north,rotate=90}, + chit/upper left/.style={chit/parts,anchor=north west}, + chit/upper right/.style={chit/parts,anchor=north east}, + chit/lower left/.style={chit/parts,anchor=south west}, + chit/lower right/.style={chit/parts,anchor=south east}, + chit/setup/.style={chit/parts}, + chit/full/.style={chit/parts}, +} +% \end{macrocode} +% \end{TikzKey} +% +% \iffalse +% -------------------------------------------------------------------- +% \fi +% +% \subsubsection{The \texttt{chit} styles} +% +% \begin{TikzKey}{/tikz/chit} +% This key sets up a node to make a chit. The key takes a single +% argument which in turn must contain key--value pairs in the +% \texttt{/chit} (or \texttt{/tikz}) namespace(s). We set the +% \texttt{shape} parameter of the node, and calls the passed keys in +% the \texttt{/chit} namespace to set-up elements of the chit. +% +% \begin{macrocode} +\tikzset{% + chit/.code={% + \pgfkeys{/tikz/transform shape,/tikz/shape=chit} + \pgfkeys{/chit/.cd,#1}}} +% \end{macrocode} +% \end{TikzKey} +% +% We define a counter to set-up unique names for chit nodes. +% +% \begin{macrocode} +\newcounter{chit@id}\setcounter{chit@id}{0} +% \end{macrocode} +% +% \iffalse +% -------------------------------------------------------------------- +% \fi +% \subsubsection{The \cs{chit} shape} +% +% \begin{Macro}{\chit@n@to,\@chit@n@to,\@@chit@n@to,\@chit@n@to@} +% +% These macros puts the NATO App6(c) symbol into a chit. The first +% macro takes the identifier and position of the symbol, and then +% scans for options. If no options are given, then we go directly +% to the rendering (\cs{@chit@n@to@}). Otherwise, we may also need +% to scan for an offset given as \parg{delta-x,delta-y}. +% +% \begin{macrocode} +\def\chit@n@to#1#2{% + %% Without a following start square bracket '[' by-pass to final + \chit@dbg{4}{Chit NATO App6(c) first step `#1' `#2'} + \@ifnextchar[{% + %\message{^^JStart square bracket}% + \@chit@n@to{#1}{#2}}{% + %\message{^^JNo start square bracket}% + \@chit@n@to@{#1}{#2}}%]] +} +% \end{macrocode} +% +% The following macro is called if we had no options. +% +% \begin{macrocode} +\def\@chit@n@to@#1#2#3\@end@chit@n@to{% + \chit@dbg{4}{Chit NATO App6(c) w/o offset: + ^^J Options: #3 + ^^J ID: #1 + ^^J Position: #2} + \node[chit/symbol,natoapp6c={#3,id=#1}] (#1) at (#2) {}; + \chit@dbg{4}{Chit NATO App6(c) ended}% +} +% \end{macrocode} +% +% This is called if we had an option-like argument. Check if we have +% an offset +% +% \begin{macrocode} +\def\@chit@n@to#1#2[#3]{% + \chit@dbg{4}{Chit NATO App6(c) second step `#1' `#2' `#3'} + \@ifnextchar({\@@chit@n@to{#1}{#2}{#3}}{\@@chit@n@to{#1}{#2}{#3}(0,0)}%) +} +% \end{macrocode} +% +% This called if we had option-like argument. +% +% \begin{macrocode} +\def\@@chit@n@to#1#2#3(#4)\@end@chit@n@to{% + \chit@dbg{4}{Chit NATO App6(c) w/offset: + ^^J Options: #3 + ^^J ID: #1 + ^^J Position: #2 + ^^J Offset: #4} + \node[chit/symbol,natoapp6c={#3,id=#1}] (#1) at ($(#2)+(#4)$) {};} +% \end{macrocode} +% \end{Macro} +% +% \begin{Macro}{\chit@tr@ns@nchor,\chit@nchor} +% +% Get anchor of sub-symbol element in chit. We need to do this, +% because the symbol is translated and scaled. +% +% \begin{macrocode} +\def\chit@tr@ns@nchor#1{% + \pgf@x=0.4\pgf@x% + \pgf@y=0.4\pgf@y\advance\pgf@y#1} +% \end{macrocode} +% +% \begin{macrocode} +\def\chit@nchor#1#2#3{% + \wg@sub@nchor{#1}{#2} + \chit@tr@ns@nchor{#3}} +\def\chit@report{} +\tikzset{ + zone turn/.style={}, + zone mult/.style={} +} +% \end{macrocode} +% \end{Macro} +% +% Now follows the actual \text{chit} shape. This is rather long, so +% we will break it up a bit +% +% +% The first thing is we declare some saved anchors. These are +% computed (and defined as internal macros) when the shape is +% instantised. The anchors give the centre and north east corner of +% the node, the place to put the NATO App6(c) symbol and factors. We +% also set a dimension for the margins (corner and factors elements). +% +% \begin{macrocode} +\pgfdeclareshape{chit}{ + \savedanchor\center{\pgf@x=0cm\pgf@y=0cm} + \savedanchor\northeast{\pgf@x=0.6cm\pgf@y=0.6cm} + \savedanchor\symbol{\pgf@x=0cm\pgf@y=0.2cm} + \savedanchor\factors{\pgf@x=0cm\pgf@y=-0.5cm} + \saveddimen\margin{\pgf@x=0.04cm} +% \end{macrocode} +% +% Next, we define some saved macros. These are called (and declares +% internal macros) when the shape is instantised. We define macros +% for the identifier, +% +% +% \begin{macrocode} + \savedmacro\id{% + \chit@dbg{4}{Chit ID: \meaning\chit@id}% + \@ifundefined{chit@id}{\let\chit@id\pgfutil@empty}{}% + \ifx\chit@id\pgfutil@empty% + \wg@r@ndom@id% + \edef\id{chit\wg@uuid}% + \else% + \edef\id{\chit@id}% + \fi% + \chit@dbg{4}{Chit ID stored: \meaning\chit@id} + } + \savedmacro\chitframeopt{% + \let\chitframeopt\pgfutil@empty% + \@ifundefined{chit@frame}{}{% + \edef\chitframeopt{\chit@frame}} + \n@to@pp@dbg{3}{Chit Frame options: \meaning\chitframeopt}% + } +% \end{macrocode} +% +% We define the regular anchors of the shape. That is, the centre, +% corners, and edges. +% +% \begin{macrocode} + \anchor{center}{\center} + \anchor{north east}{\northeast} + \anchor{north west}{\northeast\pgf@x=-\pgf@x} + \anchor{south west}{\northeast\pgf@x=-\pgf@x\pgf@y=-\pgf@y} + \anchor{south east}{\northeast\pgf@y=-\pgf@y} + \anchor{north} {\northeast\pgf@x=0cm} + \anchor{south} {\northeast\pgf@x=0cm\pgf@y=-\pgf@y} + \anchor{east} {\northeast\pgf@y=0cm} + \anchor{west} {\northeast\pgf@x=-\pgf@x\pgf@y=0cm} +% \end{macrocode} +% +% Next, we want to be able to reference the symbol anchors too. So we +% define these anchors from the embedded node anchors. Note, these +% anchors will not exist if the chit is made with +% \texttt{full=}\meta{args}. +% +% \begin{macrocode} + \anchor{symbol north east}{\chit@nchor{M\id symbol}{north east}{0.2cm}} + \anchor{symbol north west}{\chit@nchor{M\id symbol}{north west}{0.2cm}} + \anchor{symbol south east}{\chit@nchor{M\id symbol}{south east}{0.2cm}} + \anchor{symbol south west}{\chit@nchor{M\id symbol}{south west}{0.2cm}} + \anchor{symbol north} {\chit@nchor{M\id symbol}{north}{0.2cm}} + \anchor{symbol west} {\chit@nchor{M\id symbol}{west}{0.2cm}} + \anchor{symbol south} {\chit@nchor{M\id symbol}{south}{0.2cm}} + \anchor{symbol east} {\chit@nchor{M\id symbol}{east}{0.2cm}} + \anchor{symbol upper} {\chit@nchor{M\id symbol}{upper}{0.2cm}} + \anchor{symbol lower} {\chit@nchor{M\id symbol}{lower}{0.2cm}} + \anchor{symbol left} {\chit@nchor{M\id symbol}{left}{0.2cm}} + \anchor{symbol right} {\chit@nchor{M\id symbol}{right}{0.2cm}} + \anchor{symbol echelon} {\chit@nchor{M\id symbol}{north}{0.2cm}} + \anchor{symbol below} {\chit@nchor{M\id symbol}{south}{0.1cm}} +% \end{macrocode} +% +% Some anchors to sub-elements. Some of them only exists if we have +% NATO App6(c) symbol in the chit. +% +% \begin{macrocode} + \anchor{symbol} {\symbol} + \anchor{factors} {\factors} + \anchor{left} {\chit@nchor{M\id symbol}{west}{.2cm}\advance\pgf@x-\margin} + \anchor{right}{\chit@nchor{M\id symbol}{east}{.2cm}\advance\pgf@x+\margin} + \anchor{upper right} {% + \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin% + } + \anchor{upper left}{ + \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin \pgf@x=-\pgf@x% + } + \anchor{lower right} {% + \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin \pgf@y=-\pgf@y% + } + \anchor{lower left}{ + \northeast \advance\pgf@x-\margin \advance\pgf@y-\margin% + \pgf@x=-\pgf@x \pgf@y=-\pgf@y% + } +% \end{macrocode} +% +% Now for the actual path. For the background path, we simply specify +% the frame. This is so that this will get drawn (and possibly +% filled) using the appropriate options. +% +% \begin{macrocode} + \backgroundpath{% + %% This is the outline of the chit only. The rest of the chit is + %% made on the foreground "path". + \northeast% + \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y% + \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \pgfclosepath + } +% \end{macrocode} +% +% Finally, we make the foreground rendered path. This is where we do +% the most stuff. We do it in the \emph{behind} foreground path so +% that we can ensure things are drawn the way we want it. +% +% The first thing is to set-up the clipping to the chit frame. +% +% \begin{macrocode} + \behindforegroundpath{% + \chit@dbg{4}{% + Chit foreground: \meaning\id + ^^J ID (set): \meaning\chit@id + ^^J Symbol: \meaning\chit@symbol + ^^J Full: \meaning\chit@full + ^^J Factors: \meaning\chit@factors + ^^J Left: \meaning\chit@left + ^^J Right: \meaning\chit@right + ^^J Upper left: \meaning\chit@upper@left + ^^J Lower left: \meaning\chit@lower@left + ^^J Upper right: \meaning\chit@upper@right + ^^J Lower right: \meaning\chit@lower@right} + \chit@report{} + \pgfscope + % + \northeast% + \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y% + \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \pgfclosepath + \pgfusepath{clip} +% \end{macrocode} +% +% If we do not have the \texttt{symbol} key set, then we set the +% \texttt{full} key as a picture. +% +% \begin{macrocode} + \@ifundefined{chit@symbol}{% + %% Draw full stuff + \@ifundefined{chit@full}{}{% + \center\wg@tmpa=\pgf@x\wg@tmpb=\pgf@y% + \wg@pic@all{\chit@full}{}{\the\wg@tmpa,\the\wg@tmpb}{chit/full}}% + }{% +% \end{macrocode} +% +% Otherwise, we put in a node with shape \texttt{natoapp6c} and pass +% the \texttt{symbol} key--value pairs as options. +% +% \begin{macrocode} + \edef\symid{\id symbol}% + \symbol% + \edef\args{{\symid}{\the\pgf@x,\the\pgf@y}\chit@symbol}% + \chit@dbg{6}{Arguments to chit NATO symbol: \meaning\args}% + \expandafter\chit@n@to\args\@end@chit@n@to% + \chit@dbg{6}{After making NATO symbol in chit}% +% \end{macrocode} +% +% Having made the NATO App6(c) symbol, which we gave the node name +% \meta{id}\texttt{symbol} where \meta{id} is the ID of this chit, we +% can make the rest of the chit elements. These are the left and +% right elements, which are set west and east of the symbol, +% respectively; the factors; and the four corner elements. +% +% If the respective elements have not been specified, we do not make +% them. +% +% First the left and right elements. Note that these uses the anchors +% of the embedded \texttt{natoapp6c} node for placement. +% +% \begin{macrocode} + % Put in left of symbol + \@ifundefined{chit@left}{}{% + \begin{scope}[] + \pgfpointanchor{\symid}{west}% + \wg@tmpa=\pgf@x\advance\wg@tmpa-\margin% + \wg@tmpb=\pgf@y% + \wg@pic@all{\chit@left}{}{\the\wg@tmpa,\the\wg@tmpb}{chit/left}% + \end{scope}}% + % Put in right of symbol + \@ifundefined{chit@right}{}{% + \begin{scope}[] + \pgfpointanchor{\symid}{east}% + \wg@tmpa=\pgf@x\advance\wg@tmpa+\margin% + \wg@tmpb=\pgf@y% + \wg@pic@all{\chit@right}{}{\the\wg@tmpa,\the\wg@tmpb}{chit/right}% + \end{scope}}% +% \end{macrocode} +% +% Next, we want to put in the corner elements. But before we do +% that, we use our saved anchors and dimensions to calculate the +% coordinates. Note that the corner elements are anchored to the +% corners (plus margin) of the chit frame. +% +% \begin{macrocode} + % Get coordinates + \northeast% + \wg@tmpa=\pgf@x% + \wg@tmpb=\pgf@y% + \advance\wg@tmpa-\margin% + \advance\wg@tmpb-\margin% +% \end{macrocode} +% +% With the coordinates extracted, we set the four corner +% elements. Note, for the anchoring to work, we should specify +% pictures that have anchors (e.g., nodes). If not, we must take care +% to give offsets or the like. +% +% \begin{macrocode} + % Put in upper left corner + \@ifundefined{chit@upper@left}{}{% + \begin{scope}[] + \wg@pic@all{\chit@upper@left}{}{-\the\wg@tmpa,\the\wg@tmpb}{% + chit/upper left}% + \end{scope}} + % Put in upper right corner + \@ifundefined{chit@upper@right}{}{% + \begin{scope}[] + \wg@pic@all{\chit@upper@right}{}{\the\wg@tmpa,\the\wg@tmpb}{% + chit/upper right}% + \end{scope}} + % Put in lower left corner + \@ifundefined{chit@lower@left}{}{% + \begin{scope}[] + \wg@pic@all{\chit@lower@left}{}{-\the\wg@tmpa,-\the\wg@tmpb}{% + chit/lower left}% + \end{scope}} + % Put in lower right corner + \@ifundefined{chit@lower@right}{}{% + \begin{scope}[] + \wg@pic@all{\chit@lower@right}{}{\the\wg@tmpa,-\the\wg@tmpb}{% + chit/lower right}% + \end{scope}} +% \end{macrocode} +% +% Finally, we put in the unit factors. They are put at the bottom of +% the chit frame (plus margin) and are typically anchored to the south +% anchor of the element. Note, we can put in several factors if need +% be. +% +% \begin{macrocode} + % Put in factors + \@ifundefined{chit@factors}{}{% + \advance\wg@tmpb-\margin% + \begin{scope}[] + \wg@pic@all{\chit@factors}{}{0,-\the\wg@tmpb}{chit/factors}% + \end{scope}}% + }% + \endpgfscope% + % Draw frame? + \edef\tmp@opt{[\chitframeopt]} + \expandafter\scope\tmp@opt + \northeast% + \wg@tmpa=\pgf@x\wg@tmpb=\pgf@y% + \pgfpathmoveto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpb=-\wg@tmpb \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \wg@tmpa=-\wg@tmpa \pgfpathlineto{\pgfqpoint{\wg@tmpa}{\wg@tmpb}}% + \pgfclosepath + \pgfusepath{stroke} + \endscope + } +} +% \end{macrocode} +% +% \iffalse +% -------------------------------------------------------------------- +% \fi +% \subsubsection{The \cs{chit} wrapper macro} +% +% \begin{Macro}{\chit,\chit@,\chit@@} +% +% The macro to make the chits. This is a wrapper around a +% \texttt{node} with shape \texttt{chit}. The syntax of this macro +% is +% +% \begin{Syntax} +% \cs{chit}\oarg{chit options}\parg{position}\parg{identifier}; +% \end{Syntax} +% +% Note that the trailing semi-colon is optional. Here \meta{chit +% options} are any key-value pairs in the \texttt{/chit} (and +% \texttt{/tikz}) namespace. +% +% The first macro parses for options. +% +% \begin{macrocode} +\def\chit{% + \chit@dbg{5}{Chit} + \@ifnextchar[{\chit@}{\chit@[]}%] +} +% \end{macrocode} +% +% Parse for coordinates. +% +% \begin{macrocode} +\def\chit@[#1]{% + \chit@dbg{5}{Chit second: `#1'} + \@ifnextchar({\chit@@{#1}}{\chit@@{#1}(0,0)}%) +} +% \end{macrocode} +% +% Parse for name. +% +% \begin{macrocode} +\def\chit@@#1(#2){% + \@ifnextchar({\chit@@@{#1}{#2}}{\chit@@@{#1}{#2}()}%) +} +% \end{macrocode} +% +% The work horse. This simply makes a \cs{node} with the shape +% \texttt{chit}. Note, we allow for a trailing semi-colon +% (\texttt{;}) to have a similar feel to other \TikZ{} macros. +% +% \begin{macrocode} +\def\chit@@@#1#2(#3){% + \chit@dbg{5}{Chit final: + ^^J Options: #1 + ^^J Position: #2 + ^^J Name: `#3'} + \let\name\pgfutil@empty% + \chit@dbg{1}{=== Before chit node}% + \node[draw,chit={every chit/.try,id=#3,#1}] (tmp) at (#2) {}; + \chit@dbg{2}{=== After chit node}% + \ifx|#3|\relax% + \else% + \chit@dbg{3}{=== Renaming chit to user defined name `#3'}% + \pgfnoderename{#3}{tmp}% + \fi% + \@ifnextchar;{\@gobble}{}% +} +% \end{macrocode} +% \end{Macro} +% \iffalse +% </chit> +% -------------------------------------------------------------------- +% \fi |