Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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