Debian Codegraph @

texmf-dist/tex/generic/circuitikz/pgfcircvoltage.tex

raw
1 % Copyright 2018-2026 by Romano Giannetti
2 % Copyright 2015-2026 by Stefan Lindner
3 % Copyright 2013-2026 by Stefan Erhardt
4 % Copyright 2007-2026 by Massimo Redaelli
5 %
6 % This file may be distributed and/or modified
7 %
8 % 1. under the LaTeX Project Public License and/or
9 % 2. under the GNU Public License.
10 %
11 % See the files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.
12
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %% Voltage management
15
16 %% styles%<<<
17 \ctikzset{bipole voltage style/.style={}}
18 \tikzset{bipole voltage style/.code={
19 \ctikzset{bipole voltage style/.style={#1}}
20 }}
21 \tikzset{bipole voltage append style/.code={
22 \ctikzset{bipole voltage style/.append style={#1}}
23 }}
24
25 \def\ctikzactivatevoltagedirections#1{%
26 \ctikzset{#1^>/.style = {#1={##1},
27 \circuitikzbasekey/bipole/voltage/direction = forward,
28 \circuitikzbasekey/bipole/voltage/position = above
29 }}
30 \ctikzset{#1^</.style = {#1={##1},
31 \circuitikzbasekey/bipole/voltage/direction = backward,
32 \circuitikzbasekey/bipole/voltage/position = above
33 }}
34 \ctikzset{#1_>/.style = {#1={##1},
35 \circuitikzbasekey/bipole/voltage/direction = forward,
36 \circuitikzbasekey/bipole/voltage/position = below
37 }}
38 \ctikzset{#1_</.style = {#1={##1},
39 \circuitikzbasekey/bipole/voltage/direction = backward,
40 \circuitikzbasekey/bipole/voltage/position = below
41 }}
42 \ctikzset{#1_/.style = {#1={##1}, \circuitikzbasekey/bipole/voltage/position = below} }
43 \ctikzset{#1^/.style = {#1={##1}, \circuitikzbasekey/bipole/voltage/position = above} }
44 \ctikzset{#1>/.style = {#1={##1}, \circuitikzbasekey/bipole/voltage/direction = forward} }
45 \ctikzset{#1</.style = {#1={##1}, \circuitikzbasekey/bipole/voltage/direction = backward} }%
46 }
47 \ctikzactivatevoltagedirections{v}
48
49 \newif\ifpgfcirc@do@v@symbols\pgfcirc@do@v@symbolstrue
50 \ctikzset{no v symbols/.code={\pgfcirc@do@v@symbolsfalse}}
51 \ctikzset{v symbols/.code={\pgfcirc@do@v@symbolstrue}}
52 \ctikzset{v label/.style={bipole/voltage/label/name={#1}}}
53
54 % Default position varies whether the component is a voltage source
55 % or not
56 \ctikzset{v/.code = {
57 \pgfcirc@has@vtrue
58 \ifpgf@circuit@bipole@override@source@vif
59 \pgf@circuit@bipole@isvoltagefalse
60 \pgf@circuit@bipole@iscurrentfalse
61 \fi
62 \ifpgf@circuit@bipole@isvoltage
63 \pgfkeys{\circuitikzbasekey/bipole/voltage/position=above,
64 \circuitikzbasekey/bipole/voltage/direction=forward}
65 \else
66 \ifpgf@circ@oldvoltagedirection
67 \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
68 \circuitikzbasekey/bipole/voltage/direction=backward}
69 \else
70 \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
71 \circuitikzbasekey/bipole/voltage/direction=forward}
72 \fi
73 \fi
74 \ifpgf@circ@oldvoltagedirection
75 \ifpgf@circuit@bipole@iscurrent\ifpgf@circ@fixbatteries
76 \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
77 \circuitikzbasekey/bipole/voltage/direction=forward}
78 \fi\fi
79 \else
80 \ifpgf@circuit@bipole@iscurrent
81 \ifpgf@circuit@bipole@current@backward
82 \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
83 \circuitikzbasekey/bipole/voltage/direction=forward}
84 \else
85 \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
86 \circuitikzbasekey/bipole/voltage/direction=backward}
87 \fi\fi\fi
88 \pgfkeys{/tikz/circuitikz/bipole/voltage/label/name={#1}}
89 \ctikzsetvalof{bipole/voltage/label/unit}{}
90 \ifpgf@circ@siunitx
91 \pgf@circ@handleSI{#1}
92 \ifpgf@circ@siunitx@res
93 \edef\pgf@temp{\pgf@circ@handleSI@val}
94 \pgfkeyslet{/tikz/circuitikz/bipole/voltage/label/name}{\pgf@temp}
95 \edef\pgf@temp{\pgf@circ@handleSI@unit}
96 \pgfkeyslet{/tikz/circuitikz/bipole/voltage/label/unit}{\pgf@temp}
97 \else
98 \fi
99 \else
100 \fi
101 }
102 }
103 % %>>>
104
105 % american voltage font selection and symbol definition
106 % the default font command is {} --- nothing
107 \def\pgf@circ@avfont{\ctikzvalof{voltage/american font}}
108 %
109 % In the mayority of fonts, the size of - is smaller than +, so we have
110 % unaligned signs when positioned independently.
111 % See https://github.com/circuitikz/circuitikz/issues/721
112 % plus and minus symbols (default is $+$ and $\vphantom{+}-$, see pgfcirc.defines.tex)
113 %
114 \def\pgf@circ@avplus{\ctikzvalof{voltage/american plus}}
115 \def\pgf@circ@avminus{\ctikzvalof{voltage/american minus}}
116
117 %%
118 \def\setscaledRlenforclass{%
119 \csname pgf@sh@ma@\ctikzvalof{bipole/name}\endcsname
120 \ifdefined\ctikzclass
121 \edef\pgf@temp{/tikz/circuitikz/\ctikzclass/scale}
122 \pgfkeysifdefined{\pgf@temp}
123 {\pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
124 {\pgf@circ@scaled@Rlen=\pgf@circ@Rlen}
125 \else
126 \pgf@circ@scaled@Rlen=\pgf@circ@Rlen
127 \fi
128 }
129
130 %% Output routine for generic bipoles%<<<
131 % put this to true to see the voltage label coordinate anchors
132 \newif\ifpgf@circ@debugv\pgf@circ@debugvfalse
133
134 \def\pgf@circ@drawvoltagegeneric{
135 \pgfextra{
136 % \typeout{KIND:\ctikzvalof{bipole/kind}\space RLEN:\the\pgf@circ@Rlen\space SCALED:\the\pgf@circ@scaled@Rlen}
137 \ifnum \ctikzvalof{mirror value}=-1
138 \ifpgf@circuit@bipole@inverted
139 \def\distfromline{\ctikzvalof{voltage/distance from line}\pgf@circ@scaled@Rlen}
140 \else
141 \def\distfromline{-\ctikzvalof{voltage/distance from line}\pgf@circ@scaled@Rlen}
142 \fi
143 \else
144 \ifpgf@circuit@bipole@inverted
145 \def\distfromline{-\ctikzvalof{voltage/distance from line}\pgf@circ@scaled@Rlen}
146 \else
147 \def\distfromline{\ctikzvalof{voltage/distance from line}\pgf@circ@scaled@Rlen}
148 \fi
149 \fi
150 \ifpgf@circuit@bipole@voltage@below
151 \def\pgf@circ@voltage@angle{90}
152 \else
153 \def\pgf@circ@voltage@angle{-90}
154 \fi
155 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/distance from node}
156 \pgfkeysifdefined{\pgf@temp}
157 { \edef\distancefromnode{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/distance from node}} }
158 { \edef\distancefromnode{\ctikzvalof{voltage/distance from node}} }
159 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/bump b}
160 \pgfkeysifdefined{\pgf@temp}
161 { \edef\bumpb{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/bump b}} }
162 { \edef\bumpb{\ctikzvalof{voltage/bump b}} }
163 \edef\shiftv{\ctikzvalof{voltage/shift}}
164 % additional per-bipole voltage shift (internal)
165 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/additional shift}
166 \pgfkeysifdefined{\pgf@temp}
167 {
168 \edef\addvshift{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/additional shift}}
169 }
170 {
171 \edef\addvshift{0}
172 }
173 \newdimen{\absvshift}
174 \pgfmathsetlength{\absvshift}{(1+\shiftv+\addvshift)*(\distfromline)}
175 % reset anchor if american and open
176 \ifpgf@circuit@europeanvoltage
177 \else
178 \ifx\@@kind\@@open
179 \def\pgf@circ@bipole@voltage@label@anchor{center}
180 \fi
181 \fi
182 \ifpgf@circuit@bipole@voltage@raised
183 \def\pgf@circ@bipole@voltage@label@anchor{center}
184 \pgfmathsetlength{\absvshift}{\absvshift+sign(\absvshift)*height{"Q"}} % with the current font.
185 \fi
186 % apply the same shift to open "straight" voltage as raised
187 % commented out due to https://github.com/circuitikz/circuitikz/issues/821
188 % but I'm not sure if it's correct
189 % \ifpgf@circuit@bipole@voltage@straight
190 % \ifx\@@kind\@@open
191 % \def\pgf@circ@bipole@voltage@label@anchor{center}
192 % \pgfmathsetlength{\absvshift}{\absvshift+sign(\absvshift)*height{"Q"}} % with the current font.
193 % \fi
194 % \fi
195 }
196 % %\pgf@circ@Rlen/\ctikzvalof{current arrow scale} is equal to the length of the currarrow
197 %absolute move, minimum space is length of arrowhead
198 coordinate (pgfcirc@midtmp) at ($(\tikztostart) ! \pgf@circ@Rlen/\ctikzvalof{current arrow scale} ! (pgfcirc@anchorstartnode)$)
199 coordinate (pgfcirc@midtmp) at ($(pgfcirc@midtmp) ! \distancefromnode ! (pgfcirc@anchorstartnode)$)
200 coordinate (pgfcirc@Vfrom@flat) at (pgfcirc@midtmp)
201 %absolute move, minimum space is length of arrowhead
202 coordinate (pgfcirc@midtmp) at ($(\tikztotarget) ! \pgf@circ@Rlen/\ctikzvalof{current arrow scale} ! (pgfcirc@anchorendnode)$)
203 coordinate (pgfcirc@midtmp) at ($(pgfcirc@midtmp) ! \distancefromnode ! (pgfcirc@anchorendnode)$)
204 coordinate (pgfcirc@Vto@flat) at (pgfcirc@midtmp)
205 coordinate (pgfcirc@mid) at ($(pgfcirc@Vfrom@flat)!0.5!(pgfcirc@Vto@flat)$)
206
207 \ifpgf@circuit@bipole@voltage@below
208 % see comments for the "above" part (similar)
209 \ifpgf@circuit@europeanvoltage
210 \ifpgf@circuit@bipole@voltage@straight
211 coordinate (pgfcirc@bottom) at (\ctikzvalof{bipole/name}.-90)
212 coordinate (pgfcirc@Vto1) at ($(pgfcirc@mid)+(pgfcirc@bottom)-(pgfcirc@Vfrom@flat)$)
213 coordinate (pgfcirc@Vfrom1) at ($(pgfcirc@mid)+(pgfcirc@bottom)-(pgfcirc@Vto@flat)$)
214 coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto1) ! \absvshift!90 : (pgfcirc@Vfrom1)$)
215 coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom1) ! \absvshift!-90 : (pgfcirc@Vto1)$)
216 coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vto)!0.5!(\pgfcirc@a@prefix-Vfrom) $)
217 coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vto)
218 \else
219 coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto@flat) ! \absvshift!90 : (pgfcirc@anchorendnode)$)
220 coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom@flat) ! \absvshift!-90 : (pgfcirc@anchorstartnode)$)
221 coordinate (pgfcirc@Vcont1t) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-110)$)
222 coordinate (pgfcirc@Vcont2t) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-70)$)
223 coordinate (\pgfcirc@a@prefix-Vcont1) at ($(pgfcirc@Vcont1t) ! -\absvshift!90 : (pgfcirc@Vcont2t)$)
224 coordinate (\pgfcirc@a@prefix-Vcont2) at ($(pgfcirc@Vcont2t) ! -\absvshift!-90 : (pgfcirc@Vcont1t)$)
225 coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vcont2)!0.5!(\pgfcirc@a@prefix-Vcont1)$)
226 coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vcont2)
227 \fi
228 \else
229 % we are in case of american here
230 coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto@flat) ! \absvshift!90 : (pgfcirc@anchorendnode)$)
231 coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom@flat) ! \absvshift!-90 : (pgfcirc@anchorstartnode)$)
232 coordinate (pgfcirc@bottom) at (\ctikzvalof{bipole/name}.-90)
233 coordinate (pgfcirc@Vdir0) at ($(pgfcirc@mid)+(pgfcirc@bottom)-(pgfcirc@Vfrom@flat)$)
234 coordinate (\pgfcirc@a@prefix-Vlab) at ($(pgfcirc@bottom) ! \absvshift!-90 : (pgfcirc@Vdir0)$)
235 coordinate (pgfcirc@Vdir) at ($(pgfcirc@mid)+(\pgfcirc@a@prefix-Vlab)-(pgfcirc@Vfrom@flat)$)
236 \ifpgf@circuit@bipole@voltage@raised
237 % move the from and to up to the level of Vlab
238 coordinate (\pgfcirc@a@prefix-Vto) at ($(\pgfcirc@a@prefix-Vlab)+(pgfcirc@Vto@flat)-(pgfcirc@mid)$)
239 coordinate (\pgfcirc@a@prefix-Vfrom) at ($(\pgfcirc@a@prefix-Vlab)+(pgfcirc@Vfrom@flat)-(pgfcirc@mid)$)
240 \fi
241 \fi
242 \else
243 \ifpgf@circuit@europeanvoltage
244 \ifpgf@circuit@bipole@voltage@straight
245 coordinate (pgfcirc@top) at (\ctikzvalof{bipole/name}.90)
246 % move parallel to the component line at pgfcirc@top distance
247 coordinate (pgfcirc@Vto1) at ($(pgfcirc@mid)+(pgfcirc@top)-(pgfcirc@Vfrom@flat)$)
248 coordinate (pgfcirc@Vfrom1) at ($(pgfcirc@mid)+(pgfcirc@top)-(pgfcirc@Vto@flat)$)
249 % add the extra distance
250 coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto1) ! \absvshift!-90 : (pgfcirc@Vfrom1)$)
251 coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom1) ! \absvshift!90 : (pgfcirc@Vto1)$)
252 coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vto)!0.5!(\pgfcirc@a@prefix-Vfrom) $)
253 % direction line to shift the label later
254 coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vto)
255 \else
256 % european voltages here
257 coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto@flat) ! -\absvshift!90 : (pgfcirc@anchorendnode)$)
258 coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom@flat) ! -\absvshift!-90 : (pgfcirc@anchorstartnode)$)
259 % identify the two control points for the "arc" of the voltage
260 coordinate (pgfcirc@Vcont1t) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.110)$)
261 coordinate (pgfcirc@Vcont2t) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.70)$)
262 % and shift them a bit
263 coordinate (\pgfcirc@a@prefix-Vcont1) at ($(pgfcirc@Vcont1t) ! \absvshift!90 : (pgfcirc@Vcont2t)$)
264 coordinate (\pgfcirc@a@prefix-Vcont2) at ($(pgfcirc@Vcont2t) ! \absvshift!-90 : (pgfcirc@Vcont1t)$)
265 coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vcont2)!0.5!(\pgfcirc@a@prefix-Vcont1)$)
266 % direction line to shift the label later
267 coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vcont2)
268 \fi
269 \else
270 % we are in case of american here
271 coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto@flat) ! \absvshift!-90 : (pgfcirc@anchorendnode)$)
272 coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom@flat) ! \absvshift!90 : (pgfcirc@anchorstartnode)$)
273 coordinate (pgfcirc@top) at (\ctikzvalof{bipole/name}.90)
274 % move parallel to the component line
275 coordinate (pgfcirc@Vdir0) at ($(pgfcirc@mid)+(pgfcirc@top)-(pgfcirc@Vfrom@flat)$)
276 % and add the extra distance
277 coordinate (\pgfcirc@a@prefix-Vlab) at ($(pgfcirc@top) ! \absvshift!90 : (pgfcirc@Vdir0)$)
278 coordinate (pgfcirc@Vdir) at ($(pgfcirc@mid)+(\pgfcirc@a@prefix-Vlab)-(pgfcirc@Vfrom@flat)$)
279 \ifpgf@circuit@bipole@voltage@raised
280 % move the from and to up to the level of Vlab
281 coordinate (\pgfcirc@a@prefix-Vto) at ($(\pgfcirc@a@prefix-Vlab)+(pgfcirc@Vto@flat)-(pgfcirc@mid)$)
282 coordinate (\pgfcirc@a@prefix-Vfrom) at ($(\pgfcirc@a@prefix-Vlab)+(pgfcirc@Vfrom@flat)-(pgfcirc@mid)$)
283 \fi
284 \fi
285 \fi
286 \ifx\@@kind\@@open
287 coordinate (\pgfcirc@a@prefix-Vto) at (pgfcirc@Vto@flat)
288 coordinate (\pgfcirc@a@prefix-Vfrom) at (pgfcirc@Vfrom@flat)
289 \fi
290 \ifpgf@circ@debugv
291 node [ocirc, fill=red] at (pgfcirc@anchorstartnode) {}
292 node [ocirc, fill=blue] at (pgfcirc@anchorendnode) {}
293 node [ocirc, fill=green] at (\pgfcirc@a@prefix-Vto) {}
294 node [ocirc, fill=yellow] at (\pgfcirc@a@prefix-Vfrom) {}
295 node [odiamondpole, fill=green!50!black] at (pgfcirc@Vto@flat) {}
296 node [odiamondpole, fill=orange] at (pgfcirc@Vfrom@flat) {}
297 \ifpgf@circuit@europeanvoltage
298 \ifpgf@circuit@bipole@voltage@straight
299 \else
300 node [osquarepole, fill=red] at (\pgfcirc@a@prefix-Vcont1) {}
301 node [osquarepole, fill=blue] at (\pgfcirc@a@prefix-Vcont2) {}
302 \fi
303 \fi
304 \fi
305
306 %
307 % Now we draw the voltage things (only if not empty --- in which case we have been
308 % called just to set the anchors)
309 %
310 \pgf@circ@ifkeyempty{bipole/voltage/label/name}\else
311 \ifpgfcirc@do@v@symbols
312 \ifpgf@circuit@europeanvoltage
313 \ifpgf@circuit@bipole@voltage@straight
314 \ifpgf@circuit@bipole@voltage@backward
315 (\pgfcirc@a@prefix-Vto) --(\pgfcirc@a@prefix-Vfrom) node[currarrow, sloped, allow upside down, pos=1,anchor=tip] {}
316 \else
317 (\pgfcirc@a@prefix-Vfrom) --(\pgfcirc@a@prefix-Vto) node[currarrow, sloped, allow upside down, pos=1,anchor=tip] {}
318 \fi
319 \else
320 \ifpgf@circuit@bipole@voltage@backward
321 (\pgfcirc@a@prefix-Vto) .. controls (\pgfcirc@a@prefix-Vcont2) and (\pgfcirc@a@prefix-Vcont1) ..
322 node[currarrow, sloped, allow upside down, pos=1, anchor=tip] {}
323 (\pgfcirc@a@prefix-Vfrom)
324 \else
325 (\pgfcirc@a@prefix-Vfrom) .. controls (\pgfcirc@a@prefix-Vcont1) and (\pgfcirc@a@prefix-Vcont2) ..
326 node[currarrow, sloped, allow upside down, pos=1, anchor=tip] {}
327 (\pgfcirc@a@prefix-Vto)
328 \fi
329 \fi
330 \else % american
331 \ifpgf@circuit@bipole@voltage@backward
332 \ifpgf@circ@oldvoltagedirection
333 (\pgfcirc@a@prefix-Vfrom) node[inner sep=0, node font=\pgf@circ@avfont,
334 anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avplus}
335 (\pgfcirc@a@prefix-Vto) node[inner sep=0, node font=\pgf@circ@avfont,
336 anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avminus}
337 \else
338 (\pgfcirc@a@prefix-Vfrom) node[inner sep=0, node font=\pgf@circ@avfont,
339 anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avminus}
340 (\pgfcirc@a@prefix-Vto) node[inner sep=0, node font=\pgf@circ@avfont,
341 anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avplus}
342 \fi
343 \else
344 \ifpgf@circ@oldvoltagedirection
345 (\pgfcirc@a@prefix-Vfrom) node[inner sep=0, node font=\pgf@circ@avfont,
346 anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avminus}
347 (\pgfcirc@a@prefix-Vto) node[inner sep=0, node font=\pgf@circ@avfont,
348 anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avplus}
349 \else
350 (\pgfcirc@a@prefix-Vfrom) node[inner sep=0, node font=\pgf@circ@avfont,
351 anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avplus}
352 (\pgfcirc@a@prefix-Vto) node[inner sep=0, node font=\pgf@circ@avfont,
353 anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avminus}
354 \fi
355 \fi
356 \fi
357 \fi % closing the ...symbol
358 \fi % Closing the ...ifempty
359 }
360 % %>>>
361
362 %% Output routine for voltage sources%<<<
363 % (ugly) workaround for https://github.com/circuitikz/circuitikz/issues/747
364 \ctikzset{voltage shift sources adjust/.initial=0.5} % coefficient added "by feel". Sorry.
365 \def\pgf@circ@drawvoltagegenerator{
366 % the following is affected indirectly by voltage/shift, you can move the arrow with voltage/bump a.
367 % it's not perfect, but I can't find the way to do it correctly...
368 \pgfextra{
369 \edef\shiftv{\ctikzvalof{voltage/shift}}
370 % distance along the 60-120 axis
371 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/bump a}
372 \pgfkeysifdefined{\pgf@temp}
373 {
374 \edef\bumpa{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/bump a}}
375 }
376 {
377 \edef\bumpa{\ctikzvalof{voltage/bump a}}
378 }
379 % additional per-bipole voltage shift (internal)
380 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/additional shift}
381 \pgfkeysifdefined{\pgf@temp}
382 {
383 \edef\addvshift{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/additional shift}}
384 }
385 {
386 \edef\addvshift{0}
387 }
388 \pgfmathsetmacro{\bumpaplus}{\bumpa + \ctikzvalof{voltage shift sources adjust}*\shiftv}
389 }
390 \ifpgf@circuit@bipole@voltage@below
391 coordinate (pgfcirc@Vfrom0) at ($(\ctikzvalof{bipole/name}.center) ! \bumpaplus ! (\ctikzvalof{bipole/name}.-120)$)
392 coordinate (pgfcirc@Vto0) at ($(\ctikzvalof{bipole/name}.center) ! \bumpaplus ! (\ctikzvalof{bipole/name}.-60)$)
393 coordinate (\pgfcirc@a@prefix-Vfrom) at ($ (pgfcirc@Vfrom0) ! \addvshift! -90: (pgfcirc@Vto0) $)
394 coordinate (\pgfcirc@a@prefix-Vto) at ($ (pgfcirc@Vto0) ! \addvshift! 90: (pgfcirc@Vfrom0) $)
395 \else
396 coordinate (pgfcirc@Vfrom0) at ($ (\ctikzvalof{bipole/name}.center) ! \bumpaplus ! (\ctikzvalof{bipole/name}.120)$)
397 coordinate (pgfcirc@Vto0) at ($ (\ctikzvalof{bipole/name}.center) ! \bumpaplus ! (\ctikzvalof{bipole/name}.60)$)
398 coordinate (\pgfcirc@a@prefix-Vfrom) at ($ (pgfcirc@Vfrom0) ! \addvshift! 90: (pgfcirc@Vto0) $)
399 coordinate (\pgfcirc@a@prefix-Vto) at ($ (pgfcirc@Vto0) ! \addvshift! -90: (pgfcirc@Vfrom0) $)
400 \fi
401 coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vto)!0.5!(\pgfcirc@a@prefix-Vfrom) $)
402 coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vto)
403 \pgf@circ@ifkeyempty{bipole/voltage/label/name}\else
404 \ifpgfcirc@do@v@symbols
405 \ifpgf@circuit@europeanvoltage
406 \ifpgf@circuit@bipole@voltage@backward
407 (\pgfcirc@a@prefix-Vto) -- node[currarrow, sloped, allow upside down, pos=1, anchor=tip] {} (\pgfcirc@a@prefix-Vfrom)
408 \else
409 (\pgfcirc@a@prefix-Vfrom) -- node[currarrow, sloped, allow upside down, pos=1, anchor=tip] {} (\pgfcirc@a@prefix-Vto)
410 \fi
411 \else% american voltage
412 \ifpgf@circuit@bipole@voltageoutsideofsymbol
413 % if it is a battery, must put + and -
414
415 \ifpgf@circ@fixbatteries
416 \ifpgf@circuit@bipole@voltage@backward
417 (\pgfcirc@a@prefix-Vfrom) node[node font=\pgf@circ@avfont] {\pgf@circ@avplus}
418 (\pgfcirc@a@prefix-Vto) node[node font=\pgf@circ@avfont] {\pgf@circ@avminus}
419 \else
420 (\pgfcirc@a@prefix-Vfrom) node[node font=\pgf@circ@avfont] {\pgf@circ@avminus}
421 (\pgfcirc@a@prefix-Vto) node[node font=\pgf@circ@avfont] {\pgf@circ@avplus}
422 \fi
423 \else
424 \ifpgf@circuit@bipole@voltage@backward
425 (\pgfcirc@a@prefix-Vfrom) node[node font=\pgf@circ@avfont] {\pgf@circ@avminus}
426 (\pgfcirc@a@prefix-Vto) node[node font=\pgf@circ@avfont] {\pgf@circ@avplus}
427 \else
428 (\pgfcirc@a@prefix-Vfrom) node[node font=\pgf@circ@avfont] {\pgf@circ@avplus}
429 (\pgfcirc@a@prefix-Vto) node[node font=\pgf@circ@avfont] {\pgf@circ@avminus}
430 \fi
431 \fi
432 \fi
433 \fi
434 \fi % closes ... ifsymbol
435 \fi % closes ...ifempty
436 }
437 % %>>>
438
439 %% Output routine (main entry point) %<<<
440 %% this is the entry point
441 %%
442 %% locally used dimensions
443 \newdimen{\pgfcirc@labelshift}
444 \newif\ifpgfcirc@v@curved % helper if --- true only if voltages are curved
445 \def\pgf@circ@drawvoltage{% node name
446 \pgfextra{%
447 % set the helper if...curved
448 \ifpgf@circuit@europeanvoltage
449 \ifpgf@circuit@bipole@voltage@straight
450 \pgfcirc@v@curvedfalse
451 \else
452 \pgfcirc@v@curvedtrue
453 \fi
454 \else
455 \pgfcirc@v@curvedfalse
456 \fi
457 % \typeout{V routine called with prefix: \pgfcirc@a@prefix}
458 % Label anchors WARNING: indentation is probably wrong
459 \edef\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
460 \ifnum\pgfcircmathresult >4 \ifnum\pgfcircmathresult <86
461 \ifpgf@circuit@bipole@voltage@below
462 \def\pgf@circ@bipole@voltage@label@anchor{north west}
463 \else
464 \def\pgf@circ@bipole@voltage@label@anchor{south east}
465 \fi
466 \fi\fi
467 \ifnum\pgfcircmathresult >85 \ifnum\pgfcircmathresult <95
468 \ifpgf@circuit@bipole@voltage@below
469 \def\pgf@circ@bipole@voltage@label@anchor{west}
470 \else
471 \def\pgf@circ@bipole@voltage@label@anchor{east}
472 \fi
473 \fi\fi
474 \ifnum\pgfcircmathresult >94 \ifnum\pgfcircmathresult <176
475 \ifpgf@circuit@bipole@voltage@below
476 \def\pgf@circ@bipole@voltage@label@anchor{south west}
477 \else \def\pgf@circ@bipole@voltage@label@anchor{north east}
478 \fi
479 \fi\fi
480 \ifnum\pgfcircmathresult >175 \ifnum\pgfcircmathresult <185
481 \ifpgf@circuit@bipole@voltage@below
482 \def\pgf@circ@bipole@voltage@label@anchor{south}
483 \else\def\pgf@circ@bipole@voltage@label@anchor{north}
484 \fi
485 \fi\fi
486 \ifnum\pgfcircmathresult >184 \ifnum\pgfcircmathresult <266
487 \ifpgf@circuit@bipole@voltage@below
488 \def\pgf@circ@bipole@voltage@label@anchor{south east}
489 \else\def\pgf@circ@bipole@voltage@label@anchor{north west}
490 \fi
491 \fi\fi
492 \ifnum\pgfcircmathresult >265 \ifnum\pgfcircmathresult <275
493 \ifpgf@circuit@bipole@voltage@below
494 \def\pgf@circ@bipole@voltage@label@anchor{east}
495 \else \def\pgf@circ@bipole@voltage@label@anchor{west}
496 \fi
497 \fi\fi
498 \ifnum\pgfcircmathresult >274 \ifnum\pgfcircmathresult <356
499 \ifpgf@circuit@bipole@voltage@below
500 \def\pgf@circ@bipole@voltage@label@anchor{north east}
501 \else\def\pgf@circ@bipole@voltage@label@anchor{south west}
502 \fi
503 \fi\fi
504 \ifnum\pgfcircmathresult >-1 \ifnum\pgfcircmathresult <5
505 \ifpgf@circuit@bipole@voltage@below
506 \def\pgf@circ@bipole@voltage@label@anchor{north}
507 \else\def\pgf@circ@bipole@voltage@label@anchor{south}
508 \fi
509 \fi\fi
510 \ifnum\pgfcircmathresult >355 \ifnum\pgfcircmathresult <361
511 \ifpgf@circuit@bipole@voltage@below
512 \def\pgf@circ@bipole@voltage@label@anchor{north}
513 \else\def\pgf@circ@bipole@voltage@label@anchor{south}
514 \fi
515 \fi\fi
516
517 % export anchor position (if not needed, is always the same macro)
518 \expandafter\xdef\csname pgfcirc@\pgfcirc@m@prefix-Vlab-anchor\endcsname{\pgf@circ@bipole@voltage@label@anchor}
519 % this must be set *before* changing for mirroring and inverting; in that case
520 % the xscale/yscale parameters take it into account
521 \ifpgf@circuit@bipole@voltage@below
522 \def\pgf@circ@bipole@voltage@label@where{-90}
523 \else
524 \def\pgf@circ@bipole@voltage@label@where{90}
525 \fi
526
527 % magic to counteract the scale and yscale effects (there should be a better way...)
528 \ifnum \ctikzvalof{mirror value}=-1
529 \ifpgf@circuit@bipole@voltage@below
530 \pgf@circuit@bipole@voltage@belowfalse
531 \else
532 \pgf@circuit@bipole@voltage@belowtrue
533 \fi
534 \fi
535
536 \ifpgf@circuit@bipole@inverted
537 \ifpgf@circuit@bipole@voltage@below
538 \pgf@circuit@bipole@voltage@belowfalse
539 \else
540 \pgf@circuit@bipole@voltage@belowtrue
541 \fi
542 \fi
543
544 % take into account scaling
545 \setscaledRlenforclass
546 % set the macro for detecting open
547 \edef\@@kind{\ctikzvalof{bipole/kind}}\edef\@@open{open}
548 % start voltage label adjustment
549 \ifpgf@circuit@europeanvoltage
550 \ifpgf@circuit@bipole@voltage@straight
551 % check for straight
552 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/straight label distance}
553 \pgfkeysifdefined{\pgf@temp}{%
554 \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/straight label distance}}%
555 % \typeout{ST:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \stdist}
556 }{\edef\labeldist{\ctikzvalof{voltage/straight label distance}}}
557 \ifpgf@circ@debugv\edef\whichtypeshift{STR}\fi
558 % do not labelshift for legacy straight open; 1.4 makes the shift null
559 \ifx\@@kind\@@open\ifpgf@adjust@open@voltage\else\edef\labeldist{1.4}\fi\fi
560 \else
561 % check for european
562 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/european label distance}
563 \pgfkeysifdefined{\pgf@temp}{%
564 \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/european label distance}}%
565 % \typeout{EU:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \eudist}
566 }{ \edef\labeldist{\ctikzvalof{voltage/european label distance}}}
567 \ifpgf@circ@debugv\edef\whichtypeshift{EUR}\fi
568 \fi
569 \else
570 % check for american
571 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/american label distance}
572 \pgfkeysifdefined{\pgf@temp}{%
573 \ifpgf@circuit@bipole@voltage@raised
574 % do not apply the shift if we are using raised american style
575 \edef\labeldist{1.4}% default value
576 \else
577 \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/american label distance}}%
578 \fi
579 % \typeout{AL:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \aldist}
580 }{\edef\labeldist{\ctikzvalof{voltage/american label distance}}}
581 \ifpgf@circ@debugv\edef\whichtypeshift{AME}\fi
582 \fi
583 % find the height of the bipole or use a default value
584 \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/height}
585 \pgfkeysifdefined{\pgf@temp}
586 {\pgfmathsetmacro{\partheightf}{0.5*\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/height}}
587 \edef\partheight{\partheightf\pgf@circ@scaled@Rlen}}
588 {\edef\partheight{(.5\pgf@circ@scaled@Rlen)}} %fallback to fixed value
589 \ifpgf@circuit@bipole@isvoltage
590 \pgfmathsetlength{\pgfcirc@labelshift}{(\labeldist-1.2)*\partheight}
591 \else
592 \pgfmathsetlength{\pgfcirc@labelshift}{(\labeldist-1.4)*\partheight}
593 \fi
594 % the value for the european was by default 1.4
595 \pgfsetcornersarced{\pgfpointorigin}% do not use rounded corners!
596 % stop the detection of open if I do not want special treatment
597 \ifpgf@adjust@open@voltage\else\edef\@@open{this-will-nEver-match}\fi
598 % \typeout{KIND\space\@@kind}
599 }%end pgfextra
600
601 \ifpgf@circuit@bipole@isvoltage
602 \pgf@circ@drawvoltagegenerator
603 % add fake cont1 and cont2 anchors for export
604 coordinate (\pgfcirc@a@prefix-Vcont1) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$)
605 coordinate (\pgfcirc@a@prefix-Vcont2) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$)
606 \else
607 \pgf@circ@drawvoltagegeneric
608 \fi
609 % % debugging
610 % \pgfextra{%
611 % \typeout{LABEL\space KIND:\@@kind\space EU:\the\pgfcirc@eushift\space AL:\the\pgfcirc@alshift\space
612 % DIRECTION:\pgf@circ@bipole@voltage@label@where}
613 % \pgf@circ@debugvtrue}
614
615 % move a bit if requested
616 coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vlab) ! \pgfcirc@labelshift ! \pgf@circ@bipole@voltage@label@where :(pgfcirc@Vdir)$)
617
618 % check for the case of american AND open
619 \ifpgf@circuit@europeanvoltage
620 \else
621 \ifx\@@kind\@@open
622 % override pgfcirc@Vlab
623 coordinate (\pgfcirc@a@prefix-Vlab) at ($(pgfcirc@Vfrom@flat)!0.5!(pgfcirc@Vto@flat)$)
624 \fi
625 \fi
626
627 \ifpgf@circ@debugv
628 node [odiamondpole, color=blue] at (\pgfcirc@a@prefix-Vlab) {}
629 node [odiamondpole, color=red] at (pgfcirc@Vdir) {}
630 node [overlay, red, font=\tiny, anchor=south east, align=right] at(pgfcirc@Vdir)
631 {\whichtypeshift:\the\pgfcirc@labelshift\\ DIR:\pgf@circ@bipole@voltage@label@where}
632 \fi
633
634 % put the node only if it's not empty
635 \pgf@circ@ifkeyempty{bipole/voltage/label/name}\else
636 node [anchor=\pgf@circ@bipole@voltage@label@anchor, inner sep=2pt,
637 \circuitikzbasekey/bipole voltage style](\ctikzvalof{bipole/name}voltage)
638 at (\pgfcirc@a@prefix-Vlab) {\pgf@circ@finallabels{voltage/label}}
639 \fi
640
641 \ifpgfcirc@v@curved\else
642 % fake Vcont1 and Vcont2 for when they are exported --- in the middle of Vto and Vfrom
643 coordinate (\pgfcirc@a@prefix-Vcont1) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$)
644 coordinate (\pgfcirc@a@prefix-Vcont2) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$)
645 \fi
646 % revert from and to (and c1 - c2) if needed (simpler than rework the positioning above...)
647 \ifpgf@circuit@bipole@voltage@backward
648 \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Vfrom}{\pgfcirc@a@prefix-Vto}
649 \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Vcont1}{\pgfcirc@a@prefix-Vcont2}
650 \fi
651
652 }%end drawvoltages
653
654 % %>>>
655
656 %% these should be arguably moved to every component definition...
657
658 % special cases for voltage positions%<<<1
659 % the KIND is the node name without SHAPE
660 % See the definition above for meaning
661 % if bipoles/KIND/voltage/straight label distance is not defined, it uses the height
662 % if bipoles/KIND/voltage/additional shift is not defined, it is 0 (extra distance)
663 %
664 \ctikzset{bipoles/generic/voltage/distance from node/.initial=0.4}
665 \ctikzset{bipoles/generic/voltage/bump b/.initial=2}
666 %
667 \ctikzset{bipoles/ageneric/voltage/distance from node/.initial=.4}
668 \ctikzset{bipoles/ageneric/voltage/bump b/.initial=2}
669 %
670 \ctikzset{bipoles/fullgeneric/voltage/distance from node/.initial=.4}
671 \ctikzset{bipoles/fullgeneric/voltage/bump b/.initial=2}
672 %
673 \ctikzset{bipoles/memristor/voltage/distance from node/.initial=.4}
674 \ctikzset{bipoles/memristor/voltage/bump b/.initial=2}
675 %
676 \ctikzset{bipoles/tline/voltage/bump b/.initial=2.4}
677 %
678 \ctikzset{bipoles/varistor/voltage/bump b/.initial=2.4}
679 \ctikzset{bipoles/varistor/voltage/american label distance/.initial=1.8}
680 %
681 \ctikzset{bipoles/photoresistor/voltage/bump b/.initial=1.6}
682 %
683 \ctikzset{bipoles/thermistor/voltage/bump b/.initial=2.4}
684 \ctikzset{bipoles/thermistor/voltage/european label distance/.initial=0.8}
685 \ctikzset{bipoles/thermistorntc/voltage/bump b/.initial=1.6}
686 \ctikzset{bipoles/thermistorntc/voltage/european label distance/.initial=0.8}
687 \ctikzset{bipoles/thermistorptc/voltage/bump b/.initial=1.6}
688 \ctikzset{bipoles/thermistorptc/voltage/european label distance/.initial=0.8}
689 %
690 \ctikzset{bipoles/ccapacitor/voltage/bump b/.initial=2.2}
691 %
692 \ctikzset{bipoles/emptyzzdiode/voltage/bump b/.initial=2.5}
693 \ctikzset{bipoles/emptyzzdiode/voltage/european label distance/.initial=1.0}
694 \ctikzset{bipoles/fullzzdiode/voltage/bump b/.initial=2.5}
695 \ctikzset{bipoles/fullzzdiode/voltage/european label distance/.initial=1.0}
696 \ctikzset{bipoles/emptythyristor/voltage/bump b/.initial=2.0}
697 \ctikzset{bipoles/emptythyristor/voltage/european label distance/.initial=1.2}
698 \ctikzset{bipoles/fullthyristor/voltage/bump b/.initial=2.0}
699 \ctikzset{bipoles/fullthyristor/voltage/european label distance/.initial=1.2}
700 \ctikzset{bipoles/emptytriac/voltage/bump b/.initial=1.8}
701 \ctikzset{bipoles/emptytriac/voltage/european label distance/.initial=0.8}
702 \ctikzset{bipoles/fulltriac/voltage/bump b/.initial=1.8}
703 \ctikzset{bipoles/fulltriac/voltage/european label distance/.initial=0.8}
704 %
705 \ctikzset{bipoles/short/voltage/american label distance/.initial=2.8}
706 \ctikzset{bipoles/open/voltage/distance from node/.initial=0.3}
707 %
708 \ctikzset{bipoles/battery/voltage/bump a/.initial=1.4}
709 \ctikzset{bipoles/vsourceAM/voltage/american label distance/.initial=1.2}
710 \ctikzset{bipoles/cvsourceAM/voltage/american label distance/.initial=1.2}
711 %%>>>
712
713 \endinput
714 % vim: set fdm=marker fmr=%<<<,%>>>: