custom_pgf-umlcd.sty 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 <xu@informatik.hu-berlin.de>, Humboldt University, Berlin
  7. % Style from: http://www.ibm.com/developerworks/cn/rational/r-uml/
  8. % Fixed by Martin Quinson (martin.quinson@loria.fr) in nov 2010 to compile with pgf 2.00
  9. % Fixed by Jean-Christophe Bach (jeanchristophe.bach@inria.fr) in apr 2011 to have enum
  10. \tikzstyle{help lines}+=[blue!50,very thin,dashed]
  11. \newcommand{\umltextcolor}{black}
  12. \newcommand{\umldrawcolor}{black}
  13. \newcommand{\umlfillcolor}{yellow!20}
  14. \tikzstyle{umlcolor}=[color=\umldrawcolor,fill=\umlfillcolor,text=\umltextcolor]
  15. \tikzstyle{umlcd style}=[umlcolor, >=angle 90]
  16. \tikzstyle{package}=[matrix, column sep=1mm, row sep=1cm, node distance=2cm]
  17. \tikzstyle{packagename}=[rectangle, minimum height=2em]
  18. \tikzstyle{umlcd style implement line}=[color=\umldrawcolor, open triangle 45-,dashed]
  19. \tikzstyle{objectline}=[color=\umldrawcolor, diamond->]
  20. \tikzstyle{umlcd style inherit line}=[color=\umldrawcolor, open triangle 45-]
  21. \tikzstyle{splitline}=[color=\umldrawcolor, dotted,font=\itshape]
  22. \tikzstyle{umlcd style class}=[rectangle split, rectangle split parts=3, every
  23. text node part/.style={text centered}, draw, minimum height=2em, umlcolor,
  24. minimum width=2cm, minimum height=1cm, node distance=2cm]
  25. %text width=3cm,
  26. \tikzstyle{umlcd style enum}=[rectangle split, rectangle split parts=2,
  27. every text node part/.style={text centered},
  28. %every text node part/.style={text ragged left,color=red},
  29. draw, minimum height=2em, umlcolor, minimum width=2cm, text width=4cm,
  30. minimum height=1cm, node distance=2cm]
  31. % declare layers
  32. \pgfdeclarelayer{background}
  33. \pgfdeclarelayer{connectionlayers}
  34. \pgfsetlayers{background,connectionlayers,main}
  35. \newcounter{umlcdClassAttributesNum}
  36. \newcounter{umlcdClassOperationsNum}
  37. \newcounter{umlcdClassAbstractClassNum}
  38. \newcounter{umlcdClassInterfaceNum}
  39. \def\umlcdPackageFit{}
  40. \newenvironment{class}[3][]%
  41. {
  42. \begin{classAndInterfaceCommon}{#1}{#2}{#3}
  43. }%
  44. {\node[this umlcd style, anchor=north] (\umlcdClassName) at (\umlcdClassPos)
  45. {\textbf{\umlcdClassName}
  46. \nodepart{second}
  47. \umlcdClassAttributes
  48. \nodepart{third}
  49. \umlcdClassOperations
  50. };
  51. \end{classAndInterfaceCommon}
  52. }
  53. \newenvironment{abstractclass}[3][]%
  54. {
  55. \begin{classAndInterfaceCommon}{#1}{#2}{#3}
  56. }%
  57. {\node[this umlcd style, anchor=north] (\umlcdClassName) at (\umlcdClassPos)
  58. {\textit{\textbf{\umlcdClassName}}
  59. \nodepart{second}
  60. \umlcdClassAttributes
  61. \nodepart{third}
  62. \umlcdClassOperations
  63. };
  64. \end{classAndInterfaceCommon}
  65. }
  66. \newenvironment{interface}[3][]%
  67. {
  68. \begin{classAndInterfaceCommon}{#1}{#2}{#3}
  69. }%
  70. {\node[this umlcd style, anchor=north] (\umlcdClassName) at (\umlcdClassPos)
  71. {$<<$interface$>>$ \\ \textbf{\umlcdClassName}
  72. \nodepart{second}
  73. \umlcdClassAttributes
  74. \nodepart{third}
  75. \umlcdClassOperations
  76. };
  77. \end{classAndInterfaceCommon}
  78. }
  79. %perso
  80. \newenvironment{enum}[3][]%
  81. {
  82. \begin{classAndInterfaceCommon}{#1}{#2}{#3}
  83. }%
  84. {\node[umlcd style enum, anchor=north] (\umlcdClassName) at (\umlcdClassPos)
  85. {$<<$enumeration$>>$ \\ \textbf{\umlcdClassName}
  86. \nodepart{second}
  87. \umlcdClassAttributes
  88. };
  89. %\begin{tabular}{c}
  90. %\end{tabular}
  91. %\begin{tabular}{l}
  92. %\end{tabular}
  93. \end{classAndInterfaceCommon}
  94. }
  95. %/perso
  96. \newenvironment*{classAndInterfaceCommon}[3]
  97. {
  98. \def\umlcdClassName{#2}%
  99. \def\umlcdClassPos{#3}
  100. \def\umlcdClassAttributes{}%
  101. \def\umlcdClassOperations{}%
  102. \def\umlcdClassAbstractClass{}%
  103. \def\umlcdClassInterface{}%
  104. \setcounter{umlcdClassAttributesNum}{0}%
  105. \setcounter{umlcdClassOperationsNum}{0}%
  106. \setcounter{umlcdClassAbstractClassNum}{0}%
  107. \setcounter{umlcdClassInterfaceNum}{0}%
  108. \tikzstyle{this umlcd style}=[umlcd style class, #1]
  109. }%
  110. {
  111. %% connections
  112. \begin{pgfonlayer}{connectionlayers}
  113. \ifnum\c@umlcdClassAbstractClassNum>0
  114. \foreach \c in {\umlcdClassAbstractClass}{
  115. \draw [umlcd style inherit line] (\c) -- (\umlcdClassName);
  116. }
  117. \fi
  118. \ifnum\c@umlcdClassInterfaceNum>0
  119. \foreach \c in {\umlcdClassInterface}{
  120. \draw [umlcd style implement line] (\c) -- (\umlcdClassName);
  121. }
  122. \fi
  123. \end{pgfonlayer}
  124. %% add to fit
  125. \let\umlcdPackageFitOld\umlcdPackageFit
  126. \protected@xdef\umlcdPackageFit{\umlcdPackageFitOld (\umlcdClassName)}
  127. }
  128. \newcommand{\attribute}[1]{%
  129. \ifnum\c@umlcdClassAttributesNum=0
  130. \protected@xdef\umlcdClassAttributes{#1}
  131. \else
  132. \let\umlcdClassAttributesOld\umlcdClassAttributes
  133. \protected@xdef\umlcdClassAttributes{\umlcdClassAttributesOld \ \newline %\\
  134. #1}
  135. \fi
  136. \stepcounter{umlcdClassAttributesNum}
  137. }
  138. \newcommand{\operation}[2][1]{%
  139. \stepcounter{umlcdClassOperationsNum}
  140. \def\virtualoperation{#2}
  141. \ifnum0=#1
  142. \def\virtualoperation{\textit{#2}}
  143. \fi
  144. \ifnum\c@umlcdClassOperationsNum=1
  145. \protected@xdef\umlcdClassOperations{\virtualoperation}
  146. \else
  147. \let\umlcdClassOperationsOld\umlcdClassOperations
  148. \protected@xdef\umlcdClassOperations{\umlcdClassOperationsOld \ \newline
  149. \virtualoperation}
  150. \fi
  151. }
  152. \newcommand{\inherit}[1]
  153. {
  154. \stepcounter{umlcdClassAbstractClassNum}
  155. \ifnum\c@umlcdClassAbstractClassNum=1
  156. \protected@xdef\umlcdClassAbstractClass{#1}
  157. \else
  158. \let\umlcdClassAbstractClassOld\umlcdClassAbstractClass
  159. \protected@xdef\umlcdClassAbstractClass{\umlcdClassAbstractClassOld,
  160. #1}
  161. \fi
  162. }
  163. \newcommand{\implement}[1]
  164. {
  165. \stepcounter{umlcdClassInterfaceNum}
  166. \ifnum\c@umlcdClassInterfaceNum=1
  167. \protected@xdef\umlcdClassInterface{#1}
  168. \else
  169. \let\umlcdClassInterfaceOld\umlcdClassInterface
  170. \protected@xdef\umlcdClassInterface{\umlcdClassInterfaceOld,
  171. #1}
  172. \fi
  173. }
  174. \newcommand{\association}[6]{
  175. \draw [umlcd style] (#1) -- (#4)
  176. node[near start, above]{#2}
  177. node[near start, below]{#3}
  178. node[near end, above]{#5}
  179. node[near end, below]{#6};
  180. }
  181. % 0 -> up
  182. % 1 -> down
  183. % 2 -> left
  184. % 3 -> right
  185. \newcommand{\myassociation}[8]{
  186. %\node({#7}){}; %[draw=white,fill=white]
  187. \ifnum0=#8
  188. \draw [umlcd style, fill=white] (#1) --
  189. node[near start, above, anchor=210]{#2}
  190. node[near start, below, anchor=150]{#3}
  191. (#7) -- (#4)
  192. node[near end, below]{#5}
  193. node[near end, above]{#6};
  194. \fi
  195. \ifnum1=#8
  196. \draw [umlcd style, fill=white] (#1) --
  197. node[near start, below, anchor=150]{#2}
  198. node[near start, above, anchor=210]{#3}
  199. (#7) -- (#4)
  200. node[near end, above]{#5}
  201. node[near end, below]{#6};
  202. \fi
  203. }
  204. \newcommand{\myassociationtwo}[8]{
  205. %\node({#7}){}; %[draw=white,fill=white]
  206. \draw [umlcd style, fill=white] (#1) --
  207. node[near start, left]{#2}
  208. node[near start, right]{#3}
  209. (#7) -- (#8) -- (#4)
  210. node[near end, left]{#5}
  211. node[near end, right]{#6};
  212. }
  213. \newcommand{\myassociationthree}[8]{
  214. %\node({#7}){}; %[draw=white,fill=white]
  215. \draw [umlcd style, fill=white] (#1) --
  216. node[near start, left]{#2}
  217. node[near start, below, xshift=-0.5cm]{#3}
  218. (#7) -- (#8) -- (#4)
  219. node[near end, below, xshift=0.5cm]{#5}
  220. node[near end, right]{#6};
  221. }
  222. %%%
  223. \newcommand{\unidirectionalAssociation}[4]{
  224. \draw [umlcd style, ->] (#1) -- (#4)
  225. node[near end, above]{#2}
  226. node[near end, below]{#3};
  227. }
  228. \newcommand{\aggregation}[4]
  229. {
  230. \draw[umlcd style, open diamond->] (#1) -- (#4)
  231. node[near end, above]{#2}
  232. node[near end, below]{#3};
  233. }
  234. \newcommand{\composition}[4]
  235. {
  236. \draw[umlcd style, fill=\umldrawcolor, diamond->] (#1) -- (#4)
  237. node[near end, above]{#2}
  238. node[near end, below]{#3};
  239. }
  240. \newenvironment{package}[1]{
  241. \def\umlcdPackageFit{}
  242. \def\umlcdPackageName{#1}
  243. }{
  244. \begin{pgfonlayer}{background}
  245. \node[umlcd style, draw, inner sep=0.5cm, fit = \umlcdPackageFit] (\umlcdPackageName) {};
  246. \node[umlcd style, draw, outer ysep=-0.5, anchor=south west] (\umlcdPackageName caption) at
  247. (\umlcdPackageName.north west) {\umlcdPackageName};
  248. \end{pgfonlayer}
  249. }
  250. %%% End of pgf-umlcd.sty
  251. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%