\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{frame}[label=this one]
  \frametitle{Catégorie des modèles}
  \tikz[overlay] \node[yshift=-2cm] at (current page.north){
    $ \mathbf{Abs}_S = (\alert{\mref} \downarrow \mathbf{Set})^{\mathbf{op}} $
  };

  \centering
  \begin{tikzpicture}[overlay,%
    node distance=13mm and 20mm,
    model/.style={draw,rectangle,on grid=true,fill=white},
    function/.style={-Stealth,thick},
    abstraction/.style={function,very thick}
    ]
    \alt<1-4>{
      \node[model,left=of current page.center]  (m1) {$\ensm[1]$};
      \node[model,above=of current page.center] (m2) {$\ensm[2]$};
      \node[model,below=of current page.center] (m3) {$\ensm[3]$};
      \node[model,right=of current page.center] (m4) {$\ensm[4]$};
    }{
      \node[model,circle,left=of current page.center]  (m1) {$\model_1$};
      \node[model,circle,above=of current page.center] (m2) {$\model_2$};
      \node[model,circle,below=of current page.center] (m3) {$\model_3$};
      \node[model,circle,right=of current page.center] (m4) {$\model_4$};
      \draw[abstraction] (m1) to (m2);
      \draw[abstraction] (m1) to (m3);
      \draw[abstraction] (m2) to (m4);
      \draw[abstraction] (m3) to (m4);
    }
    \uncover<3-4>{
      \draw[function] (m2) to (m1);
    }
    \uncover<4>{
      \draw[function] (m3) to (m1);
      \draw[function] (m4) to (m2);
      \draw[function] (m4) to (m3);
    }

    \visible<1-4>{
      \node[draw, very thick, rounded corners=2pt,inner sep=0pt,%
      minimum width=.7\textwidth,minimum height=.65\textheight,yshift=-5mm]
      (set) at (current page.center) {};
      \node[below right] (setl) at (set.north west) {$\mathbf{Set}$};
    }
    \visible<2-4>{
      \node[alert,draw,xshift=-12mm,yshift=6mm] (ms) at (set.south) {$\mref$};
      \draw[function] (ms) to (m1);
      \draw[function] (ms) to (m2);
      \draw[function] (ms) to (m3);
      \draw[function,bend right] (ms) to (m4);
    }
    \begin{pgfonlayer}{background}
      \visible<5>{
        \node[alert,draw,circle,xshift=-12mm,yshift=6mm] (ms) at (set.south) {$\model_{\texttt{Réf}}$};
        \draw[black!50,abstraction] (m1) to (ms);
        \draw[black!50,abstraction] (m2) to (ms);
        \draw[black!50,abstraction] (m3) to (ms);
        \draw[black!50,abstraction,bend left] (m4) to (ms);
      }
    \end{pgfonlayer}

    \visible<4>{
    \node[draw, dashed, very thick, rounded corners=2pt,inner sep=0pt,%
      minimum width=.5\textwidth,minimum height=.46\textheight]
      (abs) at (current page.center) {};
    \node[below right] (absl) at (abs.north west) {$\mathbf{Abs}_S$};
    }
    \visible<5>{
      \node[draw, very thick, rounded corners=2pt,inner sep=0pt,%
      minimum width=.7\textwidth,minimum height=.65\textheight,yshift=-5mm]
      (abs) at (current page.center) {};
    \node[below right] (absl) at (abs.north west) {$\mathbf{Abs}_S$};
    }

  \end{tikzpicture}
\end{frame}
