Sequence Diagram – Adding Content with TikZ UML

tikz-pgftikz-uml

Given the MWE below from Configure arrows in pgf-umlsd (compiled version on the link) :

\documentclass{article}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\usepackage[underline=false]{pgf-umlsd}
\begin{document}

\begin{figure}[H]
    \centering
    \begin{sequencediagram}
        \newinst{c}{Client}
        \newinst[6]{s}{Server}

        \mess[1]{c}{Longer label}{s}
        \mess[1]{s}{label}{c}
        \mess[1]{c}{label}{s}
        \mess[1]{s}{Longer label}{c}
    \end{sequencediagram}
    \caption{Client-Server messaging}
\end{figure}
\end{document}

I would like to add some "processing contents" on the left of the left dotted vertical bar and on the right of the right dotted vertical bar. (If possible to add some \newline inside of these "processing contents" also)


Text example "linearised"* :

        Client          Server
      c^2 | --------------->| init
          |                 | f=f(c^2)
   g=g(f) | <---------------| f
        g | --------------->| check if h=g
          | <---------------| OK

*What I mean is that I still want to use the above tex form, which has a nice rendering.

The only thing I would like to add are information on both sides at every start and end of an arrow. I am looking for a simple solution if it is possible.

Thank you in advance for any help you may provide.

Best Answer

I found the definition of \mess in the style, and adapted it as \bloodymess that has three additional arguments at the end. Mandatory arguments 4, 5, and 6 are now: the arrow direction (L, or R); the start note; and the end note. If the arrow direction is given as anything other than L or R, the text will print out directly over the beginning or end of the arrow, respectively

\documentclass{article}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\usepackage[underline=false]{pgf-umlsd}
% message between threads
% Example:
% \bloodymess[delay]{sender}{message content}{receiver}{DIR}{start note}{end note}
\newcommand{\bloodymess}[7][0]{
  \stepcounter{seqlevel}
  \path
  (#2)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess from) {};
  \addtocounter{seqlevel}{#1}
  \path
  (#4)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess to) {};
  \draw[->,>=angle 60] (mess from) -- (mess to) node[midway, above]
  {#3};

  \if R#5
    \node (#3 from) at (mess from) {\llap{#6~}};
    \node (#3 to) at (mess to) {\rlap{~#7}};
  \else\if L#5
         \node (#3 from) at (mess from) {\rlap{~#6}};
         \node (#3 to) at (mess to) {\llap{#7~}};
       \else
         \node (#3 from) at (mess from) {#6};
         \node (#3 to) at (mess to) {#7};
       \fi
  \fi
}
\begin{document}

\begin{figure}[H]
    \centering
    \begin{sequencediagram}
        \newinst{c}{Client}
        \newinst[6]{s}{Server}

        \bloodymess[1]{c}{Longer label}{s}{R}{Start}{Server receives}
        \bloodymess[1]{s}{label}{c}{L}{Server responds}{}
        \bloodymess[1]{c}{label}{s}{R}{2nd handshake begins}{}
        \bloodymess[1]{s}{Longer label}{c}{L}{}{End}
    \end{sequencediagram}
    \caption{Client-Server messaging}
\end{figure}
\end{document}

enter image description here

Related Question