File: pgfnodes.sty

package info (click to toggle)
pgf 0.65-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 760 kB
  • ctags: 15
  • sloc: sh: 51; makefile: 50
file content (411 lines) | stat: -rw-r--r-- 10,252 bytes parent folder | download | duplicates (4)
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
\ProvidesPackage{pgfnodes}[2004/10/08 ver 0.64]

% Copyright 2003 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt.

\RequirePackage{pgf}

\ProcessOptions


% Defines a circle node of name #1 at position #3 of radius #4.
%
% #1 = a name
% #2 = ``stroke'' or ``fill'' or ``fillstroke'' or ``virtual'' (= draw
%      nothing)
% #3 = a point
% #4 = a radius
%
% Example:
%
% \pgfnodecircle{mynode}[stroke]{\pgfxy(1,1)}{2cm}

\def\pgfnodecircle#1[#2]#3#4{%
  \pgf@process{#3}%
  \expandafter\def\csname pgfno@#1\endcsname{\pgf@backoffcircle{#4}}%
  \expandafter\def\csname pgfnob@#1\endcsname{\pgf@anglecircle{#4}}%
  \expandafter\edef\csname pgfnom@#1\endcsname{\noexpand\pgf@x=\pgfget
    xpt\noexpand\pgf@y=\pgfget ypt}% 
  \expandafter\ifx\csname pgf@@#2\endcsname\pgf@@virtual%
  \else%
  \pgfcircle[#2]{\csname pgfnom@#1\endcsname}{#4}%
  \fi\ignorespaces}

\def\pgf@@virtual{}


% Defines a rectangular node of name #1 with center at position #3 and
% width/height vector #4
%
% #1 = a name
% #2 = ``stroke'' or ``fill'' or ``fillstroke'' or ``virtual'' (= draw
%      nothing)
% #3 = a center
% #4 = width/height vector
%
% Example:
%
% \pgfnoderect{mynode}[stroke]{\pgfxy(1,1)}{\pgfxy(2,2)}

\def\pgfnoderect#1[#2]#3#4{%
  \pgf@process{#3}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{#4}%
  \pgf@x=.5\pgf@x%
  \pgf@y=.5\pgf@y%  
  \expandafter\edef\csname pgfno@#1\endcsname{\noexpand\pgf@backoffrect%
    {\pgfget{x}pt}{\pgfget{y}pt}}%
  \expandafter\edef\csname pgfnob@#1\endcsname{\noexpand\pgf@anglerect%
    {\pgfget{x}pt}{\pgfget{y}pt}}%
  \expandafter\edef\csname
  pgfnom@#1\endcsname{\noexpand\pgf@x=\pgfget{xa}pt\noexpand\pgf@y=\pgfget{ya}pt}% 
  \expandafter\ifx\csname pgf@@#2\endcsname\pgf@@virtual%
  \else%
  \advance\pgf@xa by-\pgf@x%
  \advance\pgf@ya by-\pgf@y%
  \edef\pgf@temp{\noexpand\pgf@x=\pgfget{xa}pt\noexpand\pgf@y=\pgfget{ya}pt}%
  \pgfrect[#2]{\pgf@temp}{#4}%
  \fi\ignorespaces}


% Defines a rectangular node of name #1 with center at position #3 
% contaning a box #4
%
% #1 = a name
% #2 = ``stroke'' or ``fill'' or ``fillstroke'' or ``virtual'' (= draw
%      nothing)
% #3 = a center
% #4 = TeX text that will be boxed
% #5 = a horizontal border offset
% #6 = a vertical border offset
%
% Example:
%
% \pgfnodebox{mynode}[stroke]{\pgfxy(1,1)}{start}{2pt}{2pt}

\def\pgfnodebox#1[#2]#3#4#5#6{%
  \pgf@makehbox{#4}%
  \pgf@x=\wd\pgf@hbox%
  \pgf@y=\ht\pgf@hbox%
  \advance\pgf@y by \dp\pgf@hbox%
  \addtolength\pgf@x{#5}%
  \addtolength\pgf@x{#5}%
  \addtolength\pgf@y{#6}%
  \addtolength\pgf@y{#6}%
  \edef\pgf@boxsize{\noexpand\pgf@x=\the\pgf@x\noexpand\pgf@y=\the\pgf@y}%
  \csname pgf@haligncenter\endcsname%
  \csname pgf@valigncenter\endcsname%
  \wd\pgf@hbox=0pt%
  \pgfputat{#3}{%
  \pgfsys@starthbox%
  \box\pgf@hbox%
  \pgfsys@endhbox}%
  \pgfnoderect{#1}[#2]{#3}{\pgf@boxsize}\ignorespaces}




% Retrieves the center of #1.
%
% #1 = a node name
%
% Example:
%
% \pgfmoveto{\pgfnodecenter{mynode}}

\def\pgfnodecenter#1{%
  \expandafter\ifx\csname pgfnom@#1\endcsname\relax%
  \GenericError{\space\space\space\@spaces\@spaces\@spaces}%
  {PGF Error: Node "#1" undefined.}{}{\@ehc}%
  \pgfpoint{0pt}{0pt}%
  \else\csname pgfnom@#1\endcsname\fi\ignorespaces}



% Returns a position relative to the center of #1.
%
% #1 = a node name
% #2 = a direction (see \pgfdirection)
% #3 = a distance
%
% Example:
%
% \pgfmoveto{\pgfnoderelative{mynode}[north]{1cm}}

\def\pgfnoderelative#1[#2]#3{%
  \pgfrelative{\pgfnodecenter{#1}}{\pgfpolar{\pgfdirection{#2}}{#3}}\ignorespaces}



% Retrieves a border point of #1 at angle #2 and distance #3 from
% border. 
%
% #1 = a node name
% #2 = an angle
% #3 = a distance from the border
%
% Example:
%
% \pgfmoveto{\pgfnodeborder{first}{30}{0pt}}
% \pgflineto{\pgfnodeborder{second}{180}{2pt}}
% \pgfstroke

\def\pgfnodeborder#1#2#3{%
  \csname pgfnob@#1\endcsname{#3}{#2}{\pgfnodecenter{#1}}\ignorespaces}



% Gives the beginning of a connection of #2 and #3, taking a
% separation distance of #1 into account.
%
% #1 = a separation distance
% #2 = a node name
% #3 = a second node name
%
% Example:
%
% \pgfmoveto{\pgfnodeconnstart{first}{second}}
% \pgflineto{\pgfnodeconnstart{second}{first}}

\def\pgfnodeconnstart[#1]#2#3{%
  \csname pgfno@#2\endcsname[#1]{\pgfnodecenter{#2}}{\pgfnodecenter{#3}}%
  \ignorespaces}



\newdimen\pgf@nodesepstart
\newdimen\pgf@nodesepend

% Sets the node separation for starts of lines.
%
% #1 = a distance
%
% Example:
%
% \pgfnodesetsepstart{2pt}

\def\pgfnodesetsepstart#1{\setlength\pgf@nodesepstart{#1}\ignorespaces}

\pgfnodesetsepstart{0pt}


% Sets the node separation for end of lines.
%
% #1 = a distance
%
% Example:
%
% \pgfnodesetsepend{2pt}

\def\pgfnodesetsepend#1{\setlength\pgf@nodesepend{#1}\ignorespaces}

\pgfnodesetsepend{0pt}




% Draws a line from #1 to #2.
%
% #1 = a node name
% #2 = a second node name
%
% Example:
%
% \pgfnodeconnline{first}{second}

\def\pgfnodeconnline#1#2{%
  \pgfmoveto{\pgfnodeconnstart[\pgf@nodesepstart]{#1}{#2}}%
  \pgflineto{\pgfnodeconnstart[\pgf@nodesepend]{#2}{#1}}%
  \pgfstroke%
  \ignorespaces}



% Draws a curve from #1 to #2. The starting angle at #1 is #3 and the
% length to the first support point is #5. The starting angle at #2
% is #4 and the length to the second support point is #6. 
%
% #1 = a node name
% #2 = a second node name
% #3 = angle at first node
% #4 = angle at second node
% #5 = distance to support point at first node
% #6 = distance to support point at second node
%
% Example:
%
% \pgfnodeconncurve{first}{second}{10}{-10}{1cm}{1cm}

\def\pgfnodeconncurve#1#2#3#4#5#6{%
  \pgfmoveto{\pgfnodeborder{#1}{#3}{\pgf@nodesepstart}}%
  \pgfbezier{\pgfnodeborder{#1}{#3}{#5}}{\pgfnodeborder{#2}{#4}{#6}}%
           {\pgfnodeborder{#2}{#4}{\pgf@nodesepend}}%
  \pgfstroke\ignorespaces}




% Put a label on a line from #1 to #2.
%
% #1 = a node name
% #2 = a second node name
% #3 = fraction of way from #1 to #2
% #4 = vertical offset
% #5 = label
%
% Example:
%
% \pgfnodelabel{first}{second}[.5][2pt]{\pgfbox[center,base]{owns}}

\def\pgfnodelabel#1#2[#3][#4]#5{%
  \pgfputat{\pgflabel%
    {#3}%
    {\pgfnodeconnstart[\pgf@nodesepstart]{#1}{#2}}%
    {\pgfnodeconnstart[\pgf@nodesepend]{#2}{#1}}%
    {#4}}%
  {#5}\ignorespaces}


% Put a rotated label on a line from #1 to #2.
%
% #1 = a node name
% #2 = a second node name
% #3 = fraction of way from #1 to #2
% #4 = vertical offset
% #5 = label
%
% Example:
%
% \pgfnodelabelrotated{first}{second}[.5][2pt]{\pgfbox[center,base]{owns}}

\def\pgfnodelabelrotated#1#2[#3][#4]#5{%
  \pgfputlabelrotated%
  {#3}%
  {\pgfnodeconnstart[\pgf@nodesepstart]{#1}{#2}}%
  {\pgfnodeconnstart[\pgf@nodesepend]{#2}{#1}}%
  {#4}%
  {#5}\ignorespaces}



% Internals

\def\pgf@backoffcircle#1[#2]#3#4{%
  % Calculate backoff for a circle of radius
  % #1 and offset separation #2. #3 is the center of the circle, #4
  % is the target point.
  \setlength\pgf@x{#1}%
  \addtolength\pgf@x{#2}%
  \edef\pgf@temp{{\pgfget x pt}}%
  \expandafter\pgfbackoff\pgf@temp{#3}{#4}\ignorespaces}

\def\pgf@anglecircle#1#2#3#4{%
  % Calculate border point. #1 is radius, #2 is additional backoff, #3
  % is an angle, #4 is the center of the circle.
  \pgfsincos{#3}%
  \setlength\pgf@xa{#1}%
  \addtolength\pgf@xa{#2}%
  \pgf@ya=\pgf@xa\relax%
  \pgf@mult{\pgf@xa}{\pgfget x}{\pgf@xa}%
  \pgf@mult{\pgf@ya}{\pgfget y}{\pgf@ya}%
  \pgf@process{#4}%
  \advance\pgf@y by\pgf@xa\relax%
  \advance\pgf@x by\pgf@ya\ignorespaces}

\def\pgf@backoffrect#1#2[#3]#4#5{%
  % Calculate backoff for a rect with half width #1,
  % half height #2, offset separation #3. #4 is the center of the rect, #5
  % is the target point.
  \pgfdiff{#4}{#5}%
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \setlength\pgf@xb{#1}%
  \setlength\pgf@yb{#2}%
  \addtolength\pgf@xb{#3}%
  \addtolength\pgf@yb{#3}%  
  \ifnum\pgf@xa<0\relax% move into first quadrant
    \pgf@x=-\pgf@x%
  \fi%
  \ifnum\pgf@ya<0\relax%
    \pgf@y=-\pgf@y%
  \fi%
  \pgf@counta=\pgf@x%
  \pgf@countb=\pgf@y%
  \divide\pgf@counta by 256\relax%
  \divide\pgf@countb by 256\relax%
  \ifnum\pgf@countb<\pgf@counta%
    \ifnum\pgf@counta<1\relax%
      \pgf@y=\pgf@yb\relax%
      \pgf@x=0pt\relax%
    \else%
      \pgf@y=16\pgf@y%
      \divide\pgf@y by \pgf@counta%
      \pgf@y=16\pgf@y%
      \pgf@mult{\pgf@y}{\pgfget{xb}}{\pgf@y}%
      \ifnum\pgf@y<\pgf@yb%
        \pgf@x=\pgf@xb%
      \else% rats, calculate intersection on upper side
        \ifnum\pgf@countb<1\relax%
          \pgf@x=\pgf@xb\relax%
          \pgf@y=0pt\relax%
        \else%
          \pgf@x=16\pgf@x%
          \divide\pgf@x by \pgf@countb%
          \pgf@x=16\pgf@x%
          \pgf@mult{\pgf@x}{\pgfget{yb}}{\pgf@x}%
          \pgf@y=\pgf@yb%
        \fi%
      \fi%  
    \fi%
  \else%
    \ifnum\pgf@countb<1\relax%
      \pgf@x=\pgf@xb\relax%
      \pgf@y=0pt\relax%
    \else%
      \pgf@x=16\pgf@x%
      \divide\pgf@x by \pgf@countb%
      \pgf@x=16\pgf@x%
      \pgf@mult{\pgf@x}{\pgfget{yb}}{\pgf@x}%
      \ifnum\pgf@x<\pgf@xb%
        \pgf@y=\pgf@yb%
      \else%
        \ifnum\pgf@counta<1\relax%
          \pgf@y=\pgf@yb\relax%
          \pgf@x=0pt\relax%
        \else%
          \pgf@y=16\pgf@y%
          \divide\pgf@y by \pgf@counta%
          \pgf@y=16\pgf@y%
          \pgf@mult{\pgf@y}{\pgfget{xb}}{\pgf@y}%
          \pgf@x=\pgf@xb%
        \fi%
      \fi%  
    \fi%
  \fi%  
  \ifnum\pgf@xa<0\relax\pgf@x=-\pgf@x\fi%
  \ifnum\pgf@ya<0\relax\pgf@y=-\pgf@y\fi%    
  \pgf@xa=\pgf@x%
  \pgf@ya=\pgf@y%
  \pgf@process{#4}%
  \advance\pgf@x by\pgf@xa%
  \advance\pgf@y by\pgf@ya\ignorespaces}

\def\pgf@anglerect#1#2#3#4#5{%
  % Calculate border point. #1/#2 is half width/height, #3 is additional backoff, #4
  % is an angle, #5 is the center of the rect.
  \pgfsincos{#4}%
  \pgf@xa=100\pgf@x%
  \pgf@ya=100\pgf@y%
  \pgf@process{#5}%
  \advance\pgf@x by\pgf@ya%
  \advance\pgf@y by\pgf@xa%
  \edef\pgf@temp{{\noexpand\pgf@x=\the\pgf@x\noexpand\pgf@y=\the\pgf@y}}%
  \expandafter\pgf@caller\pgf@temp{#1}{#2}{#3}{#5}\ignorespaces}

\def\pgf@caller#1#2#3#4#5{\pgf@backoffrect{#2}{#3}[#4]{#5}{#1}}

\endinput