% Defintion of Reo Channels and other utilities to design Reo Circuits % using the pgf (tikz) by Till Tantau (pgf manual for v2.10) % % author: Nuno Oliveira % version: 1.0 % % This package may be distributed and modified to better suit the user's % interests. Please, keep the credits to the original author (but you may % add yours) % % License: LaTeX Project Public License and/or GNU Public License. % \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{reotex}[2014/08/13 A Tex way to draw reo circuits!] %releases: %2014/08/13 - version 1.1 %WHAT HAS CHANGED: % - arrow tips used in drain/spout were corrected. The update to tikz3.0 caused a problem concerning the size of such arrows. %2012/01/05 - version 1, first published at CTAN. \RequirePackage{ifthen} \RequirePackage{tikz} \RequirePackage{verbatim} \usetikzlibrary{arrows,% decorations.pathmorphing,% decorations.shapes,% calc% } %makes @ as a normal letter and not as a special latex character... \makeatletter %%%%%% VARIABLES %%%%%%%%%%% \newdimen\rt@thearrowsize \newdimen\rt@width \newdimen\rt@xa \newdimen\rt@xb \newdimen\rt@xc \newdimen\rt@ya \newdimen\rt@yb \newdimen\rt@yc \newcommand{\rt@arrowtip}{-stealth} %%%%%%%%%%%% BASE COMMANDS %%%%%%%%%%%% \newcommand{\rt@midpoints}[4]{% \pgfextractx{\rt@xa}{\pgfpointlineattime{#1}{\pgfpointanchor{#3}{center}}{\pgfpointanchor{#4}{center}}} \pgfextracty{\rt@ya}{\pgfpointlineattime{#1}{\pgfpointanchor{#3}{center}}{\pgfpointanchor{#4}{center}}} \pgfextractx{\rt@xb}{\pgfpointlineattime{#2}{\pgfpointanchor{#3}{center}}{\pgfpointanchor{#4}{center}}} \pgfextracty{\rt@yb}{\pgfpointlineattime{#2}{\pgfpointanchor{#3}{center}}{\pgfpointanchor{#4}{center}}} } \newcommand{\rt@middlepoint}[2]{% \pgfextractx{\rt@xc}{\pgfpointlineattime{.5}{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}} \pgfextracty{\rt@yc}{\pgfpointlineattime{.5}{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}} } %%%%%%%% TIKZ DEFINITIONS %%%%%%%%%%%%%%% \tikzset{cross/.style={path picture={ \draw[black] (path picture bounding box.south east) -- (path picture bounding box.north west) (path picture bounding box.south west) -- (path picture bounding box.north east); } } } %%%%%%%%%%%%%%%% SYNCHRONOUS CHANNELS %%%%%%%%%% % Synchronous \newcommand{\sync}{% \@ifstar\sync@noarrow\sync@arrow } \newcommand{\sync@arrow}[3]{% \draw[\rt@arrowtip] #1 to #3 #2; } \newcommand{\sync@noarrow}[3]{% \draw #1 to #3 #2; } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Lossy Synchronous \newcommand{\lossysync}{% \@ifstar\lossysync@noarrow\lossysync@arrow } \newcommand{\lossysync@arrow}[3]{% \draw[\rt@arrowtip,dashed] #1 to #3 #2; } \newcommand{\lossysync@noarrow}[3]{% \draw[dashed] #1 to #3 #2; } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Synchronous Drain \newcommand{\syncdrain}{% \@ifstar \syncdrain@arrow \syncdrain@arrow } \newcommand{\syncdrain@arrow}[3]{% \draw[inwards-inwards, shorten >=-0.5mm, shorten <=-0.5mm] #1 to #3 #2; } %\newcommand{\syncdrain@noarrow}[3]{% % \draw[inwards-inwards] #1 to #2 #3; %} % Synchronous Spout \newcommand{\syncspout}{% \@ifstar \syncspout@arrow \syncspout@arrow } \newcommand{\syncspout@arrow}[3]{% \draw[outwards-outwards,shorten >=-0.5mm, shorten <=-0.5mm] #1 to #3 #2; } %\newcommand{\syncspout@noarrow}[3]{% % \draw[outwards-outwards,] #1 to #2 #3; %} %Filter \newcommand{\filter}{% \@ifstar\filter@noarrow\filter@arrow } \newcommand{\filter@arrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.25}{0.75}{rt@p1}{rt@p2} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw decorate [decoration=zigzag] {(\rt@xa,\rt@ya) -- #3 (\rt@xb,\rt@yb)}; \draw[\rt@arrowtip, thin] (\rt@xb,\rt@yb) to #2; } \newcommand{\filter@noarrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.25}{0.75}{rt@p1}{rt@p2} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw decorate [decoration=zigzag] {(\rt@xa,\rt@ya) -- #3 (\rt@xb,\rt@yb)}; \draw[thin] (\rt@xb,\rt@yb) to #2; } %%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%% ASYNCHRONOUS CHANNELS %%%%%%%%%%%% %Fifo1 (Empty) \newcommand{\fifoe}{% \@ifstar\fifoe@noarrow\fifoe@arrow } \newcommand{\fifoe@arrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.65}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} %, shorten <=1mm \draw[thin] #1 to (\rt@xa,\rt@ya); \draw decorate[decoration={shape backgrounds, shape=rectangle, shape height=7pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- (\rt@xb,\rt@yb)}; \draw[\rt@arrowtip, thin] (\rt@xb,\rt@yb) to #3 #2; } \newcommand{\fifoe@noarrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.70}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw decorate[decoration={shape backgrounds, shape=rectangle, shape height=8pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- (\rt@xb,\rt@yb)}; \draw[thin] (\rt@xb,\rt@yb) to #3 #2; } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Fifo1 (Full) \newcommand{\fifof}{% \@ifstar\fifof@noarrow\fifof@arrow } \newcommand{\fifof@arrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.65}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw decorate[decoration={shape backgrounds, shape=rectangle, shape height=7pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- node[sloped] {$\bullet$} (\rt@xb,\rt@yb)}; \draw[\rt@arrowtip, thin] (\rt@xb,\rt@yb) to #3 #2; } \newcommand{\fifof@noarrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.70}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw decorate[decoration={shape backgrounds, shape=rectangle, shape height=7pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- node[sloped] {$\bullet$} (\rt@xb,\rt@yb)}; \draw[thin] (\rt@xb,\rt@yb) to #3 #2; } %AsyncDrain \newcommand{\asyncdrain}{% \@ifstar \asyncdrain@arrow \asyncdrain@arrow } \newcommand{\asyncdrain@arrow}[3]{% \coordinate (rt@p1) at ($#1!.47!#2$); \coordinate (rt@p2) at ($(rt@p1)!6pt!90:#1$); \coordinate (rt@p3) at ($(rt@p1)!6pt!-90:#1$); \coordinate (rt@p4) at ($#1!.53!#2$); \coordinate (rt@p5) at ($(rt@p4)!6pt!90:#1$); \coordinate (rt@p6) at ($(rt@p4)!6pt!-90:#1$); \draw[inwards-inwards, thin, shorten >=-0.5mm, shorten <=-0.5mm] #1 to #3 #2; \draw[thin] (rt@p1) -- (rt@p2); \draw[thin] (rt@p1) -- (rt@p3); \draw[thin] (rt@p4) -- (rt@p5); \draw[thin] (rt@p4) -- (rt@p6); } %AsyncSpout \newcommand{\asyncspout}{% \@ifstar \asyncspout@arrow \asyncspout@arrow } \newcommand{\asyncspout@arrow}[3]{% \coordinate (rt@p1) at ($#1!.47!#2$); \coordinate (rt@p2) at ($(rt@p1)!6pt!90:#1$); \coordinate (rt@p3) at ($(rt@p1)!6pt!-90:#1$); \coordinate (rt@p4) at ($#1!.53!#2$); \coordinate (rt@p5) at ($(rt@p4)!6pt!90:#1$); \coordinate (rt@p6) at ($(rt@p4)!6pt!-90:#1$); \draw[outwards-outwards, thin,shorten >=-0.5mm, shorten <=-0.5mm] #1 to #3 #2; \draw[thin] (rt@p1) -- (rt@p2); \draw[thin] (rt@p1) -- (rt@p3); \draw[thin] (rt@p4) -- (rt@p5); \draw[thin] (rt@p4) -- (rt@p6); } %\newcommand{\asyncspout@noarrow}[3]{% %\coordinate (rt@p1) at ($#1!.47!#2$); %\coordinate (rt@p2) at ($(rt@p1)!6pt!90:#1$); %\coordinate (rt@p3) at ($(rt@p1)!6pt!-90:#1$); %\coordinate (rt@p4) at ($#1!.53!#2$); %\coordinate (rt@p5) at ($(rt@p4)!6pt!90:#1$); %\coordinate (rt@p6) at ($(rt@p4)!6pt!-90:#1$); %\draw[outwards-outwards, thin] % #1 to #3 #2; %\draw[thin] (rt@p1) -- (rt@p2); %\draw[thin] (rt@p1) -- (rt@p3); %\draw[thin] (rt@p4) -- (rt@p5); %\draw[thin] (rt@p4) -- (rt@p6); %} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %FifoN \newcommand{\fifon}{% \@ifstar\fifon@noarrow\fifon@arrow } \newcommand{\fifon@arrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.65}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw decorate[decoration={shape backgrounds, shape=rectangle, shape height=8pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- node[sloped] {\tiny 1$|$...$|$n} (\rt@xb,\rt@yb)}; \draw[\rt@arrowtip, thin] (\rt@xb,\rt@yb) to #3 #2; } \newcommand{\fifon@noarrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.70}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw decorate[decoration={shape backgrounds, shape=rectangle, shape height=8pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- node[sloped] {\tiny 1$|$...$|$n} (\rt@xb,\rt@yb)}; \draw[thin] (\rt@xb,\rt@yb) to #3 #2; } %%%%%%%%%%%%%%%%%%%%%%%%% % Shift Fifo n \newcommand{\shiftfifon}{% \@ifstar\shiftfifon@noarrow\shiftfifon@arrow } \newcommand{\shiftfifon@arrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.65}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw[dashed] decorate[decoration={shape backgrounds, shape=rectangle, shape height=8pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- node[sloped] {\tiny 1$|$...$|$n} (\rt@xb,\rt@yb)}; \draw[\rt@arrowtip, thin, dashed] (\rt@xb,\rt@yb) to #3 #2; } \newcommand{\shiftfifon@noarrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.70}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw[dashed] decorate[decoration={shape backgrounds, shape=rectangle, shape height=8pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- node[sloped] {\tiny 1$|$...$|$n} (\rt@xb,\rt@yb)}; \draw[thin, dashed] (\rt@xb,\rt@yb) to #3 #2; } %%%%%%%%%%%%%%%%%%%%%%%%%%% % Lossy Fifo n \newcommand{\lossyfifon}{% \@ifstar\lossyfifon@noarrow\lossyfifon@arrow } \newcommand{\lossyfifon@arrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.65}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[dashed, thin] #1 to (\rt@xa,\rt@ya); \draw[dashed] decorate[decoration={shape backgrounds, shape=rectangle, shape height=8pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- node[sloped] {\tiny 1$|$...$|$n} (\rt@xb,\rt@yb)}; \draw[\rt@arrowtip, thin] (\rt@xb,\rt@yb) to #3 #2; } \newcommand{\lossyfifon@noarrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.30}{0.70}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{sqrt((\rt@xa - \rt@xb)^2 + (\rt@ya - \rt@yb)^2)} \draw[dashed, thin] #1 to (\rt@xa,\rt@ya); \draw[dashed] decorate[decoration={shape backgrounds, shape=rectangle, shape height=8pt, shape width=\rt@width, shape evenly spread=1}] {(\rt@xa,\rt@ya) -- node[sloped] {\tiny 1$|$...$|$n} (\rt@xb,\rt@yb)}; \draw[thin] (\rt@xb,\rt@yb) to #3 #2; } %Timer \newcommand{\timer}{% \@ifstar\timer@noarrow\timer@arrow } \newcommand{\timer@arrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@middlepoint{rt@p1}{rt@p2} \rt@midpoints{0.4}{0.60}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{(sqrt((\rt@xa - \rt@xc)^2 + (\rt@ya - \rt@yc)^2))} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw (\rt@xc,\rt@yc) circle (\rt@width) ; \draw[\rt@arrowtip, thin] (\rt@xb,\rt@yb) to #3 #2; } \newcommand{\timer@noarrow}[3]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@middlepoint{rt@p1}{rt@p2} \rt@midpoints{0.4}{0.60}{rt@p1}{rt@p2} \pgfmathsetlength{\rt@width}{(sqrt((\rt@xa - \rt@xc)^2 + (\rt@ya - \rt@yc)^2))} \draw[thin] #1 to (\rt@xa,\rt@ya); \draw (\rt@xc,\rt@yc) circle (\rt@width) ; \draw[\rt@arrowtip, thin] (\rt@xb,\rt@yb) to #3 #2; } %Auxiliary Channel \newcommand{\baseasyncchannels@arrow}[4]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.25}{0.75}{rt@p1}{rt@p2} \draw[thin]% #1 to (\rt@xa,\rt@ya) ; \draw[white, thin] (\rt@xa,\rt@ya) to node[color=black, sloped] {{\small #4}} (\rt@xb,\rt@yb); \draw[\rt@arrowtip, thin]% (\rt@xb,\rt@yb) to #3 #2; } \newcommand{\baseasyncchannels@noarrow}[4]{% \node (rt@p1) at #1 {} ; \node (rt@p2) at #2 {} ; \rt@midpoints{0.25}{0.75}{rt@p1}{rt@p2} \draw[thin]% #1 to (\rt@xa,\rt@ya) ; \draw[white, thin] (\rt@xa,\rt@ya) to node[color=black, sloped] {{\small #4}} (\rt@xb,\rt@yb); \draw[ thin]% (\rt@xb,\rt@yb) to #3 #2; } %Ordered \newcommand{\ordered}{% \@ifstar \ordered@noarrow \ordered@arrow } \newcommand{\ordered@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{ord} } \newcommand{\ordered@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{ord} } %%%%%%%%%%%%%% %Ordered N \newcommand{\orderedn}{% \@ifstar \orderedn@noarrow \orderedn@arrow } \newcommand{\orderedn@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{ord$_n$} } \newcommand{\orderedn@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{ord$_n$} } %%%%%%%%%%%%%%%%%% %Bag \newcommand{\bag}{% \@ifstar \bag@noarrow \bag@arrow } \newcommand{\bag@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{({\tiny ...})} } \newcommand{\bag@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{({\tiny ...})} } %Bag N \newcommand{\bagn}{% \@ifstar \bagn@noarrow \bagn@arrow } \newcommand{\bagn@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{({\tiny ...})$_n$} } \newcommand{\bagn@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{({\tiny ...})$_n$} } %Set \newcommand{\set}{% \@ifstar \set@noarrow \set@arrow } \newcommand{\set@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{\{{\tiny ...}\}} } \newcommand{\set@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{\{{\tiny ...}\}} } %Set N \newcommand{\setn}{% \@ifstar \setn@noarrow \setn@arrow } \newcommand{\setn@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{\{{\tiny ...}\}$_n$} } \newcommand{\setn@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{\{{\tiny ...}\}$_n$} } %Dealy Set \newcommand{\delayset}{% \@ifstar \delayset@noarrow \delayset@arrow } \newcommand{\delayset@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{DSet} } \newcommand{\delayset@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{DSet} } %Delay Set N \newcommand{\delaysetn}{% \@ifstar \delaysetn@noarrow \delaysetn@arrow } \newcommand{\delaysetn@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{DSet$_n$} } \newcommand{\delaysetn@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{DSet$_n$} } %Keyed Set \newcommand{\keyedset}{% \@ifstar \keyedset@noarrow \keyedset@arrow } \newcommand{\keyedset@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{KSet} } \newcommand{\keyedset@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{KSet} } %Keyed Set N \newcommand{\keyedsetn}{% \@ifstar \keyedsetn@noarrow \keyedsetn@arrow } \newcommand{\keyedsetn@arrow}[3]{% \baseasyncchannels@arrow{#1}{#2}{#3}{KSet$_n$} } \newcommand{\keyedsetn@noarrow}[3]{% \baseasyncchannels@noarrow{#1}{#2}{#3}{KSet$_n$} } %%%%%%%%%%%%%% L shaped %%%%%%%%%%%%%%%%%%% %Generic\Lhannel*?[