1

I need to draw an "extended" uml diagram for problem frames. For this purpose I installed tikz-uml (because I am also using tikz for other drawings).

My packages need a stereotype, but the tikz-uml docs don't say anything about that. I would like to have a type attribute to define a stereotype. The code below does not compile.

\tikzset{
  type/.style={%
    draw,
    font={\guillemotleft #1 \guillemotright \\}}
}

\begin{tikzpicture} 
\begin{umlpackage}[type=contextDiagram,x=0,y=0]{package-name} 
\end{umlpackage} 
\end{tikzpicture}

So this is what I want to achieve:

uml diagram with one contextDiadgram package

Or is there another packege, which is more powerfull?

Thanks.

2

This is ugly, because it requires renewing the definition of a fairly complex environment that was not designed to do this (traditional UML would not have stereotypes for packages). But it gets the job done.

I assume release v1.0b (01 February 2013) of tikz-uml, available for download here.

The added code is mostly borrowed from the equivalent code in the definition of the internal \umlclass command, which does support stereotypes.

\documentclass{standalone}
\usepackage[T1]{fontenc} % for guillemots (package doc uses babel to fake them)
\usepackage{tikz-uml}
\makeatletter
\renewenvironment{umlpackage}[2][]{%
  \pgfkeys{/tikzuml/package/.cd,%
           x/.initial=0, y/.initial=0,%
           name/.initial=tikzumlEmpty, draw/.initial=\tikzumldrawcolor, type/.initial=\empty,% 
           fill/.initial=\tikzumlfillpackagecolor, text/.initial=\tikzumltextcolor,%
           .unknown/.code={%
             \let\keyname=\pgfkeyscurrentname%
             \errmessage{TIKZUML ERROR : in umlpackage, invalid option \keyname}%
                                }}%
  \pgfkeys{/tikzuml/package/.cd, #1}%
  \pgfkeys{/tikzuml/package/.cd,%
           x/.get=\xshift, y/.get=\yshift, name/.get=\tikzumlpackagename,%
           draw/.get=\tikzumlpackagedraw, fill/.get=\tikzumlpackagefill,%
           text/.get=\tikzumlpackagetext, type/.get=\umlpackagetype,}%
  %
  \ifthenelse{\equal{\umlpackagetype}{}}{%
    \def\tikzumlpackagetype{}%
  }{%
    \def\tikzumlpackagetype{\guillemotleft\umlpackagetype\guillemotright \\}%
  }%
  \ifnum\thetikzumlPackageLevel>0%
    \let\tikzumlPackage@nameold\tikzumlPackage@fitname%
    \def\tikzumlPackage@name{#2}%
    \begingroup%
      \def\_{@}\edef\x{\endgroup%
        \def\noexpand\tikzumlPackage@fitname{\tikzumlPackage@name}}\x%
    \let\tikzumlPackage@parentold\tikzumlPackage@parent%
    \edef\tikzumlPackage@parent{\tikzumlPackage@parentold @@\tikzumlPackage@nameold}%
  \else%
    \def\tikzumlPackage@parent{}%
    \def\tikzumlPackage@name{#2}%
    \begingroup%
      \def\_{@}\edef\x{\endgroup%
        \def\noexpand\tikzumlPackage@fitname{\tikzumlPackage@name}}\x%
  \fi%
  %
  \let\tikzumlPackage@nodeNameold\tikzumlPackage@nodeName%
  %  
  \begingroup%
    \def\_{_}\edef\x{\endgroup%
      \def\noexpand\tikzumlPackage@nodeName{\tikzumlPackage@name}}\x%
  %
  \ifthenelse{\equal{\tikzumlpackagename}{tikzumlEmpty}}{}{%
    \def\tikzumlPackage@nodeName{\tikzumlpackagename}%
  }%
  %
  \StrSubstitute{\tikzumlPackage@nodeName}{.}{@POINT@}{\tikzumlPackage@nodeName}%
  %
  \expandafter\gdef\csname tikzumlPackageFit\tikzumlPackage@parent @@\tikzumlPackage@fitname\endcsname{}%
  %
  \setcounter{tikzumlPackageClassNum}{0}%
  \setcounter{tikzumlPackageSubPackageNum}{0}%
  \stepcounter{tikzumlPackageLevel}%
  %
  \begin{scope}[xshift=\xshift cm, yshift=\yshift cm]%
}{%
  \addtocounter{tikzumlPackageLevel}{-1}%
  \begin{pgfonlayer}{package\thetikzumlPackageLevel}%
  %
  % if contains no class, one define a fictive node to enable the fit option
  \ifnum\c@tikzumlPackageClassNum=0%
    \ifnum\c@tikzumlPackageSubPackageNum=0%
      \node[inner sep=1.5ex] (\tikzumlPackage@nodeName-root) at (0,0) {\phantom{\tikzumlPackage@nodeName}};%
      \expandafter\xdef\csname tikzumlPackageFit\tikzumlPackage@parent @@\tikzumlPackage@fitname\endcsname{(\tikzumlPackage@nodeName-root)}%
      %
    \fi%
  \fi%
  %
  \ifnum\c@tikzumlPackageLevel>0%
    \def\tikzumlPackageFitTmp{\csname tikzumlPackageFit\tikzumlPackage@parent\endcsname}%
    \expandafter\xdef\csname tikzumlPackageFit\tikzumlPackage@parent\endcsname{\tikzumlPackageFitTmp (\tikzumlPackage@nodeName) (\tikzumlPackage@nodeName-caption)}%
    \stepcounter{tikzumlPackageSubPackageNum}%
  \fi%
  %
  \node[draw=\tikzumlpackagedraw, fill=\tikzumlpackagefill, text=\tikzumlpackagetext, font=\tikzumlfont, inner sep=1.5ex, fit = \csname tikzumlPackageFit\tikzumlPackage@parent @@\tikzumlPackage@fitname\endcsname] (\tikzumlPackage@nodeName) {};%
  \node[draw=\tikzumlpackagedraw, fill=\tikzumlpackagefill, text=\tikzumlpackagetext, font=\tikzumlfont, minimum height=1.5em, outer ysep=-0.3, anchor=south west,align=center] (\tikzumlPackage@nodeName-caption) at (\tikzumlPackage@nodeName.north west) {\tikzumlpackagetype \textbf{\tikzumlPackage@name}};%
  \end{pgfonlayer}%
  \end{scope}%
}%
\makeatother
\tikzumlset{font={\small\sffamily}}

\begin{document}
\begin{tikzpicture} 
\begin{umlpackage}[x=0,y=0,type=contextDiagram]{package-name} 
\end{umlpackage} 
\begin{umlpackage}[x=5,y=0]{package-name-no-type} 
\end{umlpackage} 
\end{tikzpicture}
\end{document}

enter image description here

You might consider using pgf-umlcd instead. It looks to support many of the same things that tikz-uml does, but pgf-umlcd is on CTAN (more officially accessible) and has developer activity in the last year (not great, I know, but the same cannot be said for tikz-uml). However, pgf-umlcd does not support package stereotypes either, so modifications would be required there too.

1

I added this feature to tikz-uml. A new release will be available soon. I was quite away from tikz-uml until now but the package will live again.

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.