Debian Codegraph @

texmf-dist/tex/latex/tikz-ladder/tikzlibrarycircuits.plc.ladder.code.tex

raw
1 %% This is file `tikzlibrarycircuits.plc.ladder.code.tex'
2 %% Version: 1.3
3 %% Version date: 2022-04-10
4 %%
5 %%
6 %% Copyright (C) 2018 by Luis Paulo Laus, [email protected]
7 %%
8 %% This package can be redistributed and/or modified under the terms
9 %% of the LaTeX Project Public License distributed from CTAN
10 %% archives in directory macros/latex/base/lppl.txt; either
11 %% version 1 of the License, or (at your option) any later version,
12 %% with `The Package' referring to the software
13 %% `tikzlibrarycircuits.plc.ladder.code.tex'
14 %% and its accompanying documentation and `The Copyright Holder'
15 %% referring to the person Luis Paulo Laus.
16 %%
17 %%
18 %% IMPORTANT NOTICE:
19 %%
20 %% For error reports, comments or suggestions in case of UNCHANGED
21 %% versions send mail to:
22 %% [email protected]
23 %%
24 %%
25 %% Change History:
26 %% 1.0: 10 January 2018: Original Version
27 %% 1.1: 06 February 2018: Macro file renamed to proper TikZ library file name.
28 %% Parent library changed from `circuit.ee' to `circuits'.
29 %% Bug fixes: added \pgfusepathqstroke where it was missing,
30 %% block anchors reworked.
31 %% 1.2: 05 December 2020: Bugfix: corrected block height when the symbol is empty ({}).
32 %% 1.3: 10 April 2022: new macro for typesetting power rails, fix the annoying bug that prints
33 %% `Missing character....'
34
35 \usetikzlibrary{circuits}
36 %
37 % Length and macros
38 %
39 \makeatletter
40 \newlength{\ladderskip}
41 \def\ladderrungsep@{0.2}
42 \def\ladderrungend#1{\pgftransformyshift{-#1\ladderskip-\ladderrungsep@\ladderskip}}% mark the end of a rung, #1 is the number of rows
43 \def\ladderpowerrails{{% draws power rails
44 \draw let \p1=(laddertopright) in%
45 (0,\y1+0.7\ladderskip) -- (0,0.8\ladderskip)%
46 (\x1,\y1+0.7\ladderskip) -- (\x1,0.8\ladderskip);}}
47
48 %
49 % Setting up a ladder
50 %
51 \tikzset{
52 ladderrungsep/.store in=\ladderrungsep@,
53 circuit plc ladder/.style={
54 circuit,
55 inputs/.style={block ladder inputs={##1}},
56 outputs/.style={block ladder outputs={##1}},
57 input sep/.style={block ladder input sep={##1}},
58 output sep/.style={block ladder output sep={##1}},
59 clksize/.style={block ladder clksize={##1}},
60 symbol/.style={ladder symbol={##1}},
61 symbol color/.style={ladder symbol color={##1}},
62 x=5\tikzcircuitssizeunit,
63 y=5\tikzcircuitssizeunit,
64 execute at begin picture={\ladderskip=\pgf@yy\coordinate (laddertopright) at (0,0);}, % sets \ladderskip and defines a point for power rails
65 every circuit plc ladder/.try
66 }
67 }
68
69 \newif\ifpgfnormallyclosednegated%
70 \pgfkeys{
71 /pgf/crossed ladder/.is if=pgfnormallyclosednegated,%
72 }
73
74 \pgfkeys{/pgf/.cd,
75 contact ladder symbol/.initial=, % no value
76 contact NC ladder symbol/.initial=, % no value
77 var contact NC ladder symbol/.initial=$/$,
78 contact N ladder symbol/.initial=N,
79 contact P ladder symbol/.initial=P,
80 coil ladder symbol/.initial=, % no value
81 coil NA ladder symbol/.initial=, % no value
82 var coil NA ladder symbol/.initial=$/$,
83 coil S ladder symbol/.initial=S,
84 coil R ladder symbol/.initial=R,
85 coil ladder curvature/.initial=0.2, % parameter for ( and ) in coils
86 ladder symbol color/.initial=, % no value
87 ladder symbol/.initial=,
88 block ladder input sep/.initial=1.6\tikzcircuitssizeunit,
89 block ladder output sep/.initial=1.6\tikzcircuitssizeunit,
90 block ladder inputs/.initial={IN},
91 block ladder outputs/.initial={Q},
92 block ladder clksize/.initial=0.8\tikzcircuitssizeunit,
93 block ladder symbol/.initial=TON, % blocks like TON, TOF, TP, ADD, CDU, CDUD\_*
94 }
95
96 % Internal macro for parsing inputs, outputs and clock inputs (no short version).
97 %
98 \expandafter\ifx\csname pgf@lib@sh@ladder@parseinout\endcsname\relax%
99 \def\pgf@lib@sh@ladder@parseinout#1{%
100 \edef\pgf@lib@sh@temp{\pgfkeysvalueof{/pgf/block ladder \pgf@lib@sh@ladder@inout}}%
101 \c@pgf@counta#1\relax%
102 \c@pgf@countb0\relax%
103 \expandafter\pgfutil@in@\expandafter,\expandafter{\pgf@lib@sh@temp}%
104 \let\pgf@lib@sh@next\pgf@lib@sh@ladder@parseinout@long%
105 \pgf@lib@sh@next%
106 }
107 \def\pgf@lib@sh@ladder@parseinout@long{%
108 \expandafter\pgf@lib@sh@ladder@parseinout@@long\pgf@lib@sh@temp,\pgf@stop,%
109 }
110 \def\pgf@lib@sh@ladder@parseinout@@long#1,{%
111 \ifx#1\pgf@stop%
112 \expandafter\edef\csname pgf@lib@sh@ladder@num\pgf@lib@sh@ladder@inout\endcsname{\the\c@pgf@countb}%
113 \let\pgf@lib@sh@next\relax%
114 \else%
115 \ifnum\c@pgf@countb=\c@pgf@counta%
116 \expandafter\edef\csname pgf@lib@sh@ladder@num\pgf@lib@sh@ladder@inout\endcsname{\the\c@pgf@countb}%
117 \let\pgf@lib@sh@next\relax%
118 \else%
119 \advance\c@pgf@countb1\relax%
120 \def\pgf@lib@sh@temp{#1}%
121 \expandafter\pgf@sh@resavedmacro\expandafter{\csname \pgf@lib@sh@ladder@inout-\the\c@pgf@countb\endcsname}{%
122 \expandafter\def\csname \pgf@lib@sh@ladder@inout-\the\c@pgf@countb\endcsname{\expandafter\pgf@lib@sh@temp}}%
123 \let\pgf@lib@sh@next\pgf@lib@sh@ladder@parseinout@@@long%
124 \fi%
125 \fi%
126 \pgf@lib@sh@next%
127 }
128 \def\pgf@lib@sh@ladder@parseinout@@@long{%
129 \pgfutil@ifnextchar x{\pgf@lib@sh@ladder@parseinout@@long}%
130 {\pgf@lib@sh@ladder@parseinout@@long}%
131 }
132 \fi%
133
134
135 % Adjust the width and height of the ladder block symbol.
136 \def\pgf@lib@sh@ladder@dimensions{
137 \[email protected]\wd\pgfnodeparttextbox
138 \[email protected]\ht\pgfnodeparttextbox
139 \advance\[email protected]\dp\pgfnodeparttextbox
140
141 %
142 % Adjust the height for the number of inputs and the width and height of the ladder block symbol.
143 %
144 \c@pgf@counta\pgf@lib@sh@ladder@numinputs
145 \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/block ladder input sep}}
146 \edef\inputsep{\the\pgf@yb}
147 \addtosavedmacro\inputsep
148 \advance\c@pgf@counta-1\relax
149 \multiply\pgf@yb\c@pgf@counta
150 \c@pgf@counta\pgf@lib@sh@ladder@numoutputs
151 \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/block ladder output sep}}
152 \edef\outputsep{\the\pgf@yc}
153 \addtosavedmacro\outputsep
154 \advance\c@pgf@counta-1\relax
155 \multiply\pgf@yc\c@pgf@counta
156 \ifdim\pgf@yb<\pgf@yc% the highest between inputs and outputs
157 \pgf@yb\pgf@yc
158 \fi
159 % now the symbol width and height
160 \begingroup% keep font setting local
161 \pgfutil@selectfont% restore font
162 \global\setbox\pgf@hbox\hbox{{\pgfkeysvalueof{/pgf/ladder symbol}}}% add braces as color-aftergroup-fix TT
163 \endgroup%
164 % \typeout{Test \the\wd\pgf@hbox \the\ht\pgf@hbox \the\dp\pgf@hbox}
165 \[email protected]\wd\pgf@hbox
166 \pgf@yc\ht\pgf@hbox
167 \advance\pgf@yc\dp\pgf@hbox
168 \ifdim\pgf@yc=0pt
169 \advance\pgf@yb4pt
170 \fi
171 \advance\pgf@yc1pt
172 \advance\[email protected]\pgf@yc
173 \advance\pgf@yc2pt
174 \edef\symbolypos{\the\pgf@yc}
175 \addtosavedmacro\symbolypos
176 \advance\[email protected]\pgf@yc
177 \advance\pgf@yc\pgf@yb
178 \[email protected]\pgf@yc
179 \ifdim\pgf@x<\pgf@xc
180 \pgf@x\pgf@xc
181 \fi
182 \ifdim\pgf@y<\pgf@yc
183 \pgf@y\pgf@yc
184 \fi
185 \pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/inner xsep}}
186 \pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/inner ysep}}
187
188 %
189 % Adjust for minimum height and width.
190 %
191 \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/minimum width}}%
192 \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/minimum height}}%
193 \ifdim\pgf@x<.5\pgf@xa%
194 \[email protected]\pgf@xa%
195 \fi%
196 \ifdim\pgf@y<.5\pgf@ya%
197 \[email protected]\pgf@ya%
198 \fi%
199 %
200 % Take into account the outer sep.
201 %
202 \pgfmathaddtolength\pgf@x{\pgfkeysvalueof{/pgf/outer xsep}}%
203 \pgfmathaddtolength\pgf@y{\pgfkeysvalueof{/pgf/outer ysep}}%
204 %
205 \edef\halfwidth{\the\pgf@x}%
206 \edef\halfheight{\the\pgf@y}%
207 \addtosavedmacro\halfwidth%
208 \addtosavedmacro\halfheight%
209
210 \advance\pgf@yb\pgf@y
211 \advance\pgf@yb-\pgf@yc
212 \edef\boxdepth{\the\pgf@yb}% below 1st input
213 \addtosavedmacro\boxdepth
214 }%
215
216
217 \def\pgf@lib@sh@ladder@inputanchor#1{%
218 \dimensions%
219 \pgfpointorigin%
220 \advance\pgf@x-\halfwidth%
221 %
222 \pgfutil@tempdima\inputsep%
223 \multiply\pgfutil@tempdima#1\relax%
224 \advance\pgf@y-\pgfutil@tempdima%
225 \advance\pgf@y\inputsep%
226 }
227
228 \def\pgf@lib@sh@ladder@outputanchor#1{%
229 \dimensions%
230 \pgfpointorigin%
231 \advance\pgf@x\halfwidth%
232 %
233 \pgfutil@tempdima\outputsep%
234 \multiply\pgfutil@tempdima#1\relax%
235 \advance\pgf@y-\pgfutil@tempdima%
236 \advance\pgf@y\outputsep%
237 }
238
239 \def\pgfutil@first@until@relax#1#2\relax{#1}
240
241 % Shapes
242 % block
243 \pgfdeclareshape{block ladder}{
244 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@block ladder\endcsname{%
245 \def\pgf@lib@sh@ladder@inout{inputs}
246 \pgf@lib@sh@ladder@parseinout{1024}% Maximum 1024 (!) inputs.
247 %
248 \pgfmathloop%
249 \ifnum\pgfmathcounter>\pgf@lib@sh@ladder@numinputs%
250 \else%
251 \pgfutil@ifundefined{pgf@anchor@block ladder@input \pgfmathcounter}{%
252 \expandafter\xdef\csname pgf@anchor@block ladder@input \pgfmathcounter\endcsname{%
253 \noexpand\pgf@lib@sh@ladder@inputanchor{\pgfmathcounter}%
254 }%
255 }{}%
256 \repeatpgfmathloop%
257 \ifnum\pgf@lib@sh@ladder@numinputs<1\relax%
258 \pgferror{A block must have at least one input}%
259 \fi%
260 %
261 \def\pgf@lib@sh@ladder@inout{outputs}
262 \pgf@lib@sh@ladder@parseinout{1024}% Maximum 1024 (!) outputs.
263 %
264 \pgfmathloop%
265 \ifnum\pgfmathcounter>\pgf@lib@sh@ladder@numoutputs%
266 \else%
267 \pgfutil@ifundefined{pgf@anchor@block ladder@output \pgfmathcounter}{%
268 \expandafter\xdef\csname pgf@anchor@block ladder@output \pgfmathcounter\endcsname{%
269 \noexpand\pgf@lib@sh@ladder@outputanchor{\pgfmathcounter}%
270 }%
271 }{}%
272 \repeatpgfmathloop%
273 \ifnum\pgf@lib@sh@ladder@numoutputs<1\relax%
274 \pgferror{A block must have at least one output}%
275 \fi%
276 }%
277
278 \savedmacro\numinputs{\let\numinputs\pgf@lib@sh@ladder@numinputs}%
279 \savedmacro\numoutputs{\let\numoutputs\pgf@lib@sh@ladder@numoutputs}%
280 \savedmacro\dimensions{%
281 \pgf@lib@sh@ladder@dimensions%
282 }
283 \savedanchor\centerpoint{%
284 \pgfpointorigin
285 }
286 \savedanchor\midpoint{%
287 \pgfpointorigin
288 \advance\[email protected]\ht\pgfnodeparttextbox
289 \advance\[email protected]\dp\pgfnodeparttextbox
290 \pgfmathaddtolength\pgf@y{+0.5ex}%
291 }
292 \savedanchor\basepoint{%
293 \pgfpointorigin
294 \advance\[email protected]\ht\pgfnodeparttextbox
295 \advance\[email protected]\dp\pgfnodeparttextbox
296 }
297 \savedanchor\textpoint{%
298 \pgfpointorigin
299 \advance\[email protected]\wd\pgfnodeparttextbox
300 \advance\[email protected]\ht\pgfnodeparttextbox
301 \advance\[email protected]\dp\pgfnodeparttextbox
302 }
303 \anchor{center}{\pgfpointorigin}%
304 \anchor{block center}{\dimensions\pgfpointorigin\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
305 \anchor{text}{\dimensions\textpoint\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
306 \anchor{mid}{\dimensions\midpoint\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
307 \anchor{mid west}{\dimensions\midpoint\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth\advance\pgf@x-\halfwidth}%
308 \anchor{mid east}{\dimensions\midpoint\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth\advance\pgf@x\halfwidth}%
309 \anchor{base}{\dimensions\basepoint\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
310 \anchor{base west}{\dimensions\basepoint\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth\advance\pgf@x-\halfwidth}%
311 \anchor{base east}{\dimensions\basepoint\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth\advance\pgf@x\halfwidth}%
312 \anchor{north}{\dimensions\pgfpointorigin\advance\pgf@y\halfheight\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
313 \anchor{south}{\dimensions\pgfpointorigin\advance\pgf@y-\boxdepth}%
314 \anchor{east}{\dimensions\pgfpointorigin\advance\pgf@x\halfwidth\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
315 \anchor{west}{\dimensions\pgfpointorigin\advance\pgf@x-\halfwidth\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
316 \anchor{north east}{\dimensions\pgfpointorigin\advance\pgf@x\halfwidth\advance\pgf@y\halfheight\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
317 \anchor{north west}{\dimensions\pgfpointorigin\advance\pgf@x-\halfwidth\advance\pgf@y\halfheight\advance\pgf@y\halfheight\advance\pgf@y-\boxdepth}%
318 \anchor{south east}{\dimensions\pgfpointorigin\advance\pgf@x\halfwidth\advance\pgf@y-\boxdepth}%
319 \anchor{south west}{\dimensions\pgfpointorigin\advance\pgf@x-\halfwidth\advance\pgf@y-\boxdepth}%
320 \backgroundpath{%
321 \dimensions%
322 \pgf@xc\halfwidth%
323 \pgf@yc\halfheight%
324 \pgfmathaddtolength\pgf@xc{-\pgfkeysvalueof{/pgf/outer xsep}}%
325 \pgfmathaddtolength\pgf@yc{-\pgfkeysvalueof{/pgf/outer ysep}}%
326
327 \pgf@yb\boxdepth%
328 \pgfmathaddtolength\pgf@yb{-\pgfkeysvalueof{/pgf/outer ysep}}%
329 {%
330 \pgfpathrectangle{\pgfqpoint{-\pgf@xc}{-\pgf@yb}}%
331 {%
332 \[email protected]\pgf@xc%
333 \[email protected]\pgf@yc%
334 }%
335 \pgfpathclose%
336 }%
337 }
338 \foregroundpath{
339 \dimensions%
340 {%
341 %
342 % Write block type (symbol)
343 %
344 \pgf@yc\symbolypos
345 \expandafter\pgftext\expandafter[/pgf/text/at=\pgfqpoint{0pt}{\pgf@yc},/pgf/text/center]{%
346 \pgfkeysgetvalue{/pgf/ladder symbol color}{\pgf@lib@sh@temp}%
347 \ifx\pgf@lib@sh@temp\pgfutil@empty%
348 \else%
349 \expandafter\color\expandafter{\pgf@lib@sh@temp}%
350 \fi%
351 \pgfkeysvalueof{/pgf/ladder symbol}%
352 }%
353 % Draw inputs.
354 %
355 \pgf@xc-\halfwidth%
356 \pgfmathaddtolength\pgf@xc{\pgfkeysvalueof{/pgf/outer xsep}}
357 \pgf@xa\pgf@xc
358 \pgfmathaddtolength\pgf@xc{\pgfkeysvalueof{/pgf/inner xsep}}
359 \pgf@yc\inputsep%
360 \pgfmathloop%
361 \ifnum\pgfmathcounter>\numinputs%
362 \else%
363 \advance\pgf@yc-\inputsep%
364 \edef\pgf@lib@sh@temp{\csname inputs-\pgfmathcounter\endcsname}
365 \pgf@xb\pgf@xc
366 \if>\expandafter\pgfutil@first@until@relax\pgf@lib@sh@temp\relax
367 \edef\pgf@lib@sh@temp{\expandafter\expandafter\expandafter\pgfutil@gobble\pgf@lib@sh@temp}
368 \pgf@ya\pgf@yc
369 \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/block ladder clksize}}
370 \pgfmathaddtolength\pgf@ya{0.5\pgf@yb}
371 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
372 \pgfmathaddtolength\pgf@ya{-0.5\pgf@yb}
373 \pgfmathaddtolength\pgf@xa{\pgf@yb}
374 \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
375 \pgfmathaddtolength\pgf@ya{-0.5\pgf@yb}
376 \pgfmathaddtolength\pgf@xa{-\pgf@yb}
377 \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
378 \pgfmathaddtolength\pgf@xb{\pgf@yb}
379 \pgfpathclose
380 \fi
381 \expandafter\pgftext\expandafter[/pgf/text/at=\pgfqpoint{\pgf@xb}{\pgf@yc},/pgf/text/left]{%
382 \pgfkeysgetvalue{/pgf/ladder symbol color}{\pgf@lib@sh@@temp}%
383 \ifx\pgf@lib@sh@@temp\pgfutil@empty%
384 \else%
385 \expandafter\color\expandafter{\pgf@lib@sh@@temp}%
386 \fi%
387 {\pgf@lib@sh@temp}%
388 }%
389 \repeatpgfmathloop%
390 % Draw outputs.
391 %
392 \pgf@xc\halfwidth%
393 \pgfmathaddtolength\pgf@xc{-\pgfkeysvalueof{/pgf/inner xsep}}
394 \pgfmathaddtolength\pgf@xc{-\pgfkeysvalueof{/pgf/outer xsep}}
395 \pgf@yc\outputsep%
396 \pgfmathloop%
397 \ifnum\pgfmathcounter>\numoutputs%
398 \else%
399 \advance\pgf@yc-\outputsep%
400 \expandafter\pgftext\expandafter[/pgf/text/at=\pgfqpoint{\pgf@xc}{\pgf@yc},/pgf/text/right]{%
401 \pgfkeysgetvalue{/pgf/ladder symbol color}{\pgf@lib@sh@temp}%
402 \ifx\pgf@lib@sh@temp\pgfutil@empty%
403 \else%
404 \expandafter\color\expandafter{\pgf@lib@sh@temp}%
405 \fi%
406 {\csname outputs-\pgfmathcounter\endcsname}%
407 }%
408 \repeatpgfmathloop%
409 }%
410 }
411 \anchorborder{%
412 \dimensions%
413 \pgfextract@process\externalpoint{}%
414 \ifdim\pgf@y<0pt%
415 \pgf@process{\pgfpointborderrectangle{\externalpoint}{\pgfqpoint{\halfwidth}{\boxdepth}}}%
416 \else%
417 \pgf@yc\halfheight
418 \advance\pgf@yc\halfheight\advance\pgf@yc-\boxdepth
419 \pgf@process{\pgfpointborderrectangle{\externalpoint}{\pgfqpoint{\halfwidth}{\pgf@yc}}}%
420 \fi%
421 }%
422 }
423
424
425
426
427 % contact
428 \pgfdeclareshape{contact ladder}
429 {
430 \inheritsavedanchors[from=rectangle]
431 \inheritanchor[from=rectangle]{center}
432 \inheritanchor[from=rectangle]{north}
433 \inheritanchor[from=rectangle]{south}
434 \inheritanchor[from=rectangle]{east}
435 \inheritanchor[from=rectangle]{west}
436 \inheritanchor[from=rectangle]{north east}
437 \inheritanchor[from=rectangle]{north west}
438 \inheritanchor[from=rectangle]{south east}
439 \inheritanchor[from=rectangle]{south west}
440 \inheritanchor[from=rectangle]{input}
441 \inheritanchor[from=rectangle]{output}
442 \inheritanchorborder[from=rectangle] % New:
443 \anchor{input}{
444 \pgf@process{\northeast}%
445 \pgf@ya=.5\pgf@y%
446 \pgf@process{\southwest}%
447 \pgf@y=.5\pgf@y%
448 \advance\pgf@y by \pgf@ya%
449 }
450 \anchor{output}{%
451 \pgf@process{\southwest}%
452 \pgf@ya=.5\pgf@y%
453 \pgf@process{\northeast}%
454 \pgf@y=.5\pgf@y%
455 \advance\pgf@y by \pgf@ya%
456 }
457 \savedanchor\centerpoint{%
458 \[email protected]\wd\pgfnodeparttextbox%
459 \[email protected]\ht\pgfnodeparttextbox%
460 \advance\[email protected]\dp\pgfnodeparttextbox%
461 }
462
463 \backgroundpath{
464 \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
465 \pgf@xa=\pgf@x \pgf@ya=\pgf@y
466 \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
467 \pgf@xb=\pgf@x \pgf@yb=\pgf@y
468 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
469 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
470 \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
471 \ifpgfnormallyclosednegated
472 \pgfsetbeveljoin
473 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
474 \else
475 \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
476 \fi
477 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
478 \pgfusepathqstroke
479 }
480 \foregroundpath{
481 \pgftransformshift{\centerpoint}
482 \pgftext{\pgfkeysvalueof{/pgf/ladder symbol}}
483 }
484 }
485
486 % coil
487 \pgfdeclareshape{coil ladder}
488 {
489 \inheritsavedanchors[from=rectangle]
490 \inheritanchor[from=rectangle]{center}
491 \inheritanchor[from=rectangle]{north}
492 \inheritanchor[from=rectangle]{south}
493 \inheritanchor[from=rectangle]{east}
494 \inheritanchor[from=rectangle]{west}
495 \inheritanchor[from=rectangle]{north east}
496 \inheritanchor[from=rectangle]{north west}
497 \inheritanchor[from=rectangle]{south east}
498 \inheritanchor[from=rectangle]{south west}
499 \inheritanchor[from=rectangle]{input}
500 \inheritanchor[from=rectangle]{output}
501 \inheritanchorborder[from=rectangle] % New:
502 \anchor{input}{
503 \pgf@process{\northeast}%
504 \pgf@ya=.5\pgf@y%
505 \pgf@process{\southwest}%
506 \pgf@y=.5\pgf@y%
507 \advance\pgf@y by \pgf@ya%
508 }
509 \anchor{output}{%
510 \pgf@process{\southwest}%
511 \pgf@ya=.5\pgf@y%
512 \pgf@process{\northeast}%
513 \pgf@y=.5\pgf@y%
514 \advance\pgf@y by \pgf@ya%
515 }
516 \savedanchor\centerpoint{%
517 \[email protected]\wd\pgfnodeparttextbox%
518 \[email protected]\ht\pgfnodeparttextbox%
519 \advance\[email protected]\dp\pgfnodeparttextbox%
520 }
521
522 \backgroundpath{
523 \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
524 \pgf@xa=\pgf@x \pgf@ya=\pgf@y
525 \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
526 \pgf@xb=\pgf@x \pgf@yb=\pgf@y
527
528 \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/coil ladder curvature}\pgf@xb-\pgfkeysvalueof{/pgf/coil ladder curvature}\pgf@xa} % uses a reduction of 20% (by default) for beginning of the arcs, if it is 0.5 and width=height we got a circle, do not set to zero
529 \pgfmathsetlength\pgf@yc{.5\[email protected]\pgf@ya}
530 \pgfmathsetlength\pgf@ya{0.5\pgf@xc + 0.5\pgf@yc*\pgf@yc / \pgf@xc} % radius
531 \advance\pgf@xa by \pgf@xc
532 \advance\pgf@xb by-\pgf@xc
533 \pgfmathsetlength\pgf@yc{\pgf@yc / \pgf@ya}
534 \pgfmathasin{\pgf@yc}
535 \pgfmathsetlength\pgf@yc{\pgfmathresult} % angle
536 \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
537 \pgfpatharc{180-\pgf@yc}{180+\pgf@yc}{\pgf@ya}
538 \ifpgfnormallyclosednegated
539 \pgfsetbeveljoin
540 \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
541 \else
542 \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
543 \fi
544 \pgfpatharc{\pgf@yc}{-\pgf@yc}{\pgf@ya}
545 \pgfusepathqstroke
546 }
547 \foregroundpath{
548 \pgftransformshift{\centerpoint}
549 \pgftext{\pgfkeysvalueof{/pgf/ladder symbol}}
550 }
551 }
552
553 \makeatother
554
555 \tikzset{
556 circuit declare symbol=contact NO,
557 circuit declare symbol=contact NC,
558 circuit declare symbol=var contact NC,
559 circuit declare symbol=contact P,
560 circuit declare symbol=contact N,
561 circuit declare symbol=coil,
562 circuit declare symbol=coil NA,
563 circuit declare symbol=var coil NA,
564 circuit declare symbol=coil S,
565 circuit declare symbol=coil R,
566 circuit declare symbol=block,
567 set contact NO graphic={
568 circuit symbol lines,
569 circuit symbol size=width 1.5 height 2,
570 transform shape,
571 shape=contact ladder
572 },
573 set contact NC graphic={
574 circuit symbol lines,
575 circuit symbol size=width 1.5 height 2,
576 transform shape,
577 crossed ladder=true,
578 shape=contact ladder
579 },
580 set var contact NC graphic={
581 circuit symbol lines,
582 circuit symbol size=width 1.5 height 2,
583 transform shape,
584 ladder symbol=\pgfkeysvalueof{/pgf/var contact NC ladder symbol},
585 shape=contact ladder
586 },
587 set contact P graphic={
588 circuit symbol lines,
589 circuit symbol size=width 1.5 height 2,
590 transform shape,
591 ladder symbol=\pgfkeysvalueof{/pgf/contact P ladder symbol},
592 shape=contact ladder
593 },
594 set contact N graphic={
595 circuit symbol lines,
596 circuit symbol size=width 1.5 height 2,
597 transform shape,
598 ladder symbol=\pgfkeysvalueof{/pgf/contact N ladder symbol},
599 shape=contact ladder
600 },
601 set coil graphic={
602 circuit symbol lines,
603 fill=none,
604 circuit symbol size=width 2.4 height 2,
605 transform shape,
606 shape=coil ladder
607 },
608 set coil NA graphic={
609 circuit symbol lines,
610 circuit symbol size=width 2.4 height 2,
611 crossed ladder=true,
612 transform shape,
613 shape=coil ladder
614 },
615 set var coil NA graphic={
616 circuit symbol lines,
617 circuit symbol size=width 2.4 height 2,
618 ladder symbol=\pgfkeysvalueof{/pgf/var coil NA ladder symbol},
619 transform shape,
620 shape=coil ladder
621 },
622 set coil S graphic={
623 circuit symbol lines,
624 circuit symbol size=width 2.4 height 2,
625 ladder symbol=\pgfkeysvalueof{/pgf/coil S ladder symbol},
626 transform shape,
627 shape=coil ladder
628 },
629 set coil R graphic={
630 circuit symbol lines,
631 circuit symbol size=width 2.4 height 2,
632 ladder symbol=\pgfkeysvalueof{/pgf/coil R ladder symbol},
633 transform shape,
634 shape=coil ladder
635 },
636 set block graphic={
637 circuit symbol lines,
638 circuit symbol size=width 2.4 height 2,
639 ladder symbol=\pgfkeysvalueof{/pgf/block ladder symbol},
640 transform shape,
641 inner sep=.5ex,
642 shape=block ladder,
643 every ladder block/.try
644 }
645 }
646
647 \endinput