| 1 |
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––> |
| 2 |
% |
| 3 |
% tkz-orm.sty - Object-Role Modeling Diagrams in LaTeX |
| 4 |
% |
| 5 |
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––> |
| 6 |
% This is file may be be distributed and/or modified |
| 7 |
% |
| 8 |
% 1. under the LaTeX Project Public License and/or |
| 9 |
% 2. under the GNU Public License. |
| 10 |
% |
| 11 |
% Copyright 2009-2016 by Jakob Voss, Camil Staps |
| 12 |
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––> |
| 13 |
\NeedsTeXFormat{LaTeX2e} |
| 14 |
\ProvidesPackage{tkz-orm}[2016/01/15 v0.1.4 Object-Role Modeling] |
| 15 |
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––> |
| 16 |
\RequirePackage{tikz}[2009/09/04] |
| 17 |
|
| 18 |
%%%% Required pgf/TikZ libraries |
| 19 |
%\usetikzlibrary{calc} |
| 20 |
\usepgflibrary{shapes.multipart} |
| 21 |
\usetikzlibrary{shadows} |
| 22 |
\usetikzlibrary{positioning} |
| 23 |
\usetikzlibrary{calc} |
| 24 |
\usetikzlibrary{fit} |
| 25 |
|
| 26 |
\makeatletter |
| 27 |
|
| 28 |
%%%% Options |
| 29 |
|
| 30 |
%\DeclareOption*{% |
| 31 |
% \PackageWarning{tkz-orm}{Unknown option ‘\CurrentOption’}% |
| 32 |
%} |
| 33 |
|
| 34 |
\def\orm@error#1{\relax}% TODO |
| 35 |
%\def\orm@error#1{\PackageWarning{tkz-orm}{#1}}% |
| 36 |
|
| 37 |
%\pgfkeysdefargs{/tikz/ormcolorlet}{#1}{\colorlet{#2}{#1}} |
| 38 |
% \pgfkeys{/orm/.is family} % TODO |
| 39 |
|
| 40 |
\def\tkzorm{\textsf{tkz-orm}} |
| 41 |
|
| 42 |
%%%% ORM color constants |
| 43 |
\colorlet{constraintcolor}{magenta!100} |
| 44 |
\colorlet{ormconstraintcolor}{magenta!100} |
| 45 |
\colorlet{ormdeonticcolor}{blue!100} |
| 46 |
\colorlet{ormimpliedcolor}{gray!100} |
| 47 |
|
| 48 |
\def\orm@constraint@stroke{magenta} |
| 49 |
\def\orm@constraint@fill{magenta} |
| 50 |
|
| 51 |
\pgfkeysdefargs{/tikz/constraintcolor}{#1}{\colorlet{constraintcolor}{#1}} |
| 52 |
|
| 53 |
%%%% ORM width and length |
| 54 |
\newlength{\orm@linewidth} |
| 55 |
\setlength{\orm@linewidth}{0.25mm} |
| 56 |
|
| 57 |
%%%% ORM fonts |
| 58 |
\newcommand{\orm@font}{\sffamily\small} |
| 59 |
\newcommand{\orm@font@bold}{\bfseries\sffamily\small} |
| 60 |
\newcommand{\orm@font@tiny}{\sffamily\tiny} |
| 61 |
\newcommand{\orm@font@scriptsize}{\sffamily\scriptsize} |
| 62 |
\newcommand{\orm@font@bold@scriptsize}{\bfseries\sffamily\scriptsize} |
| 63 |
|
| 64 |
%%%% Text markup |
| 65 |
|
| 66 |
% textsubscript may not be defined like textsuperscript |
| 67 |
\newcommand{\orm@textsubscript}[1]{% |
| 68 |
{\m@th\ensuremath{_{\mbox{\fontsize\sf@size\z@#1}}}}} |
| 69 |
|
| 70 |
% similar to \blacktriangle (could better be implemented directly in pgf) |
| 71 |
\def\orm@blacktriangle#1{ |
| 72 |
\tikz \node[draw=none,inner sep=.2ex] { |
| 73 |
\tikz [#1]\path[fill=black] |
| 74 |
(0,0) -- (.6ex,1.3ex) -- (1.2ex,0) -- cycle;}; |
| 75 |
} |
| 76 |
\def\ormarrowup{\orm@blacktriangle{rotate=0}} |
| 77 |
\def\ormarrowdown{\orm@blacktriangle{rotate=180}} |
| 78 |
\def\ormarrowleft{\orm@blacktriangle{rotate=90}} |
| 79 |
\def\ormarrowright{\orm@blacktriangle{rotate=-90}} |
| 80 |
|
| 81 |
\def\ormtext{\orm@font} |
| 82 |
\def\ormbf{\orm@font@bold} |
| 83 |
\def\ormc{\orm@font\color{constraintcolor}} |
| 84 |
\def\ormsup#1{\textsuperscript{\orm@font@scriptsize #1}} |
| 85 |
\def\ormsub#1{\orm@textsubscript{\orm@font@scriptsize #1}} |
| 86 |
\def\ormind#1{\textsuperscript{\orm@font@bold@scriptsize\color{constraintcolor} #1}} |
| 87 |
\def\ormbraces#1{{\orm@font\textbraceleft#1\textbraceright}} |
| 88 |
\def\ormvalues#1{\ormc{\ormbraces{#1}}} |
| 89 |
|
| 90 |
\def\ormleft#1{{\ormarrowleft\ormtext #1}} |
| 91 |
\def\ormup#1{{\ormtext #1\ormarrowup}} |
| 92 |
|
| 93 |
% TODO: add '*' variant in constraint color for each command |
| 94 |
|
| 95 |
%%% Sizes |
| 96 |
\def\orm@role@linewidth{\orm@linewidth} % 0.25mm |
| 97 |
\def\orm@role@width{4mm} |
| 98 |
\def\orm@role@height{2.5mm} |
| 99 |
|
| 100 |
|
| 101 |
%%%% ORM styles |
| 102 |
|
| 103 |
\pgfkeys{/tikz/constraint stroke/.store in=\orm@constraint@stroke} |
| 104 |
\pgfkeys{/tikz/constraint fill/.store in=\orm@constraint@fill} |
| 105 |
\pgfkeys{/tikz/constraint color/.style={constraint stroke=#1,constraint fill=#1}} |
| 106 |
|
| 107 |
|
| 108 |
\tikzstyle{every orm line}= [solid,draw=black,line width=\orm@linewidth,-] |
| 109 |
\tikzstyle{orm}= [font=\orm@font,node distance=4mm, |
| 110 |
%label distance=1.5mm, |
| 111 |
%line width=\orm@linewidth, |
| 112 |
label distance=1.25mm |
| 113 |
] |
| 114 |
\tikzstyle{orm-spacious}= [orm, |
| 115 |
every object/.style={shape=circle} |
| 116 |
] |
| 117 |
|
| 118 |
\tikzstyle{every orm}= [every orm line,fill=white,orm] |
| 119 |
|
| 120 |
\tikzstyle{zoomed}= [line width=\orm@linewidth*1.5] |
| 121 |
|
| 122 |
\tikzstyle{every object}= [] |
| 123 |
\tikzstyle{every entity}= [] |
| 124 |
\tikzstyle{entity}= [every orm, |
| 125 |
shape=rectangle,rounded corners, |
| 126 |
align=center,minimum size=6mm, |
| 127 |
every object,every entity] |
| 128 |
|
| 129 |
\tikzstyle{every value}= [] |
| 130 |
\tikzstyle{value}= [every orm, |
| 131 |
shape=rectangle,rounded corners,densely dashed, |
| 132 |
align=center,minimum size=6mm, |
| 133 |
every object,every value] |
| 134 |
|
| 135 |
|
| 136 |
\tikzstyle{relationship}= [every orm line,every relationship] |
| 137 |
\tikzstyle{relation}= [relationship] |
| 138 |
\tikzstyle{plays}= [relationship] |
| 139 |
\tikzstyle{every relationship}= [] |
| 140 |
|
| 141 |
|
| 142 |
\tikzstyle{role index}= [font=\orm@font@tiny,inner sep=0,minimum width=\orm@role@width] |
| 143 |
|
| 144 |
|
| 145 |
\tikzstyle{every predicate}= [] |
| 146 |
|
| 147 |
%%% Shortcuts in tikzpicture |
| 148 |
\tikzaddtikzonlycommandshortcutdef{\entity}{\node[entity]} |
| 149 |
\tikzaddtikzonlycommandshortcutdef{\value}{\node[value]} |
| 150 |
|
| 151 |
\tikzaddtikzonlycommandshortcutdef{\unary}{\node[role]} |
| 152 |
\tikzaddtikzonlycommandshortcutdef{\role}{\node[role]} |
| 153 |
\tikzaddtikzonlycommandshortcutdef{\binary}{\node[roles]} |
| 154 |
\tikzaddtikzonlycommandshortcutdef{\roles}{\node[roles]} |
| 155 |
\tikzaddtikzonlycommandshortcutdef{\ternary}{\node[roles=3]} |
| 156 |
|
| 157 |
\tikzaddtikzonlycommandshortcutdef{\vunary}{\node[vrole]} |
| 158 |
\tikzaddtikzonlycommandshortcutdef{\vrole}{\node[vrole]} |
| 159 |
\tikzaddtikzonlycommandshortcutdef{\vbinary}{\node[vroles]} |
| 160 |
\tikzaddtikzonlycommandshortcutdef{\vroles}{\node[vroles]} |
| 161 |
\tikzaddtikzonlycommandshortcutdef{\vternary}{\node[vroles=3]} |
| 162 |
|
| 163 |
\tikzaddtikzonlycommandshortcutdef{\plays}{\draw[relationship]} |
| 164 |
|
| 165 |
% TODO: add error message if matrix package not loaded ? |
| 166 |
\tikzaddtikzonlycommandshortcutdef{\rules}{\matrix[row sep=0mm,nodes={right}]} |
| 167 |
|
| 168 |
\tikzaddtikzonlycommandshortcutdef{\limits}{\draw[limits]} |
| 169 |
\tikzaddtikzonlycommandshortcutdef{\limited}{\draw[limits]} |
| 170 |
\tikzaddtikzonlycommandshortcutdef{\limitsto}{\draw[limits to]} |
| 171 |
|
| 172 |
\tikzaddtikzonlycommandshortcutdef{\constraint}{\node[text=constraintcolor]} |
| 173 |
|
| 174 |
%%%% Textual rules |
| 175 |
|
| 176 |
\tikzset{rule/.style args={#1}{% |
| 177 |
append after command={% |
| 178 |
\bgroup% |
| 179 |
[current point is local=true] |
| 180 |
(\tikzlastnode.north west) node[font=\orm@font@bold@scriptsize, |
| 181 |
anchor=north east,inner sep=0,text=constraintcolor] {#1} |
| 182 |
\egroup% |
| 183 |
}, |
| 184 |
orm,inner sep=0.5mm, |
| 185 |
}} |
| 186 |
\tikzset{rule/.default={}} |
| 187 |
|
| 188 |
|
| 189 |
%%%% Predicates and roles |
| 190 |
\tikzstyle{all predicates}=[ |
| 191 |
every orm line, |
| 192 |
fill=white, |
| 193 |
rectangle split, |
| 194 |
inner sep=0 |
| 195 |
] |
| 196 |
|
| 197 |
\tikzset{roles/.style args={#1}{ |
| 198 |
all predicates,rectangle split parts=#1, rectangle split allocate boxes=#1, |
| 199 |
rectangle split horizontal=true, |
| 200 |
rectangle split empty part height=2.5mm,rectangle split empty part width=2.25mm, % 4-1.5 = 2.5 |
| 201 |
% every label/.style={label distance=1.5mm} |
| 202 |
%label distance=1.5mm |
| 203 |
every predicate |
| 204 |
}} |
| 205 |
\tikzset{roles/.default={2}} |
| 206 |
|
| 207 |
\tikzset{vroles/.add style={}{roles=#1,rotate=90}} |
| 208 |
\tikzset{vroles/.default={2}} |
| 209 |
\tikzstyle{role}=[roles=1] |
| 210 |
\tikzstyle{vrole}=[vroles=1] |
| 211 |
|
| 212 |
\tikzstyle{role name}=[font=\orm@font,color=blue,inner sep=0.5mm] |
| 213 |
|
| 214 |
%% end of roles |
| 215 |
|
| 216 |
% TODO: read |
| 217 |
% http://www.latex-project.org/guides/clsguide.pdf |
| 218 |
|
| 219 |
\pgfkeyssetvalue{/tkzorm/constraintstroke}{constraintcolor} |
| 220 |
\pgfkeyssetvalue{/tkzorm/constraintfill}{constraintcolor} |
| 221 |
|
| 222 |
%%% |
| 223 |
% arrow heads |
| 224 |
|
| 225 |
% dot as arrow head (no color) |
| 226 |
\pgfarrowsdeclare{dot}{dot}{ |
| 227 |
\pgfutil@tempdima=0.2pt% |
| 228 |
\advance\pgfutil@tempdima by.2\pgflinewidth% |
| 229 |
\pgfutil@tempdimb=5.5\pgfutil@tempdima\advance\pgfutil@tempdimb |
| 230 |
by\pgflinewidth |
| 231 |
\pgfarrowsleftextend{+-\pgfutil@tempdimb} |
| 232 |
\pgfutil@tempdimb=1.5\pgfutil@tempdima\advance\pgfutil@tempdimb |
| 233 |
by.5\pgflinewidth |
| 234 |
\pgfarrowsrightextend{+\pgfutil@tempdimb} |
| 235 |
}{ |
| 236 |
\pgfutil@tempdima=0.2pt% |
| 237 |
\advance\pgfutil@tempdima by.2\pgflinewidth% |
| 238 |
\pgfsetdash{}{+0pt} |
| 239 |
\pgfpathcircle{\pgfqpoint{+3\pgfutil@tempdima}{0pt}}{+4.5\pgfutil@tempdima} |
| 240 |
\pgfsetstrokecolor{\orm@constraint@stroke} |
| 241 |
\pgfsetfillcolor{\orm@constraint@fill} |
| 242 |
%\pgfsetfillcolor{\pgfkeysvalueof{/tkzorm/constraintfill}} |
| 243 |
\pgfusepathqfillstroke |
| 244 |
} |
| 245 |
|
| 246 |
% mandatory constraint dot arrow head |
| 247 |
\pgfarrowsdeclare{mdot}{mdot}{ |
| 248 |
\pgfarrowsrightextend{0pt}% put arrow head over the tip |
| 249 |
\pgfutil@tempdima=0.25mm\advance\pgfutil@tempdima by 0.5\pgflinewidth% lw |
| 250 |
\pgfarrowsleftextend{+-\pgfutil@tempdima}% for arrow composing |
| 251 |
}{ |
| 252 |
\pgfutil@tempdima=0.5mm\advance\pgfutil@tempdima by \pgflinewidth% radius |
| 253 |
\pgfutil@tempdimb=0.25mm\advance\pgfutil@tempdimb by 0.5\pgflinewidth% lw |
| 254 |
\pgfpathcircle{\pgfqpoint{0.5\pgflinewidth}{0pt}}{\pgfutil@tempdima} |
| 255 |
\pgfsetfillcolor{ormconstraintcolor} |
| 256 |
\pgfusepathqfill |
| 257 |
} |
| 258 |
|
| 259 |
% implied mandatory constraint dot arrow head |
| 260 |
\pgfarrowsdeclare{idot}{idot}{ |
| 261 |
\pgfarrowsrightextend{0pt}% put arrow head over the tip |
| 262 |
\pgfutil@tempdima=0.25mm\advance\pgfutil@tempdima by 0.5\pgflinewidth% lw |
| 263 |
\pgfarrowsleftextend{+-\pgfutil@tempdima}% for arrow composing |
| 264 |
}{ |
| 265 |
\pgfutil@tempdima=0.5mm\advance\pgfutil@tempdima by \pgflinewidth% radius |
| 266 |
\pgfpathcircle{\pgfqpoint{0.5\pgflinewidth}{0pt}}{\pgfutil@tempdima} |
| 267 |
\pgfsetfillcolor{ormimpliedcolor} |
| 268 |
\pgfusepathqfill |
| 269 |
} |
| 270 |
|
| 271 |
% deontic mandatory constraint dot arrow head |
| 272 |
\pgfarrowsdeclare{odot}{odot}{ |
| 273 |
\pgfutil@tempdima=0.5mm\advance\pgfutil@tempdima by 1.0\pgflinewidth% radius |
| 274 |
\pgfarrowsrightextend{0.5\pgfutil@tempdima}% put arrow head over the tip |
| 275 |
\pgfarrowsleftextend{0pt}% for arrow composing |
| 276 |
}{ |
| 277 |
%\pgfutil@tempdima=0.5mm\advance\pgfutil@tempdima by 1.0\pgflinewidth% radius |
| 278 |
%\pgfutil@tempdimb=0.25mm\advance\pgfutil@tempdimb by 0.5\pgflinewidth% lw |
| 279 |
%\advance\pgfutil@tempdima by -0.5\pgfutil@tempdimb% -linewidth |
| 280 |
\pgfutil@tempdima=0.475mm\advance\pgfutil@tempdima by 0.75\pgflinewidth% r-lw |
| 281 |
\pgfutil@tempdimb=0.25mm\advance\pgfutil@tempdimb by 1\pgflinewidth% lw |
| 282 |
\pgfpathcircle{\pgfqpoint{\pgfutil@tempdimb}{0pt}}{\pgfutil@tempdima} |
| 283 |
\pgfutil@tempdima=0.25mm\advance\pgfutil@tempdima by 0.5\pgflinewidth% lw |
| 284 |
\pgfsetdash{}{+0pt} |
| 285 |
\pgfsetlinewidth{\pgfutil@tempdima} |
| 286 |
\pgfsetstrokecolor{ormdeonticcolor} |
| 287 |
\pgfsetfillcolor{white} |
| 288 |
\pgfusepathqfillstroke |
| 289 |
} |
| 290 |
|
| 291 |
% implied deontic mandatory constraint dot arrow head |
| 292 |
\pgfarrowsdeclare{iodot}{iodot}{ |
| 293 |
\pgfutil@tempdima=0.5mm\advance\pgfutil@tempdima by 1.0\pgflinewidth% radius |
| 294 |
\pgfarrowsrightextend{0.5\pgfutil@tempdima}% put arrow head over the tip |
| 295 |
\pgfarrowsleftextend{0pt}% for arrow composing |
| 296 |
}{ |
| 297 |
\pgfutil@tempdima=0.475mm\advance\pgfutil@tempdima by 0.75\pgflinewidth% r-lw |
| 298 |
\pgfutil@tempdimb=0.25mm\advance\pgfutil@tempdimb by 1\pgflinewidth% lw |
| 299 |
\pgfpathcircle{\pgfqpoint{\pgfutil@tempdimb}{0pt}}{\pgfutil@tempdima} |
| 300 |
\pgfutil@tempdima=0.25mm\advance\pgfutil@tempdima by 0.5\pgflinewidth% lw |
| 301 |
\pgfsetdash{}{+0pt} |
| 302 |
\pgfsetlinewidth{\pgfutil@tempdima} |
| 303 |
\pgfsetstrokecolor{ormimpliedcolor} |
| 304 |
\pgfsetfillcolor{white} |
| 305 |
\pgfusepathqfillstroke |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
% filled arrow for subtyping, subset constraints and value-comparision constraints |
| 310 |
\pgfarrowsdeclare{orm arrow}{orm arrow} |
| 311 |
{ |
| 312 |
\pgfutil@tempdima=0.5pt% |
| 313 |
\advance\pgfutil@tempdima by.1\pgflinewidth% |
| 314 |
\pgfutil@tempdimb=8.705\pgfutil@tempdima\advance\pgfutil@tempdimb by.5\pgflinewidth% |
| 315 |
\pgfarrowsleftextend{+-\pgfutil@tempdimb} |
| 316 |
\pgfutil@tempdimb=.5\pgfutil@tempdima\advance\pgfutil@tempdimb by1.28\pgflinewidth% |
| 317 |
\pgfarrowsrightextend{+\pgfutil@tempdimb} |
| 318 |
}{ |
| 319 |
\pgfutil@tempdima=0.5pt% |
| 320 |
\advance\pgfutil@tempdima by.1\pgflinewidth% |
| 321 |
\pgfsetdash{}{+0pt} |
| 322 |
\pgfsetmiterjoin |
| 323 |
\pgfpathmoveto{\pgfpointadd{\pgfqpoint{0.5\pgfutil@tempdima}{0pt}}{\pgfqpointpolar{157}{10\pgfutil@tempdima}}} |
| 324 |
\pgfpathlineto{\pgfqpoint{0.5\pgfutil@tempdima}{0\pgfutil@tempdima}} |
| 325 |
\pgfpathlineto{\pgfpointadd{\pgfqpoint{0.5\pgfutil@tempdima}{0pt}}{\pgfqpointpolar{-157}{10\pgfutil@tempdima}}} |
| 326 |
\pgfpathclose |
| 327 |
\pgfsetfillcolor{ormconstraintcolor} % TODO: change if implied, deontic etc. |
| 328 |
%\pgfsetstrokefillcolor{ormconstraintcolor} % TODO: change if implied, deontic etc. |
| 329 |
\pgfusepathqfillstroke |
| 330 |
} |
| 331 |
|
| 332 |
% line styles that enable the mandatory constraint arrow tip |
| 333 |
\tikzstyle{required} =[relationship,mdot-] |
| 334 |
\tikzstyle{required by} =[relationship,-mdot] |
| 335 |
\tikzstyle{both required} =[relationship,mdot-mdot] |
| 336 |
|
| 337 |
% aliases |
| 338 |
\tikzstyle{mandatory} =[required] |
| 339 |
\tikzstyle{both mandatory}=[both required] |
| 340 |
\tikzstyle{optional} =[relationship] |
| 341 |
|
| 342 |
|
| 343 |
% draw a mandatory constraint arrow tip over a node |
| 344 |
\tikzset{constraint dot/.style={append after command={ |
| 345 |
(\tikzlastnode.center) edge[required] (\tikzlastnode.center) |
| 346 |
}}} |
| 347 |
\tikzstyle{cdot} =[constraint dot] |
| 348 |
|
| 349 |
|
| 350 |
%%%% Constraint symbols |
| 351 |
\tikzstyle{every constraint}= [] |
| 352 |
% TODO: every uniqueness bar |
| 353 |
\tikzstyle{every constraint line}= [every orm line,draw=constraintcolor,every constraint] |
| 354 |
%\tikzstyle{every constraint line}= [line width=\orm@linewidth,draw=constraintcolor,solid] |
| 355 |
\tikzstyle{every constraint circle}=[] |
| 356 |
\tikzstyle{constraint circle}= [every orm,every constraint line, |
| 357 |
shape=circle, |
| 358 |
font=\orm@font@scriptsize, |
| 359 |
minimum size=4mm,,inner sep=0pt, |
| 360 |
every constraint circle] |
| 361 |
\tikzstyle{constraint no circle}= [constraint circle,draw=none,fill=none] |
| 362 |
|
| 363 |
\tikzstyle{limits}= [every constraint line,dotted] |
| 364 |
\tikzstyle{limits to}= [every constraint line,dashed,-orm arrow] |
| 365 |
|
| 366 |
|
| 367 |
% internal uniqueness constraint |
| 368 |
|
| 369 |
% Implied and duplicated model parts: |
| 370 |
|
| 371 |
\tikzstyle{duplicated}= [drop shadow] |
| 372 |
\tikzstyle{duplicated model}= [every orm/.append style={drop shadow}, |
| 373 |
every predicate/.append style={drop shadow}] |
| 374 |
|
| 375 |
\tikzstyle{every implied line}= [constraintcolor=gray!80,thin] |
| 376 |
\tikzstyle{every implied}= [fill=gray!30,every implied line] |
| 377 |
|
| 378 |
\tikzstyle{implied}=[ |
| 379 |
every orm/.append style={every implied}, |
| 380 |
every orm line/.append style={every implied line},, |
| 381 |
constraint color=gray!100,thin, |
| 382 |
every relationship/.style={fill=gray!30}, |
| 383 |
required/.append style={idot-}, |
| 384 |
required by/.append style={-idot}, |
| 385 |
both required/.append style={idot-idot} |
| 386 |
] |
| 387 |
\tikzstyle{implied model}=[implied] |
| 388 |
|
| 389 |
\tikzstyle{deontic}= [ |
| 390 |
every orm line/.append style={constraintcolor=blue!100}, |
| 391 |
constraintcolor=blue!100, |
| 392 |
constraint color=blue!100, |
| 393 |
required/.append style={odot-}, |
| 394 |
required by/.append style={-odot}, |
| 395 |
both required/.append style={odot-odot} |
| 396 |
] |
| 397 |
|
| 398 |
|
| 399 |
%%%% Constraints |
| 400 |
|
| 401 |
% Define a constraints type |
| 402 |
% |
| 403 |
% #1 = name of the constraint |
| 404 |
% #2 = path code to be drawn above the constraint circle with |append after command| |
| 405 |
% |
| 406 |
\newcommand{\constraintdeclare}[2]{% |
| 407 |
\tikzset{constraint/#1/.style={constraint circle,append after command={#2}}}% |
| 408 |
} |
| 409 |
|
| 410 |
% Define a constraint alias |
| 411 |
% |
| 412 |
% #1 = alias name |
| 413 |
% #2 = name of the constraint |
| 414 |
% |
| 415 |
\newcommand{\constraintdeclarealias}[2]{% |
| 416 |
\tikzset{constraint/#1/.style={constraint=#2}}% |
| 417 |
} |
| 418 |
|
| 419 |
% Define a constraint by drawing another node at the some position as the current node |
| 420 |
\newcommand{\constraintdeclareasnode}[2]{ |
| 421 |
\constraintdeclare{#1}{ |
| 422 |
(\tikzlastnode.center) node[anchor=center] {\tikz{#2}} |
| 423 |
}} |
| 424 |
|
| 425 |
% style /tikz/constraint and its keys |
| 426 |
\tikzset{constraint/.is choice} |
| 427 |
|
| 428 |
%\tikzset{constraint/misc/.style={constraint circle,text=constraintcolor}}% |
| 429 |
|
| 430 |
|
| 431 |
%\constraintdeclarealias{le}{symmetric} |
| 432 |
%\tikzset{constraint/le/.append style={label={[text=constraintcolor,font=\orm@font@scriptsize]center:$<$}}} |
| 433 |
|
| 434 |
% TODO: clean up code |
| 435 |
\tikzset{constraint/</.style={ |
| 436 |
constraint circle, |
| 437 |
append after command={ |
| 438 |
\bgroup% |
| 439 |
[current point is local=true] |
| 440 |
(\tikzlastnode) +(180:2mm) node[cdot]{} |
| 441 |
+(0:2mm) node[cdot]{} |
| 442 |
\egroup% |
| 443 |
}, |
| 444 |
label={[text=constraintcolor,font=\orm@font@scriptsize]center:$<$} |
| 445 |
}} |
| 446 |
% TODO: clean up code |
| 447 |
\tikzset{constraint/ge/.style={ |
| 448 |
constraint circle, |
| 449 |
append after command={ |
| 450 |
\bgroup% |
| 451 |
[current point is local=true] |
| 452 |
(\tikzlastnode) +(180:2mm) node[cdot]{} |
| 453 |
+(0:2mm) node[cdot]{} |
| 454 |
\egroup% |
| 455 |
}, |
| 456 |
label={[text=constraintcolor,font=\orm@font@scriptsize]center:$\ge$} |
| 457 |
}} |
| 458 |
% TODO: clean up code |
| 459 |
\tikzset{constraint/>/.style={ |
| 460 |
constraint circle, |
| 461 |
append after command={ |
| 462 |
\bgroup% |
| 463 |
[current point is local=true] |
| 464 |
(\tikzlastnode) +(180:2mm) node[cdot]{} |
| 465 |
+(0:2mm) node[cdot]{} |
| 466 |
\egroup% |
| 467 |
}, |
| 468 |
label={[text=constraintcolor,font=\orm@font@scriptsize]center:$>$} |
| 469 |
}} |
| 470 |
% TODO: clean up code |
| 471 |
\tikzset{constraint/le/.style={ |
| 472 |
constraint circle, |
| 473 |
append after command={ |
| 474 |
\bgroup% |
| 475 |
[current point is local=true] |
| 476 |
(\tikzlastnode) +(180:2mm) node[cdot]{} |
| 477 |
+(0:2mm) node[cdot]{} |
| 478 |
\egroup% |
| 479 |
}, |
| 480 |
label={[text=constraintcolor,font=\orm@font@scriptsize]center:$\le$} |
| 481 |
}} |
| 482 |
|
| 483 |
%\tikzstyle{entity}= [every orm, |
| 484 |
% shape=rectangle,rounded corners, |
| 485 |
% align=center,minimum size=6mm, |
| 486 |
% every object,every entity] |
| 487 |
\tikzset{constraint/text/.style={color=constraintcolor,font=\orm@font,align=center}} |
| 488 |
|
| 489 |
\tikzset{constraint/.default=text} |
| 490 |
|
| 491 |
% TODO: color=constraintcolor |
| 492 |
|
| 493 |
|
| 494 |
%%%% Ring constraints |
| 495 |
|
| 496 |
% TODO: possibly join with cdot |
| 497 |
\tikzstyle{ormdot}= [fill=constraintcolor,radius=.6mm,draw=none] |
| 498 |
|
| 499 |
|
| 500 |
\constraintdeclareasnode{acyclic}{ |
| 501 |
\path [ormdot] (90:2mm) circle; |
| 502 |
\path [ormdot] (210:2mm) circle; |
| 503 |
\path [ormdot] (330:2mm) circle; |
| 504 |
\draw [every constraint line] |
| 505 |
(270:1mm) edge (270:3mm); |
| 506 |
} |
| 507 |
%\constraintdeclarealias{DAG}{acyclic} % directed-acyclic-graph (DAG) |
| 508 |
|
| 509 |
\constraintdeclareasnode{intransitive}{ |
| 510 |
\fill[every constraint line,fill=white,draw=white] circle (2.2mm); |
| 511 |
\path [ormdot] (90:2mm) circle; |
| 512 |
\path [ormdot] (210:2mm) circle; |
| 513 |
\path [ormdot] (330:2mm) circle; |
| 514 |
\path[every constraint line,rounded corners=0] (90:2mm) -- (210:2mm) -- (330:2mm) -- (90:2mm); |
| 515 |
\draw[every constraint line] (270:0mm) to (270:1.75mm); |
| 516 |
} |
| 517 |
|
| 518 |
% TODO: document |
| 519 |
\constraintdeclareasnode{strongly intransitive}{ |
| 520 |
\fill[every constraint line,fill=white,draw=white] circle (2.2mm); |
| 521 |
\path [ormdot] (90:2mm) circle; |
| 522 |
\path [ormdot] (30:1mm) circle; |
| 523 |
\path [ormdot] (210:2mm) circle; |
| 524 |
\path [ormdot] (330:2mm) circle; |
| 525 |
\path[every constraint line,rounded corners=0] (90:2mm) -- (210:2mm) -- (330:2mm) -- (90:2mm); |
| 526 |
\draw[every constraint line] (270:0mm) to (270:1.75mm); |
| 527 |
} |
| 528 |
|
| 529 |
% TODO: document tree and otree |
| 530 |
\constraintdeclareasnode{tree}{ |
| 531 |
\fill[every constraint line,fill=white,draw=white] circle (2.2mm); |
| 532 |
\path [ormdot] (90:2mm) circle; |
| 533 |
\path [ormdot] (210:2mm) circle; |
| 534 |
\path [ormdot] (330:2mm) circle; |
| 535 |
\path[every constraint line,rounded corners=0] (339:2mm) -- (90:2mm) -- (210:2mm); |
| 536 |
} |
| 537 |
|
| 538 |
\constraintdeclareasnode{otree}{ |
| 539 |
\fill[every constraint line,fill=white,draw=white] circle (2.2mm); |
| 540 |
\path [ormdot] (90:2mm) circle; |
| 541 |
\path [ormdot] (210:2mm) circle; |
| 542 |
\path [ormdot] (330:2mm) circle; |
| 543 |
\path[every constraint line,rounded corners=0] (339:2mm) -- (90:2mm) -- (210:2mm); |
| 544 |
\path[every constraint line,rounded corners=0] |
| 545 |
(.8mm,-0mm) -- (-.6mm,-1mm) -- (.8mm,-2mm); |
| 546 |
} |
| 547 |
|
| 548 |
\constraintdeclareasnode{purely reflexive}{ |
| 549 |
\path[use as bounding box] (270:2.75mm) -- (90:2.75mm); |
| 550 |
\path [ormdot] (180:2mm) circle; |
| 551 |
\draw[every constraint line] (90:1.25mm) to (270:1.25mm); |
| 552 |
% (-.8mm, .4mm) -- (.8mm, .4mm) |
| 553 |
% (-.8mm,-.4mm) -- (.8mm,-.4mm); |
| 554 |
} |
| 555 |
|
| 556 |
\constraintdeclareasnode{reflexive}{ |
| 557 |
\path[use as bounding box] (270:2.75mm) -- (90:2.75mm); |
| 558 |
\path [ormdot] (180:2mm) circle; |
| 559 |
} |
| 560 |
|
| 561 |
\constraintdeclareasnode{irreflexive}{ |
| 562 |
\path[use as bounding box] (270:2.75mm) -- (90:2.75mm); |
| 563 |
\path [ormdot] (180:2mm) circle; |
| 564 |
% \draw [every constraint line] (90:1.25mm) -- (270:1.25mm); |
| 565 |
\draw [every constraint line] (270:1mm) to (270:2.75mm); |
| 566 |
} |
| 567 |
|
| 568 |
\constraintdeclareasnode{symmetric irreflexive}{ |
| 569 |
\path [ormdot] (180:2mm) circle; |
| 570 |
\path [ormdot] ( 0:2mm) circle; |
| 571 |
\draw [every constraint line] |
| 572 |
(-.8mm, .4mm) -- (.8mm, .4mm) |
| 573 |
(-.8mm,-.4mm) -- (.8mm,-.4mm) |
| 574 |
(90:1.25mm) to (270:1.25mm); |
| 575 |
} |
| 576 |
|
| 577 |
\constraintdeclareasnode{transitive}{ |
| 578 |
\draw[every constraint line,fill=white,draw=white] circle (2.2mm); |
| 579 |
\path [ormdot] (90:2mm) circle; |
| 580 |
\path [ormdot] (210:2mm) circle; |
| 581 |
\path [ormdot] (330:2mm) circle; |
| 582 |
\draw[every constraint line] (90:2mm) -- (210:2mm) -- (330:2mm) -- (90:2mm); |
| 583 |
} |
| 584 |
|
| 585 |
\constraintdeclareasnode{acyclic intransitive}{ |
| 586 |
\path [ormdot] (90:2mm) circle; |
| 587 |
\path [ormdot] (210:2mm) circle; |
| 588 |
\path [ormdot] (330:2mm) circle; |
| 589 |
\path[every constraint line] (90:2mm) -- (210:2mm) -- (330:2mm) -- (90:2mm); |
| 590 |
\draw[every constraint line] (270:0mm) to (270:2.75mm); |
| 591 |
} |
| 592 |
|
| 593 |
\constraintdeclareasnode{symmetric}{ |
| 594 |
\path [ormdot] (180:2mm) circle; |
| 595 |
\path [ormdot] ( 0:2mm) circle; |
| 596 |
} |
| 597 |
|
| 598 |
\constraintdeclareasnode{asymmetric}{ |
| 599 |
\path[use as bounding box] (270:2.75mm) -- (90:2.75mm); |
| 600 |
\path [ormdot] (+2mm,0mm) circle; |
| 601 |
\path [ormdot] (-2mm,0mm) circle; |
| 602 |
\draw [every constraint line] (270:1mm) to (270:2.75mm); |
| 603 |
} |
| 604 |
|
| 605 |
\constraintdeclareasnode{antisymmetric}{ |
| 606 |
\path [ormdot] (180:2mm) circle; |
| 607 |
\path [ormdot] ( 0:2mm) circle; |
| 608 |
\draw[every constraint line] (90:2.75mm) to (270:2.75mm); |
| 609 |
} |
| 610 |
|
| 611 |
\constraintdeclareasnode{tree}{ |
| 612 |
\draw [every constraint line,fill=white,draw=white] circle (2.2mm); |
| 613 |
\path [ormdot] (90:2mm) circle; |
| 614 |
\path [ormdot] (210:2mm) circle; |
| 615 |
\path [ormdot] (330:2mm) circle; |
| 616 |
\draw [every constraint line] (210:2mm) -- (90:2mm) -- (330:2mm); |
| 617 |
} |
| 618 |
|
| 619 |
% TODO: strictly order, total, connected, etc. |
| 620 |
|
| 621 |
|
| 622 |
% TODO: test and document this |
| 623 |
\tikzset{objectification/.style={ |
| 624 |
entity,fill=none, |
| 625 |
append after command={ |
| 626 |
\bgroup% |
| 627 |
[current point is local=true] |
| 628 |
node[orm,above=0 of \tikzlastnode] {``#1''} |
| 629 |
\egroup% |
| 630 |
} |
| 631 |
}} |
| 632 |
|
| 633 |
|
| 634 |
%%%% Subtypes |
| 635 |
% TODO: how to get current line width? |
| 636 |
\tikzstyle{inheritance}=[line width=\orm@linewidth*1.5,>=orm arrow, |
| 637 |
draw,color=constraintcolor] |
| 638 |
\tikzstyle{subtype}=[inheritance,<-,solid] |
| 639 |
\tikzstyle{suptype}=[inheritance,->,solid] |
| 640 |
\tikzstyle{subinterface}=[subtype,dashed] |
| 641 |
\tikzstyle{supinterface}=[suptype,dashed] |
| 642 |
|
| 643 |
%%%% Role indices |
| 644 |
|
| 645 |
\tikzset{index/.code={\orm@parse@index#1:\pgf@nil}} |
| 646 |
\tikzset{index/.default=1} |
| 647 |
|
| 648 |
\def\orm@parse@index#1:#2\pgf@nil{% |
| 649 |
\def\orm@temp{#2}% |
| 650 |
\ifx\orm@temp\pgfutil@empty% |
| 651 |
\orm@@parse@index1:#1:\pgf@nil% |
| 652 |
\else% |
| 653 |
\orm@@parse@index#1:#2\pgf@nil% |
| 654 |
\fi% |
| 655 |
} |
| 656 |
|
| 657 |
% \orm@verticalfalse |
| 658 |
% \orm@verticaltrue |
| 659 |
% \tikz@do@alignfalse |
| 660 |
|
| 661 |
\def\orm@@parse@index#1:#2:\pgf@nil{% |
| 662 |
\tikzset{append after command={% |
| 663 |
\bgroup% |
| 664 |
[current point is local=true] |
| 665 |
let \n1 = {#1*\orm@role@width} in |
| 666 |
(\tikzlastnode.west) to[draw=none] |
| 667 |
node[role index,pos=1,sloped,anchor=east] {#2} |
| 668 |
($(\tikzlastnode.west)!\n1!(\tikzlastnode.east)$) |
| 669 |
\egroup% |
| 670 |
} |
| 671 |
}} |
| 672 |
\tikzset{index/.default=1} |
| 673 |
|
| 674 |
|
| 675 |
%%%% Uniqueness constraint bars |
| 676 |
|
| 677 |
\def\orm@rolebar@length#1{#1*\orm@role@width-2*\orm@role@linewidth} |
| 678 |
\def\orm@rolebar@shift{0.75mm} % = 3*0.25mm |
| 679 |
|
| 680 |
\def\orm@rolebar@xshifta#1{\orm@role@linewidth+#1*\orm@role@width-\orm@role@width} |
| 681 |
\def\orm@rolebar@xshiftb#1{#1*\orm@role@width-\orm@role@linewidth} |
| 682 |
\def\orm@rolebar@yshift#1{% |
| 683 |
\ifnum#1<0-\fi0.5*\orm@role@height+#1*\orm@rolebar@shift% |
| 684 |
} |
| 685 |
|
| 686 |
\tikzstyle{uniqueness bar}=[every constraint line,-] |
| 687 |
\tikzstyle{skipped uniqueness bar}=[ |
| 688 |
every constraint line,-,dotted,preaction={every constraint line,-,white} |
| 689 |
] |
| 690 |
|
| 691 |
\def\orm@unique@bar@normal{uniqueness bar} |
| 692 |
\def\orm@unique@bar@skipped{skipped uniqueness bar} |
| 693 |
\global\let\orm@unique@bar@style=\orm@unique@bar@normal |
| 694 |
|
| 695 |
%% |
| 696 |
% Styles to draw external constraints |
| 697 |
% |
| 698 |
\pgfkeys{ |
| 699 |
/orm/external constraint/.style={ |
| 700 |
every constraint line, |
| 701 |
fill=white,text=constraintcolor,align=center, |
| 702 |
font=\orm@font@scriptsize,minimum size=4mm,inner sep=0pt |
| 703 |
} |
| 704 |
} |
| 705 |
|
| 706 |
% Defines an external constraints as node shape, based on the circle shape |
| 707 |
% The symbol is *always* drawn but circle and fill can be modified. |
| 708 |
% You can still modify the layout via color, line width, stroke opacity. |
| 709 |
% The shapes do not respect outer sep (outer xsep/outer ysep) yet (TODO). |
| 710 |
\newcommand{\constraintdeclareshape}[2]{% |
| 711 |
\expandafter\pgfdeclareshape{#1}{ |
| 712 |
\inheritsavedanchors[from=circle] |
| 713 |
\inheritanchor[from=circle]{north} |
| 714 |
\inheritanchor[from=circle]{north west} |
| 715 |
\inheritanchor[from=circle]{north east} |
| 716 |
\inheritanchor[from=circle]{center} |
| 717 |
\inheritanchor[from=circle]{west} |
| 718 |
\inheritanchor[from=circle]{east} |
| 719 |
\inheritanchor[from=circle]{mid} |
| 720 |
\inheritanchor[from=circle]{mid west} |
| 721 |
\inheritanchor[from=circle]{mid east} |
| 722 |
\inheritanchor[from=circle]{base} |
| 723 |
\inheritanchor[from=circle]{base west} |
| 724 |
\inheritanchor[from=circle]{base east} |
| 725 |
\inheritanchor[from=circle]{south} |
| 726 |
\inheritanchor[from=circle]{south west} |
| 727 |
\inheritanchor[from=circle]{south east} |
| 728 |
\inheritanchorborder[from={circle}] |
| 729 |
\backgroundpath{% \behindbackgroundpath and \beforebackgroundpath don't do. |
| 730 |
\pgfsetdash{}{0pt}% solid circle |
| 731 |
\pgfutil@tempdima=\radius% |
| 732 |
\pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}% |
| 733 |
\pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}% |
| 734 |
\ifdim\pgf@xb<\pgf@yb% |
| 735 |
\advance\pgfutil@tempdima by-\pgf@yb% |
| 736 |
\else% |
| 737 |
\advance\pgfutil@tempdima by-\pgf@xb% |
| 738 |
\fi% |
| 739 |
\pgfpathcircle{\centerpoint}{\pgfutil@tempdima}% |
| 740 |
} |
| 741 |
\foregroundpath{% |
| 742 |
\pgfsetdash{}{0pt}% |
| 743 |
\pgfsetbuttcap% |
| 744 |
\pgfsetmiterjoin% |
| 745 |
#2 \pgfusepathqstroke% |
| 746 |
} |
| 747 |
} |
| 748 |
\tikzset{constraint/#1/.style={/orm/external constraint,shape=#1}} |
| 749 |
\tikzset{#1 constraint/.style={/orm/external constraint,shape=#1}} |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
\constraintdeclareshape{unique}{ |
| 754 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\radius}% |
| 755 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\radius}% |
| 756 |
} |
| 757 |
|
| 758 |
\constraintdeclareshape{preferred unique}{ |
| 759 |
\centerpoint \pgf@xc=\pgf@x \pgf@yc=\pgf@y% |
| 760 |
\pgfutil@tempdima=\pgflinewidth% |
| 761 |
\[email protected]\pgfutil@tempdima% |
| 762 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\radius\advance\pgf@y by-\pgfutil@tempdima}% |
| 763 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\radius\advance\pgf@y by-\pgfutil@tempdima}% |
| 764 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\radius\advance\pgf@y by\pgfutil@tempdima}% |
| 765 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\radius\advance\pgf@y by\pgfutil@tempdima}% |
| 766 |
} |
| 767 |
|
| 768 |
\constraintdeclareshape{equal}{ |
| 769 |
\pgfutil@tempdima=\radius% x |
| 770 |
\[email protected]\pgfutil@tempdima% |
| 771 |
\pgfutil@tempdimb=\radius% y |
| 772 |
\[email protected]\pgfutil@tempdimb% |
| 773 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgfutil@tempdima\advance\pgf@y by\pgfutil@tempdimb}% |
| 774 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgfutil@tempdima\advance\pgf@y by\pgfutil@tempdimb}% |
| 775 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgfutil@tempdima\advance\pgf@y by-\pgfutil@tempdimb}% |
| 776 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgfutil@tempdima\advance\pgf@y by-\pgfutil@tempdimb}% |
| 777 |
} |
| 778 |
|
| 779 |
\constraintdeclareshape{subset}{ |
| 780 |
\pgf@xa=\radius \[email protected]\pgf@xa% xa = 0.5 r |
| 781 |
\pgf@ya=\radius \[email protected]\pgf@ya% ya = 0.4 r |
| 782 |
\[email protected]\pgf@ya% yb = 0.5 ya = 0.2 r |
| 783 |
\pgf@xb=\pgf@xa \advance\pgf@xb by -\pgf@yb% |
| 784 |
|
| 785 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@y by-\pgf@ya}% |
| 786 |
\pgfpathlineto{\centerpoint\advance\pgf@x by \pgf@xa\advance\pgf@y by-\pgf@ya}% |
| 787 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by \pgf@xa}% |
| 788 |
\pgfpathlineto{\centerpoint\advance\pgf@x by-\pgf@xb}% |
| 789 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by \pgf@xa\advance\pgf@y by\pgf@ya}% |
| 790 |
\pgfpathlineto{\centerpoint\advance\pgf@x by-\pgf@xb\advance\pgf@y by\pgf@ya}% |
| 791 |
\pgfpatharc{90}{270}{\pgf@yb} |
| 792 |
} |
| 793 |
|
| 794 |
\constraintdeclareshape{supset}{ |
| 795 |
\pgf@xa=\radius \[email protected]\pgf@xa% xa = 0.5 r |
| 796 |
\pgf@ya=\radius \[email protected]\pgf@ya% ya = 0.4 r |
| 797 |
\[email protected]\pgf@ya% yb = 0.5 ya = 0.2 r |
| 798 |
\pgf@xb=\pgf@xa \advance\pgf@xb by -\pgf@yb% |
| 799 |
|
| 800 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@y by-\pgf@ya}% |
| 801 |
\pgfpathlineto{\centerpoint\advance\pgf@x by \pgf@xa\advance\pgf@y by-\pgf@ya}% |
| 802 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xa}% |
| 803 |
\pgfpathlineto{\centerpoint\advance\pgf@x by \pgf@xb}% |
| 804 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@y by\pgf@ya}% |
| 805 |
\pgfpathlineto{\centerpoint\advance\pgf@x by \pgf@xb\advance\pgf@y by\pgf@ya}% |
| 806 |
\pgfpatharc{90}{-90}{\pgf@yb} |
| 807 |
} |
| 808 |
|
| 809 |
\constraintdeclareshape{exclusive}{% exclusive constraint ('x') |
| 810 |
\pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfqpointpolar{45}{\radius}}}% |
| 811 |
\pgfpathlineto{\pgfpointadd{\centerpoint}{\pgfqpointpolar{225}{\radius}}}% |
| 812 |
\pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfqpointpolar{135}{\radius}}}% |
| 813 |
\pgfpathlineto{\pgfpointadd{\centerpoint}{\pgfqpointpolar{-45}{\radius}}}% |
| 814 |
} |
| 815 |
|
| 816 |
% inclusive-or (disjunctive mandatory role) constraint |
| 817 |
\constraintdeclareshape{mandatory}{ |
| 818 |
\pgf@xa=\radius \[email protected]\pgf@xa% |
| 819 |
\pgfpathcircle{\centerpoint}{\pgf@xa} |
| 820 |
\pgfsetfillcolor{constraintcolor} % TODO: constraitfillcolor / not for deontic |
| 821 |
% use deontic dot instead? |
| 822 |
\pgfusepathqfillstroke |
| 823 |
} |
| 824 |
|
| 825 |
% exclusive-or constraint ('xor' or 'partition') |
| 826 |
\constraintdeclareshape{partition}{ |
| 827 |
\pgf@xa=\radius \[email protected]\pgf@xa% |
| 828 |
\pgfpathcircle{\centerpoint}{\pgf@xa} |
| 829 |
\pgfsetfillcolor{constraintcolor} % TODO: constraitfillcolor / not for deontic |
| 830 |
\pgfusepathqfillstroke |
| 831 |
\pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfqpointpolar{45}{\radius}}}% |
| 832 |
\pgfpathlineto{\pgfpointadd{\centerpoint}{\pgfqpointpolar{225}{\radius}}}% |
| 833 |
\pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfqpointpolar{135}{\radius}}}% |
| 834 |
\pgfpathlineto{\pgfpointadd{\centerpoint}{\pgfqpointpolar{-45}{\radius}}}% |
| 835 |
} |
| 836 |
|
| 837 |
% Collection constraints (not standard ORM2) |
| 838 |
\constraintdeclareshape{rank}{% aka ordered set |
| 839 |
\pgf@xa=\radius \[email protected]\pgf@xa% |
| 840 |
\pgf@ya=\radius \[email protected]\pgf@ya% |
| 841 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by\pgf@ya}% |
| 842 |
\pgfpathlineto{\centerpoint\advance\pgf@x by-\pgf@ya}% |
| 843 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by-\pgf@ya}% |
| 844 |
} |
| 845 |
\constraintdeclareshape{sequence}{% |
| 846 |
\pgf@xa=\radius \[email protected]\pgf@xa% |
| 847 |
\pgf@ya=\radius \[email protected]\pgf@ya% |
| 848 |
\pgf@xc=\radius \[email protected]\pgf@xc% |
| 849 |
|
| 850 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by\pgf@ya}% |
| 851 |
\pgfpathlineto{\centerpoint\advance\pgf@x by-\pgf@ya}% |
| 852 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by-\pgf@ya}% |
| 853 |
\pgfusepathqstroke |
| 854 |
|
| 855 |
\pgfsetdash{{\pgflinewidth}{1pt}}{0pt}% dotted |
| 856 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\radius}% |
| 857 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\radius}% |
| 858 |
} |
| 859 |
\constraintdeclareshape{weak sequence}{% |
| 860 |
\pgf@xa=\radius \[email protected]\pgf@xa% |
| 861 |
\pgf@xb=\pgflinewidth% |
| 862 |
\pgf@yb=\radius \[email protected]\pgf@yb% |
| 863 |
\pgf@ya=\radius \[email protected]\pgf@ya% |
| 864 |
|
| 865 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by\pgf@ya\advance\pgf@y by\pgf@yb}% |
| 866 |
\pgfpathlineto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@y by\pgf@yb}% |
| 867 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by-\pgf@ya\advance\pgf@y by\pgf@yb}% |
| 868 |
|
| 869 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@x by-\pgf@xb\advance\pgf@y by-\pgf@yb}% |
| 870 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@x by-\pgf@xb\advance\pgf@y by-\pgf@ya\advance\pgf@y by-\pgf@yb}% |
| 871 |
\pgfusepathqstroke |
| 872 |
|
| 873 |
\pgfsetdash{{\pgflinewidth}{1pt}}{0pt}% dotted |
| 874 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\radius\advance\pgf@y by\pgf@yb}% |
| 875 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\radius\advance\pgf@y by\pgf@yb}% |
| 876 |
} |
| 877 |
|
| 878 |
\constraintdeclareshape{weak rank}{% aka poset |
| 879 |
\pgf@xa=\radius \[email protected]\pgf@xa% |
| 880 |
\pgf@xb=\pgflinewidth% |
| 881 |
\pgf@yb=\radius \[email protected]\pgf@yb% |
| 882 |
\pgf@ya=\radius \[email protected]\pgf@ya% |
| 883 |
|
| 884 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by\pgf@ya\advance\pgf@y by\pgf@yb}% |
| 885 |
\pgfpathlineto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@y by\pgf@yb}% |
| 886 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by-\pgf@ya\advance\pgf@y by\pgf@yb}% |
| 887 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@x by-\pgf@xb\advance\pgf@y by-\pgf@yb}% |
| 888 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@x by-\pgf@xb\advance\pgf@y by-\pgf@ya\advance\pgf@y by-\pgf@yb}% |
| 889 |
} |
| 890 |
|
| 891 |
\constraintdeclareshape{counted}{ |
| 892 |
\pgf@xa=\radius \[email protected]\pgf@xa% |
| 893 |
\pgf@xb=\radius \[email protected]\pgf@xb% |
| 894 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@y by\pgf@xb} |
| 895 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by\pgf@xb} |
| 896 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xa\advance\pgf@y by-\pgf@xb} |
| 897 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xa\advance\pgf@y by-\pgf@xb} |
| 898 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by\pgf@xb\advance\pgf@y by\pgf@xa} |
| 899 |
\pgfpathlineto{\centerpoint\advance\pgf@x by\pgf@xb\advance\pgf@y by-\pgf@xa} |
| 900 |
\pgfpathmoveto{\centerpoint\advance\pgf@x by-\pgf@xb\advance\pgf@y by\pgf@xa} |
| 901 |
\pgfpathlineto{\centerpoint\advance\pgf@x by-\pgf@xb\advance\pgf@y by-\pgf@xa} |
| 902 |
} |
| 903 |
%\constraintdeclarealias{in bag}{counted} |
| 904 |
%\constraintdeclarealias{in multiset}{counted} |
| 905 |
|
| 906 |
\constraintdeclareshape{external}{} % needed because shapes are in /orm/... |
| 907 |
\constraintdeclareshape{misc}{} % alias for 'external' |
| 908 |
|
| 909 |
%\constraintdeclare{custom}{} % empty constraint circle |
| 910 |
|
| 911 |
\constraintdeclarealias{required}{mandatory} |
| 912 |
\constraintdeclarealias{total}{mandatory} |
| 913 |
\constraintdeclarealias{or}{mandatory} |
| 914 |
\constraintdeclarealias{x}{exclusive} |
| 915 |
\constraintdeclarealias{xor}{partition} |
| 916 |
|
| 917 |
%% |
| 918 |
% Styles to draw uniqueness bars |
| 919 |
% |
| 920 |
\pgfkeys{/orm/.cd, |
| 921 |
uniqueness bar from/.initial=1,% |
| 922 |
uniqueness bar to/.initial=1,% |
| 923 |
uniqueness bar level/.initial=1,% |
| 924 |
uniqueness bar roles/.initial=1,% |
| 925 |
uniqueness bar set roles/.style={% |
| 926 |
/orm/uniqueness bar roles=#1, |
| 927 |
/pgf/minimum width=#1*4mm |
| 928 |
}, |
| 929 |
uniqueness bar lower/.initial=0,% |
| 930 |
uniqueness bar from/.value required,% |
| 931 |
uniqueness bar to/.value required,% |
| 932 |
uniqueness bar level/.value required,% |
| 933 |
uniqueness bar roles/.value required,% |
| 934 |
uniqueness bar set roles/.value required,% |
| 935 |
uniqueness bar lower/.value required,% |
| 936 |
uniqueness bar style/.style={} |
| 937 |
} |
| 938 |
|
| 939 |
% |
| 940 |
% This node shape draws a uniqueness bar above or below a predicate node. |
| 941 |
% You should use is to shape an invisible node of same size and position |
| 942 |
% as the predicate to constraint. The bar is affected by several styles |
| 943 |
% named '/orm/uniqueness bar ...' each. |
| 944 |
% |
| 945 |
\pgfdeclareshape{uniqueness bar}{ |
| 946 |
\inheritsavedanchors[from=rectangle] |
| 947 |
\inheritanchorborder[from=rectangle] |
| 948 |
\inheritanchor[from=rectangle]{north} |
| 949 |
\inheritanchor[from=rectangle]{west} |
| 950 |
\inheritanchor[from=rectangle]{east} |
| 951 |
\inheritanchor[from=rectangle]{south} |
| 952 |
\inheritanchor[from=rectangle]{center} |
| 953 |
\savedmacro\barlevel{% |
| 954 |
\edef\barlevel{\pgfkeysvalueof{/orm/uniqueness bar level}}% |
| 955 |
\edef\barfrom{\pgfkeysvalueof{/orm/uniqueness bar from}}% |
| 956 |
\edef\barto{\pgfkeysvalueof{/orm/uniqueness bar to}}% |
| 957 |
\edef\barroles{\pgfkeysvalueof{/orm/uniqueness bar roles}}% |
| 958 |
\edef\barlower{\pgfkeysvalueof{/orm/uniqueness bar lower}}% |
| 959 |
} |
| 960 |
\foregroundpath{ |
| 961 |
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y |
| 962 |
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y |
| 963 |
\pgfmathsetlength\pgfutil@tempdima{ |
| 964 |
(\pgf@xb-\pgf@xa-\pgflinewidth) / (\barroles>0 ? \barroles : 1) |
| 965 |
}% role width |
| 966 |
\pgf@xb=\pgf@xa |
| 967 |
\advance\pgf@xa by 1.5\pgflinewidth% |
| 968 |
\advance\pgf@xa by -1\pgfutil@tempdima% |
| 969 |
\advance\pgf@xa by \barfrom\pgfutil@tempdima% |
| 970 |
\advance\pgf@xb by-0.5\pgflinewidth% |
| 971 |
\advance\pgf@xb by \barto\pgfutil@tempdima% |
| 972 |
\pgfmathsetlength\pgfutil@tempdima{\barlevel}% |
| 973 |
\pgfutil@tempdimb=3\pgflinewidth% level distance |
| 974 |
\ifdim\pgfutil@tempdima<0pt% |
| 975 |
\advance\pgf@ya by +0.5\pgflinewidth% |
| 976 |
\advance\pgf@ya by \barlower\pgfutil@tempdimb% |
| 977 |
\advance\pgf@ya by \barlevel\pgfutil@tempdimb% |
| 978 |
\pgf@yb=\pgf@ya% |
| 979 |
\else% |
| 980 |
\advance\pgf@yb by-0.5\pgflinewidth% |
| 981 |
\advance\pgf@yb by -\barlower\pgfutil@tempdimb% |
| 982 |
\advance\pgf@yb by \barlevel\pgfutil@tempdimb% |
| 983 |
\fi% |
| 984 |
\pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yb}}% |
| 985 |
\pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}% |
| 986 |
} |
| 987 |
} |
| 988 |
|
| 989 |
|
| 990 |
% Power types |
| 991 |
\tikzset{power/.style args={#1}{ |
| 992 |
append after command={ |
| 993 |
\pgfextra{ |
| 994 |
\node[entity,shape=rectangle,rounded corners,fit={(\tikzlastnode)},label={[font=\orm@font]#1}] at (\tikzlastnode) (\tikzlastnode-power) {}; |
| 995 |
} |
| 996 |
} |
| 997 |
} |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
% Sequence types |
| 1002 |
\tikzset{sequence/.style args={#1}{ |
| 1003 |
append after command={ |
| 1004 |
\pgfextra{ |
| 1005 |
\node[entity,shape=rectangle,rounded corners=0pt,fit={(\tikzlastnode)},label={[font=\orm@font]#1}] at (\tikzlastnode) (\tikzlastnode-sequence) {}; |
| 1006 |
} |
| 1007 |
} |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
|
| 1012 |
\tikzset{ |
| 1013 |
unique/.code={\orm@parse@xunique#1:\pgf@nil}, |
| 1014 |
unique/.default=1, |
| 1015 |
} |
| 1016 |
|
| 1017 |
% parses '<which>:<level>' and '<which>' |
| 1018 |
\def\orm@parse@xunique#1:#2\pgf@nil{% |
| 1019 |
\def\orm@temp{#2}% |
| 1020 |
\ifx\orm@temp\pgfutil@empty% |
| 1021 |
\orm@@parse@xunique#1:1:\pgf@nil% |
| 1022 |
\else% |
| 1023 |
\orm@@parse@xunique#1:#2\pgf@nil% |
| 1024 |
\fi% |
| 1025 |
} |
| 1026 |
|
| 1027 |
% parses n-m:<level> and n:<level> |
| 1028 |
\def\orm@@parse@xunique#1:#2:\pgf@nil{% |
| 1029 |
\pgfutil@in@{-}{#1}% |
| 1030 |
\ifpgfutil@in@% |
| 1031 |
\orm@parse@xunique@@bar#1:#2\pgf@nil% |
| 1032 |
\else% |
| 1033 |
\orm@parse@xunique@@bar#1-#1:#2\pgf@nil% |
| 1034 |
\fi% |
| 1035 |
} |
| 1036 |
|
| 1037 |
\def\orm@parse@xunique@@bar#1-#2:#3\pgf@nil{% |
| 1038 |
\def\orm@tempA{#1}% |
| 1039 |
\ifx\orm@tempA\pgfutil@empty% |
| 1040 |
\relax% |
| 1041 |
\orm@parse@xunique@@bar#2-#2:-1\pgf@nil |
| 1042 |
\else% |
| 1043 |
\tikzset{append after command={ |
| 1044 |
\bgroup% |
| 1045 |
[current point is local=true] |
| 1046 |
let \p1 = (\tikzlastnode.west), \p2 = (\tikzlastnode.east) |
| 1047 |
in \pgfextra{\pgfmathparse{(\x2-\x1)/4mm}} |
| 1048 |
(\tikzlastnode) node[ |
| 1049 |
/orm/uniqueness bar from/.expand once=#1, |
| 1050 |
/orm/uniqueness bar to/.expand once=#2, |
| 1051 |
/orm/uniqueness bar set roles/.expand once=\pgfmathresult, |
| 1052 |
/orm/uniqueness bar level=#3, |
| 1053 |
shape=uniqueness bar, |
| 1054 |
\orm@unique@bar@style, |
| 1055 |
minimum height=2.5mm, |
| 1056 |
/orm/uniqueness bar style |
| 1057 |
]{} |
| 1058 |
\egroup |
| 1059 |
}}% |
| 1060 |
\fi% |
| 1061 |
} |
| 1062 |
|
| 1063 |
%% Skipped uniqueness bar |
| 1064 |
% TODO: remove this duplicated code. |
| 1065 |
|
| 1066 |
\tikzset{ |
| 1067 |
skip unique/.code={\orm@parse@sunique#1:\pgf@nil}, |
| 1068 |
skip unique/.default=1, |
| 1069 |
} |
| 1070 |
|
| 1071 |
% parses '<which>:<level>' and '<which>' |
| 1072 |
\def\orm@parse@sunique#1:#2\pgf@nil{% |
| 1073 |
\def\orm@temp{#2}% |
| 1074 |
\ifx\orm@temp\pgfutil@empty% |
| 1075 |
\orm@@parse@sunique#1:1:\pgf@nil% |
| 1076 |
\else% |
| 1077 |
\orm@@parse@sunique#1:#2\pgf@nil% |
| 1078 |
\fi% |
| 1079 |
} |
| 1080 |
|
| 1081 |
% parses n-m:<level> and n:<level> |
| 1082 |
\def\orm@@parse@sunique#1:#2:\pgf@nil{% |
| 1083 |
\pgfutil@in@{-}{#1}% |
| 1084 |
\ifpgfutil@in@% |
| 1085 |
\orm@parse@sunique@@bar#1:#2\pgf@nil% |
| 1086 |
\else% |
| 1087 |
\orm@parse@sunique@@bar#1-#1:#2\pgf@nil% |
| 1088 |
\fi% |
| 1089 |
} |
| 1090 |
|
| 1091 |
\def\orm@parse@sunique@@bar#1-#2:#3\pgf@nil{% |
| 1092 |
\def\orm@tempA{#1}% |
| 1093 |
\ifx\orm@tempA\pgfutil@empty% |
| 1094 |
\relax% |
| 1095 |
\orm@parse@xunique@@bar#2-#2:-1\pgf@nil |
| 1096 |
\else% |
| 1097 |
\tikzset{append after command={ |
| 1098 |
\bgroup% |
| 1099 |
[current point is local=true] |
| 1100 |
let \p1 = (\tikzlastnode.west), \p2 = (\tikzlastnode.east) |
| 1101 |
in \pgfextra{\pgfmathparse{(\x2-\x1)/4mm}} |
| 1102 |
\pgfextra{\let\orm@unique@bar@style=\orm@unique@bar@skipped}% |
| 1103 |
(\tikzlastnode) node[ |
| 1104 |
/orm/uniqueness bar from/.expand once=#1, |
| 1105 |
/orm/uniqueness bar to/.expand once=#2, |
| 1106 |
/orm/uniqueness bar set roles/.expand once=\pgfmathresult, |
| 1107 |
/orm/uniqueness bar level=#3, |
| 1108 |
shape=uniqueness bar, |
| 1109 |
\orm@unique@bar@style, |
| 1110 |
minimum height=2.5mm |
| 1111 |
]{} |
| 1112 |
\egroup |
| 1113 |
}}% |
| 1114 |
\fi% |
| 1115 |
} |
| 1116 |
|
| 1117 |
% TODO: add optional parameters and document this |
| 1118 |
\tikzstyle{preferred unique}=[unique=1:1,unique=1:2] |
| 1119 |
|
| 1120 |
\makeatother |
| 1121 |
|
| 1122 |
%<–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––> |
| 1123 |
\endinput |