-
Notifications
You must be signed in to change notification settings - Fork 2
/
pgf-umlcd.sty
299 lines (259 loc) · 7.55 KB
/
pgf-umlcd.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Start of pgf-umlcd.sty
%
% Some macros for UML Class Diagrams.
% Home page of project: http://pgf-umlcd.googlecode.com/
% Author: Xu Yuan <[email protected]>, Humboldt University, Berlin
% Style from: http://www.ibm.com/developerworks/cn/rational/r-uml/
%
\usetikzlibrary{arrows,shapes.multipart,backgrounds,fit}
\tikzstyle{help lines}+=[blue!50,very thin,dashed]
%\newcommand{\umltextcolor}{black}
%\newcommand{\umldrawcolor}{purple}
%\newcommand{\umlfillcolor}{yellow!20}
\tikzstyle{umlcolor}=[color=\umldrawcolor,fill=\umlfillcolor,text=\umltextcolor]
\tikzstyle{umlcd style}=[umlcolor, >=angle 90]
\tikzstyle{package}=[matrix, column sep=1mm, row sep=1cm, node distance=2cm]
\tikzstyle{packagename}=[rectangle, minimum height=2em]
\tikzstyle{umlcd style implement line}=[color=\umldrawcolor, open triangle 45-,dashed]
\tikzstyle{objectline}=[color=\umldrawcolor, diamond->]
\tikzstyle{umlcd style inherit line}=[color=\umldrawcolor, open triangle 45-]
\tikzstyle{splitline}=[color=\umldrawcolor, dotted,font=\itshape]
\tikzstyle{umlcd style class}=[rectangle split, rectangle split parts=3,
every text node part/.style={text centered},
draw, minimum height=2em, umlcolor, minimum width=2cm, text width=5cm,
minimum height=1cm, node distance=2cm]
\tikzstyle{umlcd style dashed line}=[color=\umldrawcolor, >=angle 90,dashed]
\tikzstyle{umlcd style school}=[]
\newif\ifschool\schoolfalse
\DeclareOption{school}{\tikzstyle{umlcd style school}=[rounded corners] \schooltrue}
\newif\ifsimplified\simplifiedfalse
\DeclareOption{simplified}{\simplifiedtrue}
\ProcessOptions\relax
% declare layers
\pgfdeclarelayer{background}
\pgfdeclarelayer{connectionlayers}
\pgfsetlayers{background,connectionlayers,main}
\newcounter{umlcdClassAttributesNum}
\newcounter{umlcdClassOperationsNum}
\newcounter{umlcdClassAbstractClassNum}
\newcounter{umlcdClassInterfaceNum}
\newcounter{umlcdClassSplitPartNum}
\def\umlcdPackageFit{}
\newenvironment{class}[3][]%
{
\begin{classAndInterfaceCommon}{#1}{#2}{#3}
}%
{\calcuateNumberOfParts{}
\node[this umlcd style, anchor=north] (\umlcdClassName) at (\umlcdClassPos)
{\textbf{\umlcdClassName}
\insertAttributesAndOperations{}
};
\end{classAndInterfaceCommon}
}
\newenvironment{interface}[3][]%
{
\begin{classAndInterfaceCommon}{#1}{#2}{#3}
}%
{\calcuateNumberOfParts{}
\node[this umlcd style, anchor=north] (\umlcdClassName) at (\umlcdClassPos)
{$<<$interface$>>$ \\ \textbf{\umlcdClassName}
\insertAttributesAndOperations{}
};
\end{classAndInterfaceCommon}
}
\newenvironment{abstractclass}[3][]%
{
\begin{classAndInterfaceCommon}{#1}{#2}{#3}
}%
{\calcuateNumberOfParts{}
\node[this umlcd style, anchor=north] (\umlcdClassName) at (\umlcdClassPos)
{$<<$abstract$>>$ \\ \textbf{\umlcdClassName}
\insertAttributesAndOperations{}
};
\end{classAndInterfaceCommon}
}
\newenvironment{object}[3][]%
{
\begin{classAndInterfaceCommon}{#1}{#2}{#3}
}%
{
% customized
\ifsimplified
\calcuateNumberOfParts{}
\else
\ifnum\c@umlcdClassOperationsNum>0
\setcounter{umlcdClassSplitPartNum}{3}
\protected@xdef\umlcdSplitPart{3}
\else
\setcounter{umlcdClassSplitPartNum}{2}
\protected@xdef\umlcdSplitPart{2}
\fi
\fi
\node[this umlcd style, anchor=north, umlcd style school] (\umlcdClassName) at (\umlcdClassPos)
{ \ifschool
\textbf{\umlcdClassName}
\else
\underline{\textbf{\umlcdClassName}}
\fi
\insertAttributesAndOperations{}
};
\end{classAndInterfaceCommon}
}
\newcommand*{\insertAttributesAndOperations}
{
\ifnum\c@umlcdClassSplitPartNum>1
\nodepart{second}
\fi
\umlcdClassAttributes
\ifnum\c@umlcdClassSplitPartNum>2
\nodepart{third}
\fi
\umlcdClassOperations
}
\newcommand*{\calcuateNumberOfParts}
{
% calcuate the number of parts
\ifsimplified
\setcounter{umlcdClassSplitPartNum}{1}
\ifnum\c@umlcdClassAttributesNum>0
\stepcounter{umlcdClassSplitPartNum}
\fi
\ifnum\c@umlcdClassOperationsNum>0
\stepcounter{umlcdClassSplitPartNum}
\fi
\else
\setcounter{umlcdClassSplitPartNum}{3}% three parts by default
\fi
\protected@xdef\umlcdSplitPart{3}
\ifnum\c@umlcdClassSplitPartNum=1
\protected@xdef\umlcdSplitPart{1}
\fi
\ifnum\c@umlcdClassSplitPartNum=2
\protected@xdef\umlcdSplitPart{2}
\fi
}
\newenvironment*{classAndInterfaceCommon}[3]
{
\def\umlcdClassName{#2}%
\def\umlcdClassPos{#3}
\def\umlcdClassAttributes{}%
\def\umlcdClassOperations{}%
\def\umlcdClassAbstractClass{}%
\def\umlcdClassInterface{}%
\setcounter{umlcdClassAttributesNum}{0}%
\setcounter{umlcdClassOperationsNum}{0}%
\setcounter{umlcdClassAbstractClassNum}{0}%
\setcounter{umlcdClassInterfaceNum}{0}%
\tikzstyle{this umlcd style}=[umlcd style class, rectangle split
parts=\umlcdSplitPart, #1]
}%
{
%% connections
\begin{pgfonlayer}{connectionlayers}
\ifnum\c@umlcdClassAbstractClassNum>0
\foreach \c in {\umlcdClassAbstractClass}{
\draw [umlcd style inherit line] (\c) -- (\umlcdClassName);
}
\fi
\ifnum\c@umlcdClassInterfaceNum>0
\foreach \c in {\umlcdClassInterface}{
\draw [umlcd style implement line] (\c) -- (\umlcdClassName);
}
\fi
\end{pgfonlayer}
%% add to fit
\let\umlcdPackageFitOld\umlcdPackageFit
\protected@xdef\umlcdPackageFit{\umlcdPackageFitOld (\umlcdClassName)}
}
\newcommand{\attribute}[1]{%
\ifnum\c@umlcdClassAttributesNum=0
\protected@xdef\umlcdClassAttributes{#1}
\else
\let\umlcdClassAttributesOld\umlcdClassAttributes
\protected@xdef\umlcdClassAttributes{\umlcdClassAttributesOld \ \newline
#1}
\fi
\stepcounter{umlcdClassAttributesNum}
}
\newcommand{\operation}[2][1]{%
\stepcounter{umlcdClassOperationsNum}
\def\virtualoperation{#2}
\ifnum0=#1
\def\virtualoperation{\textit{#2}}
\fi
\ifnum\c@umlcdClassOperationsNum=1
\protected@xdef\umlcdClassOperations{\virtualoperation}
\else
\let\umlcdClassOperationsOld\umlcdClassOperations
\protected@xdef\umlcdClassOperations{\umlcdClassOperationsOld \ \newline
\virtualoperation}
\fi
}
\newcommand{\inherit}[1]
{
\stepcounter{umlcdClassAbstractClassNum}
\ifnum\c@umlcdClassAbstractClassNum=1
\protected@xdef\umlcdClassAbstractClass{#1}
\else
\let\umlcdClassAbstractClassOld\umlcdClassAbstractClass
\protected@xdef\umlcdClassAbstractClass{\umlcdClassAbstractClassOld,
#1}
\fi
}
\newcommand{\implement}[1]
{
\stepcounter{umlcdClassInterfaceNum}
\ifnum\c@umlcdClassInterfaceNum=1
\protected@xdef\umlcdClassInterface{#1}
\else
\let\umlcdClassInterfaceOld\umlcdClassInterface
\protected@xdef\umlcdClassInterface{\umlcdClassInterfaceOld,
#1}
\fi
}
\newcommand{\association}[6]{
\draw [umlcd style] (#1) -- (#4)
node[near start, above]{#2}
node[near start, below]{#3}
node[near end, above]{#5}
node[near end, below]{#6};
}
\newcommand{\unidirectionalAssociation}[4]{
\draw [umlcd style, ->] (#1) -- (#4)
node[near end, above]{#2}
node[near end, below]{#3};
}
\newcommand{\aggregation}[4]
{
\draw[umlcd style, open diamond->] (#1) -- (#4)
node[near end, above]{#2}
node[near end, below]{#3};
}
\newcommand{\composition}[4]
{
\draw[umlcd style, fill=\umldrawcolor, diamond->] (#1) -- (#4)
node[near end, above]{#2}
node[near end, below]{#3};
}
\newenvironment{package}[1]{
\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) {\umlcdPackageName};
\end{pgfonlayer}
}
\newcommand{\switchUmlcdSchool}{
\ifschool
\tikzstyle{umlcd style school}=[]
\schoolfalse
\else
\tikzstyle{umlcd style school}=[rounded corners]
\schooltrue
\fi
}
%%% End of pgf-umlcd.sty
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%