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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
% 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.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Voltage management
\ctikzset{v^>/.style = {
v = #1,
\circuitikzbasekey/bipole/voltage/direction = forward,
\circuitikzbasekey/bipole/voltage/position = above
}
}
\ctikzset{v^</.style = {
v = #1,
\circuitikzbasekey/bipole/voltage/direction = backward,
\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 = backward,
\circuitikzbasekey/bipole/voltage/position = below
}
}
% Default position varies whether the component is a voltage source
% or not
\ctikzset{v/.code = {
\ifpgf@circuit@bipole@isvoltage
\pgfkeys{\circuitikzbasekey/bipole/voltage/position=above,
\circuitikzbasekey/bipole/voltage/direction=forward}
\else
\pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
\circuitikzbasekey/bipole/voltage/direction=backward}
\fi
\pgfkeys{/tikz/circuitikz/bipole/voltage/label/name=#1}
\ctikzsetvalof{bipole/voltage/label/unit}{}
\ifpgf@circ@siunitx
\pgf@circ@handleSI{#1}
\ifpgf@circ@siunitx@res
\edef\pgf@temp{\pgf@circ@handleSI@val}
\pgfkeyslet{/tikz/circuitikz/bipole/voltage/label/name}{\pgf@temp}
\edef\pgf@temp{\pgf@circ@handleSI@unit}
\pgfkeyslet{/tikz/circuitikz/bipole/voltage/label/unit}{\pgf@temp}
\else
\fi
\else
\fi
}
}
\ctikzset{v_/.style = {v = #1, \circuitikzbasekey/bipole/voltage/position = below} }
\ctikzset{v^/.style = {v = #1, \circuitikzbasekey/bipole/voltage/position = above} }
\ctikzset{v>/.style = {v = #1, \circuitikzbasekey/bipole/voltage/direction = forward} }
\ctikzset{v</.style = {v = #1, \circuitikzbasekey/bipole/voltage/direction = backward} }
%% Output routine for generic bipoles
\def\pgf@circ@drawvoltagegeneric{
\pgfextra{
\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@voltage@below
\def\pgf@circ@voltage@angle{90}
\else
\def\pgf@circ@voltage@angle{-90}
\fi
}
coordinate (pgfcirc@mid) at ($(\tikztostart) ! \ctikzvalof{voltage/distance from node} ! (\ctikzvalof{bipole/name}.left)$)
coordinate (pgfcirc@Vfrom) at ($(pgfcirc@mid) ! -\ctikzvalof{voltage/distance from line}\pgf@circ@Rlen ! \pgf@circ@voltage@angle:(\ctikzvalof{bipole/name}.left)$)
coordinate (pgfcirc@mid) at ($(\tikztotarget) ! \ctikzvalof{voltage/distance from node} ! (\ctikzvalof{bipole/name}.right)$)
coordinate (pgfcirc@Vto) at ($(pgfcirc@mid) ! \ctikzvalof{voltage/distance from line}\pgf@circ@Rlen ! \pgf@circ@voltage@angle : (\ctikzvalof{bipole/name}.right)$)
\ifpgf@circuit@bipole@voltage@below
coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump b} ! (\ctikzvalof{bipole/name}.-110)$)
coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump b} ! (\ctikzvalof{bipole/name}.-70)$)
\else
coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump b} ! (\ctikzvalof{bipole/name}.110)$)
coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump b} ! (\ctikzvalof{bipole/name}.70)$)
\fi
\ifpgf@circuit@europeanvoltage
\ifpgf@circuit@bipole@voltage@backward
(pgfcirc@Vto) .. controls (pgfcirc@Vcont2) and (pgfcirc@Vcont1) ..
node[currarrow, sloped, allow upside down, pos=1] {}
(pgfcirc@Vfrom)
\else
(pgfcirc@Vfrom) .. controls (pgfcirc@Vcont1) and (pgfcirc@Vcont2) ..
node[currarrow, sloped, allow upside down, pos=1] {}
(pgfcirc@Vto)
\fi
\else
\ifpgf@circuit@bipole@voltage@backward
(pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{$+$}
(pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{$-$}
\else
(pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{$-$}
(pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{$+$}
\fi
\fi
}
%% Output routine for voltage sources
\def\pgf@circ@drawvoltagegenerator{
\ifpgf@circuit@bipole@voltage@below
coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.-120)$)
coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.-60)$)
\else
coordinate (pgfcirc@Vcont1) at ($ (\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.120)$)
coordinate (pgfcirc@Vcont2) at ($ (\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.60)$)
\fi
\ifpgf@circuit@europeanvoltage
\ifpgf@circuit@bipole@voltage@backward
(pgfcirc@Vcont2) -- node[currarrow, sloped, allow upside down, pos=1] {} (pgfcirc@Vcont1)
\else
(pgfcirc@Vcont1) -- node[currarrow, sloped, allow upside down, pos=1] {} (pgfcirc@Vcont2)
\fi
\else % american voltage
\pgfextra{
\edef\pgf@temp{\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}}
\def\pgf@circ@temp{battery}
}
\ifx\pgf@temp\pgf@circ@temp % if it is a battery, must put + and -
\ifpgf@circuit@bipole@voltage@backward
(pgfcirc@Vcont2) node {$-$} (pgfcirc@Vcont1) node {$+$}
\else
(pgfcirc@Vcont1) node {$-$} (pgfcirc@Vcont2) node {$+$}
\fi
\fi
\fi
}
%% Output routine
\def\pgf@circ@drawvoltage{ % node name
\pgfextra{
\edef\pgf@circ@ffffff{\ctikzvalof{bipole/direction}}
\def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@ffffff\pgf@nil}
\ifnum\pgfcircmathresult >4 \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 <256
\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 >284 \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 <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
\ifnum\pgfcircmathresult >355
\ifpgf@circuit@bipole@voltage@below
\def\pgf@circ@bipole@voltage@label@anchor{north}
\else\def\pgf@circ@bipole@voltage@label@anchor{south}
\fi
\fi
\ifpgf@circuit@bipole@voltage@below
\def\pgf@circ@bipole@voltage@label@where{-90}
\else
\def\pgf@circ@bipole@voltage@label@where{90}
\fi
}
\ifpgf@circuit@bipole@isvoltage
\pgf@circ@drawvoltagegenerator
\else
\pgf@circ@drawvoltagegeneric
\fi
coordinate (Vlab) at ($(\ctikzvalof{bipole/name}.center) !
\ifpgf@circuit@europeanvoltage\ctikzvalof{voltage/european label distance}\else\ctikzvalof{voltage/american label distance}\fi !
(\ctikzvalof{bipole/name}.\pgf@circ@bipole@voltage@label@where)$)
node [anchor=\pgf@circ@bipole@voltage@label@anchor, inner sep=0]
at (Vlab) { \pgf@circ@finallabel{voltage/} }
}
\endinput
coordinate (pgfcirc@Vcont1) at ($ (\ctikzvalof{bipole/name}.center) !
\ctikzvalof{voltage/bump b} !
(\ctikzvalof{bipole/name}.-110) $)
coordinate (pgfcirc@Vcont2) at ($ (\ctikzvalof{bipole/name}.center) !
\ctikzvalof{voltage/bump b} !
(\ctikzvalof{bipole/name}.-70) $)
\else
coordinate (pgfcirc@Vcont1) at ($ (\ctikzvalof{bipole/name}.center) !
\ctikzvalof{voltage/bump b} !
(\ctikzvalof{bipole/name}.110) $)
coordinate (pgfcirc@Vcont2) at ($ (\ctikzvalof{bipole/name}.center) !
\ctikzvalof{voltage/bump b} !
(\ctikzvalof{bipole/name}.70) $)
\fi
|