Debian Codegraph @

texmf-dist/tex/latex/tikz-inet/tikz-inet.sty

raw
1 % Copyright 2008 by Marc de Falco
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 \NeedsTeXFormat{LaTeX2e}
9 \ProvidesPackage{tikz-inet}[2008/06/02 v0.1 tikz interaction nets library]
10 \RequirePackage{tikz}
11 \RequirePackage{ifthen}
12
13 % We need this to load the \emph{isosceles triangle} shape
14 \usetikzlibrary{shapes.geometric}
15 \usetikzlibrary{shadows}
16 \usetikzlibrary{positioning}
17 \usetikzlibrary{matrix}
18 \usetikzlibrary{fit}
19
20 \pgfkeys{/pgf/.cd,
21 arity/.initial=4,
22 }
23
24 % The definition of the shape of a cell
25 \pgfdeclareshape{cellule}{
26 \savedmacro\arity{%
27 \pgfmathtruncatemacro\arity{\pgfkeysvalueof{/pgf/arity}}%
28 }
29
30 \inheritsavedanchors[from=isosceles triangle]
31 \inheritanchorborder[from=isosceles triangle]
32 \inheritanchor[from=isosceles triangle]{center}
33 \inheritanchor[from=isosceles triangle]{left corner}
34 \inheritanchor[from=isosceles triangle]{right corner}
35 \inheritanchor[from=isosceles triangle]{south}
36 \inheritanchor[from=isosceles triangle]{west}
37 \inheritanchor[from=isosceles triangle]{north east}
38 \inheritanchor[from=isosceles triangle]{north west}
39 \inheritanchor[from=isosceles triangle]{south east}
40 \inheritanchor[from=isosceles triangle]{south west}
41 \inheritanchor[from=isosceles triangle]{east}
42 \inheritanchor[from=isosceles triangle]{north}
43 \inheritanchor[from=isosceles triangle]{lower left}
44 \inheritanchor[from=isosceles triangle]{apex}
45
46 \anchor{above pax}{
47 \trianglepoints
48 \pgfmathrotatepointaround{
49 \pgfpointadd{
50 \pgfpointadd{\pgfpoint{-2ex}{0cm}}{
51 \pgfpointlineattime{0.5}
52 {\lowerleftanchor}{\lowerrightanchor}
53 }
54 }
55 {\centerpoint}
56 }{\centerpoint}{\rotate}
57 }
58
59
60 \anchor{above middle pax}{
61 \trianglepoints
62 \pgfmathrotatepointaround{
63 \pgfpointadd{
64 \pgfpointadd{\pgfpoint{-2ex}{0cm}}{
65 \pgfpointlineattime{0.5}
66 {\lowerleftanchor}{\lowerrightanchor}
67 }
68 }
69 {\centerpoint}
70 }{\centerpoint}{\rotate}
71 }
72
73 \anchor{pax}{
74 \trianglepoints
75 \pgfmathrotatepointaround{
76 \pgfpointadd{\pgfpointlineattime{0.5}
77 {\lowerleftanchor}{\lowerrightanchor}}{\centerpoint}}
78 {\centerpoint}{\rotate}
79 }
80
81
82 \anchor{middle pax}{
83 \trianglepoints
84 \pgfmathrotatepointaround{
85 \pgfpointadd{\pgfpointlineattime{0.5}
86 {\lowerleftanchor}{\lowerrightanchor}}{\centerpoint}}
87 {\centerpoint}{\rotate}
88 }
89
90 \anchor{above left pax}{
91 \trianglepoints
92 \pgfmathrotatepointaround{
93 \pgfpointadd{
94 \pgfpointadd{\pgfpoint{-2ex}{0cm}}{
95 \pgfpointlineattime{0.25}
96 {\lowerleftanchor}{\lowerrightanchor}
97 }
98 }
99 {\centerpoint}
100 }{\centerpoint}{\rotate}
101 }
102
103
104 \anchor{left pax}{
105 \trianglepoints
106 \pgfmathrotatepointaround{
107 \pgfpointadd{\pgfpointlineattime{0.25}
108 {\lowerleftanchor}{\lowerrightanchor}}{\centerpoint}}
109 {\centerpoint}{\rotate}
110 }
111
112 \anchor{above right pax}{
113 \trianglepoints
114 \pgfmathrotatepointaround{
115 \pgfpointadd{
116 \pgfpointadd{\pgfpoint{-2ex}{0cm}}{
117 \pgfpointlineattime{0.75}
118 {\lowerleftanchor}{\lowerrightanchor}
119 }
120 }
121 {\centerpoint}
122 }{\centerpoint}{\rotate}
123 }
124
125
126 \anchor{right pax}{
127 \trianglepoints
128 \pgfmathrotatepointaround{
129 \pgfpointadd{\pgfpointlineattime{0.75}
130 {\lowerleftanchor}{\lowerrightanchor}}{\centerpoint}}
131 {\centerpoint}{\rotate}
132 }
133
134 \anchor{above pal}{
135 \trianglepoints
136 \pgfpointadd{\centerpoint}{
137 \pgfmathrotatepointaround{
138 \pgfpointadd{\pgfpoint{2ex}{0cm}}{\apexanchor}}
139 {\pgfpointorigin}{\rotate}
140 }
141 }
142
143
144 \anchor{pal}{
145 \trianglepoints
146 \pgfpointadd{\centerpoint}{
147 \pgfmathrotatepointaround{
148 \pgfpointadd{\pgfpoint{-0.07cm}{0cm}}{\apexanchor}
149 }{\pgfpointorigin}{\rotate}
150 }
151 }
152
153
154 \backgroundpath{
155 \trianglepoints{
156 \pgftransformshift{\centerpoint}
157 \pgftransformrotate{\rotate}
158 \pgfpathmoveto{\apex}
159 \pgfpathlineto{
160 \pgfpointlineattime{0.8}{\apex}{\lowerleft}
161 }
162 \pgfpathcurveto{
163 \pgfpointlineattime{0.9}{\apex}{\lowerleft}
164 }{
165 \pgfpointlineattime{0.1}{\lowerleft}{\lowerleft\pgf@y-\pgf@y}
166 }{
167 \pgfpointlineattime{0.2}{\lowerleft}{\lowerleft\pgf@y-\pgf@y}
168 }
169 \pgfpathlineto{
170 \pgfpointlineattime{0.8}{\lowerleft}{\lowerleft\pgf@y-\pgf@y}
171 }
172 \pgfpathcurveto{
173 \pgfpointlineattime{0.9}{\lowerleft}{\lowerleft\pgf@y-\pgf@y}
174 }{
175 \pgfpointlineattime{0.1}{\lowerleft\pgf@y-\pgf@y}{\apex}
176 }{
177 \pgfpointlineattime{0.2}{\lowerleft\pgf@y-\pgf@y}{\apex}
178 }
179
180 \pgfpathclose
181 }
182 }
183
184 \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@cellule\endcsname{%
185 \c@pgf@counta\arity\relax%
186 \pgfmathloop%
187 \ifnum\c@pgf@counta>0\relax%
188 \pgfutil@ifundefined{pgf@anchor@cellule@pax\space\the\c@pgf@counta}{%
189 % I HATE TeX
190 \expandafter\xdef\csname pgf@anchor@cellule@pax\space\the\c@pgf@counta\endcsname{%
191 \noexpand\pgfmathadd@{\noexpand\arity}{-1}%
192 \noexpand\c@pgf@countb=\noexpand\pgfmathresult%
193 \noexpand\pgfmathadd@{\the\c@pgf@counta}{-1}%
194 \noexpand\pgfmathdivide@{\noexpand\pgfmathresult}%
195 {\noexpand\the\c@pgf@countb}%
196 \noexpand\pgfmathmultiply@{\noexpand\pgfmathresult}{0.5}%
197 \noexpand\pgfmathadd@{\noexpand\pgfmathresult}{0.25}%
198 \noexpand\let\noexpand\time\noexpand\pgfmathresult%
199 \noexpand\trianglepoints%
200 \noexpand\pgfmathrotatepointaround{%
201 \noexpand\pgfpointadd{%
202 \noexpand\pgfpointlineattime%
203 {\noexpand\time}%
204 {\noexpand\lowerleftanchor}%
205 {\noexpand\lowerrightanchor}%
206 }{\noexpand\centerpoint}%
207 }{\noexpand\centerpoint}{\noexpand\rotate}%
208 }%
209 \expandafter\xdef\csname pgf@anchor@cellule@above pax\space\the\c@pgf@counta\endcsname{%
210 \noexpand\pgfmathadd@{\noexpand\arity}{-1}%
211 \noexpand\c@pgf@countb=\noexpand\pgfmathresult%
212 \noexpand\pgfmathadd@{\the\c@pgf@counta}{-1}%
213 \noexpand\pgfmathdivide@{\noexpand\pgfmathresult}%
214 {\noexpand\the\c@pgf@countb}%
215 \noexpand\pgfmathmultiply@{\noexpand\pgfmathresult}{0.5}%
216 \noexpand\pgfmathadd@{\noexpand\pgfmathresult}{0.25}%
217 \noexpand\let\noexpand\time\noexpand\pgfmathresult%
218 \noexpand\trianglepoints
219 \noexpand\pgfmathrotatepointaround{%
220 \noexpand\pgfpointadd{%
221 \noexpand\pgfpointadd{
222 \noexpand\pgfpoint{-2ex}{0cm}}{%
223 \noexpand\pgfpointlineattime%
224 {\noexpand\time}%
225 {\noexpand\lowerleftanchor}%
226 {\noexpand\lowerrightanchor}%
227 }%
228 }{\noexpand\centerpoint}%
229 }%
230 {\noexpand\centerpoint}%
231 {\noexpand\rotate}%
232 }%
233 }{\c@pgf@counta0\relax}%
234 \advance\c@pgf@counta-1\relax%
235 \repeatpgfmathloop%
236 }%
237
238 }
239
240 \newcommand\inetoptions{\setkeys{inet}}
241 \newcommand{\inetcolor}{red}
242 \define@key{inet}{color}{\renewcommand{\inetcolor}{#1}}
243 \newcommand{\inet@defaultangle}{0}
244 \define@key{inet}{defaultangle}{\renewcommand{\inet@defaultangle}{#1}}
245
246 \newcount\inet@angle
247 \inet@angle=0
248
249 \tikzset{wirestyle/.style = {draw, line width=0.15ex, line cap=rect}}
250 \tikzset{cellstyle/.style = {
251 draw, line width=0.2ex, fill=white,
252 inner sep=0.2ex,
253 }}
254 \tikzset{boxstyle/.style = {draw,line width=0.1ex}}
255 \tikzfading[name=inet fading,
256 left color=transparent!0,
257 right color=transparent!100]
258 \tikzset{fancywirestyle/.style = {draw, line width=0.15ex,
259 draw=black!50!#1,
260 double=white!50!#1,double distance=0.2ex,
261 }}
262 \tikzset{fancycellstyle/.style={%
263 general shadow={fill, shadow scale=1.0,%
264 shadow xshift=0.3ex,shadow yshift=-0.3ex,opacity=0.2},
265 line width=0.15ex,%
266 inner sep=0.2ex,%
267 draw=black!50!#1,%
268 top color=#1,%
269 bottom color=white,%!80!#1,%
270 shading angle=\inet@angle,%
271 }}
272 \tikzset{fancyboxstyle/.style = {line width=0.2ex,fill opacity=0.5,
273 fill=white!20!#1,draw=black!30!#1}}
274
275 \newif\ifinet@fancy\inet@fancyfalse
276
277 \DeclareOption{fancy}{\inet@fancytrue}
278 \DeclareOption{nofancy}{\inet@fancyfalse}
279
280 \newcommand{\inetfancy}{\inet@fancytrue}
281 \newcommand{\inetnofancy}{\inet@fancyfalse}
282
283 \newcommand{\inetsetfancycellstyle}[1]{
284 \tikzset{fancycellstyle/.style = {#1}}%
285 }
286 \newcommand{\inetsetfancywirestyle}[1]{
287 \tikzset{fancycellstyle/.style = {#1}}%
288 }
289
290 \DeclareOption*{\expandafter\inetoptions\expandafter{\CurrentOption}}
291 \ProcessOptions\relax
292
293 \pgfdeclarelayer{wire layer}
294 \pgfdeclarelayer{box layer}
295 \pgfsetlayers{box layer,wire layer,main}
296
297 \makeatletter
298
299 \newcommand{\inetcellstyle}{%
300 \ifinet@fancy fancycellstyle\else cellstyle\fi%
301 }
302
303 \newcommand{\inetwirestyle}{%
304 \ifinet@fancy fancywirestyle\else wirestyle\fi%
305 }
306
307 \newcommand{\inetboxstyle}{%
308 \ifinet@fancy fancyboxstyle\else boxstyle\fi%
309 }
310
311
312 \newcommand{\inetcell}[1][]{%
313 \@ifnextchar({%
314 \inetcell@ii[#1]%
315 }{%
316 \inetcell@iib[#1]%
317 }%
318 }
319
320 \def\inetcell@iib[#1]#2{%
321 \inetcell@ii[#1](#2){#2}%
322 }
323
324 \def\inetcell@ii[#1](#2)#3{%
325 \@ifnextchar[{\inetcell@iii[#1](#2){#3}%
326 }{\inetcell@iii[#1](#2){#3}[\inet@defaultangle]}%
327 }
328
329 \def\inetcell@iii[#1](#2)#3[#4]{%
330 \ifthenelse{\equal{#4}{U}}{\inet@angle=180}{%
331 \ifthenelse{\equal{#4}{D}}{\inet@angle=0}{%
332 \ifthenelse{\equal{#4}{L}}{\inet@angle=270}{%
333 \ifthenelse{\equal{#4}{R}}{\inet@angle=90}{\inet@angle=#4}%
334 }%
335 }%
336 }%
337 \node[%
338 \inetcellstyle=\inetcolor%
339 ,shape border rotate=\inet@angle-90%
340 ,cellule, isosceles triangle apex angle=60,%
341 shape border uses incircle, #1] (#2) {#3};%
342 }
343
344 \def\inetwirecoords(#1)(#2){%
345 \begin{pgfonlayer}{wire layer}%
346 \draw[\ifinet@fancy fancywirestyle\else wirestyle\fi=\inetcolor]%
347 (#1) -- (#2);%
348 \end{pgfonlayer}
349 }
350
351 \def\inetwire{%
352 \@ifnextchar[{\inetwire@i}{\inetwire@i[]}%
353 }
354
355 \def\inetwire@i[#1](#2.#3)(#4.#5){%
356 \begin{pgfonlayer}{wire layer}%
357 \draw[\inetwirestyle=\inetcolor,#1]%
358 (#2.#3) .. controls (#2.above #3) and (#4.above #5) .. (#4.#5);%
359 \end{pgfonlayer}%
360 }
361
362 \def\inetwirefree{%
363 \@ifnextchar[{\inetwirefree@i}{\inetwirefree@i[]}%
364 }
365 \def\inetwirefree@i[#1](#2.#3){%
366 \begin{pgfonlayer}{wire layer}%
367 \draw[\ifinet@fancy fancywirestyle\else wirestyle\fi=\inetcolor,#1]%
368 (#2.#3) -- (#2.above #3);%
369 \end{pgfonlayer}%
370 }
371
372 \newcommand{\inetloop}[1][]{%
373 \begin{pgfonlayer}{wire layer}%
374 \node[\ifinet@fancy fancywirestyle\else wirestyle\fi=\inetcolor,%
375 #1,circle,inner sep=6pt] {};
376 \end{pgfonlayer}%
377 }
378
379 \newcommand{\inetbox}[1][]{%
380 \inetbox@i[#1]%
381 }
382
383 \def\inetbox@i[#1]#2(#3){%
384 \begin{pgfonlayer}{box layer}%
385 \node[\ifinet@fancy fancyboxstyle\else boxstyle\fi=\inetcolor,
386 fit=#2,inner sep=10pt,#1] (#3) {};%
387 \end{pgfonlayer}%
388 }
389
390 \newcommand{\inetprombox}[1][]{%
391 \inetprombox@i[#1]%
392 }
393 \def\inetprombox@i[#1]#2(#3){%
394 \inetbox@i[#1]{#2}(b#3)%
395 \inetcell[above=-4ex of b#3.south](#3){$!$}%
396 %\inetcell[above=-4ex of $(b#3.south west)!.75!(b#3.south)$](#3){$!$}%
397 }
398
399 \makeatother
400
401 \endinput