summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/circuitikz/pgfcirccurrent.tex
blob: b8cf0555900730fa8c42c788a9e93fbb8ab75d93 (plain)
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
% 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.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Current handling

%% styles
\ctikzset{bipole current style/.style={}}
\tikzset{bipole current style/.code={
        \ctikzset{bipole current style/.style={#1}}
}}
\tikzset{bipole current append style/.code={
        \ctikzset{bipole current style/.append style={#1}}
}}

%% Options
\ctikzset{i^>/.style = {
        i = #1,
        \circuitikzbasekey/bipole/current/direction = forward,
        \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = above
    }
}

\ctikzset{i_>/.style = {
        i = #1,
        \circuitikzbasekey/bipole/current/direction = forward,
        \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = below
    }
}

\ctikzset{i>^/.style = {
        i = #1,
        \circuitikzbasekey/bipole/current/direction = forward,
        \circuitikzbasekey/bipole/current/x position = before,
        \circuitikzbasekey/bipole/current/y position = above
    }
}

\ctikzset{i>_/.style = {
        i = #1,
        \circuitikzbasekey/bipole/current/direction = forward,
        \circuitikzbasekey/bipole/current/x position = before,
        \circuitikzbasekey/bipole/current/y position = below
    }
}

\ctikzset{i^</.style = {
        i = #1,
        \circuitikzbasekey/bipole/current/direction = backward,
        \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = above
    }
}

\ctikzset{i_</.style = {
        i = #1,
        \circuitikzbasekey/bipole/current/direction = backward,
        \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = below
    }
}

\ctikzset{i<^/.style = {
        i = #1,
        \circuitikzbasekey/bipole/current/direction = backward,
        \circuitikzbasekey/bipole/current/x position = before,
        \circuitikzbasekey/bipole/current/y position = above
    }
}

\ctikzset{i<_/.style = {
        i = #1,
        \circuitikzbasekey/bipole/current/direction = backward,
        \circuitikzbasekey/bipole/current/x position = before,
        \circuitikzbasekey/bipole/current/y position = below
    }
}

\ctikzset{i/.code = {
        \pgfkeys{\circuitikzbasekey/bipole/current/direction = forward,
            \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = above }
        \pgfkeys{/tikz/circuitikz/bipole/current/label/name=#1}
        \ctikzsetvalof{bipole/current/label/unit}{}
        \ifpgf@circ@siunitx
            \pgf@circ@handleSI{#1}
            \ifpgf@circ@siunitx@res
                \edef\pgf@temp{\pgf@circ@handleSI@val}
                \pgfkeyslet{/tikz/circuitikz/bipole/current/label/name}{\pgf@temp}
                \edef\pgf@temp{\pgf@circ@handleSI@unit}
                \pgfkeyslet{/tikz/circuitikz/bipole/current/label/unit}{\pgf@temp}
            \else
        \fi
        \else
    \fi
    %reverse current direction for voltage sources
    \ifpgf@circ@oldvoltagedirection\else
        \ifpgf@circuit@bipole@isvoltage
            \ifpgf@circuit@bipole@voltage@backward
                \pgfkeys{\circuitikzbasekey/bipole/current/direction = forward,
                    \circuitikzbasekey/bipole/current/x position = after,
                \circuitikzbasekey/bipole/current/y position = below }
            \else
                \pgfkeys{\circuitikzbasekey/bipole/current/direction = backward,
                    \circuitikzbasekey/bipole/current/x position = before,
                \circuitikzbasekey/bipole/current/y position = above }
            \fi\fi\fi
    }
}

\ifpgf@circ@oldvoltagedirection
    \ctikzset{i</.style = { i = #1, \circuitikzbasekey/bipole/current/direction = backward } }
\else
    \ctikzset{i</.style = { i = #1, \circuitikzbasekey/bipole/current/direction = backward, \circuitikzbasekey/bipole/current/x position = before } }
\fi
\ctikzset{i_/.style = { i = #1, \circuitikzbasekey/bipole/current/y position = below } }
\ctikzset{i>/.style = {i = #1, \circuitikzbasekey/bipole/current/direction = forward } }
\ctikzset{i^/.style = { i= #1, \circuitikzbasekey/bipole/current/y position = above } }

%% Output routine
\def\pgf@circ@drawcurrent{
    \pgfextra{
        \edef\pgf@circ@ffffff{\pgf@circ@direction}
        \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@ffffff\pgf@nil}

        \ifnum\pgfcircmathresult >4 \ifnum\pgfcircmathresult <86
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{north west} \else \def\pgf@circ@dir{south east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >85 \ifnum\pgfcircmathresult <95
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{west} \else \def\pgf@circ@dir{east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >94 \ifnum\pgfcircmathresult <176
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{south west}\else \def\pgf@circ@dir{north east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >175 \ifnum\pgfcircmathresult <185
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{south}\else\def\pgf@circ@dir{north}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >184 \ifnum\pgfcircmathresult <266
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{south east}\else\def\pgf@circ@dir{north west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >265 \ifnum\pgfcircmathresult <275
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{east}\else \def\pgf@circ@dir{west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >274 \ifnum\pgfcircmathresult <356
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{north east}\else\def\pgf@circ@dir{south west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult <5
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{north}\else\def\pgf@circ@dir{south}
        \fi
        \fi
        \ifnum\pgfcircmathresult >355
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{north}\else\def\pgf@circ@dir{south}
        \fi
    \fi

    \ifpgf@circuit@bipole@current@below
        \def\pgf@circ@bipole@current@label@where{-90}
    \else
        \def\pgf@circ@bipole@current@label@where{+90}
    \fi
    }

    \pgfextra{\def\pgf@temp{short}\edef\pgf@circ@temp{\ctikzvalof{bipole/kind}}}
    \ifx\pgf@circ@temp\pgf@temp%draw current at a short at middle of the line
        (\tikztostart)--(\tikztotarget)
    \else% normal bipole or source
        \ifpgf@circuit@bipole@current@before
            (\tikztostart)--(anchorstartnode)
        \else
            (anchorendnode)--(\tikztotarget)
        \fi
    \fi
    \ifpgf@circuit@bipole@current@backward
        \pgfextra{
            \pgfmathsubtract{\pgf@circ@ffffff}{180}
            \edef\pgf@circ@ffffff{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
        }
    \fi
    coordinate[currarrow,pos=\ctikzvalof{current/distance},rotate=\pgf@circ@ffffff,
    anchor=center](Iarrow)
    (Iarrow.\pgf@circ@bipole@current@label@where)
    node[anchor=\pgf@circ@dir, \circuitikzbasekey/bipole current style]
    (\ctikzvalof{bipole/name}current){\pgf@circ@finallabels{current/label}}
}

\endinput