[Tex/LaTex] On a problem related to UML class diagram using pgf-umlcd

pgf-umlcdtikz-pgf

I use the pgf-umlcd package written by Xu Yuan (see http://code.google.com/p/pgf-umlcd/)
in order to write UML class diagrams. It is easy to use – however there is a bug which I don't know how to fix.

In the below snippet there is a description of a package
System.Lang
Compiling the file leads to the Error message:

!Package pgf Error: No shape named System is known....

\documentclass{minimal}
%%%% Tikz pictures
\usepackage{tikz} 
%%%% UML Class Diagrams
\usepackage[simplified]{pgf-umlcd} 
\begin{document}
\begin{tikzpicture}%[show background grid]
\begin{package}{System.Lang} % <<<<-------- The problem is here!

    \begin{interface}{ISet}{7,0}
        \attribute{NoOfItems}
        \operation{Add(element)}
    \end{interface}

\end{package}
\end{tikzpicture} 
\end{document}

I have tried inconvenient work arounds, like drawing up the System package too – but that did not work either.
At the moment I only use the sub-folder name instead of System.Lang, which leads to new problems because the name of the "reversed root" is not unique in the system I work with.

Any ideas?

Best Answer

This is caused by the period in your package name System.Lang. The name is also used to name the package node. However, in TikZ, periods are used to separate the node name from an anchor, so the period can't be used in the name itself.

As a fix, you can introduce an optional parameter for the package environment that will be used as the node name instead of the package name that is displayed.

If you add

\renewenvironment{package}[2][\umlcdPackageTitle]{
\edef\umlcdPackageTitle{#2}
\def\umlcdPackageFit{}
\def\umlcdPackageName{#1}
}{
  \begin{pgfonlayer}{background}
  \node[umlcd style, draw, inner sep=0.5cm, fit = \umlcdPackageFit] (\umlcdPackageName) {};
  \node[umlcd style, draw, outer ysep=-0.5, anchor=south west] (\umlcdPackageName caption) at
  (\umlcdPackageName.north west) {\umlcdPackageTitle};
  \end{pgfonlayer}
}

to your preamble, you can create a new package using

\begin{package}[SystemLang]{System.Lang}

where SystemLang is the internal node name that you can use for drawing connections, for example, and System.Lang is the text that will be used in the package title. The normal syntax \begin{package}{<package title>} will also still work.

\documentclass{minimal}
%%%% Tikz pictures
\usepackage{tikz} 
%%%% UML Class Diagrams
\usepackage[simplified]{pgf-umlcd} 

\renewenvironment{package}[2][\umlcdPackageTitle]{
\edef\umlcdPackageTitle{#2}
\def\umlcdPackageFit{}
\def\umlcdPackageName{#1}
}{
  \begin{pgfonlayer}{background}
  \node[umlcd style, draw, inner sep=0.5cm, fit = \umlcdPackageFit] (\umlcdPackageName) {};
  \node[umlcd style, draw, outer ysep=-0.5, anchor=south west] (\umlcdPackageName caption) at
  (\umlcdPackageName.north west) {\umlcdPackageTitle};
  \end{pgfonlayer}
}


\begin{document}
\begin{tikzpicture}%[show background grid]
\begin{package}[SystemLang]{System.Lang} % <<<<-------- The problem is here!

    \begin{interface}{ISet}{7,0}
        \attribute{NoOfItems}
        \operation{Add(element)}
    \end{interface}

\end{package}

\end{tikzpicture} 
\end{document}
Related Question