summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tikz-timing/tikz-timing-counters.sty
blob: 04a1488b15de86ed133fcf57d37679a8cbf22838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
%%
%% This is file `tikz-timing-counters.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tikz-timing.dtx  (with options: `lib,lib-counters')
%% 
%% Copyright (C) 2009 by Martin Scharrer <martin@scharrer-online.de>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008/05/04 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Martin Scharrer.
%% 
%% This work consists of the files tikz-timing.dtx, tikz-timing.ins
%% and the derived file tikz-timing.sty.
%% 
\RequirePackage{svn-prov}[2009/05/03]
\ProvidesPackageSVN[tikz-timing-counters]
  {$Id: tikz-timing.dtx 1657 2010-01-17 13:26:00Z martin $}
  [v0.7b
   TikZ-Timing Library for
   counter values]
\GetFileInfoSVN*%
\RequirePackage{tikz-timing}[\filedate]%
\DefineFileInfoSVN
\newif\if@tikztiming@counter@wraps

\tikzset{%
  timing/new counter/.style={timing/counter/new={#1}},
  timing/counter/.cd,
  new/.code={\tikztiming@counter@new{#1}},
  new/.value required,
  opt/.cd,
  char/.initial=,
  char/.value required,
  reset char/.initial=,
  reset char/.value required,
  reset type/.is choice,
  reset type/width/.code={\def\tikztiming@resettype{0}},
  reset type/arg/.code={\def\tikztiming@resettype{1}},
  reset type/both/.code={\def\tikztiming@resettype{2}},
  reset type/Both/.code={\def\tikztiming@resettype{3}},
  half width char/.initial=,
  half width char/.value required,
  base/.initial=10,
  base/.value required,
  increment/.initial=1,
  increment/.value required,
  max value/.initial=,
  max value/.value required,
  min value/.initial=,
  min value/.value required,
  wraps/.is if=@tikztiming@counter@wraps,
  digits/.initial=,
  digits/.value required,
  fg style/.initial=,
  bg style/.initial=,
  text style/.initial=,
  text format/.initial=,
  fg style/.value required,
  bg style/.value required,
  text style/.value required,
  text format/.value required,
}
\def\tikztiming@counter@textformat{}%
\def\tikztimingcounter#1{%
  \csname tikztiming@counter@#1\endcsname
}
\def\tikztimingsetcounter#1#2{%
  \begingroup
    \pgfmathtruncatemacro\@tempa{#2}%
    \expandafter\global\expandafter\let\csname tikztiming@counter@#1\endcsname\@tempa
  \endgroup
}
\def\tikztiming@counter@new#1{%
 \begingroup
  \def\tikztiming@resettype{0}%
  \pgfqkeys{/tikz/timing/counter/opt}{#1}%
  \tikzset{timing/counter/opt/char/.get=\counterchar}%
  \ifx\counterchar\empty
    \PackageError{tikz-timing-counters}{Counter character must be given using
    the 'char' key!}{}{}{}%
    \endgroup
  \else
    \pgfkeys{/tikz/timing/counter/opt/min value/.get=\min}%
    \pgfkeys{/tikz/timing/counter/opt/max value/.get=\max}%
    \if@tikztiming@counter@wraps
      \ifx\min\empty
        \def\min{0}%
      \fi
      \ifx\max\empty
        \PackageError{tikz-timing-counters}{The option 'wraps' needs the option 'max value' to be set!}{}{}{}%
      \fi
      \def\@tempb{%
        \noexpand\tikztiming@counter@wrap%
          {\expandafter\unexpanded\expandafter{\min}}%
          {\expandafter\unexpanded\expandafter{\max}}%
      }%
    \else
      \ifx\min\empty
        \ifx\max\empty
          \let\@tempb\empty
        \else
          \def\@tempb{%
            \noexpand\tikztiming@counter@maxsat%
              {\expandafter\unexpanded\expandafter{\max}}%
          }%
        \fi
      \else
        \ifx\max\empty
          \def\@tempb{%
            \noexpand\tikztiming@counter@minsat%
              {\expandafter\unexpanded\expandafter{\min}}%
          }%
        \else
          \def\@tempb{%
            \noexpand\tikztiming@counter@minmaxsat%
              {\expandafter\unexpanded\expandafter{\min}}%
              {\expandafter\unexpanded\expandafter{\max}}%
          }%
        \fi
      \fi
    \fi
    \pgfkeys{/tikz/timing/counter/opt/fg style/.get=\fgstyle}%
    \pgfkeys{/tikz/timing/counter/opt/bg style/.get=\bgstyle}%
    \pgfkeys{/tikz/timing/counter/opt/text style/.get=\textstyle}%
    \pgfkeys{/tikz/timing/counter/opt/text format/.get=\textformat}%
    \pgfkeys{/tikz/timing/counter/opt/increment/.get=\increment}%
    \edef\@tempa{%
      \noexpand\tikztiming@counter@new@
        {\pgfkeysvalueof{/tikz/timing/counter/opt/char}}%
        {\pgfkeysvalueof{/tikz/timing/counter/opt/base}}%
        {\pgfkeysvalueof{/tikz/timing/counter/opt/half width char}}%
        {\pgfkeysvalueof{/tikz/timing/counter/opt/reset char}}%
        {\pgfkeysvalueof{/tikz/timing/counter/opt/digits}}%
        {\expandafter\unexpanded\expandafter{\increment}}%
        {\@tempb}%
        {\min}%
        {\tikztiming@resettype}%
        {\expandafter\unexpanded\expandafter{\fgstyle}}%
        {\expandafter\unexpanded\expandafter{\bgstyle}}%
        {\expandafter\unexpanded\expandafter{\textstyle}}%
        {\expandafter\unexpanded\expandafter{\textformat}}%
    }%
    \expandafter\expandafter\expandafter\endgroup
    \expandafter\@tempa
  \fi
}
\def\tikztiming@counter@new@#1#2#3#4#5#6#7#8#9{%
  \ifx\empty#8\empty
    \@namedef{tikztiming@counter@#1}{0}%
  \else
    \expandafter
    \pgfmathtruncatemacro\csname tikztiming@counter@#1\endcsname{#8}%
  \fi
  \tikztimingmetachar{#1}[1]{ { [timing/counter/#1] ##1D{[timing/counter/#1/text]\tikztiming@counter@vs{#1}{#2}{#5}{#6}{#7}} } }%
  \ifx\empty#3\empty
      \tikztiming@iflower{#1}{}%
        {\lowercase{\tikztimingmetachar{#1}}[1]%
          { { [timing/counter/#1] ##1d{[timing/counter/#1/text]\tikztiming@counter@vs{#1}{#2}{#5}{#6}{#7}}} }%
        }%
  \else
    \tikztimingmetachar{#3}[1]{%
      { [timing/counter/#1] ##1d{[timing/counter/#1/text]\tikztiming@counter@vs{#1}{#2}{#5}{#6}{#7}} }%
    }%
  \fi
  \ifx\empty#4\empty\else
    \ifcase0#9\relax
      \tikztimingmetachar{#4}[1]{[|/utils/exec=\tikztiming@counter@reset{#1}{##1}|]}%
    \or
      \tikztimingmetachar{#4}[2]{[|/utils/exec=\tikztimingsetcounter{#1}{##2}|]}%
    \or
      \uppercase{\tikztimingmetachar{#4}}[1]{[|/utils/exec=\tikztiming@counter@reset{#1}{##1}|]}%
      \lowercase{\tikztimingmetachar{#4}}[2]{[|/utils/exec=\tikztimingsetcounter{#1}{##2}|]}%
    \or
      \lowercase{\tikztimingmetachar{#4}}[1]{[|/utils/exec=\tikztiming@counter@reset{#1}{##1}|]}%
      \uppercase{\tikztimingmetachar{#4}}[2]{[|/utils/exec=\tikztimingsetcounter{#1}{##2}|]}%
    \fi
  \fi
  \tikztiming@counter@new@@{#1}%
}
\def\tikztiming@counter@new@@#1#2#3#4#5{%
  \tikzset{timing/counter/#1/.style={}}%
  \ifx\empty#2\empty\else
    \tikzset{timing/counter/#1/.append style={%
      /tikz/timing/d/.style={#2}%
    }}%
  \fi
  \ifx\empty#3\empty\else
    \tikzset{timing/counter/#1/.append style={%
      /tikz/timing/d/background/.style={#3}%
    }}%
  \fi
  \tikzset{timing/counter/#1/text/.style={#4}}%
  \ifx\empty#5\empty\else
    \tikzset{timing/counter/#1/.append style={%
      /utils/exec={\def\tikztiming@counter@textformat{#5}}%
    }}%
  \fi
}
\def\tikztiming@counter@reset#1#2{%
  \begingroup
    \pgfmathtruncatemacro\@tempa{round((#2)/\tikztiming@wscale)}%
    \expandafter\global\expandafter\let\csname tikztiming@counter@#1\endcsname\@tempa
  \endgroup
}
\def\tikztiming@counter@vs#1#2#3#4#5{%
  \begingroup
    \ifx\empty#3\empty\else
      \pgfmathsetbasenumberlength{#3}%
    \fi
    \ifnum#2=10
      \expandafter\expandafter\expandafter\tikztiming@counter@textformat
      \expandafter\expandafter\expandafter{\csname tikztiming@counter@#1\endcsname}%
    \else
      \pgfmathdectoBase\pgfmathresult{\@nameuse{tikztiming@counter@#1}}{#2}%
      \expandafter\tikztiming@counter@textformat\expandafter{\pgfmathresult}%
    \fi
    \edef\N{\@nameuse{tikztiming@counter@#1}}%
    \pgfmathtruncatemacro\N{\N + #4}%
    #5%
    \expandafter\global\expandafter\let\csname tikztiming@counter@#1\endcsname\N
  \endgroup
}
\def\tikztiming@counter@minsat#1{%
  \pgfmathtruncatemacro\MIN{#1}%
  \ifnum\N<\MIN \let\N\MIN \fi
}
\def\tikztiming@counter@maxsat#1{%
  \pgfmathtruncatemacro\MAX{#1}%
  \ifnum\N>\MAX \let\N\MAX \fi
}
\def\tikztiming@counter@minmaxsat#1#2{%
  \tikztiming@counter@minsat{#1}%
  \tikztiming@counter@maxsat{#2}%
}
\def\tikztiming@counter@wrap#1#2{%
  \pgfmathtruncatemacro\MIN{#1}%
  \pgfmathtruncatemacro\MAX{#2}%
  \ifnum\N>\MAX
    \pgfmathtruncatemacro\N{\MIN + (\N-\MAX-1)}%
  \fi
  \ifnum\N<\MIN
    \pgfmathtruncatemacro\N{\MAX - (\MIN-\N+1)}%
  \fi
}
\RequirePackage{pgfopts}
\ProcessPgfOptions{/tikz/timing/counter}
\endinput
%%
%% End of file `tikz-timing-counters.sty'.