Showing posts with label tikz. Show all posts
Showing posts with label tikz. Show all posts

Friday, February 10, 2012

Using tikz-uml to create uml diagrams in latex

At Uni we are learning UML for documenting our products. Therefore we need at tool to create these. I had a hard time finding a good, free, gui tool, so I settled for a LaTeX/TikZ solutions, since we use LaTeX for reports anyway. I will here briefly describe how to get started using tikz-uml, as the package is called.

First step is to go and download tikz-uml here.

Assuming you are on linux, unzip the tikz-uml.sty file in a folder: ~/texmf/tex/latex/tikz-uml/. Windows people should be able to find a similar folder in their C:\Program Files\Miktex folder somewhere, as far as I recall.

Now run the command:

texhash ~/texmf
to make Latex aware of the newly installed package. (I do not know how to do this in Windows. Possibly through the Miktex package manager?)

Now you are ready to get stated using tikz-uml. Usage examples are found here. A simple template to get started could be:

\documentclass[12pt,article]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\linespread{1.05}
\usepackage{tikz}
\usepackage{tikz-uml} 
\usepackage{amsmath}
\begin{document}

\begin{tikzpicture}
\begin{umlsystem}[x=0, y=0]{Name of system} 
% Code from official documentation goes here...
\end{umlsystem}
% And here
\end{tikzpicture}

\end{document}

Example of Use Case model

Here is the code for a use case diagram using tikz-uml:

\documentclass[12pt,article]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\linespread{1.05}
\usepackage{tikz}
\usepackage{tikz-uml} 
\usepackage{amsmath}
\usepackage{savetrees}
\begin{document}

\begin{figure}[h!]
\begin{tikzpicture}
\begin{umlsystem}{Schedule}
\umlusecase[x=-3]{Check Request}
\umlusecase[x=3]{Ask Constraints}
\umlusecase[x=-2,y=-2]{Deny Request}
\umlusecase[x=3, y=-2]{Collect Constraints}
\umlusecase[x=-3,y=-4]{Determine Schedule}
\umlusecase[x=3,y=-4]{Merge Constraints} 
\umlusecase[y=-6]{Resolve Conflicts}
\end{umlsystem}

\umlactor[x=-8]{Initiator}
\umlactor[x=-8,y=-6]{Participant A}
\umlactor[x=8]{Participant B}
\umlactor[x=8,y=-6]{Conflict Resolver} 

\umlassoc{Initiator}{usecase-1}
\umlassoc{Initiator}{usecase-3}
\umlassoc{Participant A}{usecase-5}
\umlassoc{Participant B}{usecase-2}
\umlassoc{Participant B}{usecase-4}
\umlassoc{Conflict Resolver}{usecase-7}

\umlextend{usecase-2}{usecase-3}
\umlinclude{usecase-5}{usecase-7}
\end{tikzpicture}
\caption{Example of Use case diagram using tikz-uml. Examlpe from the book Requirements Engineering by Axel van Lamsweerde.}
\end{figure}

\end{document}
and the result:

More examples may come as we learn more about it.