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
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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.