summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/circuits/tikzlibrarycircuits.code.tex
blob: 56a5340f99e24c7a0e0b765b72d9159febdc4571 (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
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
261
262
263
264
265
266
% Copyright 2008 by Till Tantau and others Wibrow
%
% 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/generic/pgf/licenses/LICENSE for more details.

\usetikzlibrary{calc,decorations.markings}%


%
% Indicate that the picture contains a circuit
%
\tikzset{
  circuit/.style={
    every circuit/.try,
    /utils/exec=\tikz@lib@circ@on@tofalse,
    execute at begin to={
      \tikz@lib@circ@on@totrue
      \let\tikz@lib@circ@start@node\pgfutil@empty
      \def\tikz@lib@circ@end{-- (\tikztotarget) \tikztonodes}
    }
  }
}%

\newif\iftikz@lib@circ@on@to


%
% General management
%

\tikzset{
  circuit handle symbol/.code={%
    \global\advance\tikz@lib@circ@count by1\relax%
    \iftikz@lib@circ@on@to
      {%
        % Compute the tikz@time...
        \pgfkeys{
          /pgf/key filters/active families or no family/.install key filter={/pgf/key filters/false}{/pgf/key filters/false},
          /tikz/circuits/pos grabber/.activate family}
        \pgfqkeysfiltered{/tikz}{pos=.5,#1}%
        \expandafter%
      }%
      \expandafter\def\expandafter\tikz@lib@circ@pos\expandafter{\tikz@time}%
      \pgfkeysalso{to path={
         \pgfextra{\tikz@lib@circ@on@tofalse}
         decorate [decoration={markings,mark connection node=mark node}]
          {
            \tikz@lib@circ@start@node
            \tikz@lib@circ@end
          }
        }}
      \ifx\tikz@lib@circ@pos\tikz@zero@text%
        \def\tikz@lib@circ@start@node{%
          {\pgfextra{\tikz@lib@circ@compute@direction{\tikz@lib@circ@start}}%
          node[alias=tikz@lib@circ@node@start,at={(0,0)},#1,pos=]{}}(tikz@lib@circ@node@start)}%
      \else%
        \ifx\tikz@lib@circ@pos\tikz@one@text%
          \def\tikz@lib@circ@end{
            {\pgfextra{\tikz@lib@circ@compute@direction{\tikz@lib@circ@target}}%
              node[alias=tikz@lib@circ@node\the\tikz@lib@circ@count,at={(0,0)},#1,pos=]{}}
            --(tikz@lib@circ@node\the\tikz@lib@circ@count)\tikztonodes
          }%
        \else%
          \edef\tikz@marshal{mark=at position \tikz@lib@circ@pos\space with}%
          \def\tikz@marshala{decoration=}%
          \expandafter\expandafter\expandafter\tikzset%
          \expandafter\expandafter\expandafter{\expandafter\tikz@marshala\expandafter{\tikz@marshal{\node[alias=mark node,#1,pos=]{};}}}
        \fi%
      \fi%
    \else
      \pgfkeysalso{#1}
    \fi
  }
}%
\newcount\tikz@lib@circ@count
\def\tikz@zero@text{0.0}%
\def\tikz@one@text{1.0}%

\def\tikz@lib@circ@compute@direction#1{%
  \tikz@scan@one@point\tikz@lib@circ@save@start(\tikztostart)%
  \tikz@scan@one@point\tikz@lib@circ@save@target(\tikztotarget)%
  \pgf@process{\pgfpointnormalised{\pgfpointdiff{\tikz@lib@circ@start}{\tikz@lib@circ@target}}}%
  \pgf@ya=-\pgf@y%
  \pgftransformcm{\the\pgf@x}{\the\pgf@y}{\the\pgf@ya}{\the\pgf@x}{#1}%
}%
\def\tikz@lib@circ@save@start#1{\def\tikz@lib@circ@start{#1}}%
\def\tikz@lib@circ@save@target#1{\def\tikz@lib@circ@target{#1}}%

\tikzset{
  circuits/pos grabber/.is family,
  pos/.belongs to family=/tikz/circuits/pos grabber,
  at start/.belongs to family=/tikz/circuits/pos grabber,
  very near start/.belongs to family=/tikz/circuits/pos grabber,
  near start/.belongs to family=/tikz/circuits/pos grabber,
  midway/.belongs to family=/tikz/circuits/pos grabber,
  near end/.belongs to family=/tikz/circuits/pos grabber,
  very near end/.belongs to family=/tikz/circuits/pos grabber,
  at end/.belongs to family=/tikz/circuits/pos grabber
}%


%
% Declaring a new symbol
%
\tikzset{
  circuit declare symbol/.style args={#1}{
    % Declares a new circuit symbol.
    %
    % #1 = name
    % #2 = factor for default minimum width
    % #3 = factor for default minimum height
    %
    % The following styles are defined:
    %
    % #1
    % Can be given as an option to a "node" command or to a "to"
    % command. It takes a set of options as parameter that will be
    % passed to the option.
    %
    % set #1 graphic
    % This keys can be set to the necessary options to make a normal
    % node look like the symbol. For instance, for a resistor that is
    % rendered as a rectangle, this keys can be set, basically, to
    % "rectangle,draw". Set this key to use a different appearance for
    % symbols of kind #1.
    %
    % every #1
    % This style will be included with every symbols of this kind and
    % can be used to configure them further.
    %
    % every circuit symbol
    % This style is also included with every symbol.
    #1/.style={circuit handle symbol={
        inner sep=0.5pt,
        every circuit symbol,
        #1/graphic,
        every #1/.try,
        ##1}
    },
    #1/graphic/.style={},
    set #1 graphic/.style={#1/graphic/.style={##1}}
  },
  circuit symbol unit/.code=\pgfmathsetlength\tikzcircuitssizeunit{#1},
  circuit symbol size/.style args={width #1 height #2}{
    minimum width=#1*\tikzcircuitssizeunit,
    minimum height=#2*\tikzcircuitssizeunit
  },
  huge circuit symbols/.style={circuit symbol unit=10pt},
  large circuit symbols/.style={circuit symbol unit=8pt},
  medium circuit symbols/.style={circuit symbol unit=7pt},
  small circuit symbols/.style={circuit symbol unit=6pt},
  tiny circuit symbols/.style={circuit symbol unit=5pt},
}%

\newdimen\tikzcircuitssizeunit
\tikzcircuitssizeunit=7pt


%
% Annotations
%

\tikzset{
  circuit declare annotation/.style args={#1#2#3}{%
    #1/.style={
      append after command={%
        \bgroup
          [current point is local=true]
          [every circuit annotation/.try]
          [every #1/.try]
          [shift={(\tikzlastnode.north)}]
          [annotation arrow,->]
          [label distance=#2,##1]
          #3
          \tikz@after@path%
        \egroup%
      }
    },
    #1'/.style={
      append after command={%
        \bgroup
          [current point is local=true]
          [every circuit annotation/.try]
          [every #1/.try]
          [shift={(\tikzlastnode.south)},yscale=-1]
          [annotation arrow,->]
          [label distance=#2,##1]
          #3
          \tikz@after@path%
        \egroup%
      }
    }
  },
  annotation arrow/.style = {
    /utils/exec={\pgfsetarrowoptions{direction ee}{.4*\the\tikzcircuitssizeunit+.3*\the\pgflinewidth}},
    >=direction ee
  }
}%



%
% Rotating symbols
%
\tikzset{
  point up/.style={rotate=90},
  point down/.style={rotate=-90},
  point left/.style={rotate=180},
  point right/.style={}
}%



%
% Basic theming
%

\tikzset{
  every circuit symbol/.style={},
  circuit symbol open/.style={draw},
  circuit symbol filled/.style={draw,fill=black},
  circuit symbol lines/.style={draw},
  circuit symbol wires/.style={draw},
}%





%
% Labels
%

\tikzset{
  info/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@plain{\tikz@lib@circ@lab@plain[]}#1\pgf@stop},%}
  info'/.code={\pgfutil@ifnextchar[\tikz@lib@circ@labp@plain{\tikz@lib@circ@labp@plain[]}#1\pgf@stop},%}
  info sloped/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@sloped@plain{\tikz@lib@circ@lab@sloped@plain[]}#1\pgf@stop},%}
  info' sloped/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@slopedp@plain{\tikz@lib@circ@lab@slopedp@plain[]}#1\pgf@stop},%}
  circuit declare unit/.style 2 args={
    %
    % Defines four styles that can be used to add labels to a node.
    %
    #1/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab{\tikz@lib@circ@lab[]}##1\pgf@stop{#2}{#1}},%}
    #1 sloped/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@sloped{\tikz@lib@circ@lab@sloped[]}##1\pgf@stop{#2}{#1}},%}
    #1'/.code={\pgfutil@ifnextchar[\tikz@lib@circ@labp{\tikz@lib@circ@labp[]}##1\pgf@stop{#2}{#1}},%}
    #1' sloped/.code={\pgfutil@ifnextchar[\tikz@lib@circ@lab@slopedp{\tikz@lib@circ@lab@slopedp[]}##1\pgf@stop{#2}{#1}}%}
  }
}%

\def\tikz@lib@circ@lab[#1]#2\pgf@stop#3#4{\tikzset{label={[every info/.try,every #4/.try,#1]$\mathrm{#2#3}$}}}%
\def\tikz@lib@circ@lab@sloped[#1]#2\pgf@stop#3#4{\tikzset{label={[every info/.try,every #4/.try,transform shape,#1]$\mathrm{#2#3}$}}}%
\def\tikz@lib@circ@labp[#1]#2\pgf@stop#3#4{\tikzset{label={[label position=below,every info/.try,every #4/.try,#1]$\mathrm{#2#3}$}}}%
\def\tikz@lib@circ@lab@slopedp[#1]#2\pgf@stop#3#4{\tikzset{label={[label position=below,every info/.try,every #4/.try,transform shape,#1]$\mathrm{#2#3}$}}}%

\def\tikz@lib@circ@lab@plain[#1]#2\pgf@stop{\tikzset{label={[every info/.try,#1]#2}}}%
\def\tikz@lib@circ@lab@sloped@plain[#1]#2\pgf@stop{\tikzset{label={[every info/.try,transform shape,#1]#2}}}%
\def\tikz@lib@circ@labp@plain[#1]#2\pgf@stop{\tikzset{label={[label position=below,every info/.try,#1]#2}}}%
\def\tikz@lib@circ@lab@slopedp@plain[#1]#2\pgf@stop{\tikzset{label={[label position=below,every info/.try,transform shape,#1]#2}}}%



\endinput