root/gaphor/tags/gaphor-0.12.3/doc/items.tex

Revision 1121, 13.8 kB (checked in by arjanmol, 2 years ago)

Merged changed from new-canvas branch to trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 \documentclass{book}
2 \usepackage[papername = a4paper, margin = 3cm]{geometry}
3 \usepackage{graphicx}
4 \usepackage{hyperref}
5 \usepackage{listings}
6 \usepackage{float}
7
8 \title{Gaphor Diagram Item Model}
9 \author{wrobell@pld-linux.org}
10
11 \newfloat{code}{th}{code}
12
13 \lstnewenvironment{pylst}{\lstset{language=Python}}{}
14
15 \newcommand{\rmodule}[1]{\texttt{#1}}
16 \newcommand{\rclass}[1]{\texttt{#1}}
17 \newcommand{\rattr}[1]{\texttt{#1}}
18 \newcommand{\rstereotype}[1]{\texttt{<<#1>>}}
19 \newcommand{\warning}[1]{\textbf{WARNING:~#1}}
20
21 %\newenvironment{description}
22 %               {\list{}{\labelwidth\z@ \itemindent-\leftmargin
23 %                        \let\makelabel\descriptionlabel}}
24 %               {\endlist}
25 %\newcommand*\descriptionlabel[1]{\hspace\labelsep
26 %                                \normalfont\bfseries #1}
27
28 % length class, method and attribute block descriptions
29 \newlength{\dscwidth}
30 \setlength{\dscwidth}{\textwidth}
31 \addtolength{\dscwidth}{-7em}
32
33 \newlength{\abdscwidth}
34 \setlength{\abdscwidth}{\textwidth}
35 \addtolength{\abdscwidth}{-5em}
36
37 \newlength{\adscwidth}
38 \setlength{\adscwidth}{\textwidth}
39 \addtolength{\adscwidth}{-9em}
40
41 \newcommand{\dlabel}[1]{\par\noindent\makebox[6em][r]{\textbf{#1:}}\hspace{1em}}
42
43 \newenvironment{entitydesc}{%
44 \dlabel{Description}%
45 \begin{minipage}[t]{\dscwidth}
46 }{%
47 \end{minipage}
48 }
49
50 \newcommand{\pre}{\dlabel{Pre}~}
51 \newcommand{\post}{\dlabel{Post}~}
52
53 \newenvironment{slist}{%
54     \begin{list}{-}{%
55         \setlength{\labelwidth}{3pt}%
56         \setlength{\leftmargin}{1em}%
57         \setlength{\labelsep}{2pt}%
58         \setlength{\rightmargin}{0pt}%
59         \setlength{\itemsep}{0pt}%
60         \setlength{\parsep}{0pt}%
61         \setlength{\topsep}{2pt}%
62         \setlength{\partopsep}{0pt}%
63     }%
64 }{%
65     \end{list}%\vspace{3pt}%
66 }
67
68 % class
69 \newenvironment{class}[1]{%
70 \dlabel{\underline{Class}}\texttt{#1}\nopagebreak[4]
71 }{%
72 \par\vspace{2em}
73 }
74
75 % attributes
76 \newenvironment{attrs}{%
77 \\[1ex]
78 \noindent\hspace*{5em}\begin{minipage}[t]{\abdscwidth}
79 }{%
80 \end{minipage}\\[-2ex]
81 }
82
83 \newcommand{\iattr}[2]{%
84 \makebox[3em][r]{\texttt{#1}:}\hspace*{1em}%
85 \begin{minipage}[t]{\adscwidth}
86 #2%
87 \end{minipage}\\
88 }
89
90 % methods
91 \newenvironment{method}[1]{%
92 \vspace*{2ex}
93 \dlabel{\underline{Method}}\texttt{#1}
94 }{%
95 \par
96 }
97
98 \begin{document}
99 \maketitle
100
101 \chapter{Basic Classes of Diagram Items}
102 \section{Introduction}
103 UML specification defines UML data model, which is used by Gaphor to store
104 information about a modeled system. The UML data model is visualized by
105 the Gaphas library, a general purpose diagram drawing library. Notation
106 of UML diagram items is also specified by the UML specification.
107
108 The Gaphas library supports basic drawing operations but there are many
109 entities and behaviors, which are common to many or all diagram items, i.e.
110 stereotypes, item name, popup menu, positioning of associated items, etc.
111
112 We have to identify common elements and behaviors of UML diagram items
113 and define basic diagram items classes, which will be used
114 by Gaphor to provide modeling functionality.
115
116 Note that, the diagram item hierarchy does not have to follow the hierarchy
117 defined in the UML model.
118
119 \section{Problem Description}
120
121 \subsection{Items and Diacanvas}\label{gaphor:basic:itemsandcanvas}
122 Diacanvas library supports different canvas objects
123 \begin{itemize}
124 \item canvas element
125 \item canvas line
126 \end{itemize}
127
128 Because of differences between them, Basic diagram item class cannot be
129 directly associated with canvas lines or canvas elements. Connection between
130 canvas classes and items has to be established by different abstract
131 classes.
132
133 \subsection{Items and UML Model Classes}
134 Generaly there is a one to one association between an item and an UML class,
135 but it is not always that simple.
136 For example one diagram item can visualize more than one UML class
137 \begin{itemize}
138 \item decision node item can represent combined decision and merge nodes
139 \item fork node item can represent combined fork and join nodes
140 \end{itemize}
141
142 Also, there can be situation, when there is no UML class visualized, i.e.
143 in case of a CommentLine.
144
145 \subsection{Line Items}
146 Lines have at least two handles. These handles are reffered to as head (first
147 handle) and tail (last handle) of line.
148
149 When a user puts an item on a diagram, then the last handle can be moved to
150 a desired point. The same applies to line items. User puts a line on diagram,
151 head is set in mouse cursor point and tail is moved to desired point.
152
153 Head and tail concepts are also used in Gaphas in case of canvas lines.
154 Head of line item is at the same end as head of canvas line. The same
155 applies for tail.
156
157 \subsection{Item Styles}\label{itemstyles}
158 All the items are going to contain different parts.
159 Many of such parts can be shared by other items, for example
160 \begin{itemize}
161 \item UML named elements (see named items) have names, which
162     can be displayed in different places, i.e. class --- top--center,
163     use case --- middle--center
164 \item every UML class can have stereotypes, which should be displayed
165     over items' name
166 \end{itemize}
167
168 Above can be described as styles (i.e.\ similar to CSS).
169
170 It should be possible to implement common behaviour in basic item classes,
171 which should be parametrized by item's style information. For example,
172 named element item should set position of name depending on styles.
173
174 \section{Styles}
175 Class \rclass{ElementItem} defined below should define following styles
176 \begin{description}
177 \item[min--size] minimal size of an item; minimal width and height are
178     initialized using this style information
179 \end{description}
180
181 \section{Classes}
182 \rclass{DiagramItem} class is a basic, abstract class for all items. Every
183 item class is created using \rclass{DiagramItemMeta} metaclass.
184
185 Different canvas elements (see~\ref{gaphor:basic:itemsandcanvas}) are
186 supported with classes
187 \begin{itemize}
188 \itemsep0pt
189 \item \rclass{LineItem}
190 \item \rclass{ElementItem}
191 \item \rclass{FeatureItem}
192 \end{itemize}
193
194 \begin{class}{DiagramItemMeta}
195 \begin{attrs}
196 \iattr{\_\_uml\_\_}{UML class associated with item}
197 \iattr{\_\_stereotype\_\_}{item static stereotype}
198 \iattr{\_\_style\_\_}{used to define new and override item style information}
199 \iattr{style}{used to obtain item style information, also information derived from base classes}
200 \end{attrs}
201 \begin{entitydesc}
202 Metaclass for all items. Assigns information about UML class, stereotypes,
203 styles, etc.\ to every item class.
204 \end{entitydesc}
205 \end{class}
206
207 \begin{class}{DiagramItem}
208 \begin{attrs}
209 \iattr{subject}{reference to UML class instance}
210 \iattr{popup\_menu}{item popup menu definition, i.e. rename, delete, etc.}
211 \end{attrs}
212 \begin{entitydesc}
213 Basic class for all diagram items.
214 \end{entitydesc}
215 \end{class}
216
217 \begin{class}{LineItem}
218 \begin{attrs}
219 \iattr{head}{reference to head handle of a line}
220 \iattr{tail}{reference to tail handle of a line}
221 \end{attrs}
222 \begin{entitydesc}
223 Canvas line based items like dependencies, association, flows, message, etc.
224 \end{entitydesc}
225 \end{class}
226
227 \begin{class}{ElementItem}
228 \begin{attrs}
229 \iattr{min\_width}{minimal item width}
230 \iattr{min\_height}{minimal item height}
231 \end{attrs}
232 \begin{entitydesc}
233 Canvas element based items like class, component, lifeline,
234 comment, activity nodes, etc.
235
236 Minimal width and height are initialized from minimal size style
237 information. These two values can change during item lifecycle (i.e.\ name
238 can be expanded or shrinked), therefore minimal size style information
239 guards initial minimal dimensions of element item.
240 \end{entitydesc}
241 \end{class}
242
243 \begin{class}{FeatureItem}
244 \begin{entitydesc}
245 Canvas element, which is part of an item. For example represents
246 attributes and methods of classes.
247 \end{entitydesc}
248 \end{class}
249
250 \section{Methods}
251 \begin{method}{DiagramItem.set\_subject}
252 \begin{attrs}
253 \iattr{subject}{reference to UML class instance}
254 \end{attrs}
255 \begin{entitydesc}
256 assign UML class instance to an item
257 \end{entitydesc}
258 \end{method}
259
260 \chapter{Align of Item Elements}
261 \section{Introduction}
262 \begin{figure}
263 \begin{center}
264 \includegraphics[width=.5\textwidth]{flow}
265 \end{center}
266 \caption{Flow Item example}\label{items:example:flow}
267 \end{figure}
268
269 Many items consist of several elements, for example flow item is a line
270 with
271 \begin{itemize}
272 \item stereotype
273 \item name
274 \item guard
275 \end{itemize}
276 These elements are aligned to a line of flow (see
277 figure~\ref{items:example:flow})
278 \begin{itemize}
279 \item stereotype is near one of the ends of line
280 \item name is under stereotype
281 \item guard is near the middle of line
282 \end{itemize}
283
284 Element of items are aligned according to attributes of
285 \rclass{ItemAlign} and \rclass{LineAlign} classes. Align information is
286 assigned to every item element, but position is calculated from item
287 perspective, for example
288 \begin{itemize}
289 \item align of an element to the (left, top) with margin $(10, 15, 15, 5)$
290 puts an element in (left, top) corner of item; it is located $10px$ from the top
291 and $5px$ from the left of item
292 \item align of an element as above but outside item puts an element $10px$
293 from top and $5px$ from the left of item; top and left margin values are
294 used for top vertical and left horizontal align
295 \end{itemize}
296 See figure~\ref{items:align} for more examples.
297
298 \begin{figure}
299 \begin{center}
300 \includegraphics[width=.95\textwidth]{align}
301 \end{center}
302 \caption{Align of Item Elements}\label{items:align}
303 \end{figure}
304
305 Align constants and classes are defined in \rmodule{gaphor::diagram::align} module.
306
307 \subsection{Stereotype and Name Alignment}
308
309 There are two important elements of items
310 \begin{itemize}
311 \item every item shown on diagram has stereotype (even item for Stereotype
312     UML class, which stereotype is \rstereotype{stereotype})
313 \item many items has names
314 \end{itemize}
315
316 Therefore every item class has \rattr{s\_align} attribute, which defines
317 align of stereotypes.
318
319 Named items are aligned according to \rattr{n\_align} attribute. If
320 stereotype and name align values are the same, then name is put
321 centered under stereotype.
322
323 \warning{What about FeatureItem stereotype?}
324
325 \chapter{Named Items}
326 \section{Problem Description}
327 Named items represent those UML classes, which derive from NamedElement.
328
329 All named items are editable, so user can double click on an item and
330 change or enter name of UML object.
331
332 There should be minimal size (which is default, initial one) of named
333 items. Every named item can have its own minimal size. Size of named item
334 can be changed by an user. There are some cases, when size cannot be
335 changed, i.e. initial node item.
336
337 It should be possible to align name of named element with styles
338 (see~\ref{itemstyles}) as depending on an element, the name can be
339 displayed in different places related to an item, i.e.
340 \begin{itemize}
341 \item class               --- top center
342 \item use case            --- middle center
343 \item object node         --- middle center
344 \item actor               --- bottom center, outside item bounduaries
345 \item initial action node --- top left, outside item bounduaries
346 \item decision node       --- bottom center, outside item bounduaries
347 \end{itemize}
348
349 %fixme: there can be items with initial name and without initial name
350
351 \section{Styles}
352 Kind of information we need to align the name
353 \begin{itemize}
354 \item horizontal align information (left, center or right)
355 \item vertical align information (top, middle or bottom)
356 \item padding specified as in CSS (top right bottom left)
357 \item is name outside an item?
358 \end{itemize}
359
360 Styles for name align are defined in table~\ref{nameditems:styles:spec}
361 (see diagram~\ref{nameditems:styles:example} for example).
362
363 \begin{table}
364 \begin{center}
365 \begin{tabular}{|l|l|l|}
366 \hline
367 Name           & Default value     & Description \\
368 \hline
369 name--align    & ('center', 'top') & align information \\
370 name--padding  & (5, 5, 5, 5)      & name padding \\
371 name--outside  & False             & name outside/inside item bounduaries \\
372 \hline
373 \end{tabular}
374 \caption{Specification of name align styles}\label{nameditems:styles:spec}
375 \end{center}
376 \end{table}
377
378 \begin{code}
379 \lstset{language={Python}}
380 \begin{pylst}
381 class NamedItem(DiagramItem):
382     __style__ = {
383         'name-align' : ('center', 'top'),
384         'name-padding': (5, 5, 5, 5),
385         'name-outside': False,
386     }
387 \end{pylst}
388 \caption{Named items style example}\label{nameditems:styles:example}
389 \end{code}
390
391 \section{Classes}
392 Class NamedItem is a base class for all named items.
393
394 \begin{class}{NamedItem}
395 \begin{entitydesc}
396 Calculates minimal size based on name size. Draws UML object's name using
397 style information.
398 \end{entitydesc}
399 \end{class}
400
401 %%%
402 %We have to distinguish between two kind of named elements. One is related
403 %to canvas elements and second is related to canvas lines. For example, name
404 %of UML object can be positioned inside or outside canvas element (class vs.
405 %initial node), also name can be centered or on left/right side of canvas
406 %element. In case of canvas line based items name can be near head, tail
407 %or centre of a line and name can be put horizontaly or along line path.
408 %%%
409
410
411 %\subsection{Canvas Element Named Items}
412
413 %\subsection{Canvas Line Named Items}
414
415 \chapter{Relationships}
416
417 Relationships are implemented using Python descriptors. See Relationship,
418 DependencyRelationship and AssociationRelationship classes for examples.
419
420 \chapter{Profiles}
421
422 \section{Gaphor Stereotypes}
423
424 \begin{description}
425 \item[name] UML class of an item derives from NamedElement; name
426         should be shown on diagram
427 \item[nostereotype] item does not allow to edit stereotypes
428 \end{description}
429
430 \section{Diacanvas Stereotypes}
431
432 \begin{description}
433 \item[editable] item is editable when it is possible to change name of an
434     item by clicking twice on it
435 \end{description}
436
437
438 %fixme: chapter below should be chapter with number
439 \chapter{Glossary}
440
441 \begin{description}
442 \item[static stereotype] stereotype, which is always assigned
443     to an item; for example interface item is annotated with
444     \rstereotype{interface} stereotype
445
446 \item[item] item put on diagram by user, i.e. ClassItem, AssociationItem;
447     conforms to UML notation of UML metamodel classes
448
449 \item[UML class] class defined in UML metamodel
450 \end{description}
451
452 \end{document}
Note: See TracBrowser for help on using the browser.