]> git.saurik.com Git - wxWidgets.git/blame_incremental - contrib/docs/latex/ogl/sample.tex
don't use wxStaticCast to wxBookCtrlBase -- it doesn't work
[wxWidgets.git] / contrib / docs / latex / ogl / sample.tex
... / ...
CommitLineData
1\chapter{OGLEdit: a sample OGL application}\label{ogledit}%
2\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
3\setfooter{\thepage}{}{}{}{}{\thepage}
4
5OGLEdit is a sample OGL application that allows the user to draw, edit,
6save and load a few shapes. It should clarify aspects of OGL usage, and
7can act as a template for similar applications. OGLEdit can be found in\rtfsp
8{\tt samples/ogledit} in the OGL distribution.
9
10$$\image{10cm;0cm}{ogledit.eps}$$\par
11
12The wxWindows document/view model has been used in OGL, to reduce the amount of
13housekeeping logic required to get it up and running. OGLEdit also provides
14a demonstration of the Undo/Redo capability supported by the document/view classes,
15and how a typical application might implement this feature.
16
17\section{OGLEdit files}
18
19OGLEdit comprises the following source files.
20
21\begin{itemize}\itemsep=0pt
22\item doc.h, doc.cpp: MyDiagram, DiagramDocument, DiagramCommand, MyEvtHandler
23classes related to diagram functionality and documents.
24\item view.h, view.cpp: MyCanvas, DiagramView classes related to visualisation of
25the diagram.
26\item ogledit.h, ogledit.cpp: MyFrame, MyApp classes related to the overall application.
27\item palette.h, palette.cpp: EditorToolPalette implementing the shape palette.
28\end{itemize}
29
30\section{How OGLEdit works}
31
32OGLEdit defines a DiagramDocument class, each of instance of which holds a MyDiagram
33member which itself contains the shapes.
34
35In order to implement specific mouse behaviour for shapes, a class MyEvtHandler is
36defined which is `plugged into' each shape when it is created, instead of overriding each shape class
37individually. This event handler class also holds a label string.
38
39The DiagramCommand class is the key to implementing Undo/Redo. Each instance of DiagramCommand
40stores enough information about an operation (create, delete, change colour etc.) to allow
41it to carry out (or undo) its command. In DiagramView::OnMenuCommand, when the user initiates the
42command, a new DiagramCommand instance is created which is then sent to the document's
43command processor (see wxWindows manual for more information about doc/view and command
44processing).
45
46Apart from menu commands, another way commands are initiated is by the user left-clicking on
47the canvas or right-dragging on a node. MyCanvas::OnLeftClick in view.cpp shows how
48the appropriate wxClassInfo is passed to a DiagramCommand, to allow DiagramCommand::Do
49to create a new shape given the wxClassInfo.
50
51The MyEvtHandler right-drag methods in doc.cpp implement drawing a line between
52two shapes, detecting where the right mouse button was released and looking for a second
53shape. Again, a new DiagramCommand instance is created and passed to the command
54processor to carry out the command.
55
56DiagramCommand::Do and DiagramCommand::Undo embody much of the
57interesting interaction with the OGL library. A complication of note
58when implementing undo is the problem of deleting a node shape which has
59one or more arcs attached to it. If you delete the node, the arc(s)
60should be deleted too. But multiple arc deletion represents more information
61that can be incorporated in the existing DiagramCommand scheme. OGLEdit
62copes with this by treating each arc deletion as a separate command, and
63sending Cut commands recursively, providing an undo path. Undoing such a
64Cut will only undo one command at a time - not a one to one
65correspondence with the original command - but it's a reasonable
66compromise and preserves Do/Undo while keeping our DiagramCommand class
67simple.
68
69\section{Possible enhancements}
70
71OGLEdit is very simplistic and does not employ the more advanced features
72of OGL, such as:
73
74\begin{itemize}\itemsep=0pt
75\item attachment points (arcs are drawn to particular points on a shape)
76\item metafile and bitmaps shapes
77\item divided rectangles
78\item composite shapes, and constraints
79\item creating labels in shape regions
80\item arc labels (OGL has support for three movable labels per arc)
81\item spline and multiple-segment line arcs
82\item adding annotations to node and arc shapes
83\item line-straightening (supported by OGL) and alignment (not supported directly by OGL)
84\end{itemize}
85
86These could be added to OGLEdit, at the risk of making it a less
87useful example for beginners.