# protocol message diagram - rectangle

\documentclass{article}
\usepackage[margin=12mm]{geometry}
\usepackage{hyperref}
\usepackage[underline=true]{pgf-umlsd}
\usetikzlibrary{calc}
\begin{document}

\begin{sequencediagram}
\newinst{ue}{UE}
\newinst[3]{nodeb}{Node B}
\newinst[3]{rnc}{RNC}
\mess{ue}{RRC Connection Request}{rnc}
\mess{rnc}{Establish Request}{nodeb}
\mess{nodeb}{Establish Confirm}{rnc}
\mess{rnc}{RRC Connection Setup}{ue}
\postlevel
\mess{nodeb}{Synchronization Indication}{rnc}
\filldraw[fill=black!30] ($(RRC Connection Setup to)+(0,-.3)$) rectangle ($(Synchronization Indication from) +(0,.3)$)
node[midway] {L1 Synchronization};
\mess{ue}{RRC Connection Setup Complete}{rnc}
\end{sequencediagram}

\end{document}


if I would like to draw a rectangle at above all message, large from first node to the end node, between the nodes and the first message RRC Connection Request; or draw a rectangle large from first node to the end node at bottom, under the last message RRC Connection Setup Complete, all like the rectangle in the picture "L1 Synchronization" How can I do it?

-

It is the same trick than the one used in another question, i.e. to use the names that pgf-umlsd gives to the nodes from and to of each message, with a little calculation to adjust the position of the corners of the rectangle.

In this case, the difficult part is to draw that rectangle in the background, but it is easy once you know that pgf-umlsd also defines a background layer called umlsd@background.

\documentclass{article}
\usepackage[margin=12mm]{geometry}
\usepackage{hyperref}
\usepackage[underline=true]{pgf-umlsd}
\usetikzlibrary{calc}
\begin{document}
\begin{sequencediagram}
\newinst{ue}{UE}
\newinst[3]{nodeb}{Node B}
\newinst[3]{rnc}{RNC}
\mess{ue}{RRC Connection Request}{rnc}
\mess{rnc}{Establish Request}{nodeb}
\mess{nodeb}{Establish Confirm}{rnc}
\mess{rnc}{RRC Connection Setup}{ue}
\postlevel
\mess{nodeb}{Synchronization Indication}{rnc}
\filldraw[fill=black!30] ($(RRC Connection Setup to)+(0,-.3)$) rectangle ($(Synchronization Indication from) +(0,.3)$)
node[midway] {L1 Synchronization};
\mess{ue}{RRC Connection Setup Complete}{rnc}
\begin{pgfonlayer}{umlsd@background}
\fill[red!30, rounded corners]
($(RRC Connection Request from)+(-1ex,1.5em)$) rectangle ($(RRC Connection Setup Complete to)+(1ex, -1.5ex)$);
\end{pgfonlayer}
\end{sequencediagram}
\end{document}


# Update: addressing question in comment

The mechanics and the syntax is always the same. To draw a rectangle at any point you need to provide the coordinates of two opposite corners of the rectangle. And since you rectangles always go from one exterme of a message to other extreme of a message, you can use the special names that pgf-umlsd defines for you each time you use \mess. The name of those nodes are the second argument of \mess (the text of the message) plus the word from or to to denote the extremes origin and end, respectively, of the message.

Once those coordinates have been found, you will want to displace them a bit. For example, the rectangle which says "L1 Synchronization" does not start exactly at the end of "RRC Connection Setup", but below it. You can use the special syntax ($(coordinate name)+(x,y)$) to add the amounts x (for horizontal displacements) and y (for vertical ones) to the given (coordinate name). Hence, one corner of the rectangle "L1 Synchronization" is at ($(RRC Connection Setup to)+(0,-.3)$).

Using the same idea, the first rectangle at top will be:

($(RRC Connection Request from)+(0,6mm)$) rectangle ($(RRC Connection Request to)+(0,12mm)$)


being 6em and 12m the amount to add to y, which will produce a rectangle of 6mm height. You have to find those amounts by trial and error.

The rectangle at bottom will be (note that it will have also a height of 6mm:

($(RRC Connection Setup Complete from)+(0,-2mm)$) rectangle ($(RRC Connection Setup Complete to)+(0,-8mm)$)


The only detail to address is that there must be space in the figure to accomodate that rectangle, so that it does not overlap other messages. You can use the command \postlevel to "open" a vertical gap at the appropiate points. In your case, those points will be before the first \mess and after the last one.

This is the complete code:

\usepackage[margin=12mm]{geometry}
\usepackage{hyperref}
\usepackage[underline=true]{pgf-umlsd}
\usetikzlibrary{calc}
\begin{document}

\begin{sequencediagram}
\newinst{ue}{UE}
\newinst[3]{nodeb}{Node B}
\newinst[3]{rnc}{RNC}
\postlevel     % Open space for top rectangle
\mess{ue}{RRC Connection Request}{rnc}
\mess{rnc}{Establish Request}{nodeb}
\mess{nodeb}{Establish Confirm}{rnc}
\mess{rnc}{RRC Connection Setup}{ue}
\postlevel
\mess{nodeb}{Synchronization Indication}{rnc}
\filldraw[fill=black!30] ($(RRC Connection Setup to)+(0,-.3)$) rectangle ($(Synchronization Indication from) +(0,.3)$)
node[midway] {L1 Synchronization};
\mess{ue}{RRC Connection Setup Complete}{rnc}
\postlevel    % Open space for bottom rectangle
% Top rectangle
\filldraw[fill=black!30] ($(RRC Connection Request from)+(0,6mm)$) rectangle ($(RRC Connection Request to)+(0,12mm)$);

% Bottom rectangle
\filldraw[fill=black!30] ($(RRC Connection Setup Complete from)+(0,-2mm)$) rectangle ($(RRC Connection Setup Complete to)+(0,-8mm)$);
\end{sequencediagram}
\end{document}


And the result is:

If you want those gray rectangles do not overlap the vertical dashed lines, you can draw them in the background, using the technique shown in the first part of this answer (for the pink rectangle). I think the above explanations will suffice to put any other rectangle between any other desired points.

-
hello jLDiaz I expressed myself badly. I meant a rectangle like the one in figure called "L1 sinchronization." instead of being positioned between two messages, the first positioned above the first message, the second rectangle below the last message, in both cases in width as the entire message "RRC Connection Request", from the first node to the last node, and the same height of rectangle "L1 Synchronization" –  user21431 Mar 16 '13 at 22:05
@user21431 Updated my answer. See if this is what you wanted. –  JLDiaz Mar 17 '13 at 15:25
thanks, that's exactly what I wanted to achieve. I tried to just put the same strings of code but the error was that I had placed it at the beginning and not the end of the sequencediagram –  user21431 Mar 17 '13 at 17:26