summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pgf/compatibility/pgfautomata.sty
blob: 965fa30fed7b17891a0e5615b2a5b706eada57c9 (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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\RequirePackage{pgfrcs}

\ProvidesPackageRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/latex/pgf/compatibility/pgfautomata.sty,v 1.3 2006/10/11 15:22:27 tantau Exp $


\RequirePackage{pgf}

\PackageWarning{pgfautomata}{This package is obsolete.}

\ProcessOptions

%
% Package for drawing finite automata. 
%


\newdimen\pgf@stateradius
\newdimen\pgf@mooreradius
\newdimen\pgf@doublethickness
\newdimen\pgf@statebackoff




% Automaton environment - setup of certain drawing parameters like arrows.
%
% Example:
%
% \begin{pgfpicture}{-2cm}{-2cm}{2cm}{2cm}%
%   \begin{pgfautomaton}
%     \pgfstaterejecting{q1}{\pgforigin}{$q_1$}
%     \pgfstateaccepting{q2}{\pgfstaterelative[east]{q1}{1cm}}{$q_2$}
%     \pgfstateaccepting{q3}{\pgfstaterelative[east]{q2}{1cm}}{$q_3$}
%
%     \pgfstateconnect{q1}{q2}[.5]{$0$}
%     \pgfstateconnect{q2}{q3}[.5]{$1$}
%     \pgfstateloop{q1}{90}{$1$}
%     \pgfstateloop{q2}{90}{$1$}
%   \end{pgfautomaton}
% \end{pgfpicture}

\def\pgfautomaton{\begin{pgfscope}%
  \pgfsetendarrow{\pgfarrowto}%
  \pgfnodesetsepend{4pt}\ignorespaces}
\def\endpgfautomaton{\end{pgfscope}}



% Set the outer state radius to #1.
% 
% #1 = new state radius.
% 
% Example:
%
% \pgfsetstateradius{10pt}

\def\pgfsetstateradius#1{\setlength\pgf@stateradius{#1}\ignorespaces}

\pgfsetstateradius{1em}



% Set the state radius for Moore states to #1.
% 
% #1 = new state radius.
% 
% Example:
%
% \pgfsetstatemooreradius{10pt}

\def\pgfsetstatemooreradius#1{\setlength\pgf@mooreradius{#1}\ignorespaces}

\pgfsetstatemooreradius{2em}



% Set the distance between the outer and the inner circle in an
% accepting state.
% 
% #1 = new distance radius.
% 
% Example:
%
% \pgfsetstatecircledistance{1.2pt}

\def\pgfsetstatecircledistance#1{\setlength\pgf@doublethickness{#1}\ignorespaces}

\pgfsetstatecircledistance{1.6pt}



% Set the distance between a connecting line and a label to #1.
% 
% #1 = new distance
% 
% Example:
%
% \pgfsetstatelabeldistance{4pt}

\def\pgfsetstatelabeldistance#1{\setlength\pgf@statebackoff{#1}\ignorespaces}

\pgfsetstatelabeldistance{4pt}


% Draws an accepting state #1 with name #3 at position #2.
%
% #1 = a name
% #2 = a point
% #3 = a text
%
% Example:
%
% \pgfstateaccepting{q1}{\pgfxy(1,1)}{$q_1$}

\def\pgfstateaccepting#1#2#3{%
  \pgfnodecircle{#1}[stroke]{#2}{\pgf@stateradius}%
  \pgfputat{#2}{\pgfbox[center,center]{#3}}%
  {%
  \pgf@xa=\pgf@stateradius%
  \advance\pgf@xa by-\pgf@doublethickness%
  \pgfcircle[stroke]{#2}{\pgf@xa}}\ignorespaces}


% Draws a rejecting state #1 with name #3 at position #2.
%
% #1 = a name
% #2 = a point
% #3 = a text
%
% Example:
%
% \pgfstaterejecting{q2}{\pgfstatedirection[n]{q1}}{$q_2$}

\def\pgfstaterejecting#1#2#3{%
  \pgfnodecircle{#1}[stroke]{#2}{\pgf@stateradius}%
  \pgfputat{#2}{\pgfbox[center,center]{#3}}\ignorespaces}


% Draws a Moore state #1 with name #3 and output #4 at position #2.
%
% #1 = a name
% #2 = a point
% #3 = a text
% #4 = an output text
%
% Example:
%
% \pgfstatemoore{q}{\pgfxy(1,1)}{$q_1$}{$0,1$}

\def\pgfstatemoore#1#2#3#4{%
  \pgfnodecircle{#1}[stroke]{#2}{\pgf@mooreradius}%
  \begin{pgftranslate}{#2}%
    \begin{pgfscope}%
      \pgfsetdash{{2pt}{1pt}}{0pt}%
      \pgfmoveto{\pgfpoint{-\pgf@mooreradius}{0cm}}%
      \pgflineto{\pgfpoint{\pgf@mooreradius}{0cm}}%
      \pgfqstroke%
    \end{pgfscope}%       
    \pgfputat{\pgfpoint{0cm}{0.4\pgf@mooreradius}}{\pgfbox[center,base]{#3}}%
    \pgfputat{\pgfpoint{0cm}{-0.2\pgf@mooreradius}}{\pgfbox[center,top]{#4}}%
  \end{pgftranslate}\ignorespaces}




% Connect states #1 and #2 and draw #4 above label, #3-th part of the
% way from #1 to #2.
%
% #1 = a start state
% #2 = an end state
% #3 = a fraction of the distance between the two
% #4 = a label
%
% Example:
%
% \pgfstateconnect{q1}{q2}[.5]{$0$}

\def\pgfstateconnect#1#2[#3]#4{%
  \pgfnodeconnline{#1}{#2}%
  \pgfnodelabel{#1}{#2}[#3][\pgf@statebackoff]%
    {\pgfbox[center,bottom]{#4}}\ignorespaces}


  
% Connect states #1 and #2 and draw #4 above label, #3-th part of the
% way from #1 to #2.
%
% #1 = a start state
% #2 = an end state
% #3 = a fraction of the distance between the two
% #4 = a label
%
% Example:
%
% \pgfstateconnectrotated{q1}{q2}[.5]{$0$}

\def\pgfstateconnectrotated#1#2[#3]#4{%
  \pgfnodeconnline{#1}{#2}%
  \pgfnodelabelrotated{#1}{#2}[#3][\pgf@statebackoff]%
    {\pgfbox[center,bottom]{#4}}\ignorespaces}


  
% Connect state #1 with itself with label #3 and a loop going in
% direction #2.
%
% #1 = a state
% #2 = an angle
% #3 = a label
%
% Example:
%
% \pgfstateloop{q1}{90}{$0$}

\def\pgfstateloop#1#2#3{%
  \c@pgf@counta=#2\relax%
  \c@pgf@countb=#2\relax%
  \advance\c@pgf@counta by15\relax%
  \advance\c@pgf@countb by-15\relax%
  \pgfnodeconncurve{#1}{#1}{\the\c@pgf@counta}{\the\c@pgf@countb}{2\pgf@stateradius}{2\pgf@stateradius}%
  \pgfputat{\pgfnodeborder{#1}{#2}{2.25\pgf@stateradius}}{\pgfbox[center,center]{#3}}\ignorespaces}



% Connect states #1 and #2 and draw #4 above label, #3-th part of the
% way from #1 to #2.
%
% #1 = a start state
% #2 = an end state
% #3 = a start angle
% #4 = an end angle
%
% Example:
%
% \pgfstatecurve{q1}{q2}{10}{-10}

\def\pgfstatecurve#1#2#3#4{%
  \pgfnodeconncurve{#1}{#2}{#3}{#4}{2\pgf@stateradius}{2\pgf@stateradius}\ignorespaces}

  

% Give a position relative to some state.
%
% #1 = a direction
% #2 = a state
% #3 = a distance
%
% Example:
%
% \pgfstaterelative[east]{q2}{1cm}

\def\pgfstaterelative{\pgfnoderelative}


  
% Draw an initial state by drawing an inleading line.
%
% #1 = a state
% #2 = a direction leading into the state (n,s,e,w)
% #3 = a label (for example ``start'')
%
% Example:
%
% \pgfstateinitial{q1}[w]{start}

\def\pgfstateinitial#1[#2]#3{{%
    \pgfmoveto{\pgfrelative{\pgfnodeborder{#1}{\pgfdirection{#2}}{-2pt}}%
      {\pgfpolar{\pgfdirection{#2}}{1.5\pgf@stateradius}}}%
    \pgflineto{\pgfnodeborder{#1}{\pgfdirection{#2}}{\pgf@nodesepend}}%
    \pgfstroke%
    \edef\temp{[\csname pgf@statepos\pgfdirection{#2}\endcsname]}%
    \pgfputat{\pgfrelative{\pgfnodeborder{#1}{\pgfdirection{#2}}{0pt}}%
      {\pgfpolar{\pgfdirection{#2}}{1.5\pgf@stateradius}}}%
    {\expandafter\pgfbox\temp{#3}}}\ignorespaces}

\expandafter\def\csname pgf@statepos0\endcsname{left,center}
\expandafter\def\csname pgf@statepos90\endcsname{center,bottom}
\expandafter\def\csname pgf@statepos180\endcsname{right,center}
\expandafter\def\csname pgf@statepos270\endcsname{center,top}



% Draw an final state by drawing an outleading line.
%
% #1 = a state
% #2 = a direction leading out of the state (valid directions are
%      n,s,e,w) 
% #3 = a label (for example ``exit'')
%
% Example:
%
% \pgfstatefinal{q1}[right]{accept}

\def\pgfstatefinal#1[#2]#3{{%
    \pgfmoveto{\pgfnodeborder{#1}{\pgfdirection{#2}}{\pgf@nodesepstart}}%
    \pgflineto{\pgfrelative{\pgfnodeborder{#1}{\pgfdirection{#2}}{-\pgf@nodesepend}}%
      {\pgfpolar{\pgfdirection{#2}}{1.5\pgf@stateradius}}}%
    \pgfstroke%
    \edef\tempb{[\csname pgf@statepos\pgfdirection{#2}\endcsname]}%
    \pgfputat{\pgfrelative{\pgfnodeborder{#1}{\pgfdirection{#2}}{0pt}}%
      {\pgfpolar{\pgfdirection{#2}}{1.5\pgf@stateradius}}}%
    {\expandafter\pgfbox\tempb{#3}}}\ignorespaces}



\endinput