-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtikz-multinets.sty
2069 lines (1934 loc) · 72.1 KB
/
tikz-multinets.sty
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Copyright 2017 by Sallaccio,
% comprehensive of the
% copyright 2008 by Marc de Falco
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tikz-multinets}[2017/05/01 v0.1 Tikz Interaction Multinets library, by Sallaccio]
% Modifications from v0.1 tikz interaction nets library by Marc de Falco:
% - apex angle of simple cells (from 60 to 100)
% - added multiport cells and 1-port cells
% - added multiwires
% - added empty node with anchors above and above above for better building of wires
% - added external auxiliary and principal ports to bypass cells
% - added commands for : cellheight, size of principal port in multicells, port size, free wire size, bypass
% distance
\RequirePackage{tikz}
\RequirePackage{ifthen}
\RequirePackage{pgffor}
% \RequirePackage{xstring}
% We need this to load the \emph{isosceles triangle} shape and \emph{trapezium} shape
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shadows}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix}
\usetikzlibrary{fit}
\usetikzlibrary{calc}
% \usepackage{pgfmath}
\newif\ifshownodes
\newif\ifshowports
\newif\ifshowportsincell
% Package option for linear logic
\newif\iflinlogic
\linlogicfalse
\DeclareOption{linlogic}{\linlogictrue}
\ProcessOptions\relax
\pgfkeys{
/pgf/.cd,
arity/.initial=4,
coarity/.initial=2,
precise/.is if=precisewires,
show nodes/.is if=shownodes,
show ports/.is if=showports,
% direction/.initial=west,
% direction/.store in=\direct,
/cell/.cd,
show ports/.is if=showportsincell,
arity/.initial=0 % Used by simple cell but only when drawing ports
}
%%%%%%%% CONSTANTS %%%%%%%%%
\newcommand{\inetportsize}{.6cm} % sets the 'length' of each principal port in a multicell
\newcommand{\inetcellheight}{.8cm} % sets the (minimal) height of cells
\newcommand{\abovedistance}{.15cm} % sets the distance between a port and its 'above' coordinate
\newcommand{\aboveabovedistance}{.5cm} % sets the distance between a port and its 'above above' coordinate
\newcommand{\bypassdistance}{.3cm} % sets the distance of the exterior principal and auxiliary ports
\newcommand{\inetwirefreelength}{.3cm} % sets the length of free wires
\newcommand{\inetportnamedistance}{.3cm} % sets the distance of the name of a port from its representation
\newcommand{\inetbracedistance}{\abovedistance+.2cm} % sets the distance of the braces from the ports it embraces
\newcommand{\inetbracetextdistance}{\inetbracedistance+.4cm} % sets the distance of the text over the braces from the ports it embraces
\newcommand{\inetsetportlength}[1]{
\renewcommand{\abovedistance}{#1}
\renewcommand{\aboveabovedistance}{(#1+.35cm)}
}
\newcommand{\inetsetportsize}[1]{\renewcommand{\inetportsize}{#1}}
\newcommand{\inetsetcellheight}[1]{\renewcommand{\inetcellheight}{#1}}
\newcommand{\inetsetabovedistance}[1]{\renewcommand{\abovedistance}{#1}}
\newcommand{\inetsetaboveabovedistance}[1]{\renewcommand{\aboveabovedistance}{#1}}
\newcommand{\inetsetbypassdistance}[1]{\renewcommand{\bypassdistance}{#1}}
\newcommand{\inetsetwirefreelength}[1]{\renewcommand{\inetwirefreelength}{#1}}
\newcommand{\inetsetportnamedistance}[1]{\renewcommand{\inetportnamedistance}{#1}}
\newcommand{\inetsetbracedistance}[1]{\renewcommand{\inetbracedistance}{#1}}
\newcommand{\inetsetbracetextdistance}[1]{\renewcommand{\inetbracetextdistance}{#1}}
\def\signfornodes{\Large +} % sets the respresentation of hidden nodes if 'show nodes' option is on
\def\inetwirelayer{wire layer}
\newcommand{\inetwiresunder}{\def\inetwirelayer{below layer}}
%%%%%%%% DECLARATION OF USABLE COMMANDS %%%%%%%%%
% \inetfancy % use fancy style
% \inetnofancy % do not use fancy style
% \inetsetfancycellstyle}[1] % set fancy style for all kinds of cells
% \inetsetfancywirestyle}[1] % set fancy style for wires
% \inetsetfancyfreewirestyle}[1] % set fancy style for free wires
% \inetsetfancyportstyle}[1] % set fancy style for ports
% \inetsetfancyboxstyle}[1] % set fancy style for boxes
\newcommand{\inetcell}{\INETcell} % create a cell with one principal port (triangle)
\newcommand{\inetmulticell}{\INETmulticell} % create a cell with multiple principal ports (trapezium)
\newcommand{\inetzerocell}{\INETzerocell} % create a cell with zero auxiliary ports (circle)
\newcommand{\inetport}{\INETport} % create a port on a cell
\newcommand{\inetportnamed}{\INETportnamed}
\newcommand{\inetwirefree}{\INETwirefree} % create a free wire from a port of a cell
\newcommand{\inetwirecoords}{\INETwirecoords} % create a wire between two positions
\newcommand{\inetwire}{\INETsmoothwire} % create a wire between two ports
\newcommand{\inetprecisewire}{\INETprecisewire} % create a precise wire between two ports through nodes
\newcommand{\inetsmoothwire}{\INETsmoothwire} % create a simple wire between two ports through nodes
\newcommand{\inetshortwire}{\INETshortwire} % create a short wire between two ports
\newcommand{\inetveryshortwire}{\INETveryshortwire} % create a very short wire between two ports
\newcommand{\inetmultiwire}{\INETmultiwire} % create a multiwire (precise or simple depending on \inetwire)
\newcommand{\inetwirearoundleft}{\INETwirearoundleft} % create a wire around a cell on its left
\newcommand{\inetwirearoundright}{\INETwirearoundright} % create a wire around a cell on its right
\newcommand{\inetnode}{\INETnode} % create a node for wires to go through
\newcommand{\inetloop}{\INETloop} % create a loop wire
\newcommand{\inetbox}{\INETbox} % create a box
\newcommand{\inetprombox}{\INETprombox} % create a linear logic promotion box
\newcommand{\inetdotsabove}{\INETdotsabove} % dots above a port
\newcommand{\inetbrace}{\INETbrace} % braces imbracing ports of some cells
\newcommand{\inetdotsbetween}{\INETdotsbetween} % dots between two positions
\newcommand{\nodebetween}{\INETnodebetween} % node in the middle of two positions
\newcommand{\inetmulticelltype}{\INETmulticelltype} % declare a multicell of some type: label, coarity, arity
\newcommand{\inetmulticellshape}{\INETmulticellshape} % declare a multicell of some shape: coarity, arity
\newcommand{\inetprecisewires}{\renewcommand{\inetwire}{\INETprecisewire}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SHAPES AND PORTS OF MULTICELLS, CELLS, ZEROCELLS, NODES %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEFINITION OF SHAPE AND PORTS OF A MULTICELL
\pgfdeclareshape{multicellule}{
\savedmacro\arity{%
\pgfmathtruncatemacro\arity{\pgfkeysvalueof{/pgf/arity}}%
}%
\savedmacro\coarity{%
\pgfmathtruncatemacro\coarity{\pgfkeysvalueof{/pgf/coarity}}%
}%
\inheritsavedanchors[from=trapezium]
\inheritanchorborder[from=trapezium]
\inheritanchor[from=trapezium]{center}
\inheritanchor[from=trapezium]{south}
\inheritanchor[from=trapezium]{west}
\inheritanchor[from=trapezium]{east}
\inheritanchor[from=trapezium]{north}
\inheritanchor[from=trapezium]{bottom left corner}
\inheritanchor[from=trapezium]{bottom right corner}
\inheritanchor[from=trapezium]{top left corner}
\inheritanchor[from=trapezium]{top right corner}
\inheritanchor[from=trapezium]{top side}
\inheritanchor[from=trapezium]{bottom side}
% Definition of pax in case arity = 1 (for compatibility with simple cells)
\anchor{pax}{
\installtrapeziumparameters
\pgfpointlineattime{0.5}{\lowerleftpoint}{\lowerrightpoint}
}
\anchor{above pax}{
\installtrapeziumparameters
\pgfmathrotatepointaround{
\pgfpointadd{\pgfpoint{0ex}{-\abovedistance}}
{\pgfpointlineattime{0.5}{\lowerleftpoint}{\lowerrightpoint}}
}{
\pgfpointlineattime{0.5}{\lowerleftpoint}{\lowerrightpoint}
}{ \rotate }
}
\anchor{above above pax}{
\installtrapeziumparameters
\pgfmathrotatepointaround{
\pgfpointadd{\pgfpoint{0ex}{-\aboveabovedistance}}
{\pgfpointlineattime{0.5}{\lowerleftpoint}{\lowerrightpoint}}
}{
\pgfpointlineattime{0.5}{\lowerleftpoint}{\lowerrightpoint}
}{ \rotate }
}
% Definition of simili auxiliary port outside of the cell on its left side
% in order to help build wires around cells
\anchor{leftext pax}{
\installtrapeziumparameters
\pgfpointlineatdistance{-\bypassdistance}{\lowerleftpoint}{\lowerrightpoint}
}
\anchor{above leftext pax}{
\installtrapeziumparameters
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointlineatdistance{-\bypassdistance}{\lowerleftpoint}{\lowerrightpoint}
}{\pgfpoint{0ex}{-\abovedistance}}
}{
\pgfpointlineatdistance{-\bypassdistance}{\lowerleftpoint}{\lowerrightpoint}
}{\rotate}
}
\anchor{above above leftext pax}{
\installtrapeziumparameters
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointlineatdistance{-\bypassdistance}{\lowerleftpoint}{\lowerrightpoint}
}{\pgfpoint{0ex}{-\aboveabovedistance}}
}{
\pgfpointlineatdistance{-\bypassdistance}{\lowerleftpoint}{\lowerrightpoint}
}{\rotate}
}
% Definition of simili auxiliary port outside of the cell on its right side
% in order to help build wires around cells
\anchor{rightext pax}{
\installtrapeziumparameters
\pgfpointlineatdistance{-\bypassdistance}{\lowerrightpoint}{\lowerleftpoint}
}
\anchor{above rightext pax}{
\installtrapeziumparameters
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointlineatdistance{-\bypassdistance}{\lowerrightpoint}{\lowerleftpoint}
}{\pgfpoint{0ex}{-\abovedistance}}
}{
\pgfpointlineatdistance{-\bypassdistance}{\lowerrightpoint}{\lowerleftpoint}
}{\rotate}
}
\anchor{above above rightext pax}{
\installtrapeziumparameters
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointlineatdistance{-\bypassdistance}{\lowerrightpoint}{\lowerleftpoint}
}{\pgfpoint{0ex}{-\aboveabovedistance}}
}{
\pgfpointlineatdistance{-\bypassdistance}{\lowerrightpoint}{\lowerleftpoint}
}{\rotate}
}
% Definition of a port aligned with the principal port outside of the cell on its left side
% in order to help build wires around cells
\anchor{leftext pal}{
\installtrapeziumparameters
\pgfmathrotatepointaround{%
\csname pgf@anchor@multicellule@rightext pax\endcsname%
}{\centerpoint}{180}%
}
\anchor{above leftext pal}{
\installtrapeziumparameters
\pgfmathrotatepointaround{%
\csname pgf@anchor@multicellule@above rightext pax\endcsname%
}{\centerpoint}{180}%
}
\anchor{above above leftext pal}{
\installtrapeziumparameters
\pgfmathrotatepointaround{%
\csname pgf@anchor@multicellule@above above rightext pax\endcsname%
}{\centerpoint}{180}%
}
% Definition of a port aligned with the principal port outside of the cell on its right side
% in order to help build wires around cells
\anchor{rightext pal}{
\installtrapeziumparameters
\pgfmathrotatepointaround{%
\csname pgf@anchor@multicellule@leftext pax\endcsname%
}{\centerpoint}{180}%
}
\anchor{above rightext pal}{
\installtrapeziumparameters
\pgfmathrotatepointaround{%
\csname pgf@anchor@multicellule@above leftext pax\endcsname%
}{\centerpoint}{180}%
}
\anchor{above above rightext pal}{
\installtrapeziumparameters
\pgfmathrotatepointaround{%
\csname pgf@anchor@multicellule@above above leftext pax\endcsname%
}{\centerpoint}{180}%
}
% Definition of an anchor outside of the cell on its west and east sides
% in order to help build wires around cells
\anchor{westwest}{
\installtrapeziumparameters
\pgfpointadd{\pgf@anchor@multicellule@west}{\pgfpoint{-\bypassdistance}{0ex}}
}
\anchor{easteast}{
\installtrapeziumparameters
\pgfpointadd{\pgf@anchor@multicellule@east}{\pgfpoint{\bypassdistance}{0ex}}
}
%
% Definition of 'pax k' (k-th auxiliary port) [no default];
\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@multicellule\endcsname{%
\c@pgf@counta\arity\relax%
\pgfmathloop%
\ifnum\c@pgf@counta>0\relax%
\pgfutil@ifundefined{pgf@anchor@multicellule@pax\space\the\c@pgf@counta}{%
% I HATE TeX
\expandafter\xdef\csname pgf@anchor@multicellule@pax\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathadd@{\noexpand\arity}{1}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathdivide@{\the\c@pgf@counta}%
{\noexpand\the\c@pgf@countb}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\installtrapeziumparameters%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\lowerleftpoint}%
{\noexpand\lowerrightpoint}%
}%
\expandafter\xdef\csname pgf@anchor@multicellule@above pax\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathadd@{\noexpand\arity}{1}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathdivide@{\the\c@pgf@counta}%
{\noexpand\the\c@pgf@countb}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\installtrapeziumparameters
\noexpand\pgfmathrotatepointaround{%
\noexpand\pgfpointadd{
\noexpand\pgfpoint{0cm}{-\noexpand\abovedistance}
}{%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\lowerleftpoint}%
{\noexpand\lowerrightpoint}%
}%
}{\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\lowerleftpoint}%
{\noexpand\lowerrightpoint}
}{\noexpand\rotate}%
}%
\expandafter\xdef\csname pgf@anchor@multicellule@above above pax\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathadd@{\noexpand\arity}{1}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathdivide@{\the\c@pgf@counta}%
{\noexpand\the\c@pgf@countb}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\installtrapeziumparameters
\noexpand\pgfmathrotatepointaround{%
\noexpand\pgfpointadd{
\noexpand\pgfpoint{0cm}{-\noexpand\aboveabovedistance}
}{%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\lowerleftpoint}%
{\noexpand\lowerrightpoint}%
}%
}{\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\lowerleftpoint}%
{\noexpand\lowerrightpoint}
}{\noexpand\rotate}%
}%
}{\c@pgf@counta0\relax}%
\advance\c@pgf@counta-1\relax%
\repeatpgfmathloop%
}%
% Definition of 'pal k' (k-th principal port) [no default];
\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@multicellule\endcsname{%
\c@pgf@counta\coarity\relax%
\pgfmathloop%
\ifnum\c@pgf@counta>0\relax%
\pgfutil@ifundefined{pgf@anchor@multicellule@pal\space\the\c@pgf@counta}{%
% I HATE TeX
\expandafter\xdef\csname pgf@anchor@multicellule@pal\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathmultiply@{\noexpand\coarity}{2}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathmultiply@{\the\c@pgf@counta}{2}%
\noexpand\pgfmathadd@{\noexpand\pgfmathresult}{-1}%
\noexpand\pgfmathdivide@{\noexpand\pgfmathresult}%
{\noexpand\the\c@pgf@countb}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\installtrapeziumparameters%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\upperrightpoint}%
{\noexpand\upperleftpoint}%
}%
\expandafter\xdef\csname pgf@anchor@multicellule@above pal\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathmultiply@{\noexpand\coarity}{2}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathmultiply@{\the\c@pgf@counta}{2}%
\noexpand\pgfmathadd@{\noexpand\pgfmathresult}{-1}%
\noexpand\pgfmathdivide@{\noexpand\pgfmathresult}%
{\noexpand\the\c@pgf@countb}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\installtrapeziumparameters
\noexpand\pgfmathrotatepointaround{%
\noexpand\pgfpointadd{
\noexpand\pgfpoint{0cm}{\noexpand\abovedistance}
}{%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\upperrightpoint}%
{\noexpand\upperleftpoint}%
}%
}{\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\upperrightpoint}%
{\noexpand\upperleftpoint}
}{\noexpand\rotate}%
}%
\expandafter\xdef\csname pgf@anchor@multicellule@above above pal\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathmultiply@{\noexpand\coarity}{2}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathmultiply@{\the\c@pgf@counta}{2}%
\noexpand\pgfmathadd@{\noexpand\pgfmathresult}{-1}%
\noexpand\pgfmathdivide@{\noexpand\pgfmathresult}%
{\noexpand\the\c@pgf@countb}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\installtrapeziumparameters
\noexpand\pgfmathrotatepointaround{%
\noexpand\pgfpointadd{
\noexpand\pgfpoint{0cm}{\noexpand\aboveabovedistance}
}{%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\upperrightpoint}%
{\noexpand\upperleftpoint}%
}%
}{\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\upperrightpoint}%
{\noexpand\upperleftpoint}
}{\noexpand\rotate}%
}%
}{\c@pgf@counta0\relax}%
\advance\c@pgf@counta-1\relax%
\repeatpgfmathloop%
}
% Definition of the form of the multicell: a trapezium with rounded corners on the longest side
\backgroundpath{
\installtrapeziumparameters{
% \pgftransformshift{\basepoint}
% \pgftransformrotate{\rotate}
\pgfpathmoveto{\upperleftpoint}
\pgfpathlineto{
\pgfpointlineattime{0.8}{\upperleftpoint}{\lowerleftpoint}
}
\pgfpathcurveto{
\pgfpointlineattime{0.8}{\upperleftpoint}{\lowerleftpoint}
}{
\lowerleftpoint
}{
\pgfpointlineattime{0.1}{\lowerleftpoint}{\lowerrightpoint}
}
\pgfpathlineto{
\pgfpointlineattime{0.9}{\lowerleftpoint}{\lowerrightpoint}
}
\pgfpathcurveto{
\pgfpointlineattime{0.9}{\lowerleftpoint}{\lowerrightpoint}
}{
\lowerrightpoint
}{
\pgfpointlineattime{0.2}{\lowerrightpoint}{\upperrightpoint}
}
\pgfpathlineto{
\pgfpointlineattime{0.3}{\lowerrightpoint}{\upperrightpoint}
}
\pgfpathlineto{
\upperrightpoint
}
\pgfpathclose
}
}
}
% DEFINITION OF SHAPE AND PORTS OF A SIMPLE CELL
\pgfdeclareshape{cellule}{
\savedmacro\arity{%
\pgfmathtruncatemacro\arity{\pgfkeysvalueof{/pgf/arity}}%
}
\inheritsavedanchors[from=isosceles triangle]
\inheritanchorborder[from=isosceles triangle]
\inheritanchor[from=isosceles triangle]{center}
\inheritanchor[from=isosceles triangle]{left corner}
\inheritanchor[from=isosceles triangle]{right corner}
\inheritanchor[from=isosceles triangle]{south}
\inheritanchor[from=isosceles triangle]{west}
\inheritanchor[from=isosceles triangle]{north east}
\inheritanchor[from=isosceles triangle]{north west}
\inheritanchor[from=isosceles triangle]{south east}
\inheritanchor[from=isosceles triangle]{south west}
\inheritanchor[from=isosceles triangle]{east}
\inheritanchor[from=isosceles triangle]{north}
\inheritanchor[from=isosceles triangle]{lower left}
\inheritanchor[from=isosceles triangle]{apex}
% Definition of pax in case arity = 1
\anchor{pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointlineattime{0.5}
{\lowerleftanchor}
{\lowerrightanchor}
}{\centerpoint}
}
{\centerpoint}{\rotate}
}
\anchor{above pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointadd{\pgfpoint{-\abovedistance}{0cm}}{
\pgfpointlineattime{0.5}
{\lowerleftanchor}
{\lowerrightanchor}
}
}
{\centerpoint}
}{\centerpoint}{\rotate}
}
\anchor{above above pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointadd{\pgfpoint{-\aboveabovedistance}{0cm}}{
\pgfpointlineattime{0.5}{\lowerleftanchor}{\lowerrightanchor}
}
}
{\centerpoint}
}
{\centerpoint}{\rotate}
}
% Definition of middle pax (ususally used if arity = 3; in fact, equal to just 'pax')
\anchor{middle pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointlineattime{0.5}{\lowerleftanchor}{\lowerrightanchor}
}{\centerpoint}
}
{\centerpoint}{\rotate}
}
\anchor{above middle pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointadd{\pgfpoint{-\abovedistance}{0cm}}{
\pgfpointlineattime{0.5}
{\lowerleftanchor}{\lowerrightanchor}
}
}
{\centerpoint}
}{\centerpoint}{\rotate}
}
\anchor{above above middle pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointadd{\pgfpoint{-\aboveabovedistance}{0cm}
}{
\pgfpointlineattime{0.5}{\lowerleftanchor}{\lowerrightanchor}
}
}
{\centerpoint}
}{\centerpoint}{\rotate}
}
% Definition of left pax (usually used if arity = 2 or 3, but always defined)
\anchor{left pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointlineattime{0.25}{\lowerleftanchor}{\lowerrightanchor}
}{\centerpoint}
}
{\centerpoint}{\rotate}
}
\anchor{above left pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointadd{
\pgfpoint{-\abovedistance}{0cm}
}{
\pgfpointlineattime{0.25}{\lowerleftanchor}{\lowerrightanchor}
}
}
{\centerpoint}
}{\centerpoint}{\rotate}
}
\anchor{above above left pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointadd{
\pgfpoint{-\aboveabovedistance}{0cm}
}{
\pgfpointlineattime{0.25}{\lowerleftanchor}{\lowerrightanchor}
}
}
{\centerpoint}
}{\centerpoint}{\rotate}
}
% Definition of right pax (usually used if arity = 2 or 3, but always defined)
\anchor{right pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointlineattime{0.75}{\lowerleftanchor}{\lowerrightanchor}
}
{\centerpoint}
}
{\centerpoint}{\rotate}
}
\anchor{above right pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointadd{\pgfpoint{-\abovedistance}{0cm}}
{
\pgfpointlineattime{0.75}{\lowerleftanchor}{\lowerrightanchor}
}
}
{\centerpoint}
}{\centerpoint}{\rotate}
}
\anchor{above above right pax}{
\trianglepoints
\pgfmathrotatepointaround{
\pgfpointadd{
\pgfpointadd{\pgfpoint{-\aboveabovedistance}{0cm}}
{
\pgfpointlineattime{0.75}{\lowerleftanchor}{\lowerrightanchor}
}
}
{\centerpoint}
}{\centerpoint}{\rotate}
}
% Definition of principal port
\anchor{pal}{
\trianglepoints
\pgfpointadd{\centerpoint}{
\pgfmathrotatepointaround{
\pgfpointadd{\pgfpoint{-0.07cm}{0cm}}{\apexanchor}
% \apexanchor
}{\pgfpointorigin}{\rotate}
}
}
\anchor{above pal}{
\trianglepoints
\pgfpointadd{\centerpoint}{
\pgfmathrotatepointaround{
\pgfpointadd{\pgfpoint{\abovedistance-0.07cm}{0cm}}{\apexanchor}
}
{\pgfpointorigin}{\rotate}
}
}
\anchor{above above pal}{
\trianglepoints
\pgfpointadd{\centerpoint}{
\pgfmathrotatepointaround{
\pgfpointadd{\pgfpoint{\aboveabovedistance-0.07cm}{0cm}}{\apexanchor}
}
{\pgfpointorigin}{\rotate}
}
}
\anchor{pal 1}{
\trianglepoints
\pgfpointadd{\centerpoint}{
\pgfmathrotatepointaround{
\pgfpointadd{\pgfpoint{-0.07cm}{0cm}}{\apexanchor}
}{\pgfpointorigin}{\rotate}
}
}
% Definition of principal port as first port of a multicell for consistency
\anchor{above pal 1}{
\trianglepoints
\pgfpointadd{\centerpoint}{
\pgfmathrotatepointaround{
\pgfpointadd{\pgfpoint{\abovedistance}{0cm}}{\apexanchor}
}
{\pgfpointorigin}{\rotate}
}
}
\anchor{above above pal 1}{
\trianglepoints
\pgfpointadd{\centerpoint}{
\pgfmathrotatepointaround{
\pgfpointadd{\pgfpoint{\aboveabovedistance}{0cm}}{\apexanchor}
}
{\pgfpointorigin}{\rotate}
}
}
% Definition of simili auxiliary port outside of the cell on its left side
% in order to help build wires around cells
\anchor{leftext pax}{
\trianglepoints
\pgfmathrotatepointaround{%
\pgfpointadd{%
\pgfpointlineatdistance%
{-\bypassdistance}{\lowerleftanchor}{\lowerrightanchor}%
}{\centerpoint}%
}{\centerpoint}{\rotate}%
}
\anchor{above leftext pax}{
\trianglepoints
\pgfmathrotatepointaround{%
\pgfpointadd{%
\pgfpointadd{
\pgfpoint{-\abovedistance}{0cm}}{%
\pgfpointlineatdistance%
{-\bypassdistance}{\lowerleftanchor}{\lowerrightanchor}%
}%
}{\centerpoint}%
}%
{\centerpoint}%
{\rotate}%
}
\anchor{above above leftext pax}{
\trianglepoints
\pgfmathrotatepointaround{%
\pgfpointadd{%
\pgfpointadd{
\pgfpoint{-\aboveabovedistance}{0cm}}{%
\pgfpointlineatdistance{-\bypassdistance}{\lowerleftanchor}{\lowerrightanchor}%
}%
}{\centerpoint}%
}%
{\centerpoint}%
{\rotate}%
}
% Definition of simili auxiliary port outside of the cell on its right side
% in order to help build wires around cells
\anchor{rightext pax}{
\trianglepoints
\pgfmathrotatepointaround{%
\pgfpointadd{%
\pgfpointlineatdistance%
{-\bypassdistance}{\lowerrightanchor}{\lowerleftanchor}%
}{\centerpoint}%
}{\centerpoint}{\rotate}%
}
\anchor{above rightext pax}{
\trianglepoints
\pgfmathrotatepointaround{%
\pgfpointadd{%
\pgfpointadd{
\pgfpoint{-\abovedistance}{0cm}}{%
\pgfpointlineatdistance%
{-\bypassdistance}{\lowerrightanchor}{\lowerleftanchor}%
}%
}{\centerpoint}%
}%
{\centerpoint}%
{\rotate}%
}
\anchor{above above rightext pax}{
\trianglepoints
\pgfmathrotatepointaround{%
\pgfpointadd{%
\pgfpointadd{
\pgfpoint{-\aboveabovedistance}{0cm}}{%
\pgfpointlineatdistance{-\bypassdistance}{\lowerrightanchor}{\lowerleftanchor}%
}%
}{\centerpoint}%
}%
{\centerpoint}%
{\rotate}%
}
% Definition of a port aligned with the principal port outside of the cell on its left side
% in order to help build wires around cells
\anchor{leftext pal}{
\trianglepoints
\pgfmathrotatepointaround{%
\csname pgf@anchor@cellule@rightext pax\endcsname%
}{\centerpoint}{180}%
}
\anchor{above leftext pal}{
\trianglepoints
\pgfmathrotatepointaround{%
\csname pgf@anchor@cellule@above rightext pax\endcsname%
}{\centerpoint}{180}%
}
\anchor{above above leftext pal}{
\trianglepoints
\pgfmathrotatepointaround{%
\csname pgf@anchor@cellule@above above rightext pax\endcsname%
}{\centerpoint}{180}%
}
% Definition of a port aligned with the principal port outside of the cell on its right side
% in order to help build wires around cells
\anchor{rightext pal}{
\trianglepoints
\pgfmathrotatepointaround{%
\csname pgf@anchor@cellule@leftext pax\endcsname%
}{\centerpoint}{180}%
}
\anchor{above rightext pal}{
\trianglepoints
\pgfmathrotatepointaround{%
\csname pgf@anchor@cellule@above leftext pax\endcsname%
}{\centerpoint}{180}%
}
\anchor{above above rightext pal}{
\trianglepoints
\pgfmathrotatepointaround{%
\csname pgf@anchor@cellule@above above leftext pax\endcsname%
}{\centerpoint}{180}%
}
% Definition of 'pax k' when arity is specified (by default 4);
% In this way, the default cell can be used as :
% arity = 1 --> 'pax' or 'middle pax'
% arity = 2 --> 'left/right pax'
% arity = 3 --> 'left/middle/right pax'
% arity = 4 --> 'pax 1/2/3/4' and 'left/right'
\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@cellule\endcsname{%
\c@pgf@counta\arity\relax%
\pgfmathloop%
\ifnum\c@pgf@counta>0\relax%
\pgfutil@ifundefined{pgf@anchor@cellule@pax\space\the\c@pgf@counta}{%
% I HATE TeX
\expandafter\xdef\csname pgf@anchor@cellule@pax\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathadd@{\noexpand\arity}{-1}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathadd@{\the\c@pgf@counta}{-1}%
\noexpand\pgfmathdivide@{\noexpand\pgfmathresult}%
{\noexpand\the\c@pgf@countb}%
\noexpand\pgfmathmultiply@{\noexpand\pgfmathresult}{0.5}%
\noexpand\pgfmathadd@{\noexpand\pgfmathresult}{0.25}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\trianglepoints%
\noexpand\pgfmathrotatepointaround{%
\noexpand\pgfpointadd{%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\lowerleftanchor}%
{\noexpand\lowerrightanchor}%
}{\noexpand\centerpoint}%
}{\noexpand\centerpoint}{\noexpand\rotate}%
}%
\expandafter\xdef\csname pgf@anchor@cellule@above pax\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathadd@{\noexpand\arity}{-1}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathadd@{\the\c@pgf@counta}{-1}%
\noexpand\pgfmathdivide@{\noexpand\pgfmathresult}%
{\noexpand\the\c@pgf@countb}%
\noexpand\pgfmathmultiply@{\noexpand\pgfmathresult}{0.5}%
\noexpand\pgfmathadd@{\noexpand\pgfmathresult}{0.25}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\trianglepoints
\noexpand\pgfmathrotatepointaround{%
\noexpand\pgfpointadd{%
\noexpand\pgfpointadd{
\noexpand\pgfpoint{-\noexpand\abovedistance}{0cm}}{%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\lowerleftanchor}%
{\noexpand\lowerrightanchor}%
}%
}{\noexpand\centerpoint}%
}%
{\noexpand\centerpoint}%
{\noexpand\rotate}%
}%
\expandafter\xdef\csname pgf@anchor@cellule@above above pax\space\the\c@pgf@counta\endcsname{%
\noexpand\pgfmathadd@{\noexpand\arity}{-1}%
\noexpand\c@pgf@countb=\noexpand\pgfmathresult%
\noexpand\pgfmathadd@{\the\c@pgf@counta}{-1}%
\noexpand\pgfmathdivide@{\noexpand\pgfmathresult}%
{\noexpand\the\c@pgf@countb}%
\noexpand\pgfmathmultiply@{\noexpand\pgfmathresult}{0.5}%
\noexpand\pgfmathadd@{\noexpand\pgfmathresult}{0.25}%
\noexpand\let\noexpand\time\noexpand\pgfmathresult%
\noexpand\trianglepoints
\noexpand\pgfmathrotatepointaround{%
\noexpand\pgfpointadd{%
\noexpand\pgfpointadd{
\noexpand\pgfpoint{-\noexpand\aboveabovedistance}{0cm}}{%
\noexpand\pgfpointlineattime%
{\noexpand\time}%
{\noexpand\lowerleftanchor}%
{\noexpand\lowerrightanchor}%
}%
}{\noexpand\centerpoint}%
}%
{\noexpand\centerpoint}%
{\noexpand\rotate}%
}%
}{\c@pgf@counta0\relax}%
\advance\c@pgf@counta-1\relax%
\repeatpgfmathloop%
}%
% Definition of the form of the simple cell: a isoceles triangle with rounded corners
\backgroundpath{
\trianglepoints{
\pgftransformshift{\centerpoint}
\pgftransformrotate{\rotate}
\pgfpathmoveto{\apex}
\pgfpathlineto{
\pgfpointlineattime{0.7}{\apex}{\lowerleft}
}
\pgfpathcurveto{
\pgfpointlineattime{0.9}{\apex}{\lowerleft}
}{
\pgfpointlineattime{0.1}{\lowerleft}{\lowerleft\pgf@y-\pgf@y}
}{
\pgfpointlineattime{0.2}{\lowerleft}{\lowerleft\pgf@y-\pgf@y}
}
\pgfpathlineto{
\pgfpointlineattime{0.8}{\lowerleft}{\lowerleft\pgf@y-\pgf@y}
}
\pgfpathcurveto{
\pgfpointlineattime{0.9}{\lowerleft}{\lowerleft\pgf@y-\pgf@y}
}{
\pgfpointlineattime{0.1}{\lowerleft\pgf@y-\pgf@y}{\apex}
}{
\pgfpointlineattime{0.3}{\lowerleft\pgf@y-\pgf@y}{\apex}
}
\pgfpathclose
}
}
}
% DEFINITION OF SHAPE AND PORTS OF A ZEROCELL
\pgfdeclareshape{zerocellule}{
\inheritsavedanchors[from=circle]
\inheritbackgroundpath[from=circle]
\inheritanchorborder[from=circle]
\inheritanchor[from=circle]{center}
\inheritanchor[from=circle]{south}
\inheritanchor[from=circle]{north}
\inheritanchor[from=circle]{east}
\inheritanchor[from=circle]{west}
\inheritanchor[from=circle]{north east}
\inheritanchor[from=circle]{north west}
\inheritanchor[from=circle]{south east}
\inheritanchor[from=circle]{south west}
\anchor{n}{\pgf@anchor@zerocellule@north}
\anchor{above n}{\pgfpointadd{\pgfpoint{0cm}{\abovedistance}}{\pgf@anchor@zerocellule@n}}
\anchor{above above n}{\pgfpointadd{\pgfpoint{0cm}{\aboveabovedistance}}{\pgf@anchor@zerocellule@n}}
\anchor{s}{\pgf@anchor@zerocellule@south}
\anchor{above s}{\pgfpointadd{\pgfpoint{0cm}{-\abovedistance}}{\pgf@anchor@zerocellule@s}}
\anchor{above above s}{\pgfpointadd{\pgfpoint{0cm}{-\aboveabovedistance}}{\pgf@anchor@zerocellule@s}}
\anchor{w}{\pgf@anchor@zerocellule@west}
\anchor{above w}{\pgfpointadd{\pgfpoint{-\abovedistance}{0cm}}{\pgf@anchor@zerocellule@w}}
\anchor{above above w}{\pgfpointadd{\pgfpoint{-\aboveabovedistance}{0cm}}{\pgf@anchor@zerocellule@w}}
\anchor{e}{\pgf@anchor@zerocellule@east}
\anchor{above e}{\pgfpointadd{\pgfpoint{\abovedistance}{0cm}}{\pgf@anchor@zerocellule@e}}
\anchor{above above e}{\pgfpointadd{\pgfpoint{\aboveabovedistance}{0cm}}{\pgf@anchor@zerocellule@e}}
\anchor{ne}{\csname pgf@anchor@zerocellule@north east\endcsname}
\anchor{above ne}{\pgfpointadd{\pgfpoint{.7*\abovedistance}{.7*\abovedistance}}{\pgf@anchor@zerocellule@ne}}
\anchor{above above ne}{\pgfpointadd{\pgfpoint{.7*\aboveabovedistance}{.7*\aboveabovedistance}}{\pgf@anchor@zerocellule@ne}}
\anchor{nw}{\csname pgf@anchor@zerocellule@north west\endcsname}
\anchor{above nw}{\pgfpointadd{\pgfpoint{-.7*\abovedistance}{.7*\abovedistance}}{\pgf@anchor@zerocellule@nw}}
\anchor{above above nw}{\pgfpointadd{\pgfpoint{-.7*\aboveabovedistance}{.7*\aboveabovedistance}}{\pgf@anchor@zerocellule@nw}}
\anchor{se}{\csname pgf@anchor@zerocellule@south east\endcsname}
\anchor{above se}{\pgfpointadd{\pgfpoint{.7*\abovedistance}{-.7*\abovedistance}}{\pgf@anchor@zerocellule@se}}
\anchor{above above se}{\pgfpointadd{\pgfpoint{.7*\aboveabovedistance}{-.7*\aboveabovedistance}}{\pgf@anchor@zerocellule@se}}
\anchor{sw}{\csname pgf@anchor@zerocellule@south west\endcsname}
\anchor{above sw}{\pgfpointadd{\pgfpoint{-.7*\abovedistance}{-.7*\abovedistance}}{\pgf@anchor@zerocellule@sw}}
\anchor{above above sw}{\pgfpointadd{\pgfpoint{-.7*\aboveabovedistance}{-.7*\aboveabovedistance}}{\pgf@anchor@zerocellule@sw}}
\anchor{northeast}{\pgf@anchor@zerocellule@ne}
\anchor{northwest}{\pgf@anchor@zerocellule@nw}
\anchor{southeast}{\pgf@anchor@zerocellule@se}
\anchor{southwest}{\pgf@anchor@zerocellule@sw}
\anchor{above north}{\csname pgf@anchor@zerocellule@above n\endcsname}
\anchor{above south}{\csname pgf@anchor@zerocellule@above s\endcsname}
\anchor{above east}{\csname pgf@anchor@zerocellule@above e\endcsname}
\anchor{above west}{\csname pgf@anchor@zerocellule@above w\endcsname}
\anchor{above northeast}{\csname pgf@anchor@zerocellule@above ne\endcsname}
\anchor{above northwest}{\csname pgf@anchor@zerocellule@above nw\endcsname}
\anchor{above southeast}{\csname pgf@anchor@zerocellule@above se\endcsname}
\anchor{above southwest}{\csname pgf@anchor@zerocellule@above sw\endcsname}
\anchor{above north east}{\csname pgf@anchor@zerocellule@above ne\endcsname}
\anchor{above north west}{\csname pgf@anchor@zerocellule@above nw\endcsname}
\anchor{above south east}{\csname pgf@anchor@zerocellule@above se\endcsname}
\anchor{above south west}{\csname pgf@anchor@zerocellule@above sw\endcsname}
\anchor{above above north}{\csname pgf@anchor@zerocellule@above above n\endcsname}
\anchor{above above south}{\csname pgf@anchor@zerocellule@above above s\endcsname}
\anchor{above above east}{\csname pgf@anchor@zerocellule@above above e\endcsname}
\anchor{above above west}{\csname pgf@anchor@zerocellule@above above w\endcsname}
\anchor{above above northeast}{\csname pgf@anchor@zerocellule@above above ne\endcsname}
\anchor{above above northwest}{\csname pgf@anchor@zerocellule@above above nw\endcsname}
\anchor{above above southeast}{\csname pgf@anchor@zerocellule@above above se\endcsname}
\anchor{above above southwest}{\csname pgf@anchor@zerocellule@above above sw\endcsname}