# How to extend pgf-umlcd with self association connection?

I have the following UML diagram describing an OrganizationUnit with Persons that fill zero to many Vacancies. The problem lies with need to have nested OrganizationUnits, since pgf-umlcd does not support self association and the graphical result of using \association is bad.

\begin{tikzpicture}
\begin{class}[text width=8 cm]{OrganizationUnit}{0,0}
\attribute{name: String}
\attribute{contactInformation: List<String>}
\end{class}
\begin{class}{Person}{-5, -5}
\attribute{name : String}
\attribute{title: String}
\attribute{yearOfBirth: Integer}
\end{class}
\begin{class}{Vacancy}{5, -5}
\attribute{title: String}
\end{class}

\association{OrganizationUnit}{}{1}{Person}{0..*}{belongs to}
\association{OrganizationUnit}{}{1}{Vacancy}{0..*}{}
\association{Vacancy}{}{0..*}{Person}{1}{fills}
\association{OrganizationUnit}{}{1}{OrganizationUnit}{}{0..*}
\end{tikzpicture}


How would I go about extending the pgf-umlcd to implement \selfAssociation?

-

Figured it out, mostly:

Editing the pgf-umlcd.sty, I added the following:

\newcommand{\selfAssociation}[5]{
\draw [umlcd style] (#1.north) -- ($(#1.north) + (0, 1)$)
node[midway, left]{#2}
node[midway, right]{#3};
\draw [umlcd style] ($(#1.north) + (0,1)$) -- ($(#1.east) + (1.5,2)$);
\draw [umlcd style] ($(#1.east) + (1.5,2)$) -- ($(#1.east) + (1.5,0)$);
\draw [umlcd style] ($(#1.east) + (1.5,0)$) -- (#1.east)
node[midway, above]{#4}
node[midway, below]{#5};
}


And use it as such:

\selfAssociation{OrganizationUnit}{belongs to}{0,1}{contains}{0..*}


This approach has two problems as far as I can tell:

1. It "uses up" the north and east connections always -you might want to choose the direction in which the selfassociation lines are drawn.

2. The corners are not straight: This is because the east is the vertical middle of the class, and since classes can vary by height, you can never know how to position that corner.

Any ideas on how to fix these issues would be appreciated.

-