Debian Codegraph @

texmf-dist/tex/generic/circuitikz/pgfcircflow.tex

raw
1 % Copyright 2018-2026 by Romano Giannetti
2 % Copyright 2015-2026 by Stefan Lindner
3 % Copyright 2013-2026 by Stefan Erhardt
4 % Copyright 2007-2026 by Massimo Redaelli
5 %
6 % This file may be distributed and/or modified
7 %
8 % 1. under the LaTeX Project Public License and/or
9 % 2. under the GNU Public License.
10 %
11 % See the files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.
12
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %% flow handling
15
16
17 %% styles
18 \ctikzset{bipole flow style/.style={}}
19 \tikzset{bipole flow style/.code={
20 \ctikzset{bipole flow style/.style={#1}}
21 }}
22 \tikzset{bipole flow append style/.code={
23 \ctikzset{bipole flow style/.append style={#1}}
24 }}
25
26 %% Options
27 \def\ctikzactivateflowdirections#1{%
28 \ctikzset{#1^>/.style = {#1={##1},
29 \circuitikzbasekey/bipole/flow/direction = forward,
30 \circuitikzbasekey/bipole/flow/x position = after,
31 \circuitikzbasekey/bipole/flow/y position = above
32 }}
33 \ctikzset{#1_>/.style = {#1={##1},
34 \circuitikzbasekey/bipole/flow/direction = forward,
35 \circuitikzbasekey/bipole/flow/x position = after,
36 \circuitikzbasekey/bipole/flow/y position = below
37 }}
38 \ctikzset{#1>^/.style = {#1={##1},
39 \circuitikzbasekey/bipole/flow/direction = forward,
40 \circuitikzbasekey/bipole/flow/x position = before,
41 \circuitikzbasekey/bipole/flow/y position = above
42 }}
43 \ctikzset{#1>_/.style = {#1={##1},
44 \circuitikzbasekey/bipole/flow/direction = forward,
45 \circuitikzbasekey/bipole/flow/x position = before,
46 \circuitikzbasekey/bipole/flow/y position = below
47 }}
48 \ctikzset{#1^</.style = {#1={##1},
49 \circuitikzbasekey/bipole/flow/direction = backward,
50 \circuitikzbasekey/bipole/flow/x position = after,
51 \circuitikzbasekey/bipole/flow/y position = above
52 }}
53 \ctikzset{#1_</.style = {#1={##1},
54 \circuitikzbasekey/bipole/flow/direction = backward,
55 \circuitikzbasekey/bipole/flow/x position = after,
56 \circuitikzbasekey/bipole/flow/y position = below
57 }}
58 \ctikzset{#1<^/.style = {#1={##1},
59 \circuitikzbasekey/bipole/flow/direction = backward,
60 \circuitikzbasekey/bipole/flow/x position = before,
61 \circuitikzbasekey/bipole/flow/y position = above
62 }}
63 \ctikzset{#1<_/.style = {#1={##1},
64 \circuitikzbasekey/bipole/flow/direction = backward,
65 \circuitikzbasekey/bipole/flow/x position = before,
66 \circuitikzbasekey/bipole/flow/y position = below
67 }}
68 \ctikzset{#1</.style = {#1={##1}, \circuitikzbasekey/bipole/flow/direction = backward}}
69 \ctikzset{#1_/.style = {#1={##1}, \circuitikzbasekey/bipole/flow/y position = below}}
70 \ctikzset{#1>/.style = {#1={##1}, \circuitikzbasekey/bipole/flow/direction = forward}}
71 \ctikzset{#1^/.style = {#1={##1}, \circuitikzbasekey/bipole/flow/y position = above}}
72 }
73 \ctikzactivateflowdirections{f}
74 \newif\ifpgfcirc@do@f@symbols\pgfcirc@do@f@symbolstrue
75 \ctikzset{no f symbols/.code={\pgfcirc@do@f@symbolsfalse}}
76 \ctikzset{f symbols/.code={\pgfcirc@do@f@symbolstrue}}
77 \ctikzset{f label/.style={bipole/flow/label/name={#1}}}
78
79 \ctikzset{f/.code = {
80 \pgfcirc@has@ftrue
81 \ifpgf@circuit@bipole@override@source@vif
82 \pgf@circuit@bipole@isvoltagefalse
83 \pgf@circuit@bipole@iscurrentfalse
84 \fi
85 \pgfkeys{\circuitikzbasekey/bipole/flow/direction = forward,
86 \circuitikzbasekey/bipole/flow/x position = after,
87 \circuitikzbasekey/bipole/flow/y position = above }
88 \pgfkeys{/tikz/circuitikz/bipole/flow/label/name={#1}}
89 \ctikzsetvalof{bipole/flow/label/unit}{}
90 \ifpgf@circ@siunitx
91 \pgf@circ@handleSI{#1}
92 \ifpgf@circ@siunitx@res
93 \edef\pgf@temp{\pgf@circ@handleSI@val}
94 \pgfkeyslet{/tikz/circuitikz/bipole/flow/label/name}{\pgf@temp}
95 \edef\pgf@temp{\pgf@circ@handleSI@unit}
96 \pgfkeyslet{/tikz/circuitikz/bipole/flow/label/unit}{\pgf@temp}
97 \else
98 \fi
99 \else
100 \fi
101 }
102 }
103
104 %% Output routine
105
106 \def\pgf@circ@drawflow{
107 \pgfextra{
108 \edef\pgf@circ@rounded@dir{\pgf@circ@direction}
109 \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@rounded@dir\pgf@nil}
110
111 \ifnum\pgfcircmathresult >4 \ifnum\pgfcircmathresult <86
112 \ifpgf@circuit@bipole@flow@below
113 \def\pgf@circ@dir{north west} \else \def\pgf@circ@dir{south east}
114 \fi
115 \fi\fi
116 \ifnum\pgfcircmathresult >85 \ifnum\pgfcircmathresult <95
117 \ifpgf@circuit@bipole@flow@below
118 \def\pgf@circ@dir{west} \else \def\pgf@circ@dir{east}
119 \fi
120 \fi\fi
121 \ifnum\pgfcircmathresult >94 \ifnum\pgfcircmathresult <176
122 \ifpgf@circuit@bipole@flow@below
123 \def\pgf@circ@dir{south west}\else \def\pgf@circ@dir{north east}
124 \fi
125 \fi\fi
126 \ifnum\pgfcircmathresult >175 \ifnum\pgfcircmathresult <185
127 \ifpgf@circuit@bipole@flow@below
128 \def\pgf@circ@dir{south}\else\def\pgf@circ@dir{north}
129 \fi
130 \fi\fi
131 \ifnum\pgfcircmathresult >184 \ifnum\pgfcircmathresult <266
132 \ifpgf@circuit@bipole@flow@below
133 \def\pgf@circ@dir{south east}\else\def\pgf@circ@dir{north west}
134 \fi
135 \fi\fi
136 \ifnum\pgfcircmathresult >265 \ifnum\pgfcircmathresult <275
137 \ifpgf@circuit@bipole@flow@below
138 \def\pgf@circ@dir{east}\else \def\pgf@circ@dir{west}
139 \fi
140 \fi\fi
141 \ifnum\pgfcircmathresult >274 \ifnum\pgfcircmathresult <356
142 \ifpgf@circuit@bipole@flow@below
143 \def\pgf@circ@dir{north east}\else\def\pgf@circ@dir{south west}
144 \fi
145 \fi\fi
146 \ifnum\pgfcircmathresult <5
147 \ifpgf@circuit@bipole@flow@below
148 \def\pgf@circ@dir{north}\else\def\pgf@circ@dir{south}
149 \fi
150 \fi
151 \ifnum\pgfcircmathresult >355
152 \ifpgf@circuit@bipole@flow@below
153 \def\pgf@circ@dir{north}\else\def\pgf@circ@dir{south}
154 \fi
155 \fi
156
157 \ifpgf@circuit@bipole@flow@below
158 \def\pgf@circ@bipole@flow@label@where{-90}
159 \else
160 \def\pgf@circ@bipole@flow@label@where{+90}
161 \fi
162 % export anchor position (if not needed, is always the same macro)
163 \expandafter\xdef\csname pgfcirc@\pgfcirc@m@prefix-Flab-anchor\endcsname{\pgf@circ@dir}
164 }
165
166 \pgfextra{\def\pgf@temp{short}\edef\pgf@circ@temp{\ctikzvalof{bipole/kind}}}
167 \ifx\pgf@circ@temp\pgf@temp%draw current at a short at middle of the line
168 coordinate (pgfcirc@Ffrom@flat) at (\tikztostart)
169 coordinate (pgfcirc@Fto@flat) at (\tikztotarget)
170 \else% normal bipole or source
171 \ifpgf@circuit@bipole@flow@before
172 coordinate (pgfcirc@Ffrom@flat) at (\tikztostart)
173 coordinate (pgfcirc@Fto@flat) at (pgfcirc@anchorstartnode)
174 \else
175 coordinate (pgfcirc@Ffrom@flat) at (pgfcirc@anchorendnode)
176 coordinate (pgfcirc@Fto@flat) at (\tikztotarget)
177 \fi
178 \fi
179 \pgfextra{
180 \newdimen{\absfshift}
181 \def\flow@offset{\ctikzvalof{flow/offset}\pgf@circ@Rlen}
182 \absfshift=\flow@offset
183 \ifpgf@circuit@bipole@flow@backward
184 \pgfmathsubtract{\pgf@circ@rounded@dir}{180}
185 \edef\pgf@circ@rounded@dir{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
186 \fi
187 }
188 \ifpgf@circuit@bipole@flow@below
189 coordinate (pgfcirc@Ffrom@up) at ($(pgfcirc@Ffrom@flat) ! \absfshift !-90: (pgfcirc@Fto@flat)$)
190 coordinate (pgfcirc@Fto@up) at ($(pgfcirc@Fto@flat) ! \absfshift !90: (pgfcirc@Ffrom@flat)$)
191 \else
192 coordinate (pgfcirc@Ffrom@up) at ($(pgfcirc@Ffrom@flat) ! \absfshift !90: (pgfcirc@Fto@flat)$)
193 coordinate (pgfcirc@Fto@up) at ($(pgfcirc@Fto@flat) ! \absfshift !-90: (pgfcirc@Ffrom@flat)$)
194 \fi
195 coordinate (\pgfcirc@a@prefix-Fpos) at ($(pgfcirc@Ffrom@up) ! \ctikzvalof{flow/distance} !(pgfcirc@Fto@up)$)
196 \pgfextra{
197 \absfshift=0.25\pgf@circ@Rlen% This is half size of the "flowarrow" shape!
198 }
199 coordinate (\pgfcirc@a@prefix-Ffrom) at ($(\pgfcirc@a@prefix-Fpos)!\absfshift!(pgfcirc@Ffrom@up)$)
200 coordinate (\pgfcirc@a@prefix-Fto) at ($(\pgfcirc@a@prefix-Fpos)!\absfshift!(pgfcirc@Fto@up) $)
201 %
202 % coordinate (\pgfcirc@a@prefix-Fpos) at
203 % ([yshift=\flow@offset]$(\pgfcirc@a@prefix-Ffrom)! \ctikzvalof{flow/distance} !(\pgfcirc@a@prefix-Fto)$)
204 % export the flow direction
205 \pgfextra{\expandafter\xdef\csname pgfcirc@\pgfcirc@m@prefix-Farrow-direction\endcsname{\pgf@circ@rounded@dir}}
206 % if the flow label is not empty (in which case we have already all the anchors)
207 \pgf@circ@ifkeyempty{bipole/flow/label/name}\else
208 % the flow arrow is really a node "flowarrow", not a real arrow
209 \ifpgfcirc@do@f@symbols
210 node[flowarrow, rotate=\pgf@circ@rounded@dir, anchor=center](Farrowpos) at (\pgfcirc@a@prefix-Fpos) {}
211 \else
212 node[flowarrow, rotate=\pgf@circ@rounded@dir, anchor=center,
213 circuitikz/phantom@flowarrow](Farrowpos) at (\pgfcirc@a@prefix-Fpos) {}
214 \fi
215 node[anchor=\pgf@circ@dir, \circuitikzbasekey/bipole flow style]
216 (\ctikzvalof{bipole/name}flow) at (Farrowpos.\pgf@circ@bipole@flow@label@where) {\pgf@circ@finallabels{flow/label}}
217 \fi
218 % adjust from and to before exporting --- it's much more simple like this then rework the algorithm above
219 \ifpgf@circuit@bipole@flow@backward
220 \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Ffrom}{\pgfcirc@a@prefix-Fto}
221 \fi
222
223 }
224
225 \endinput