% Demonstration of pgf-umlsd.sty, a set of convenient macros for drawing
% UML sequence diagrams. Written by Xu Yuan <xuyuan.cn AT gmail.com> from
% Southeast University, China.
% The project is hosted at Google code: http://code.google.com/p/pgf-umlsd/ 
\documentclass{article}

\usepackage{tikz}
\usepackage{pgf-umlsd}
\usepgflibrary{arrows} % for pgf-umlsd


\begin{document}

\begin{figure}
  \centering

  \begin{sequencediagram}
    \newthread{ss}{}{SimulationServer}
    \newinst{ctr}{}{SimControlNode}
    \newinst{ps}{}{PhysicsServer}
    \newinst[1]{sense}{}{SenseServer}

    \begin{call}{ss}{Initialize()}{sense}{}
    \end{call}
    \begin{sdloop}{Run Loop}
      \begin{call}{ss}{StartCycle()}{ctr}{}
        \begin{call}{ctr}{ActAgent()}{sense}{}
        \end{call}
      \end{call}
      \begin{call}{ss}{Update()}{ps}{}
        \begin{call}{ps}{PrePhysicsUpdate()}{sense}{state}
        \end{call}
        \begin{callself}{ps}{PhysicsUpdate()}{}
        \end{callself}
        \begin{call}{ps}{PostPhysicsUpdate()}{sense}{}
        \end{call}
      \end{call}
      \begin{call}{ss}{EndCycle()}{ctr}{}
        \begin{call}{ctr}{SenseAgent()}{sense}{}
        \end{call}
      \end{call}
    \end{sdloop}
  \end{sequencediagram}

  \caption{UML sequence diagram demo.}
\end{figure}

\begin{figure}
  \centering

  \begin{sequencediagram}
    \newthread{ss}{}{SimulationServer}
    \newinst{ps}{}{PhysicsServer}
    \newinst[1]{sense}{}{SenseServer}
    \newthread[red]{ctr}{}{SimControlNode}

    \begin{sdloop}[green!20]{Run Loop}
      \mess{ctr}{StartCycle}{ss}
      \begin{call}{ss}{Update()}{ps}{}
        \prelevel
        \begin{callself}{ctr}{SenseAgent()}{}
          \begin{call}[3]{ctr}{Read}{sense}{}
          \end{call}
        \end{callself}
        \prelevel\prelevel\prelevel\prelevel
        \setthreadbias{west}
        \begin{call}{ps}{PrePhysicsUpdate()}{sense}{}
        \end{call}
        \setthreadbias{center}
        \begin{callself}{ps}{Update()}{}
        \end{callself}
        \begin{call}{ps}{PostPhysicsUpdate()}{sense}{}
        \end{call}
      \end{call}
      \mess{ss}{EndCycle}{ctr}
      \begin{callself}{ctr}{ActAgent()}{}
        \begin{call}{ctr}{Write}{sense}{}
        \end{call}
      \end{callself}
    \end{sdloop}

  \end{sequencediagram}

  \caption{Example of a sequence with parallel activities.}
\end{figure}

\end{document}

