\NeedsTeXFormat{LaTeX2e}[1999/01/01]
\ProvidesPackage{grafcet}[2007/03/05]

\RequirePackage{tikz}
\usetikzlibrary{shapes,arrows}
\RequirePackage{ifthen}
\RequirePackage{ifsym}
%macros commande diverses


\newcommand{\Etape}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [draw, rectangle, 
    minimum height=2.5em,minimum width=2.5em] (X#2) {#2};
\node (AX#2) at (X#2){};
\DecaleNoeudy[2.5]{X#2}{NoeudGraf}
\node (VX#2) at (NoeudGraf) {};
}

\newcommand{\EtapeSeule}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [draw, rectangle, 
    minimum height=2.5em,minimum width=2.5em] (X#2) {#2};
\node (AX#2) at (X#2){};
}
\newcommand{\EtapeInit}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [draw, rectangle, 
    minimum height=2.5em,minimum width=2.5em] (X#2) {#2};
\path (X#2.north west) --++(0.3em,0) coordinate(NOh) -- (X#2.north east)--++(-0.3em,0)coordinate(NEh);
\path (X#2.south west) --++(0.3em,0) coordinate(SOh) -- (X#2.south east)--++(-0.3em,0)coordinate(SEh);
\path (X#2.north west) --++(0,-0.3em) coordinate(NOv) -- (X#2.south west)--++(0,0.3em)coordinate(SOv);
\path (X#2.north east) --++(0,-0.3em) coordinate(NEv) -- (X#2.south east)--++(0,0.3em)coordinate(SEv);

\draw (NOh|-NOv)coordinate(NO) -- (SOh|-SOv) coordinate (SO) -- (SEh|-SEv)coordinate(SE) -- (NEh|-NEv) -- cycle;
%\node (coin1) at (X#2.north west)[minimum size=0.1em]{}{};
%\node (coin2) at (X#2.south east)[minimum size=0.1em]{}{};
%\draw (coin1.south east) rectangle (coin2.north west);
\node (AX#2) at (X#2){};
\DecaleNoeudy[2.5]{X#2}{NoeudGraf}
\node (VX#2) at (NoeudGraf) {};
}

\newcommand{\MacroEtape}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [draw, rectangle, 
    minimum height=2.5em,minimum width=2.5em] (X#2) {#2};
\node (coin1) at (X#2.north west)[minimum size=0.1em]{}{};
\node (coin2) at (X#2.south east)[minimum size=0.1em]{}{};
\node (coin3) at (X#2.north east)[minimum size=0.1em]{}{};
\node (coin4) at (X#2.south west)[minimum size=0.1em]{}{};
\draw (coin1.south) -- (coin3.south);
\draw (coin2.north) -- (coin4.north);
\node (AX#2) at (X#2){};
\DecaleNoeudy[2.5]{X#2}{NoeudGraf}
\node (VX#2) at (NoeudGraf) {};
}
\newcommand{\MacroEtapeE}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [draw, rectangle, 
    minimum height=2.5em,minimum width=2.5em] (X#2) {#2};
\node (coin1) at (X#2.north west)[minimum size=0.1em]{}{};
\node (coin2) at (X#2.south east)[minimum size=0.1em]{}{};
\node (coin3) at (X#2.north east)[minimum size=0.1em]{}{};
\node (coin4) at (X#2.south west)[minimum size=0.1em]{}{};
\draw (coin1.south) -- (coin3.south);
\node (AX#2) at (X#2){};
\DecaleNoeudy[2.5]{X#2}{NoeudGraf}
\node (VX#2) at (NoeudGraf) {};
}

\newcommand{\MacroEtapeS}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [draw, rectangle, 
    minimum height=2.5em,minimum width=2.5em] (X#2) {#2};
\node (coin1) at (X#2.north west)[minimum size=0.1em]{}{};
\node (coin2) at (X#2.south east)[minimum size=0.1em]{}{};
\node (coin3) at (X#2.north east)[minimum size=0.1em]{}{};
\node (coin4) at (X#2.south west)[minimum size=0.1em]{}{};
\draw (coin2.north) -- (coin4.north);
\node (AX#2) at (X#2){};
\DecaleNoeudy[2.5]{X#2}{NoeudGraf}
\node (VX#2) at (NoeudGraf) {};
}

\newcommand{\EtapeEncapsulante}[2][NoeudGraf]{
\node[inner sep=0,outer sep=0] (NoeudGraf) at (#1) [draw, rectangle, 
    minimum height=2.5em,minimum width=2.5em] (X#2) {#2};

\path (X#2.north west) --++(0.8em,0) coordinate(NOh) -- (X#2.north east)--++(-0.8em,0)coordinate(NEh);
\path (X#2.south west) --++(0.8em,0) coordinate(SOh) -- (X#2.south east)--++(-0.8em,0)coordinate(SEh);
\path (X#2.north west) --++(0,-0.8em) coordinate(NOv) -- (X#2.south west)--++(0,0.8em)coordinate(SOv);
\path (X#2.north east) --++(0,-0.8em) coordinate(NEv) -- (X#2.south east)--++(0,0.8em)coordinate(SEv);

\draw (X#2.north west) -- (NOh) -- (NOv) -- cycle;
\draw (X#2.south west) -- (SOh) -- (SOv) -- cycle;
\draw (X#2.north east) -- (NEh) -- (NEv) -- cycle;
\draw (X#2.south east) -- (SEh) -- (SEv) -- cycle;

\node (AX#2) at (X#2){};
\DecaleNoeudy[2.5]{X#2}{NoeudGraf}
\node (VX#2) at (NoeudGraf) {};
}

\newcommand{\EtapeEncapsulanteInit}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [draw, rectangle, 
    minimum height=2.5em,minimum width=2.5em] (X#2) {#2};
\path (X#2.north west) --++(0.3em,0) coordinate(NOh) -- (X#2.north east)--++(-0.3em,0)coordinate(NEh);
\path (X#2.south west) --++(0.3em,0) coordinate(SOh) -- (X#2.south east)--++(-0.3em,0)coordinate(SEh);
\path (X#2.north west) --++(0,-0.3em) coordinate(NOv) -- (X#2.south west)--++(0,0.3em)coordinate(SOv);
\path (X#2.north east) --++(0,-0.3em) coordinate(NEv) -- (X#2.south east)--++(0,0.3em)coordinate(SEv);

\draw (NOh|-NOv)coordinate(NO) -- (SOh|-SOv) coordinate (SO) -- (SEh|-SEv)coordinate(SE) -- (NEh|-NEv)coordinate(NE) -- cycle;

\path (NO) --++(0.5em,0) coordinate(NOh) -- (NE)--++(-0.5em,0)coordinate(NEh);
\path (SO) --++(0.5em,0) coordinate(SOh) -- (SE)--++(-0.5em,0)coordinate(SEh);
\path (NO) --++(0,-0.5em) coordinate(NOv) -- (SO)--++(0,0.5em)coordinate(SOv);
\path (NE) --++(0,-0.5em) coordinate(NEv) -- (SE)--++(0,0.5em)coordinate(SEv);

\draw (NO) -- (NOh) -- (NOv) -- cycle;
\draw (SO) -- (SOh) -- (SOv) -- cycle;
\draw (NE) -- (NEh) -- (NEv) -- cycle;
\draw (SE) -- (SEh) -- (SEv) -- cycle;

\node (AX#2) at (X#2){};
\DecaleNoeudy[2.5]{X#2}{NoeudGraf}
\node (VX#2) at (NoeudGraf) {};
}

\newcommand{\LienActivation}[1]{
\DecaleNoeudx[-2]{#1}{LA}
\node (LA#1) at (LA) {\textbf *};
}

\newcommand{\EtapeActive}[1]{
\DecaleNoeudy[1]{#1}{EA}
\node (EA#1) at (EA) {\textbullet};
}

\newcommand{\CadreEncap}[4]{
\draw (#1) rectangle (#2);
\DecaleNoeudx[3]{#1}{NumEtape}
\node (NumEtape) at (NumEtape)[right,fill=white]{#3}{};
\DecaleNoeudx[-3]{#2}{NumEncap}
\node (NumEncap) at (NumEncap)[left,fill=white]{#4}{}; 
}

\newenvironment{Encap}[4][encapsulation]
{\def\encap1{#1}
\def\nometape{#3}
\def\nomgraphe{#4}

\matrix[matrix anchor=north west] (#1) at (#2)
\bgroup
  \node(espace){};\\
  \begin{scope}
}
{
\end{scope}\\
\egroup;
\path (\encap1.north west) -- node[pos=0.3](nometape){\nometape} (\encap1.north east);
\path (\encap1.south west) -- node[pos=0.3](nomgraphe){\nomgraphe} (\encap1.south east);
\draw (nometape) -- (\encap1.east|-nometape) --++(0.5em,0)|- (nomgraphe);
\draw (nometape) -- (\encap1.west|-nometape) --++(-0.5em,0)|- (nomgraphe);
}




\newcommand{\Comment}[3][0]{
\DecaleNoeudx[#1]{#2}{comm#2}
\draw (comm#2) node[text width=15em,text justified,right]{\og\textit{ #3 }\fg};
}


\newcommand{\Transition}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [minimum height=2.5em,minimum width=1em] (T#2) {};
\draw (T#2.west) -- (T#2.east);
\draw (T#2.north) -- (T#2.south);
\node (RT#2) at (T#2.east){};
\DecaleNoeudy[2.5]{T#2}{NoeudGraf}
\node (VT#2) at (NoeudGraf) {};
}

\newcommand{\TransitionSource}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [minimum height=2.5em,minimum width=1em] (T#2) {};
\draw (T#2.west) -- (T#2.east);
\draw (T#2.base) -- (T#2.south);
\node (RT#2) at (T#2.east){};
\DecaleNoeudy[2.5]{T#2}{NoeudGraf}
\node (VT#2) at (NoeudGraf) {};
}

\newcommand{\TransitionPuits}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) [minimum height=2.5em,minimum width=1em] (T#2) {};
\draw (T#2.west) -- (T#2.east);
\draw (T#2.north) -- (T#2.base);
\node (RT#2) at (T#2.east){};
\DecaleNoeudy[2.5]{T#2}{NoeudGraf}
\node (VT#2) at (NoeudGraf) {};
}

\newcommand{\Action}[3][0]{
\foreach \x in {#3}
{\node (NoeudGraf) at (A#2.east) [draw, rectangle, right,minimum height=2.5em,
 minimum width=2.5em] (A#2) {\x};
}
}




\newcommand{\ActionFranchissement}[2]{
\draw (#1.center) --  ++ (1.5em,-2em) node[name=A#1]{} ;
\node[draw, rectangle, right,minimum height=2.5em, minimum width=2.5em] (A#1) at (A#1) {#2};
}

\newcommand{\ActionActiv}[1]{
\node (coin1) at (A#1.north west)[minimum size=1.5em]{}{};
%\draw [-triangle 90] (coin1.base) -- (coin1.north);
\draw[fill] (coin1.base)--++(0,0.3em)--++(0.3em,0)--++(-0.3em,0.4em) --++(-0.3em,-0.4em)--++(0.3em,0);
}
\newcommand{\ActionDesactiv}[1]{
\node (coin1) at (A#1.south west)[minimum size=1.2em]{}{};
%\draw [-triangle 90] (coin1.base) -- (coin1.south);
%\draw [-triangle 90] (coin1.base) -- (coin1.north);
\draw[fill] (coin1.base)--++(0,-0.3em)--++(0.3em,0)--++(-0.3em,-0.4em) --++(-0.3em,+0.4em)--++(0.3em,0);
}

\newcommand{\ActionCond}[2]{
\node (coin1) at (A#1.north west)[minimum size=1.5em]{};
\draw  (coin1.east) -- (coin1.north east)[name=vcond];
\node (cond) at (coin1.east) [above right]{\small{#2}};
}
\newcommand{\ActionEvenement}[2]{
\node (coin1) at (A#1.north west)[minimum size=1.5em]{};
\node (coin2) at (coin1.north east) [minimum size=0.5em]{};
\node (coin2) at (coin2.south) [minimum size=0.5em]{};
\draw [fill] (coin1.east) -- (coin2.north)--(coin2.west)--(coin2.south);
\node (cond) at (coin1.east) [above right]{#2};

}
\newcommand{\ActionX}[3][2.5]{
\DecaleNoeudx[#1]{#2}{A#2};
\draw (#2) -- (A#2.east);
\foreach \x in {#3}
{\node (NoeudGraf) at (A#2.east) [draw, rectangle, right,minimum height=2.5em,
 minimum width=2.5em] (A#2) {\x};
}
}
\newcommand{\ActionXV}[3][2.5]{
\DecaleNoeudx[#1]{#2}{A#2};
\draw (#2) --coordinate[midway](LA#2)coordinate[midway](LA#2b) (A#2.east);
\foreach \x in {#3}
{\DecaleNoeudy[2.5]{A#2}{NA#2};
\draw(LA#2) |- (A#2.east);
\node (NoeudGraf) at (A#2.east) [draw, rectangle,right,minimum height=2.5em,
 minimum width=2.5em] (A#2) {\x};
\DecaleNoeudy[0]{NA#2}{A#2}
}
}



\newcommand{\ActionEfface}[2][2.5]{
\DecaleNoeudx[#1]{#2}{A#2};
\draw [white] (#2) -- (A#2.east);
{\node (NoeudGraf) at (A#2.east) [draw,fill, color=white ,rectangle, right,minimum height=2.5em,
 minimum width=2.5em] (A#2) { };
}
}


\newcommand{\Forcage}[3][0]{
\foreach \x in {#3}
{\node (NoeudGraf) at (A#2.east) [draw, rectangle, right,minimum height=2.5em,
 minimum width=2.5em] (A#2) {\x};
 \node (coin1) at (A#2.north west)[minimum size=0.1em]{}{};
\node (coin2) at (A#2.south east)[minimum size=0.1em]{}{};
\draw (coin1.south east) rectangle (coin2.north west);
}
}

\newcommand{\ForcageX}[3][2.5]{
\DecaleNoeudx[#1]{#2}{A#2};
\draw (#2) -- (A#2.east);
\foreach \x in {#3}
{\node (noeudaction) at (A#2.east) [draw, rectangle, right,minimum height=2.5em,
 minimum width=2.5em] (A#2) {\x};
\node (coin1) at (A#2.north west)[minimum size=0.1em]{}{};
\node (coin2) at (A#2.south east)[minimum size=0.1em]{}{};
\draw (coin1.south east) rectangle (coin2.north west);
}
}


\newcommand{\ForcageXV}[3][2.5]{
\DecaleNoeudx[#1]{#2}{A#2};
\draw (#2) --coordinate[midway](LA#2)coordinate[midway](LA#2b) (A#2.east);
\foreach \x in {#3}
{\DecaleNoeudy[2.5]{A#2}{NA#2};
\draw(LA#2) |- (A#2.east);
\node (noeudaction) at (A#2.east) [draw, rectangle, right,minimum height=2.5em,
 minimum width=2.5em] (A#2) {\x};
\node (coin1) at (A#2.north west)[minimum size=0.1em]{}{};
\node (coin2) at (A#2.south east)[minimum size=0.1em]{}{};
\draw (coin1.south east) rectangle (coin2.north west);
\DecaleNoeudy[0]{NA#2}{A#2};
}
}




\newcommand{\Recept}[2]{
\node (NoeudGraf) at (R#1.east) [right,minimum height=0em,
 minimum width=0em] (Rcp#1) {#2};
}

\newcommand{\Recepts}[1]{
\foreach \trans / \receptivite  in {#1}{
\Recept{T\trans}{\receptivite};
}
}

\newcommand{\TransitionRecept}[3][NoeudGraf]{
\Transition[#1]{#2}
\Recept{T#2}{#3}
}

\newcommand{\Actions}[1]{
\foreach \etape / \action  in {#1}{
\ActionX{X\etape}{\action};
}
}

\newcommand{\ActionRecept}[1]{
\foreach \etape / \action / \receptivite in {#1}{
  \ifthenelse{\equal{\action}{}}{}
  {\ActionX{X\etape}{\action};} 
\Recept{T\etape}{\receptivite};
}
}


\newcommand{\EtapeAction}[3][NoeudGraf]{
\Etape[#1]{#2}
  \ifthenelse{\equal{#3}{}}{}
  {\ActionX{X#2}{#3}} 
}

\newcommand{\EtapeInitAction}[3][NoeudGraf]{
\EtapeInit[#1]{#2}
  \ifthenelse{\equal{#3}{}}{}
  {\ActionX{X#2}{#3}} 
}

\newcommand{\EtapeTransition}[4][NoeudGraf]{
\Etape[#1]{#2}
  \ifthenelse{\equal{#3}{}}{}
  {\ActionX{X#2}{#3}} 
\Transition{#2}
\Recept{T#2}{#4}
}

\newcommand{\EtapeInitTransition}[4][NoeudGraf]{
\EtapeInit[#1]{#2}
  \ifthenelse{\equal{#3}{}}{}
  {\ActionX{X#2}{#3}} 
\Transition{#2}
\Recept{T#2}{#4}
}


\newcommand{\SequenceET}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) {};
\foreach \x in {#2}
{\Etape[NoeudGraf]{\x}
\DecaleNoeudy[2.5]{X\x}{NoeudGraf}
\Transition[NoeudGraf]{\x}
\DecaleNoeudy[2.5]{T\x}{NoeudGraf}
\node (VT\x) at (NoeudGraf) {};
}
}

\newcommand{\SequenceTT}[3][NoeudGraf]{
\node (NoeudGraf) at (#1) {};
\Transition[NoeudGraf]{#2}
\DecaleNoeudy[2.5]{T#2}{NoeudGraf}
\foreach \x in {#3}
{\Etape[NoeudGraf]{\x}
\DecaleNoeudy[2.5]{X\x}{NoeudGraf}
\Transition[NoeudGraf]{\x}
\node (Ts) at (T\x) [minimum height=2.5em,minimum width=1em]{};
\DecaleNoeudy[2.5]{T\x}{NoeudGraf}
\node (VT\x) at (NoeudGraf) {};
\node (VTs) at (VT\x) [minimum height=2.5em,minimum width=1em]{};
}
}

\newcommand{\SequenceTE}[4][NoeudGraf]{
\node (NoeudGraf) at (#1) {};
\Transition[NoeudGraf]{#2}
\SequenceEE{#3}{#4}
}


\newcommand{\SequenceEE}[3][NoeudGraf]{
\node (NoeudGraf) at (#1) {};
\foreach \x in {#2}
{\Etape[NoeudGraf]{\x}
\DecaleNoeudy[2.5]{X\x}{NoeudGraf}
\Transition[NoeudGraf]{\x}
\DecaleNoeudy[2.5]{T\x}{NoeudGraf}
\node (VT\x) at (NoeudGraf) {};
}
\Etape[NoeudGraf]{#3}
\DecaleNoeudy[2.5]{X#3}{NoeudGraf}
\node (VX#3) at (NoeudGraf) {};
}


\newcommand{\Graphe}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) {};
\node (debut) at (#1)[minimum size=2.5em] {};
\foreach \x / \y / \z in {#2}{
\Etape[NoeudGraf]{\x}
\DecaleNoeudy[2.5]{X\x}{NoeudGraf}
\Transition[NoeudGraf]{\x}
\DecaleNoeudy[2.5]{T\x}{NoeudGraf}
}
\ActionRecept{#2}
}
\newcommand{\GrapheBoucle}[2][NoeudGraf]{
\node (NoeudGraf) at (#1) {};
\node (debutgraphe) at (#1)[minimum size=2.5em] {};
\foreach \x / \y / \z in {#2}{
\Etape[NoeudGraf]{\x}
\DecaleNoeudy[2.5]{X\x}{NoeudGraf}
\Transition[NoeudGraf]{\x}
\node (fingraphe) at (T\x)[minimum size=2.5em] {};
\DecaleNoeudy[2.5]{T\x}{NoeudGraf}
}
\ActionRecept{#2}
\LienRetour{fingraphe}{debutgraphe}
}

\newcommand{\SautEtapes}[4][-5]{
\DivOU{#2}{#1/L#2s,2/L#2}
\Transition[L#2s]{#2s}
\SequenceTT[L#2]{#2}{#3}
\DecaleNoeudy[-2.5]{NoeudGraf}{VNoeudGraf}
\ConvOU[-2]{Ts}{T#2s}{#4}
}

\newcommand{\RepriseEtapes}[4][-5]{
\DecaleNoeudx[#1]{#2}{#2r}
\DecaleNoeudx[-1]{#2r}{#2r}
\DecaleNoeudx[#1]{V#2}{V#2r}
\DecaleNoeudx[-1]{V#2r}{V#2r}
\node(V#2r) at (V#2r) [minimum height=2.5em,minimum width=1em,rectangle]{};
\ConvOU[-1]{#2}{#2r}{noeudreprise}
\SequenceEE[noeudreprise]{#3}{#4}
\DivOU{X#4}{#1/L#4r,1/L#4}
\Transition[L#4]{#4}
\Transition[L#4r]{#4r}
\LienRetour[2]{T#4r}{V#2r}
}

\newcommand{\DivET}[2]{
\node (div1) at (#1)[minimum height=2.5em,minimum width=1em]{};
\draw (div1.base) -- (div1.south){};
\DecaleNoeudy[2.5]{#1}{div1}
\foreach \x / \y in {#2} {
\DecaleNoeudx[\x]{div1}{div2}
\node (V\y) at (div2)[minimum height=2.5em,minimum width=1em]{};
\draw (V\y.base) -- (V\y.north);
\draw [double distance=0.15em,thick] (div1.north) -- (V\y.north east) --(V\y.north west) {}{};
\node (\y) at (V\y){}[minimum size=0];
\node (V\y) at (V\y.south){};
}
}

\newcommand{\BrancheOU}[2][0]{
\node[below of=V#2,node distance=1 em,minimum height=2.5em,minimum width=1em](NoeudGraf){};
\node [right of=NoeudGraf, node distance=#1 em,minimum height=2.5em,minimum width=1em] (NoeudGraf){};
\draw (#2.south) -- ++(0,-0.5em) -| (NoeudGraf);
}

\newcommand{\FinBrancheOU}[3][0]{
\ifthenelse{\equal{CountB}{}}{
\node[below of=V#3,node distance=2 em,minimum height=2.5em,minimum width=1em](NoeudGraf){};
\node [right of=NoeudGraf, node distance=#1 em,minimum height=2.5em,minimum width=1em] (NoeudGraf){};
\draw (#3.south) -- ++(0,-0.5em) -| (NoeudGraf);}
{ aaa}
}

\newcommand{\FinBrancheOUa}[3][0]{
\newboolean{TestBoucle}
\ifthenelse{\boolean{TestBoucle}{true}}{\draw(T53) -- (#3);}{
\node[below of=V#2,node distance=2 em,minimum height=2.5em,minimum width=1em](NoeudGraf){};
\node [right of=NoeudGraf, node distance=#1 em,minimum height=2.5em,minimum width=1em] (NoeudGraf){};
\node[minimum height=2.5em,minimum width=1em] (#3) at (NoeudGraf){};
\draw (#2.south) -- ++(0,-0.5em) -| (NoeudGraf);
with:
\setboolean{TestBoucle}{true}
}

}


\newcommand{\DivOU}[2]{
\node (div1) at (V#1)[minimum height=2.5em,minimum width=1em]{};
\draw (div1.base) -- (div1.north) {}{};
\foreach \x / \y in {#2} {
\DecaleNoeudx[\x]{div1}{div2}
\node (div2) at (div2)[minimum height=2.5em,minimum width=1em]{};
\node (\y) at (div2)[minimum height=2.5em,minimum width=1em]{};
\draw (div1.base) -- (\y.east) --(\y.west) {}{};
\node (\y) at (div2.south)[minimum height=2.5em,minimum width=1em]{};
\draw(\y.base)--(\y.north){}{};
}
}


\newcommand{\ConvET}[4][0]{
\node (div) at (#2) [minimum height=2.5em,minimum width=1em]{};
\DecaleNoeudy[2.5]{div}{div}
\foreach \x in {#3}{
\draw (#2) -- (div.base) -| (\x);\node (int\x) at (div.base -|\x) {};
}
\DecaleNoeudx[#1]{div}{#4}
\DecaleNoeudy[1.5]{#4}{#4}
\draw (#4.base) |- (div.base);
\foreach \x in {#3}{
\draw [double distance=0.15em,thick](int\x.east) -- (int\x.west);
\draw [double distance=0.15em,thick](int\x.east) -- (div.east);
}
\draw [double distance=0.15em,thick](div.west) -- (div.east);
}


\newcommand{\ConvOU}[4][0]{
\node (div#2) at (#2.base)[minimum height=2.5em,minimum width=1em]{};
\DecaleNoeudx[0]{div#2}{div#2}
\DecaleNoeudy[1.3]{div#2}{div}
\DecaleNoeudx[#1]{V#2}{#4}
\foreach \x in {#3} {
\draw (div.base)--(div.east)--(div.west)  -| (\x.base);
\node (divi) at (div.west -| \x.base) [minimum width=1em,minimum height=2.5em]{};
\draw (divi.west) -- (divi.east);
}
\DecaleNoeudy[1.5]{#4}{#4}
\draw (div#2.base)--(div.base)-|(#4.north);
}

\newcommand{\DecaleNoeudx}[3][0]{
\node [right of=#2, node distance=#1em](#3) {};
\node (#3) at (#3) [rectangle,minimum height=2.5em,minimum width=1em]{};
}
\newcommand{\DecaleNoeudy}[3][0]{
\node [below of=#2, node distance=#1em](#3) {};
\node (#3) at (#3) [rectangle,minimum height=2.5em,minimum width=1em]{};
}


\newcommand{\LienRetour}{\@ifstar\LienRetourUp\LienRetourN}

\newcommand{\LienRetourN}[3][4]{
\node [left of=#2, node distance=#1em, minimum size=0cm](retourb#2) {};
\node [above of=#3, node distance=2.5em, minimum size=0cm](retourh#2) {};
%\DecaleNoeudx[-#1]{retourh#2}{retourh#2}
\draw[->,>=latex'](#2.base)--(#2.south)-|(retourb#2.north)--(retourb#2|-#3)|-(retourh#2.base)-| (#3.north);
}

\newcommand{\LienRetourUp}[4][4]{
\node [left of=#2, node distance=#1em, minimum size=0cm](retourb#2) {};
\node [above of=#3, node distance=#4em, minimum size=0cm](retourh#2) {};
%\DecaleNoeudx[-#1]{retourh#2}{retourh#2}
\draw[->,>=latex'](#2.base)--(#2.south)-|(retourb#2.north)--(retourb#2|-#3)|-(retourh#2.base)-| (#3.north);
}

\newcommand{\LienRetoura}[3][4]{
\node [left of=#3, node distance=#1em, minimum size=0cm](retourb#2) {};
\node [above of=retourb#2, node distance=2.5em, minimum size=0cm](retourh#2) {};
%\DecaleNoeudx[-#1]{retourh#2}{retourh#2}
\draw [->,>=latex'] (#2.base)--(#2.south)-| (retourh#2.base)  -|   node[name=#2-#3,near end,right] {} (#3.north) ;
}

\newcommand{\Lien}[4][0]{
\node [above of=#4, node distance=2.5em, minimum size=0cm](retourh#3) {};
\DecaleNoeudy[#1]{retourh#3}{retourh#3}
\draw [->,>=latex'] (#2.base) -- (#2.south) -| (#3.base) |- (retourh#3.base) -- (#4.north);
}

\newcommand{\Lieny[2]}[2.5]{
\DecaleNoeudy[#1]{#2}{V#2}
\draw  (#2.base) -- (V#2.base) {};
\DecaleNoeudy[#1]{#2}{#2}
}
\newcommand{\LienET[2]}[2.5]{
\DecaleNoeudy[#1]{#2}{V#2}
\draw  (#2) -- (V#2.base) {};
}
\newcommand{\LienTE[2]}[2.5]{
\DecaleNoeudy[#1]{#2}{V#2}
\draw  (#2.base) -- (V#2) {};
}


\newcommand{\LienRetourOU}[3][4]{
\coordinate [left of=#2, node distance=#1em, minimum size=0cm](retourb#2) {};
\coordinate [above of=#3, node distance=3.5em, minimum size=0cm](retourh#2) {};
\coordinate [above of=#3, node distance=2.5em, minimum size=0cm](retourh#3) {};
%\DecaleNoeudx[-#1]{retourh#2}{retourh#2}
\draw (#2.base) -- (#2.south) -| (retourb#2) -- (retourb#2 |- #3)coordinate[pos=0.5,name=df]coordinate[pos=0.55,name=ff] |-
(retourh#2-|#2) -- (retourh#3 -|#2) --++(-0.5em,0) -++ (1em,0) -|(#3.north) ;
\draw[-latex] (df) -- (ff) ;
}


\newcommand{\EspaceV}[2][2.5]{
\node[below of=V#2,node distance=#1 em,minimum height=2.5em,minimum width=1em](NoeudGraf){};
\draw (#2.south) -- (NoeudGraf);
\node[minimum height=2.5em,minimum width=1em] (V#2) at (NoeudGraf){};
}
