1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
% Copyright 2007-2009 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 file doc/LICENSE for more details.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Bipole label positioning
%% Options
\ctikzset{label/.style = { l=#1 } }
\ctikzset{l/.code = {
\pgfkeys{/tikz/circuitikz/bipole/label/name=#1}
\ctikzsetvalof{bipole/label/unit}{}
\ifpgf@circ@siunitx
\pgf@circ@handleSI{#1}
\ifpgf@circ@siunitx@res
\edef\pgf@temp{\pgf@circ@handleSI@val}
\pgfkeyslet{/tikz/circuitikz/bipole/label/name}{\pgf@temp}
\edef\pgf@temp{\pgf@circ@handleSI@unit}
\pgfkeyslet{/tikz/circuitikz/bipole/label/unit}{\pgf@temp}
\else
\fi
\else
\fi
}}
\ctikzset{label above/.code = {
l=#1,
\circuitikzbasekey/bipole/label/position=90 }
}
\ctikzset{l^/.style = {
l=#1,
\circuitikzbasekey/bipole/label/position=90 }
}
\ctikzset{label below/.code = {
l=#1,
\circuitikzbasekey/bipole/label/position=-90 }
}
\ctikzset{l_/.style = {
l=#1,
\circuitikzbasekey/bipole/label/position=-90 }
}
\def\pgf@circ@drawlabel{
\pgfextra{
\edef\pgf@temp{\ctikzvalof{label/align}}
\def\pgf@circ@temp{straight}
}
\ifx\pgf@temp\pgf@circ@temp %straight
\pgf@circ@drawreglabel
\else
\pgfextra{\def\pgf@circ@temp{rotate}}
\ifx\pgf@temp\pgf@circ@temp %rotate
\pgf@circ@drawrotlabel
\else % smart
\pgf@circ@drawsmartlabel
\fi
\fi
}
\def\pgf@circ@drawsmartlabel{
\pgfextra{
%\pgfmathadd{\pgf@circ@direction}{360}
\pgfmathmod{\pgf@circ@direction}{90}
\edef\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
}
\ifnum \pgfcircmathresult > 20
\ifnum \pgfcircmathresult < 70 % NON quasi retto
\pgf@circ@drawrotlabel
\else
\pgf@circ@drawreglabel
\fi
\else
\pgf@circ@drawreglabel
\fi
}
%% Output routing
%% #1 - node name
\def\pgf@circ@drawrotlabel{
\pgfextra{
% calcolo rotazione label
\def\pgf@circ@temp{\ctikzvalof{bipole/label/position}} %%% àncora label
\edef\pgfcirclabrot{\pgf@circ@direction} % primo e quarto quadrante
\edef\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
\ifnum \pgfcircmathresult > 90 \ifnum \pgfcircmathresult < 270 % terzo e secondo
\pgfmathsubtract{\pgf@circ@direction}{180}
\edef\pgfcirclabrot{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
\pgfmathadd{\pgf@circ@temp}{180} %%%
\edef\pgf@circ@temp{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil} %%%
\fi\fi
\ifnum \ctikzvalof{mirror value} = -1
\pgfmathadd{\pgf@circ@temp}{180}
\edef\pgf@circ@temp{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
\fi
}
coordinate (labelcoor) at ($(\ctikzvalof{bipole/name})!2!(\ctikzvalof{bipole/name}.north)$)
(labelcoor) node [transform shape, rotate=\pgfcirclabrot] {\pgf@circ@finallabel{}}
}
\def\pgf@circ@drawreglabel{
\pgfextra{
\pgfmathsubtract{\pgf@circ@direction}{90}
\edef\pgf@circ@labanc{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
\edef\pgf@circ@temp{\ctikzvalof{bipole/label/position}} %%% àncora label
\ifnum \pgf@circ@temp < 0
\pgfmathadd{\pgf@circ@labanc}{180}
\edef\pgf@circ@labanc{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
\fi
\ifnum \ctikzvalof{mirror value} = -1
\pgfmathadd{\pgf@circ@labanc}{180}
\edef\pgf@circ@labanc{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
\fi
}
node [ anchor = \pgf@circ@labanc]
at (\ctikzvalof{bipole/name}.\pgf@circ@temp) {\pgf@circ@finallabel{}}
}
\endinput
|