wxArt2D
edit.h
Go to the documentation of this file.
1 /*! \file wx/canvas/edit.h
2  \brief editing tool for a2dCanvasObject's
3  \author Klaas Holwerda
4 
5  Copyright: 2000-2004 (c) Klaas Holwerda
6 
7  Licence: wxWidgets Licence
8 
9  RCS-ID: $Id: edit.h,v 1.23 2009/06/03 17:38:13 titato Exp $
10 */
11 
12 #ifndef __WXCANEDITOBJ_H__
13 #define __WXCANEDITOBJ_H__
14 
15 #ifndef WX_PRECOMP
16 #include "wx/wx.h"
17 #endif
18 
19 #include "wx/canvas/canobj.h"
20 #include "wx/canvas/objlist.h"
21 #include "wx/canvas/sttool.h"
22 
23 //----------------------------------------------------------------------------
24 // decls
25 //----------------------------------------------------------------------------
26 
27 class a2dCanvas;
28 class a2dCanvasDocument;
29 class a2dLayers;
30 
31 //!This tool is for editing a single object.
32 /*!
33  The object its EditStart member is called, this generates a Clone of the object
34  to be edited. And event processing is redirected to the Cloned object to edit it.
35 
36  The cloned edit copy, issues commands to the command processor of the document, and this changes
37  the original a2dCanvasObject that is being edited.
38  This then changes to make it in sync with editing clone.
39  Undo is possible because of this, but it is possible to not use commands and choose to directly
40  modify the original object.
41 
42  After editing is done a double click will call the EditEnd member of the a2dCanvasObject.
43  In the end the Cloned editing object is Released.
44 
45  If SetSingleClickToEnd() is set, a Left Down mouse event outside the object being edited,
46  also stops editing of the current object, and if subediting it even ends this tool.
47  This makes it easy to go to sublevel editing and back with just one click.
48 
49  The object itself is in control of all editing facilities of that specific object.
50  This might mean that other tools will be pushed on the tool stack, for editing of subobjects.
51 
52  The EditStart member initializes the a2dCanvasObject for editing, but only if editing is allowed by it.
53 
54  The editing Clone will have as children editing handles, which can be dragged in order to modify the object.
55  Those handles depend on the object its editing implementation.
56  Rendering of the Cloned editing object can be changed on the basis of the m_editingCopy flag if needed.
57 
58  The default editing functionality of a2dCanvasObject, is just editing its local matrix.
59 
60  The TAB charecter should be used to switch between this mode and the object specific editing mode.
61 
62  Adding editing functionality to an object is implemented by intercepting events using a static event table.
63  When the m_editingCopy is set, we know it is the cloned edit copy we are dealing with.
64  The events in this case should be handled in such a manner that the edit clone and the original object
65  will be modified.
66  Hits on child objects of the editing clone ( e.g a2dHandle ), may generate new events for
67  the editng clone object itself. a2dHandleMouseEvent is such an event. You can intercept this event
68  in the parent event table like this EVT_CANVASHANDLE_MOUSE_EVENT( OnHandleEvent ).
69  In the OnHandleEvent you can define what change a specific handle will have on the object that is edited.
70 
71  \ingroup tools
72 */
73 class A2DCANVASDLLEXP a2dObjectEditTool: public a2dStTool
74 {
75 public:
76 
77  //! push this tool on the tools stack
78  /*! \ingroup commandid
79  */
81 
82  //! when starting editing an object, this event is sent to tool
83  static const a2dSignal sig_toolStartEditObject;
84 
85  //! constructor
86  /*!
87  \param controller controller to which the editing tool was pushed.
88  \param editmode starting editing mode for objects
89  \param SingleClickToEnd stop editing with a single Left Down, else double click.
90  */
91  a2dObjectEditTool( a2dStToolContr* controller, int editmode = 1, bool SingleClickToEnd = true );
92 
93  //! constructor
94  /*!
95  \param controller controller to which the editing tool was pushed.
96  \param ic iteration context to setup the corridor
97  \param editmode starting editing mode for objects
98  \param SingleClickToEnd stop editing with a single Left Down, else double click.
99  */
100  a2dObjectEditTool( a2dStToolContr* controller, a2dIterC& ic, int editmode = 1, bool SingleClickToEnd = true );
101 
102  //! destuctor
104 
105  //! start editing object within the given iteration context its coordinate system
106  /*!
107  Start editing the object within the coordinate system defined by ic (iterative context).
108  Parent of startobject is defined in ic.
109 
110  The ic is used to calculate the editworld matrix, meaning relative to what coordinates system
111  the editing takes place. This becomes important when editing children of objects directly.
112 
113  \remark at the top level (ShowObject of view) the editorWorld is always a2dIDENTITY_MATRIX
114  else it depends on the structure of the document.
115  */
116  bool SetContext( a2dIterC& ic, a2dCanvasObject* startObject );
117 
118  //! start editing this object
119  void StartToEdit( a2dCanvasObject* startObject );
120 
121  //! restart editing (after undo event or when changing editing mode )
122  bool ReStartEdit( wxUint16 editmode );
123 
124  a2dCanvasObject* GetEditObjectCopy() { return m_canvasobject; }
125 
126  //! trigger restart editing (after undo event or when changing editing mode )
127  virtual void TriggerReStartEdit( wxUint16 editmode );
128 
129  //! save to zoom
130  bool ZoomSave() { return true;};
131 
132  //! set editing mode to start editing objects
133  void SetMode( int mode );
134 
135  //! used extarnal by controller to activate or deactivate this tool.
136  /*! If deactivated this tool, m_halted is set true. */
137  void SetActive( bool active );
138 
139  //! a single non hit Left Down click is enough to end editing of an object.
140  /*! If set false, a double click is needed. */
141  void SetSingleClickToEnd( bool SingleClickToEnd ) { m_SingleClickToEnd = SingleClickToEnd; }
142 
143  //! when set true, other views on the document are disabled when editing a object.
144  /*!
145  This option is default set true, this prevents from showing editing handles in other views while
146  editing an object in a view.
147  */
148  void SetDisableOtherViews( bool disableOtherViews ) { m_disableOtherViews = disableOtherViews; }
149 
150  void Render();
151 
152 
153 protected:
154 
155  //! To stop this tools from inside or from the outside, sets m_stop = true
156  /*! The a2dStToolContr will test this with GetStopTool() */
157  void DoStopTool( bool abort );
158 
159  void OnUndoEvent( a2dCommandProcessorEvent& WXUNUSED( event ) );
160 
161  void OnRedoEvent( a2dCommandProcessorEvent& event );
162 
163  void OnKeyDown( wxKeyEvent& event );
164 
165  void OnKeyUp( wxKeyEvent& event );
166 
167  void OnChar( wxKeyEvent& event );
168 
169  virtual void AdjustRenderOptions();
170  virtual bool EnterBusyMode();
171  virtual void FinishBusyMode( bool closeCommandGroup = true );
172  virtual void AbortBusyMode();
173 
174  //! send an event with id sig_toolComEventSetEditObject to this tool.
175  /*!
176  Use this event to do actions when a specific object was clicked for editing.
177  */
178  void SetEditObject( a2dCanvasObject* objectToEdit );
179 
180  //! redirect event to editng object or to a captured object ( handle or object itself. )
181  /*! return if event is processed or not. */
182  bool RedirectToEditObject( wxMouseEvent& event );
183 
184  //! start editing at m_canvasobject
185  virtual bool CreateToolObjects();
186 
187  //! stop editing of m_canvasobject if busy editing
188  virtual void CleanupToolObjects();
189 
190  void OnIdle( wxIdleEvent& event );
191 
192  void OnComEvent( a2dComEvent& event );
193 
194  void OnMouseEvent( wxMouseEvent& event );
195 
196  void OnDoEvent( a2dCommandProcessorEvent& event );
197 
198  virtual wxString GetCommandGroupName() { return _( "Edit object" ); }
199 
200  //! preserve the a2dCANVAS_SELECT flag after editing.
202 
203  //! a single non hit Left Down click is enough to end editing of an object.
205 
206  bool m_disableOtherViews;
207 
208  bool m_triggerRestart;
209 
210 public:
211  DECLARE_CLASS( a2dObjectEditTool )
212  DECLARE_EVENT_TABLE()
213 
214 };
215 
216 
217 //!This tool does do a hit test on objects to edit, and then starts editing the object.
218 /*!
219  When an object is hit, the object its EditStart member is called, this generates a Clone of the object
220  to be edited. And event processing is redirected to the Cloned object to edit it.
221 
222  See a2dObjectEditTool for more details on editing.
223 
224  \ingroup tools
225 */
226 class A2DCANVASDLLEXP a2dRecursiveEditTool: public a2dObjectEditTool
227 {
228 public:
229 
230  //! push this tool on the tools stack
231  /*! \ingroup commandid
232  */
234 
235  //! constructor
236  /*!
237  \param controller controller to which the editing tool was pushed.
238  \param editmode starting editing mode for objects
239  \param SingleClickToEnd stop editing with a single Left Down, else double click.
240  */
241  a2dRecursiveEditTool( a2dStToolContr* controller, int editmode = 1, bool SingleClickToEnd = true );
242 
243  //! constructor
244  /*!
245  \param controller controller to which the editing tool was pushed.
246  \param ic iteration context to setup the corridor
247  \param editmode starting editing mode for objects
248  \param SingleClickToEnd stop editing with a single Left Down, else double click.
249  */
250  a2dRecursiveEditTool( a2dStToolContr* controller, a2dIterC& ic, int editmode = 1, bool SingleClickToEnd = true );
251 
252  //! destuctor
254 
255 protected:
256 
257  void OnComEvent( a2dComEvent& event );
258 
259  void OnMouseEvent( wxMouseEvent& event );
260 
261  virtual wxString GetCommandGroupName() { return _( "Edit" ); }
262 
263 public:
264  DECLARE_CLASS( a2dRecursiveEditTool )
265  DECLARE_EVENT_TABLE()
266 
267 };
268 
269 //!This tool does do a hit test on objects to edit, and then starts editing the object.
270 /*!
271 When an object is hit, the object its EditStart member is called, and event processing is redirected to the
272 object to edit.
273 The EditStart member sets the m_editing flag and initializes the a2dCanvasObject for editing.
274 This normally means adding handles which can be dragged in order to modify the object.
275 Rendering can also be chnaged on the basis of the m_editing flag if needed.
276 The default editing functionality is just editing the a2dCanvasObject its local matrix.
277 The TAB charecter should be used to switch between this mode and the object specific editing mode.
278 There are several modes to edit an object, the main mode makes a copy of the object first and editing takes
279 place on that copy. Updating the original object when needed.
280 After editing is done a double click will call the EditEnd member of the object.
281 Adding editing functionality to an object is implemented by intercepting event using a static event table.
282 When the m_editing of a a2dCanvasObject is set, the events are handled in such a maner that the object will be modified.
283 
284  \ingroup tools
285 */
286 class A2DCANVASDLLEXP a2dMultiEditTool: public a2dObjectEditTool
287 {
288 public:
289 
290  //! push this tool on the tools stack
291  /*! \ingroup commandid
292  */
294 
295  a2dMultiEditTool( a2dStToolContr* controller );
296  ~a2dMultiEditTool();
297 
298  bool ZoomSave() { return true;};
299 
300  void OnChar( wxKeyEvent& event );
301 
302  //! start editing object
303  bool StartEditing( a2dCanvasObject* startobject );
304 
305  bool StartEditingSelected();
306 
307  void SetActive( bool active );
308 
309  bool AddToGroup( a2dCanvasObject* canvasobject );
310 
311  bool RemoveFromGroup( a2dCanvasObject* canvasobject, int index = 0 );
312 
313 protected:
314 
315  void DoStopTool( bool abort );
316 
317  bool RedirectToEditObject( wxMouseEvent& event );
318 
319  bool EditStart();
320 
321  void CleanupToolObjects();
322 
323  void OnIdle( wxIdleEvent& event );
324 
325  void OnComEvent( a2dComEvent& event );
326 
327  void OnMouseEvent( wxMouseEvent& event );
328 
329  void OnUndoEvent( a2dCommandProcessorEvent& event );
330 
331  void OnRedoEvent( a2dCommandProcessorEvent& event );
332 
333  //! this is intentioanally not a smart pointer (would create a reference loop)
335 
336 public:
337  DECLARE_CLASS( a2dMultiEditTool )
338  DECLARE_EVENT_TABLE()
339 
340 };
341 
342 
343 
344 #endif /* __WXCANEDITOBJ_H__ */
345 
346 
a2dCanvasObjectPtr m_canvasobject
This is the object currently edited.
Definition: sttool.h:381
bool ZoomSave()
save to zoom
Definition: edit.h:298
void OnUndoEvent(a2dCommandProcessorEvent &event)
handler for Undo event
Definition: sttool.cpp:1487
virtual void AdjustRenderOptions()
Adjust the rendering options to the needs of this tool.
Definition: sttool.cpp:1214
The a2dStTool is used to derive tools from.
Definition: sttool.h:115
virtual void Render()
implement rendering
Definition: sttool.cpp:1402
static const a2dCommandId COMID_PushTool_MultiEdit
push this tool on the tools stack
Definition: edit.h:293
void OnKeyUp(wxKeyEvent &event)
called on key up events
Definition: sttool.cpp:1550
virtual wxString GetCommandGroupName()
return the command group name for commands of a derived class
Definition: edit.h:261
The base class for all drawable objects in a a2dCanvasDocument.
void OnIdle(wxIdleEvent &event)
handler for idle events
Definition: sttool.cpp:1370
virtual void FinishBusyMode(bool closeCommandGroup=true)
Called when the user finishes editing a distinct object */.
Definition: sttool.cpp:1161
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
bool SetContext(a2dIterC &ic, a2dCanvasObject *startObject=NULL)
defines the context, relative to which this tools works.
Definition: sttool.cpp:1052
void OnKeyDown(wxKeyEvent &event)
called on key down events
Definition: sttool.cpp:1512
void OnMouseEvent(wxMouseEvent &event)
called on mouse events
Definition: sttool.cpp:1203
void SetDisableOtherViews(bool disableOtherViews)
when set true, other views on the document are disabled when editing a object.
Definition: edit.h:148
The a2dStToolContr is a Tool Controller specialized for working with a2dCanvasView.
Definition: sttool.h:485
virtual void DoStopTool(bool abort)
to do tool specific stuff to stop a tool. Called from StopTool().
Definition: tools.cpp:796
static const a2dSignal sig_toolStartEditObject
when starting editing an object, this event is sent to tool
Definition: edit.h:83
void OnChar(wxKeyEvent &event)
called on key events
Definition: sttool.cpp:1568
bool m_SingleClickToEnd
a single non hit Left Down click is enough to end editing of an object.
Definition: edit.h:204
a2dCanvasDocument * m_doc
this is intentioanally not a smart pointer (would create a reference loop)
Definition: edit.h:334
This tool does do a hit test on objects to edit, and then starts editing the object.
Definition: edit.h:226
static const a2dCommandId COMID_PushTool_RecursiveEdit
push this tool on the tools stack
Definition: edit.h:233
bool ZoomSave()
save to zoom
Definition: edit.h:130
This tool is for editing a single object.
Definition: edit.h:73
Each a2dCommand is given a command id at construction.
Definition: comevt.h:99
a2dCanvas is used to display one of the a2dCanvasObjects which are part of a a2dCanvasDocument object...
Definition: canvas.h:68
virtual void AbortBusyMode()
Called when the user aborts editing a distinct object */.
Definition: sttool.cpp:1178
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
virtual bool CreateToolObjects()
Create the editcopy and other tool objects (e.g. decorations)
Definition: sttool.cpp:1260
bool m_preserve_select
preserve the a2dCANVAS_SELECT flag after editing.
Definition: edit.h:201
Each a2dCanvasView needs to have a a2dCanvasDocument set in order to render data. ...
Definition: candoc.h:374
virtual void CleanupToolObjects()
Cleanup the editcopy other tool objects (e.g. decorations)
Definition: sttool.cpp:1265
void SetSingleClickToEnd(bool SingleClickToEnd)
a single non hit Left Down click is enough to end editing of an object.
Definition: edit.h:141
virtual wxString GetCommandGroupName()
return the command group name for commands of a derived class
Definition: edit.h:198
list for a2dCanvasObject
Event sent to a2dCommandProcessor.
Definition: comevt.h:701
This tool does do a hit test on objects to edit, and then starts editing the object.
Definition: edit.h:286
see a2dComEvent
Definition: gen.h:371
void OnComEvent(a2dComEvent &event)
called when a tool has changed (fill stroke layer spline )
Definition: sttool.cpp:1497
virtual bool EnterBusyMode()
starts a new action (e.g drawing something ) in a tool that is already pushed.
Definition: sttool.cpp:1147
void OnDoEvent(a2dCommandProcessorEvent &event)
handler for Do event
Definition: sttool.cpp:1492
stack based tools controller and tools for drawing and editing.
static const a2dCommandId COMID_PushTool_ObjectEdit
push this tool on the tools stack
Definition: edit.h:80
virtual void SetActive(bool active=true)
set the tool active or inactive.
Definition: sttool.cpp:1099
virtual void SetMode(int mode)
general integer to set operation modes for a tool (e.g the way it draws)
Definition: tools.h:604
edit.h Source File -- Sun Oct 12 2014 17:04:19 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation