Debian Codegraph @

texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/circuits/tikzlibrarycircuits.code.tex

raw
1 % Copyright 2019 by Till Tantau and others Wibrow
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 \usetikzlibrary{calc,decorations.markings}%
11
12
13 %
14 % Indicate that the picture contains a circuit
15 %
16 \tikzset{
17 circuit/.style={
18 every circuit/.try,
19 /utils/exec=\tikz@lib@circ@on@tofalse,
20 execute at begin to={
21 \tikz@lib@circ@on@totrue
22 \let\tikz@lib@circ@start@node\pgfutil@empty
23 \def\tikz@lib@circ@end{-- (\tikztotarget) \tikztonodes}
24 }
25 }
26 }%
27
28 \newif\iftikz@lib@circ@on@to
29
30
31 %
32 % General management
33 %
34
35 \tikzset{
36 circuit handle symbol/.code={%
37 \global\advance\tikz@lib@circ@count by1\relax%
38 \iftikz@lib@circ@on@to
39 {%
40 % Compute the tikz@time...
41 \pgfkeys{
42 /pgf/key filters/active families or no family/.install key filter={/pgf/key filters/false}{/pgf/key filters/false},
43 /tikz/circuits/pos grabber/.activate family}
44 \pgfqkeysfiltered{/tikz}{pos=.5,#1}%
45 \expandafter%
46 }%
47 \expandafter\def\expandafter\tikz@lib@circ@pos\expandafter{\tikz@time}%
48 \pgfkeysalso{to path={
49 \pgfextra{\tikz@lib@circ@on@tofalse}
50 decorate [decoration={markings,mark connection node=mark node}]
51 {
52 \tikz@lib@circ@start@node
53 \tikz@lib@circ@end
54 }
55 }}
56 \ifdim\tikz@lib@circ@pos pt=0pt\relax%
57 \def\tikz@lib@circ@start@node{%
58 {\pgfextra{\tikz@lib@circ@compute@direction{\tikz@lib@circ@start}}%
59 node[alias=tikz@lib@circ@node@start,at={(0,0)},#1,pos=]{}}(tikz@lib@circ@node@start)}%
60 \else%
61 \ifdim\tikz@lib@circ@pos pt=1pt\relax%
62 \def\tikz@lib@circ@end{
63 {\pgfextra{\tikz@lib@circ@compute@direction{\tikz@lib@circ@target}}%
64 node[alias=tikz@lib@circ@node\the\tikz@lib@circ@count,at={(0,0)},#1,pos=]{}}
65 --(tikz@lib@circ@node\the\tikz@lib@circ@count)\tikztonodes
66 }%
67 \else%
68 \edef\tikz@marshal{mark=at position \tikz@lib@circ@pos\space with}%
69 \def\tikz@marshala{decoration=}%
70 \expandafter\expandafter\expandafter\tikzset%
71 \expandafter\expandafter\expandafter{\expandafter\tikz@marshala\expandafter{\tikz@marshal{\node[alias=mark node,#1,pos=]{};}}}
72 \fi%
73 \fi%
74 \else
75 \pgfkeysalso{#1}
76 \fi
77 }
78 }%
79 \newcount\tikz@lib@circ@count
80
81 \def\tikz@lib@circ@compute@direction#1{%
82 \tikz@scan@one@point\tikz@lib@circ@save@start(\tikztostart)%
83 \tikz@scan@one@point\tikz@lib@circ@save@target(\tikztotarget)%
84 \pgf@process{\pgfpointnormalised{\pgfpointdiff{\tikz@lib@circ@start}{\tikz@lib@circ@target}}}%
85 \pgf@ya=-\pgf@y%
86 \pgftransformcm{\the\pgf@x}{\the\pgf@y}{\the\pgf@ya}{\the\pgf@x}{#1}%
87 }%
88 \def\tikz@lib@circ@save@start#1{\def\tikz@lib@circ@start{#1}}%
89 \def\tikz@lib@circ@save@target#1{\def\tikz@lib@circ@target{#1}}%
90
91 \tikzset{
92 circuits/pos grabber/.is family,
93 pos/.belongs to family=/tikz/circuits/pos grabber,
94 at start/.belongs to family=/tikz/circuits/pos grabber,
95 very near start/.belongs to family=/tikz/circuits/pos grabber,
96 near start/.belongs to family=/tikz/circuits/pos grabber,
97 midway/.belongs to family=/tikz/circuits/pos grabber,
98 near end/.belongs to family=/tikz/circuits/pos grabber,
99 very near end/.belongs to family=/tikz/circuits/pos grabber,
100 at end/.belongs to family=/tikz/circuits/pos grabber
101 }%
102
103
104 %
105 % Declaring a new symbol
106 %
107 \tikzset{
108 circuit declare symbol/.style args={#1}{
109 % Declares a new circuit symbol.
110 %
111 % #1 = name
112 % #2 = factor for default minimum width
113 % #3 = factor for default minimum height
114 %
115 % The following styles are defined:
116 %
117 % #1
118 % Can be given as an option to a "node" command or to a "to"
119 % command. It takes a set of options as parameter that will be
120 % passed to the option.
121 %
122 % set #1 graphic
123 % This keys can be set to the necessary options to make a normal
124 % node look like the symbol. For instance, for a resistor that is
125 % rendered as a rectangle, this keys can be set, basically, to
126 % "rectangle,draw". Set this key to use a different appearance for
127 % symbols of kind #1.
128 %
129 % every #1
130 % This style will be included with every symbols of this kind and
131 % can be used to configure them further.
132 %
133 % every circuit symbol
134 % This style is also included with every symbol.
135 #1/.style={circuit handle symbol={
136 inner sep=0.5pt,
137 every circuit symbol,
138 #1/graphic,
139 every #1/.try,
140 ##1}
141 },
142 #1/graphic/.style={},
143 set #1 graphic/.style={#1/graphic/.style={##1}}
144 },
145 circuit symbol unit/.code=\pgfmathsetlength\tikzcircuitssizeunit{#1},
146 circuit symbol size/.style args={width #1 height #2}{
147 minimum width={(#1)*\tikzcircuitssizeunit},
148 minimum height={(#2)*\tikzcircuitssizeunit}
149 },
150 huge circuit symbols/.style={circuit symbol unit=10pt},
151 large circuit symbols/.style={circuit symbol unit=8pt},
152 medium circuit symbols/.style={circuit symbol unit=7pt},
153 small circuit symbols/.style={circuit symbol unit=6pt},
154 tiny circuit symbols/.style={circuit symbol unit=5pt},
155 }%
156
157 \newdimen\tikzcircuitssizeunit
158 \tikzcircuitssizeunit=7pt
159
160
161 %
162 % Annotations
163 %
164
165 \tikzset{
166 circuit declare annotation/.style args={#1#2#3}{%
167 #1/.style={
168 append after command={%
169 \bgroup
170 [current point is local=true]
171 [every circuit annotation/.try]
172 [every #1/.try]
173 [shift={(\tikzlastnode.north)}]
174 [annotation arrow,->]
175 [label distance=#2,##1]
176 #3
177 \tikz@after@path%
178 \egroup%
179 }
180 },
181 #1'/.style={
182 append after command={%
183 \bgroup
184 [current point is local=true]
185 [every circuit annotation/.try]
186 [every #1/.try]
187 [shift={(\tikzlastnode.south)},yscale=-1]
188 [annotation arrow,->]
189 [label distance=#2,##1]
190 #3
191 \tikz@after@path%
192 \egroup%
193 }
194 }
195 },
196 annotation arrow/.style = {
197 /utils/exec={\pgfsetarrowoptions{direction ee}{.4*\the\tikzcircuitssizeunit+.3*\the\pgflinewidth}},
198 >=direction ee
199 }
200 }%
201
202
203
204 %
205 % Rotating symbols
206 %
207 \tikzset{
208 point up/.style={rotate=90},
209 point down/.style={rotate=-90},
210 point left/.style={rotate=180},
211 point right/.style={}
212 }%
213
214
215
216 %
217 % Basic theming
218 %
219
220 \tikzset{
221 every circuit symbol/.style={},
222 circuit symbol open/.style={draw},
223 circuit symbol filled/.style={draw,fill=black},
224 circuit symbol lines/.style={draw},
225 circuit symbol wires/.style={draw},
226 }%
227
228
229
230
231
232 %
233 % Labels
234 %
235
236 \tikzset{
237 info/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@plain{\tikz@lib@circ@lab@plain[]}#1\pgf@stop},%}
238 info'/.code={\pgfutil@ifnextchar[\tikz@lib@circ@labp@plain{\tikz@lib@circ@labp@plain[]}#1\pgf@stop},%}
239 info sloped/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@sloped@plain{\tikz@lib@circ@lab@sloped@plain[]}#1\pgf@stop},%}
240 info' sloped/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@slopedp@plain{\tikz@lib@circ@lab@slopedp@plain[]}#1\pgf@stop},%}
241 circuit declare unit/.style 2 args={
242 %
243 % Defines four styles that can be used to add labels to a node.
244 %
245 #1/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab{\tikz@lib@circ@lab[]}##1\pgf@stop{#2}{#1}},%}
246 #1 sloped/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@sloped{\tikz@lib@circ@lab@sloped[]}##1\pgf@stop{#2}{#1}},%}
247 #1'/.code={\pgfutil@ifnextchar[\tikz@lib@circ@labp{\tikz@lib@circ@labp[]}##1\pgf@stop{#2}{#1}},%}
248 #1' sloped/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@slopedp{\tikz@lib@circ@lab@slopedp[]}##1\pgf@stop{#2}{#1}}%}
249 }
250 }%
251
252 \def\tikz@lib@circ@lab[#1]#2\pgf@stop#3#4{\tikzset{label={[every info/.try,every #4/.try,#1]$\mathrm{#2#3}$}}}%
253 \def\tikz@lib@circ@lab@sloped[#1]#2\pgf@stop#3#4{\tikzset{label={[every info/.try,every #4/.try,transform shape,#1]$\mathrm{#2#3}$}}}%
254 \def\tikz@lib@circ@labp[#1]#2\pgf@stop#3#4{\tikzset{label={[label position=below,every info/.try,every #4/.try,#1]$\mathrm{#2#3}$}}}%
255 \def\tikz@lib@circ@lab@slopedp[#1]#2\pgf@stop#3#4{\tikzset{label={[label position=below,every info/.try,every #4/.try,transform shape,#1]$\mathrm{#2#3}$}}}%
256
257 \def\tikz@lib@circ@lab@plain[#1]#2\pgf@stop{\tikzset{label={[every info/.try,#1]#2}}}%
258 \def\tikz@lib@circ@lab@sloped@plain[#1]#2\pgf@stop{\tikzset{label={[every info/.try,transform shape,#1]#2}}}%
259 \def\tikz@lib@circ@labp@plain[#1]#2\pgf@stop{\tikzset{label={[label position=below,every info/.try,#1]#2}}}%
260 \def\tikz@lib@circ@lab@slopedp@plain[#1]#2\pgf@stop{\tikzset{label={[label position=below,every info/.try,transform shape,#1]#2}}}%
261
262
263
264 \endinput