% Copyright 2018-2020 by Romano Giannetti % Copyright 2015-2020 by Stefan Lindner % Copyright 2013-2020 by Stefan Erhardt % Copyright 2007-2020 by Massimo Redaelli % % 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Voltage management %% styles \ctikzset{bipole voltage style/.style={}} \tikzset{bipole voltage style/.code={ \ctikzset{bipole voltage style/.style={#1}} }} \tikzset{bipole voltage append style/.code={ \ctikzset{bipole voltage style/.append style={#1}} }} \ctikzset{v^>/.style = { v = #1, \circuitikzbasekey/bipole/voltage/direction = forward, \circuitikzbasekey/bipole/voltage/position = above } } \ctikzset{v^/.style = { v = #1, \circuitikzbasekey/bipole/voltage/direction = forward, \circuitikzbasekey/bipole/voltage/position = below } } \ctikzset{v_/.style = {v = #1, \circuitikzbasekey/bipole/voltage/direction = forward} } \ctikzset{v4 \ifnum\pgfcircmathresult <86 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{north west} \else \def\pgf@circ@bipole@voltage@label@anchor{south east} \fi \fi\fi \ifnum\pgfcircmathresult >85 \ifnum\pgfcircmathresult <95 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{west} \else \def\pgf@circ@bipole@voltage@label@anchor{east} \fi \fi\fi \ifnum\pgfcircmathresult >94 \ifnum\pgfcircmathresult <176 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{south west} \else \def\pgf@circ@bipole@voltage@label@anchor{north east} \fi \fi\fi \ifnum\pgfcircmathresult >175 \ifnum\pgfcircmathresult <185 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{south} \else\def\pgf@circ@bipole@voltage@label@anchor{north} \fi \fi\fi \ifnum\pgfcircmathresult >184 \ifnum\pgfcircmathresult <266 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{south east} \else\def\pgf@circ@bipole@voltage@label@anchor{north west} \fi \fi\fi \ifnum\pgfcircmathresult >265 \ifnum\pgfcircmathresult <275 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{east} \else \def\pgf@circ@bipole@voltage@label@anchor{west} \fi \fi\fi \ifnum\pgfcircmathresult >274 \ifnum\pgfcircmathresult <356 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{north east} \else\def\pgf@circ@bipole@voltage@label@anchor{south west} \fi \fi\fi \ifnum\pgfcircmathresult >-1 \ifnum\pgfcircmathresult <5 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{north} \else\def\pgf@circ@bipole@voltage@label@anchor{south} \fi \fi\fi \ifnum\pgfcircmathresult >355 \ifnum\pgfcircmathresult <361 \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@anchor{north} \else\def\pgf@circ@bipole@voltage@label@anchor{south} \fi \fi\fi % this must be set *before* changing for mirroring and inverting; in that case % the xscale/yscale parameters take it into account \ifpgf@circuit@bipole@voltage@below \def\pgf@circ@bipole@voltage@label@where{-90} \else \def\pgf@circ@bipole@voltage@label@where{90} \fi % magic to counteract the scale and yscale effects (there should be a better way...) \ifnum \ctikzvalof{mirror value}=-1 \ifpgf@circuit@bipole@voltage@below \pgf@circuit@bipole@voltage@belowfalse \else \pgf@circuit@bipole@voltage@belowtrue \fi \fi \ifpgf@circuit@bipole@inverted \ifpgf@circuit@bipole@voltage@below \pgf@circuit@bipole@voltage@belowfalse \else \pgf@circuit@bipole@voltage@belowtrue \fi \fi % take into account scaling \setscaledRlenforclass \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/european label distance} \pgfkeysifdefined{\pgf@temp} { \edef\eudist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/european label distance}} } { \edef\eudist{\ctikzvalof{voltage/european label distance}} } % find the height of the bipole or use a default value \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/height} \pgfkeysifdefined{\pgf@temp} {\pgfmathsetmacro{\partheightf}{0.5*\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/height}} \edef\partheight{\partheightf\pgf@circ@scaled@Rlen}} {\edef\partheight{(.5\pgf@circ@scaled@Rlen)}} %fallback to fixed value \newdimen{\alshift} % this is more or less the same of the legacy code; we shift the american label a bit % outside the (+) -- (-) line \pgfmathsetlength{\alshift}{(\ctikzvalof{voltage/american label distance}-0.6)*\partheight} \pgfsetcornersarced{\pgfpointorigin}% do not use rounded corners! }%end pgfextra \ifpgf@circuit@bipole@isvoltage \pgf@circ@drawvoltagegenerator \else \pgf@circ@drawvoltagegeneric \fi \ifpgf@circuit@bipole@voltage@straight coordinate (Vlab) at ($(pgfcirc@Vto)!0.5!(pgfcirc@Vfrom) $) node [anchor=\pgf@circ@bipole@voltage@label@anchor, inner sep=2pt, \circuitikzbasekey/bipole voltage style](\ctikzvalof{bipole/name}voltage) at (Vlab) {\pgf@circ@finallabels{voltage/label}} \else \ifpgf@circuit@europeanvoltage coordinate (Vlab) at ($(pgfcirc@Vcont1)!0.5!(pgfcirc@Vcont2)$) \else coordinate (Vlab) at ($(pgfcirc@Vfrom)!0.5!(pgfcirc@Vto)$) \ifpgf@circuit@bipole@isvoltage\else % add a bit of space for american labels above their symbols in the normal case. You can avoid that % with voltage/american label distance=0.5 (it's measured from the center of the component, in heights) coordinate (Vlab) at ($(Vlab) ! \alshift ! \pgf@circ@bipole@voltage@label@where :(pgfcirc@Vto)$) \fi \fi node [anchor=\pgf@circ@bipole@voltage@label@anchor, inner sep=2pt, \circuitikzbasekey/bipole voltage style](\ctikzvalof{bipole/name}voltage) at (Vlab) {\pgf@circ@finallabels{voltage/label}} \fi }%end drawvoltages \endinput