|
1 | | -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 | | -% Start of pgf-umlcd.sty |
3 | | -% |
4 | | -% Some macros for UML Class Diagrams. |
5 | | -% Home page of project: http://pgf-umlcd.googlecode.com/ |
6 | | -% Author: Xu Yuan <[email protected]>, Humboldt University, Berlin |
7 | | -% Style from: http://www.ibm.com/developerworks/cn/rational/r-uml/ |
8 | | -% |
9 | | - |
| 1 | +% SPDX-License-Identifier: GPL-2.0-only OR LPPL-1.3c |
10 | 2 | \NeedsTeXFormat{LaTeX2e}[1999/12/01] |
11 | 3 | \ProvidesPackage{pgf-umlcd}[2011/10/01 v0.3dev Some LaTeX macros for |
12 | 4 | UML Class Diagrams.] |
13 | 5 |
|
14 | 6 | \RequirePackage{tikz} |
| 7 | +\usetikzlibrary{umlcd} |
15 | 8 |
|
16 | | -\usetikzlibrary{arrows,shapes.multipart,backgrounds,fit} |
17 | | -\tikzstyle{help lines}+=[blue!50,very thin,dashed] |
18 | | - |
19 | | -\newcommand{\umltextcolor}{black} |
20 | | -\newcommand{\umldrawcolor}{purple} |
21 | | -\newcommand{\umlfillcolor}{yellow!20} |
22 | | -\tikzstyle{umlcolor}=[color=\umldrawcolor,fill=\umlfillcolor,text=\umltextcolor] |
23 | | -\tikzstyle{umlcd style}=[umlcolor, >=angle 90] |
24 | | - |
25 | | -\tikzstyle{package}=[matrix, column sep=1mm, row sep=1cm, node distance=2cm] |
26 | | -\tikzstyle{packagename}=[rectangle, minimum height=2em] |
27 | | - |
28 | | -\tikzstyle{umlcd style implement line}=[color=\umldrawcolor, open triangle 45-,dashed] |
29 | | -\tikzstyle{objectline}=[color=\umldrawcolor, diamond->] |
30 | | -\tikzstyle{umlcd style inherit line}=[color=\umldrawcolor, open triangle 45-] |
31 | | -\tikzstyle{splitline}=[color=\umldrawcolor, dotted,font=\itshape] |
32 | | - |
33 | | -\tikzstyle{umlcd style class}=[rectangle split, rectangle split parts=3, |
34 | | -every text node part/.style={text centered}, |
35 | | -draw, minimum height=2em, umlcolor, minimum width=2cm, text width=5cm, |
36 | | -minimum height=1cm, node distance=2cm] |
37 | | - |
38 | | - |
39 | | -\tikzstyle{umlcd style dashed line}=[color=\umldrawcolor, >=angle 90,dashed] |
40 | | - |
41 | | -\tikzstyle{umlcd style school}=[] |
42 | | -\newif\ifschool\schoolfalse |
43 | | -\DeclareOption{school}{\tikzstyle{umlcd style school}=[rounded corners] \schooltrue} |
44 | | -\newif\ifsimplified\simplifiedfalse |
45 | | -\DeclareOption{simplified}{\simplifiedtrue} |
| 9 | +\DeclareOption{school}{\tikzset{umlcd style school/.style={rounded corners}}\pgfumlcd@schooltrue} |
| 10 | +\DeclareOption{simplified}{\pgfumlcd@simplifiedtrue} |
46 | 11 | \ProcessOptions\relax |
47 | | - |
48 | | - |
49 | | -% declare layers |
50 | | -\pgfdeclarelayer{background} |
51 | | -\pgfdeclarelayer{connectionlayers} |
52 | | -\pgfsetlayers{background,connectionlayers,main} |
53 | | - |
54 | | -\newcounter{umlcdClassAttributesNum} |
55 | | -\newcounter{umlcdClassOperationsNum} |
56 | | -\newcounter{umlcdClassAbstractClassNum} |
57 | | -\newcounter{umlcdClassInterfaceNum} |
58 | | -\newcounter{umlcdClassSplitPartNum} |
59 | | - |
60 | | -\def\umlcdPackageFit{} |
61 | | - |
62 | | -\newenvironment{class}[3][]% |
63 | | -{ |
64 | | -\begin{classAndInterfaceCommon}{#1}{#2}{#3} |
65 | | -}% |
66 | | -{\calcuateNumberOfParts{} |
67 | | -\node[anchor=north, this umlcd style] (\umlcdClassName) at (\umlcdClassPos) |
68 | | - {\textbf{\umlcdClassName} |
69 | | -\insertAttributesAndOperations{} |
70 | | -}; |
71 | | - |
72 | | -\end{classAndInterfaceCommon} |
73 | | -} |
74 | | - |
75 | | -\newenvironment{interface}[3][]% |
76 | | -{ |
77 | | -\begin{classAndInterfaceCommon}{#1}{#2}{#3} |
78 | | -}% |
79 | | -{\calcuateNumberOfParts{} |
80 | | -\node[anchor=north,this umlcd style] (\umlcdClassName) at (\umlcdClassPos) |
81 | | - {$<<$interface$>>$ \\ \textbf{\umlcdClassName} |
82 | | -\insertAttributesAndOperations{} |
83 | | -}; |
84 | | - |
85 | | -\end{classAndInterfaceCommon} |
86 | | -} |
87 | | - |
88 | | -\newenvironment{abstractclass}[3][]% |
89 | | -{ |
90 | | -\begin{classAndInterfaceCommon}{#1}{#2}{#3} |
91 | | -}% |
92 | | -{\calcuateNumberOfParts{} |
93 | | -\node[anchor=north, this umlcd style] (\umlcdClassName) at (\umlcdClassPos) |
94 | | - {$<<$abstract$>>$ \\ \textbf{\umlcdClassName} |
95 | | -\insertAttributesAndOperations{} |
96 | | -}; |
97 | | - |
98 | | -\end{classAndInterfaceCommon} |
99 | | -} |
100 | | - |
101 | | -\newenvironment{staticclass}[3][]% |
102 | | -{ |
103 | | -\begin{classAndInterfaceCommon}{#1}{#2}{#3} |
104 | | -}% |
105 | | -{\calcuateNumberOfParts{} |
106 | | -\node[this umlcd style, anchor=north] (\umlcdClassName) at (\umlcdClassPos) |
107 | | - {$<<$static$>>$ \\ \textbf{\umlcdClassName} |
108 | | -\insertAttributesAndOperations{} |
109 | | -}; |
110 | | - |
111 | | -\end{classAndInterfaceCommon} |
112 | | -} |
113 | | - |
114 | | -% TODO: here the name of \umlcdClassName and \umlObjectName should be |
115 | | -% switched, it is only for reusing \classAndInterfaceCommon at the |
116 | | -% moment. |
117 | | -\newenvironment{object}[3][]% |
118 | | -{ |
119 | | -\begin{classAndInterfaceCommon}{#1}{#2}{#3} |
120 | | -\def\@instanceOf{} |
121 | | -\def\@@instanceOf{} |
122 | | -}% |
123 | | -{ |
124 | | - % customized |
125 | | - \ifsimplified |
126 | | - \calcuateNumberOfParts{} |
127 | | - \else |
128 | | - \ifnum\c@umlcdClassOperationsNum>0 |
129 | | - \setcounter{umlcdClassSplitPartNum}{3} |
130 | | - \protected@xdef\umlcdSplitPart{3} |
131 | | - \else |
132 | | - \setcounter{umlcdClassSplitPartNum}{2} |
133 | | - \protected@xdef\umlcdSplitPart{2} |
134 | | - \fi |
135 | | - \fi |
136 | | - |
137 | | - \ifx\@instanceOf\@@instanceOf |
138 | | - \def\umldObjectName{\umlcdClassName} |
139 | | - \else |
140 | | - \def\umldObjectName{\umlcdClassName : \@instanceOf} |
141 | | - \fi |
142 | | - |
143 | | -\node[anchor=north, this umlcd style, umlcd style school] (\umlcdClassName) at (\umlcdClassPos) |
144 | | - { \ifschool |
145 | | - \textbf{\umldObjectName} |
146 | | - \else |
147 | | - \underline{\textbf{\umldObjectName}} |
148 | | - \fi |
149 | | - \insertAttributesAndOperations{} |
150 | | -}; |
151 | | - |
152 | | -\end{classAndInterfaceCommon} |
153 | | -} |
154 | | - |
155 | | -\newcommand*{\insertAttributesAndOperations} |
156 | | -{ |
157 | | - \ifnum\c@umlcdClassSplitPartNum>1 |
158 | | - \nodepart{second} |
159 | | - \fi |
160 | | - \umlcdClassAttributes |
161 | | - \ifnum\c@umlcdClassSplitPartNum>2 |
162 | | - \nodepart{third} |
163 | | - \fi |
164 | | - \umlcdClassOperations |
165 | | -} |
166 | | - |
167 | | -\newcommand*{\calcuateNumberOfParts} |
168 | | -{ |
169 | | - % calcuate the number of parts |
170 | | - \ifsimplified |
171 | | - \setcounter{umlcdClassSplitPartNum}{1} |
172 | | - \ifnum\c@umlcdClassAttributesNum>0 |
173 | | - \stepcounter{umlcdClassSplitPartNum} |
174 | | - \fi |
175 | | - \ifnum\c@umlcdClassOperationsNum>0 |
176 | | - \stepcounter{umlcdClassSplitPartNum} |
177 | | - \fi |
178 | | - \else |
179 | | - \setcounter{umlcdClassSplitPartNum}{3}% three parts by default |
180 | | - \fi |
181 | | - |
182 | | - \protected@xdef\umlcdSplitPart{3} |
183 | | - \ifnum\c@umlcdClassSplitPartNum=1 |
184 | | - \protected@xdef\umlcdSplitPart{1} |
185 | | - \fi |
186 | | - \ifnum\c@umlcdClassSplitPartNum=2 |
187 | | - \protected@xdef\umlcdSplitPart{2} |
188 | | - \fi |
189 | | -} |
190 | | - |
191 | | -\newenvironment*{classAndInterfaceCommon}[3] |
192 | | -{ |
193 | | -\def\umlcdClassName{#2}% |
194 | | -\def\umlcdClassPos{#3} |
195 | | -\def\umlcdClassAttributes{}% |
196 | | -\def\umlcdClassOperations{}% |
197 | | -\def\umlcdClassAbstractClass{}% |
198 | | -\def\umlcdClassInterface{}% |
199 | | -\setcounter{umlcdClassAttributesNum}{0}% |
200 | | -\setcounter{umlcdClassOperationsNum}{0}% |
201 | | -\setcounter{umlcdClassAbstractClassNum}{0}% |
202 | | -\setcounter{umlcdClassInterfaceNum}{0}% |
203 | | -\tikzstyle{this umlcd style}=[umlcd style class, rectangle split |
204 | | - parts=\umlcdSplitPart, #1] |
205 | | -}% |
206 | | -{ |
207 | | -%% connections |
208 | | -\begin{pgfonlayer}{connectionlayers} |
209 | | -\ifnum\c@umlcdClassAbstractClassNum>0 |
210 | | -\foreach \c in \umlcdClassAbstractClass { |
211 | | - \draw [umlcd style inherit line] (\c) -- (\umlcdClassName); |
212 | | -} |
213 | | -\fi |
214 | | - |
215 | | -\ifnum\c@umlcdClassInterfaceNum>0 |
216 | | -\foreach \c in \umlcdClassInterface { |
217 | | - \draw [umlcd style implement line] (\c) -- (\umlcdClassName); |
218 | | -} |
219 | | -\fi |
220 | | -\end{pgfonlayer} |
221 | | - |
222 | | -%% add to fit |
223 | | -\let\umlcdPackageFitOld\umlcdPackageFit |
224 | | -\protected@xdef\umlcdPackageFit{\umlcdPackageFitOld (\umlcdClassName)} |
225 | | -} |
226 | | - |
227 | | -\newcommand{\attribute}[1]{% |
228 | | -\ifnum\c@umlcdClassAttributesNum=0 |
229 | | -\protected@xdef\umlcdClassAttributes{#1} |
230 | | -\else |
231 | | -\let\umlcdClassAttributesOld\umlcdClassAttributes |
232 | | -\protected@xdef\umlcdClassAttributes{\umlcdClassAttributesOld \ \newline |
233 | | - #1} |
234 | | -\fi |
235 | | -\stepcounter{umlcdClassAttributesNum} |
236 | | -} |
237 | | - |
238 | | -\newcommand{\operation}[2][1]{% |
239 | | -\stepcounter{umlcdClassOperationsNum} |
240 | | - |
241 | | -\def\virtualoperation{#2} |
242 | | -\ifnum0=#1 |
243 | | -\def\virtualoperation{\textit{#2}} |
244 | | -\fi |
245 | | - |
246 | | -\ifnum\c@umlcdClassOperationsNum=1 |
247 | | -\protected@xdef\umlcdClassOperations{\virtualoperation} |
248 | | -\else |
249 | | -\let\umlcdClassOperationsOld\umlcdClassOperations |
250 | | -\protected@xdef\umlcdClassOperations{\umlcdClassOperationsOld \ \newline |
251 | | - \virtualoperation} |
252 | | -\fi |
253 | | -} |
254 | | - |
255 | | -\newcommand{\inherit}[1] |
256 | | -{ |
257 | | -\stepcounter{umlcdClassAbstractClassNum} |
258 | | -\ifnum\c@umlcdClassAbstractClassNum=1 |
259 | | -\protected@xdef\umlcdClassAbstractClass{#1} |
260 | | -\else |
261 | | -\let\umlcdClassAbstractClassOld\umlcdClassAbstractClass |
262 | | -\protected@xdef\umlcdClassAbstractClass{\umlcdClassAbstractClassOld, |
263 | | - #1} |
264 | | -\fi |
265 | | -} |
266 | | - |
267 | | -\newcommand{\implement}[1] |
268 | | -{ |
269 | | -\stepcounter{umlcdClassInterfaceNum} |
270 | | -\ifnum\c@umlcdClassInterfaceNum=1 |
271 | | -\protected@xdef\umlcdClassInterface{#1} |
272 | | -\else |
273 | | -\let\umlcdClassInterfaceOld\umlcdClassInterface |
274 | | -\protected@xdef\umlcdClassInterface{\umlcdClassInterfaceOld, |
275 | | - #1} |
276 | | -\fi |
277 | | -} |
278 | | - |
279 | | -\newcommand{\instanceOf}[1]{\def\@instanceOf{#1}} |
280 | | - |
281 | | -\newcommand{\association}[7][]{ |
282 | | -\draw [umlcd style,#1] (#2) -- (#5) |
283 | | - node[near start, auto]{#3} |
284 | | - node[near start, auto, swap]{#4} |
285 | | - node[near end, auto]{#6} |
286 | | - node[near end, auto, swap]{#7}; |
287 | | -} |
288 | | - |
289 | | -\newcommand{\unidirectionalAssociation}[5][]{ |
290 | | -\draw [umlcd style, ->, #1] (#2) -- (#5) |
291 | | - node[near end, auto]{#3} |
292 | | - node[near end, auto, swap]{#4}; |
293 | | -} |
294 | | - |
295 | | -\newcommand{\aggregation}[5][]{ |
296 | | -\draw[umlcd style, open diamond->, #1] (#2) -- (#5) |
297 | | - node[near end, auto]{#3} |
298 | | - node[near end, auto, swap]{#4}; |
299 | | -} |
300 | | - |
301 | | -\newcommand{\composition}[5][]{ |
302 | | -\draw[umlcd style, fill=\umldrawcolor, diamond->, #1] (#2) -- (#5) |
303 | | - node[near end, auto]{#3} |
304 | | - node[near end, auto, swap]{#4}; |
305 | | -} |
306 | | - |
307 | | -\newenvironment{package}[1]{ |
308 | | -\def\umlcdPackageFit{} |
309 | | -\def\umlcdPackageName{#1} |
310 | | -}{ |
311 | | - \begin{pgfonlayer}{background} |
312 | | - \node[umlcd style, draw, inner sep=0.5cm, fit = \umlcdPackageFit] (\umlcdPackageName) {}; |
313 | | - \node[umlcd style, draw, outer ysep=-0.5, anchor=south west] (\umlcdPackageName caption) at |
314 | | - (\umlcdPackageName.north west) {\umlcdPackageName}; |
315 | | - \end{pgfonlayer} |
316 | | -} |
317 | | - |
318 | | -\newcommand{\switchUmlcdSchool}{ |
319 | | - \ifschool |
320 | | - \tikzstyle{umlcd style school}=[] |
321 | | - \schoolfalse |
322 | | - \else |
323 | | - \tikzstyle{umlcd style school}=[rounded corners] |
324 | | - \schooltrue |
325 | | - \fi |
326 | | -} |
327 | | - |
328 | | -\pgfdeclareshape{umlcdnote}{ |
329 | | -\inheritsavedanchors[from=rectangle] % this is nearly a rectangle |
330 | | -\inheritanchorborder[from=rectangle] |
331 | | -\inheritanchor[from=rectangle]{center} |
332 | | -\inheritanchor[from=rectangle]{north} |
333 | | -\inheritanchor[from=rectangle]{south} |
334 | | -\inheritanchor[from=rectangle]{west} |
335 | | -\inheritanchor[from=rectangle]{east} |
336 | | -% ... and possibly more |
337 | | -\backgroundpath{% this is new |
338 | | -% store lower right in xa/ya and upper right in xb/yb |
339 | | -\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y |
340 | | -\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y |
341 | | -% compute corner of flipped page |
342 | | -\pgf@xc=\pgf@xb \advance\pgf@xc by-10pt % this should be a parameter |
343 | | -\pgf@yc=\pgf@yb \advance\pgf@yc by-10pt |
344 | | -% construct main path |
345 | | -\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}} |
346 | | -\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}} |
347 | | -\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}} |
348 | | -\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}} |
349 | | -\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}} |
350 | | -\pgfpathclose |
351 | | -% add little corner |
352 | | -\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}} |
353 | | -\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}} |
354 | | -\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}} |
355 | | -\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}} |
356 | | -} |
357 | | -} |
358 | | - |
359 | | -\newcommand{\umlnote}[1][]{ |
360 | | - \node[umlcd style, anchor=north, draw,shape=umlcdnote, text width=4cm, #1] |
361 | | -} |
362 | | - |
363 | | -%%% End of pgf-umlcd.sty |
364 | | -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
0 commit comments