% 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 % export anchor position (if not needed, is always the same macro) \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-Vlab-anchor\endcsname{\pgf@circ@bipole@voltage@label@anchor} % 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 \ifpgf@circuit@europeanvoltage \ifpgf@circuit@bipole@voltage@straight % check for straight \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/straight label distance} \pgfkeysifdefined{\pgf@temp}{% \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/straight label distance}}% % \typeout{ST:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \stdist} }{\edef\labeldist{\ctikzvalof{voltage/straight label distance}}} \ifpgf@circ@debugv\edef\whichtypeshift{STR}\fi \else % check for european \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/european label distance} \pgfkeysifdefined{\pgf@temp}{% \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/european label distance}}% % \typeout{EU:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \eudist} }{ \edef\labeldist{\ctikzvalof{voltage/european label distance}}} \ifpgf@circ@debugv\edef\whichtypeshift{EUR}\fi \fi \else % check for american \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/american label distance} \pgfkeysifdefined{\pgf@temp}{% \ifpgf@circuit@bipole@voltage@raised % do not apply the shift if we are using raised american style \edef\labeldist{1.4}% default value \else \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/american label distance}}% \fi % \typeout{AL:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \aldist} }{\edef\labeldist{\ctikzvalof{voltage/american label distance}}} \ifpgf@circ@debugv\edef\whichtypeshift{AME}\fi \fi % 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 \ifpgf@circuit@bipole@isvoltage \pgfmathsetlength{\pgfcirc@labelshift}{(\labeldist-1.2)*\partheight} \else \pgfmathsetlength{\pgfcirc@labelshift}{(\labeldist-1.4)*\partheight} \fi % the value for the european was by default 1.4 \pgfsetcornersarced{\pgfpointorigin}% do not use rounded corners! % set the macro for detecting open \edef\@@kind{\ctikzvalof{bipole/kind}}\edef\@@open{open} \ifpgf@adjust@open@voltage\else\edef\@@open{this-will-nEver-match}\fi % \typeout{KIND\space\@@kind} }%end pgfextra \ifpgf@circuit@bipole@isvoltage \pgf@circ@drawvoltagegenerator % add fake cont1 and cont2 anchors for export coordinate (\pgfcirc@a@prefix-Vcont1) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$) coordinate (\pgfcirc@a@prefix-Vcont2) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$) \else \pgf@circ@drawvoltagegeneric \fi % % debugging % \pgfextra{% % \typeout{LABEL\space KIND:\@@kind\space EU:\the\pgfcirc@eushift\space AL:\the\pgfcirc@alshift\space % DIRECTION:\pgf@circ@bipole@voltage@label@where} % \pgf@circ@debugvtrue} % move a bit if requested coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vlab) ! \pgfcirc@labelshift ! \pgf@circ@bipole@voltage@label@where :(pgfcirc@Vdir)$) % check for the case of american AND open \ifpgf@circuit@europeanvoltage \else \ifx\@@kind\@@open % override pgfcirc@Vlab coordinate (\pgfcirc@a@prefix-Vlab) at ($(pgfcirc@Vfrom@flat)!0.5!(pgfcirc@Vto@flat)$)\fi \fi \ifpgf@circ@debugv node [odiamondpole, color=blue] at (\pgfcirc@a@prefix-Vlab) {} node [odiamondpole, color=red] at (pgfcirc@Vdir) {} node [overlay, red, font=\tiny, anchor=south east, align=right] at(pgfcirc@Vdir) {\whichtypeshift:\the\pgfcirc@labelshift\\ DIR:\pgf@circ@bipole@voltage@label@where} \fi % put the node only if it's not empty \pgf@circ@ifkeyempty{bipole/voltage/label/name}\else node [anchor=\pgf@circ@bipole@voltage@label@anchor, inner sep=2pt, \circuitikzbasekey/bipole voltage style](\ctikzvalof{bipole/name}voltage) at (\pgfcirc@a@prefix-Vlab) {\pgf@circ@finallabels{voltage/label}} \fi \ifpgfcirc@v@curved\else % fake Vcont1 and Vcont2 for when they are exported --- in the middle of Vto and Vfrom coordinate (\pgfcirc@a@prefix-Vcont1) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$) coordinate (\pgfcirc@a@prefix-Vcont2) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$) \fi % revert from and to (and c1 - c2) if needed (simpler than rework the positioning above...) \ifpgf@circuit@bipole@voltage@backward \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Vfrom}{\pgfcirc@a@prefix-Vto} \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Vcont1}{\pgfcirc@a@prefix-Vcont2} \fi }%end drawvoltages \endinput