1

I'm using Modelio but I want to do everything on my paper with LaTeX, so I chose pgf-umlsd to do my sequence diagram. The trouble I have is that I don't know how to create an message to create a instance with this library, can you help me? Check the image below where you can see what I'm talking about.

this image

My first code:

\documentclass{article}
\usepackage{tikz} 
\usetikzlibrary{arrows,shadows}
\usepackage{pgf-umlsd}

\begin{document}
\begin{sequencediagram}
    \newinst{act}{Actor}
    \newthread{nr}{NetRoute}
    \newthread{nr}{NetScan}
    \begin{call}{act}{ Buscar una red}{nr}{ redes }
        %\begin{call}{act}{ Buscar una red}{nr}{ redes }
    \end{call}
\end{sequencediagram}
\end{document}

which yields:

enter image description here

  • Added, but I don't know how it can help. Thank you for your reply ;) – Daniel 976034 Jun 19 '14 at 15:17
  • The full code was on WriteLatex, but changed it! – Daniel 976034 Jun 19 '14 at 15:23
  • Sorry but I don't understand what do you want. Could explain it better? Even hand drawing it over your result could help. – Ignasi Jun 19 '14 at 16:00
  • @Ignasi, You can see it on my picture using modelio. As you can see there, a lifetime create a instance of a class sending the message "create". – Daniel 976034 Jun 19 '14 at 16:04
  • @Ignasi What I wanted to say is to have a "create" message command which creates a new instance but places the box at the message arrow's vertical position instead of at the very top of the diagram. – Daniel 976034 Jun 19 '14 at 16:17
  • Does not seem like this is a feature of pfg-umlsd http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCAQFjAA&url=http%3A%2F%2Fpgf-umlsd.googlecode.com%2Fgit-history%2Fbc853ab627d49800cd4d0346acba2740195846a3%2Ftags%2Fpgf-umlsd-0.6%2Fpgf-umlsd-manual.pdf&ei=LhSjU-vMCemp7Aa8_oDwBQ&usg=AFQjCNG8G-0L8GKOuleUjTLyi11TaLfGTg&sig2=NyOna1KgKZu6ivkvXhrWaw&bvm=bv.69411363,d.ZGU&cad=rja. But are you sure that this is the right way to do in a sequence diagram. Normally all the instances stay at the top. – LaRiFaRi Jun 19 '14 at 16:49
  • @LaRiFaRi uff, do you know another packet which let me to do this? Thanks for your time. – Daniel 976034 Jun 19 '14 at 16:56

2 Answers2

2

you may want to take a look on TikZ-uml which defines such a macro (\umlcreatecall{}{}) for you. Just download the tikz-uml.sty into your main folder and compile the following:

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-uml} 

\begin{document}
\begin{tikzpicture}
\begin{umlseqdiag}
\umlactor[class=A, fill=blue!20]{Actor}
\umlobject[class=B]{NetRoute}
\umlobject[class=C]{NetScan}
\umlcreatecall[class=D]{NetScan}{NetModel}
\begin{umlcall}[op={buscar una red}, return=redes]{NetScan}{NetModel}
\end{umlcall}
\end{umlseqdiag}
\end{tikzpicture} 
\end{document}

Which yields:

enter image description here

You should be able to adapt this to your needs. If not, it should still be possible t draw everything in TikZ or you have a look on other possible solutions for drawing UML.

LaRiFaRi
  • 43,807
1

If I well understood, you want something like \mess but with a boxed label above and a line joining label and mid point.

You can do something similar customizing \mess. I've copied \mess definition from pgf-umlsd.sty to the preamble and changed a litle bit. The result is \create{origin}{label}{destination} command with similar syntax.

\documentclass[border=2mm]{standalone}
\usepackage{tikz} 
\usetikzlibrary{arrows,shadows}
\usepackage{pgf-umlsd}

\newcommand{\create}[4][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=1mm, draw, inner sep=1pt] (create_aux_node)
  {#3} coordinate[midway] (create_aux);
   \draw (create_aux) -- (create_aux_node); 
  \node (#3 from) at (mess from) {};
  \node (#3 to) at (mess to) {};
}

\begin{document}
\begin{sequencediagram}
    \newinst{act}{Actor}
    \newthread{nr}{NetRoute}
    \newthread{ns}{NetScan}
    \begin{call}{act}{ Buscar una red}{ns}{ redes }
    \end{call}
    \create{act}{create}{nr}
\end{sequencediagram}
\end{document}

enter image description here

Ignasi
  • 136,588