\documentclass[10pt,table]{beamer}

\usepackage{pgfpages}
%\includeonlyframes{this one}
%[,label=this one]

\usepackage{polyglossia}
\setmainlanguage{french}
\setotherlanguage{english}

% Do this BEFORE unicode-math
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage{amssymb}
\usepackage{siunitx}

\usefonttheme{professionalfonts}
\usepackage{unicode-math}
% Do this AFTER any math font package (see fontspec doc)
\usepackage{fontspec}
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text}
\setromanfont{Fontin}[
  Path           = fonts/ ,
  Extension      = .ttf ,
  UprightFont    = *-Regular ,
  BoldFont       = *-Bold ,
  ItalicFont     = *-Italic ,
  SmallCapsFont  = *-SmallCaps ]
\setsansfont{Fontin-Sans}[
  Path           = fonts/ ,
  Extension      = .otf ,
  UprightFont    = *-Regular ,
  BoldFont       = *-Bold ,
  ItalicFont     = *-Italic ,
  BoldItalicFont = *-BoldItalic ,
  SmallCapsFont  = *-SmallCaps ]
%\setmonofont[Scale=0.8]{Hack}
\setmonofont{FantasqueSansMono}[
  Path           = fonts/ ,
  Extension      = .ttf ,
  UprightFont    = *-Regular ,
  BoldFont       = *-Bold ,
  ItalicFont     = *-Italic ,
  BoldItalicFont = *-BoldItalic ]

\setmathfont[mathbf=sym] {Asana-Math}[
  Path           = fonts/ ,
  Extension      = .otf ]

\usepackage{xspace}
\usepackage{xltxtra}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{pdfpages}
%\usetikzlibrary{shadows}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{backgrounds}
\usetikzlibrary{bending}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.text}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}
\usetikzlibrary{spy}


\usepackage{listings}
\lstdefinestyle{haskell}{%
language=Haskell}

\usepackage{xparse} % LaTeX3 command declaration

\usetheme{Pittsburgh}
\usecolortheme{orchid}

%Titre + sous-titre c'est mieux.
\title{Modélisation multi-niveau}
\subtitle{Un cadre théorique pour l'intégration des niveaux d'organisation dans
les modèles. Applications à l'activité spatiale et à la simulation de grandes
populations de bactéries.}

\author{Martin \textsc{Potier}}
\institute[UPE]{Université Paris-Est}
\date{6 juillet 2017}

\tikzstyle{every picture}+=[remember picture]
\tikzset{
  diagonal fill/.style 2 args={fill=#2, path picture={
      \fill[#1, sharp corners] (path picture bounding box.south west) -|
  (path picture bounding box.north east) -- cycle;}},
  reversed diagonal fill/.style 2 args={fill=#2, path picture={
      \fill[#1, sharp corners] (path picture bounding box.north west) |-
  (path picture bounding box.south east) -- cycle;}}
}
\setbeamersize{text margin left=1mm,text margin right=1mm}
%\setbeamercovered{dynamic}
\beamertemplatenavigationsymbolsempty
\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{itemize items}[default]
\setbeamertemplate{enumerate items}[default]
\setbeamertemplate{section in toc shaded}[default][20]
%\setbeamercovered{transparent=20}
%\setbeamercolor{structure}{fg=blue}
\setbeamertemplate{footline}{
  \begin{tikzpicture}[overlay]
    \node [anchor=center,white,fill=structure,circle,
      minimum size=7mm,text height=3.5mm,text depth=1.5mm,inner sep=1pt]
      at ($(current page) + (64mm,-49mm) + (-5mm,6mm)$)
      %{\insertframenumber~/~\inserttotalframenumber}
      {\large\insertframenumber};
  \end{tikzpicture}
}
\setbeamertemplate{frametitle}{
  \color{structure}
  %\bfseries
  \insertframetitle
  \par
  \vskip-12pt
  \pgfmathsetmacro{\progress}{\insertframenumber/\inserttotalframenumber}
  \pgfmathsetmacro{\progress}{126*\progress}
  \tikz[overlay]{\draw[structure,thick,gridded]
  (0,0) -- (\progress mm,0);}\par
}

% Solarized set
\definecolor{base03}{HTML}{002B36}
\definecolor{base02}{HTML}{073642}
\definecolor{base01}{HTML}{586E75}
\definecolor{base00}{HTML}{657B83}
\definecolor{base0}{HTML}{839496}
\definecolor{base1}{HTML}{93A1A1}
\definecolor{base2}{HTML}{EEE8D5}
\definecolor{base3}{HTML}{FDF6E3}
\definecolor{orange}{HTML}{CB4B16}
\definecolor{red}{HTML}{DC322F}
\definecolor{green}{HTML}{859900}
\definecolor{yellow}{HTML}{B58900}
\definecolor{magenta}{HTML}{D33682}
\definecolor{violet}{HTML}{6C71C4}
\definecolor{blue}{HTML}{268BD2}
\definecolor{cyan}{HTML}{2AA198}

% Partie multi
\colorlet{compilcol}{black!80}
% Partie activité
\colorlet{active}{red}
\colorlet{ashes}{gray!60!black}
\colorlet{fire}{orange!70!red}
\colorlet{forest}{green}
\colorlet{frontier}{green}
\colorlet{quiescent}{blue}
% Partie OTB
\colorlet{c}      {blue!60}
\colorlet{ocaml}  {green!60}
\colorlet{opencl} {red!60}
\colorlet{sbgp}   {magenta!60}

\newcount\currentimg % used in animations

%Commands and aliases
\newcommand{\mgs}{MGS\xspace}
\newcommand{\voisinde}[1]{%
  \usebeamercolor{structure}%
  \tikz[baseline,every node/.style={circle,anchor=base,inner sep=.5mm}]{%
    \draw[draw=none] node (#1) {,};%
    \uncover<2->{\node[draw,fg] (c#1) {,};}%
}}
\newcommand{\mkPart}[1]{\section{#1}\input{plan}}
\newcommand{\model}{\ensuremath{\mathfrak{M}}}
\newcommand{\bhvm}{\ensuremath{\mathfrak{B}_{\mathfrak{M}}}}
\newcommand{\ensm}[1][]{\ensuremath{E_{\mathfrak{M}_{#1}}}}
\newcommand{\mref}{\ensuremath{E_{\text{Réf}}}}
\newcommand{\sigm}{\ensuremath{\Sigma_{\mathfrak{M}}}}
\newcommand{\timm}{\ensuremath{\mathbb{T}_{\mathfrak{M}}}}
\newcommand{\phim}{\ensuremath{\Phi_{\mathfrak{M}}}}
\newcommand{\chsm}{\ensuremath{\mathbb{S}_{\mathfrak{M}}}}
\newcommand{\chvm}{\ensuremath{\mathbb{V}_{\mathfrak{M}}}}
\newcommand{\funm}{\ensuremath{f_{\mathfrak{M}}}}
\newcommand{\mesm}{\ensuremath{\mathbb{X}_{\mathfrak{M}}}}
\newcommand{\prom}{\ensuremath{\mathbb{P}_{\mathfrak{M}}}}
\newcommand{\trim}{\ensuremath{\mathcal{A}_{\mathfrak{M}}}}
\newcommand{\orr}[1]{\ensuremath{\vec{#1}}}
\newcommand{\mkCitation}[1]{{\Tiny\textcolor{gray}{{#1}}\par}}
\newcommand{\tocshowonlycurrentsection}{}
%\newcommand{\tourdelangages}[4][white][white][white][white]{
\DeclareDocumentCommand{\tourdelangages}{ O{transparent} O{transparent} O{transparent} O{transparent} }{
  \begin{tikzpicture}[overlay,%
    every node/.style={inner sep=1mm},
    wp/.style={draw,text width=2cm,font=\footnotesize,align=center,
    minimum width=22mm, minimum height=12mm},
    compilation/.style={#4,line width=5mm,-Triangle Cap}]
    \node[wp,anchor=east,xshift=-8mm] (phenotype) at (current page.east) {
        \begin{tikzpicture}
          \clip (0cm,0cm) rectangle (2cm,1cm);
          \node[anchor=center] at (1cm,0.5cm) {\includegraphics[height=1cm]{vector/badecoli}};
        \end{tikzpicture}
    };
    \node[wp,below=of phenotype] (genotype)  {
        \begin{tikzpicture}
          \clip (0cm,0cm) rectangle (2cm,1cm);
          \node[anchor=center] at (2mm,0.5cm) {\includegraphics[height=7mm,angle=47]{vector/helix}};
        \end{tikzpicture}
      };
    \node[wp,above=of phenotype] (population) {
        \begin{tikzpicture}
          \clip (0cm,0cm) rectangle (2cm,1cm);
          \node[anchor=center] at (1cm,0.5cm) {\includegraphics[height=2cm]{vector/petri}};
        \end{tikzpicture}
    };
    \draw[compilation] (population) to (phenotype);
    \draw[compilation] (phenotype)  to (genotype);
    \begin{scope}[on background layer]
      \node[fit=(genotype) (phenotype) (population),rounded corners,
      fill,#1,inner sep=3mm] {};
      \node[fit=(population) (phenotype),rounded corners,
      fill,#2,inner sep=3mm] {};
      \node[fit=(phenotype),rounded corners,
      fill,#3,inner sep=3mm] {};
    \end{scope}
  \end{tikzpicture}
}
\newcommand{\drawfigure}{\tourdelangages{}}
\DeclareDocumentCommand{\moteurs}{ O{transparent} O{transparent} O{transparent} }{
  \begin{tikzpicture}[overlay,
    node distance=8mm,
    wp/.style={draw},
    causation/.style={black!80,-{Triangle[width=8mm,length=5mm]},shorten >= 1mm,
    shorten <=1mm,line width=5mm}%
    ]
    \coordinate[xshift=-15mm] (centre) at (current page.east);
    \node[wp,above=of centre] (moteur-physique) {%
        \begin{tikzpicture}[scale=0.7]
          \clip (0cm,0cm) rectangle (3cm,2cm);
          \node[anchor=center] at (15mm,1cm) {%
            \includegraphics[height=20mm]{vector/collision}};
        \end{tikzpicture}
      };
    \node[wp,below=of centre] (moteur-chimique) {%
        \begin{tikzpicture}[scale=0.7]
          \clip (0cm,0cm) rectangle (3cm,2cm);
          \node[anchor=center] at (15mm,1cm) {%
            \includegraphics[height=14mm]{vector/chimie}};
        \end{tikzpicture}
      };
    \draw[causation,transform canvas={xshift= 6mm}] (moteur-chimique) to (moteur-physique);
    \draw[causation,transform canvas={xshift=-6mm}] (moteur-physique) to (moteur-chimique);
    \begin{scope}[on background layer]
      \node[fit=(moteur-chimique),rounded corners,
      fill,#1,inner sep=3mm] {};
      \node[fit=(moteur-physique),rounded corners,
      fill,#2,inner sep=3mm] {};
      \node[rounded corners,fill,#3,inner sep=3mm,minimum height=2cm, minimum width=3cm]
      at (barycentric cs:moteur-chimique=1,moteur-physique=1) {};
    \end{scope}
  \end{tikzpicture}
}

\makeatletter
\patchcmd{\beamer@sectionintoc}
{\vfill}
{\vskip5\itemsep}
{}
{}
\makeatother



\begin{document}
%\input{test}
%
\input{title}
\input{introduction}
\input{plan}

\renewcommand{\tocshowonlycurrentsection}{currentsection}
\renewcommand{\drawfigure}{\tourdelangages[structure!30][transparent][transparent]}
\mkPart{Vers la modélisation multi-niveau}
\input{multimodel}
\input{formalism.model.system}
\input{experimental.model}
\input{predator.prey}
\input{model.category}
\input{part1.conclude}

\renewcommand{\drawfigure}{\tourdelangages[transparent][structure!30][transparent]}
\mkPart{Topologie de l'activité}
\input{activity.motivation}
\input{mgs.topological.collections}
\input{mgs.topological.transformations}
\input{simple.ff.example}
\input{where.is.activity}
\input{example.forest.fire}
\input{example.dla}
\input{part2.conclude}

\renewcommand{\drawfigure}{\tourdelangages[transparent][transparent][structure!30]}
\mkPart{Simulateur de colonie de bactéries}
\input{otb.general}
\input{otb.organisation}
\input{chemical.model}
\input{ecoli.model}
\input{decision.model}
\input{otb.sectorisation}
\input{otb.stable.pop}
\input{otb.architecture}
\input{part3.conclude}

\input{closing}

\end{document}
%\input{bilan}
%\input{sbgp}
%\input{otb.ppm}
%\input{wave.algorithm}
%\input{activity.in.mgs}
