wxArt2D
tools.h
Go to the documentation of this file.
1 /*! \file wx/canvas/tools.h
2  \brief base classes for tools and controller on top of the tools.
3 
4  a2dToolContr gets event from a2dDrawingPart before it handles the event itself.
5  a2dToolContr has a stack of tools (a2dToolList) that contains one or more tools (a2dBaseTool).
6  The tool first in the list is the active tool, which gets the events first.
7  Tools are in general for modifying drawings interactive.
8 
9  \author Klaas Holwerda
10 
11  Copyright: 2001-2004 (c) Klaas Holwerda
12 
13  Licence: wxWidgets Licence
14 
15  RCS-ID: $Id: tools.h,v 1.28 2009/06/03 17:38:12 titato Exp $
16 */
17 
18 #ifndef __A2DCANVASTOOLS_H__
19 #define __A2DCANVASTOOLS_H__
20 
21 #ifndef WX_PRECOMP
22 #include "wx/wx.h"
23 #endif
24 
25 #include "wx/event.h"
26 
27 #include "wx/canvas/candefs.h"
28 #include "wx/general/smrtptr.h"
29 #include "wx/general/smrtptr.inl"
30 #include "wx/canvas/objlist.h"
31 
32 //----------------------------------------------------------------------------
33 // decls
34 //----------------------------------------------------------------------------
35 //initalization
36 
37 class A2DCANVASDLLEXP a2dBaseTool;
38 
39 #if defined(WXART2D_USINGDLL)
40 template class A2DCANVASDLLEXP a2dSmrtPtr< a2dBaseTool >;
41 template class A2DCANVASDLLEXP std::allocator<class a2dSmrtPtr<class a2dBaseTool> >;
42 template class A2DCANVASDLLEXP std::allocator< std::_List_nod<class a2dSmrtPtr<class a2dBaseTool>, std::allocator<class a2dSmrtPtr<class a2dBaseTool> > >::_Node >;
43 template class A2DCANVASDLLEXP std::allocator< std::_List_ptr<class a2dSmrtPtr<class a2dBaseTool>, std::allocator<class a2dSmrtPtr<class a2dBaseTool> > >::_Nodeptr >;
44 template class A2DCANVASDLLEXP std::list<class a2dSmrtPtr<class a2dBaseTool> >::iterator;
45 template class A2DCANVASDLLEXP std::list<class a2dSmrtPtr<class a2dBaseTool> >;
46 template class A2DCANVASDLLEXP a2dlist<class a2dSmrtPtr<class a2dBaseTool> >;
47 template class A2DCANVASDLLEXP a2dSmrtPtrList<a2dBaseTool>;
48 #endif
49 
50 // it is used in editor/mastertool.h
52 
53 //! list for a2dBaseTool's
54 /*!
55  used as list of tools in a2dToolContr.
56 */
57 class A2DCANVASDLLEXP a2dToolList: public a2dSmrtPtrList<a2dBaseTool>
58 {
59 public:
60  a2dToolList();
61 
62  ~a2dToolList();
63 
64 
65  //!Clone everything ( Clones objects also) in a new created list
66  a2dToolList* DoClone( a2dObject::CloneOptions options, a2dRefMap* refs ) const;
67 
68 };
69 
70 //!The a2dToolContr is the base class for Tool controller classes.
71 /*!
72 A tool controller handles redirection of events from the a2dCanvas/a2dDrawingPart Events to the
73 tools that are maintained by a controller.
74 The controller is derived from wxEvtHandler, and there for can be (un)plugged into a
75 a2dDrawingPart window.
76 It then intercepts all events on the canvas window, and sents them to the active tool.
77 The controller has a list of tools, only the active tool will react on the events.
78 More then one tool may be active, in which case skipped events will be handled by
79 later tools in the tool list. In the end skipped events in all tools
80 are handled by a2dDrawingPart itself.
81 \sa a2dBaseTool
82 \sa a2dDrawingPart
83 \sa a2dCanvas
84 
85  \ingroup tools
86 */
87 class A2DCANVASDLLEXP a2dToolContr: public a2dObject
88 {
89 public:
90 
91  //!\param view view where the controller takes events from
92  a2dToolContr( a2dDrawingPart* drawingPart );
93 
94  //! destructor
95  virtual ~a2dToolContr();
96 
97  //!sets the a2dDrawingPart on which the controller will work.
98  /*! \param view the new canvas view to work on, if NULL this a2dToolContr
99  will be disabled, and the controller will be popped out of a previous a2dCanvas.
100  */
101  void SetDrawingPart( a2dDrawingPart* drawingPart );
102 
103  //!Get the a2dDrawingPart object that the controller is plugged into
104  a2dDrawingPart* GetDrawingPart() { return m_drawingPart; }
105 
106  //! all tools currently on the tool stack will be terminated and poped ( forced )
107  /*!
108  Use this when the document of the view of this controller is changed.
109  */
110  void StopAllTools( bool abort = true );
111 
112  //! Toolcontroller can be re-initialized
113  /*!
114  After changing a document on a view, and StopAllTools() was called, this function
115  can be used to bring the controller back into a wanted state.
116  The default does nothing.
117  */
118  virtual void ReStart();
119 
120  //! can be used by a2dCanvas or a2dDrawingPart to disable this class
121  /*!
122  for events, and also pops all tools from the tool stack.
123  */
124  void Disable();
125 
126  //!get currently used eventhandler (always the first in the list)
127  a2dBaseTool* GetFirstTool() const;
128 
129  //! return reference to tool list
130  const a2dToolList& GetToolList() const { return m_tools; }
131 
132  //!process an event for the object, if the event is not handled by
133  /*! the class itself through a static event table,
134  it will be sent to the first tool via ToolsProcessEvent().
135  */
136  bool ProcessEvent( wxEvent& event );
137 
138  //! push/pop tool:
139  /*! add a tool on top of the already existing ones
140  Calls first tools start, and if this returned true the tool will be pushed.
141  \return true if tool its ToolStart() returned true;
142  */
143  virtual bool PushTool( a2dBaseTool* handler );
144 
145  //!remove first tool on the tool stack
146  /*!
147  Calls first the tool its StopTool() which prepares the tool for stopping.
148  Calling StopTool() within a tool, automatically result in the tool to be poped by the controller,
149  using this function. This happens within the event processing chain.
150 
151  \param poped the tool which is poped from the stack.
152  \param force If AllowPop() return false, the PopTool is not done, unless force is true.
153 
154  \remark the tool is removed from the stack, tools are reference counted so
155  if you want to preserve it, you can.
156 
157  \return true if a tool was available for poping.
158  */
159  virtual bool PopTool( a2dBaseToolPtr& poped, bool force = true );
160 
161  //!append a tool to the list, this tool will recieve an event if the other skipped the event to process. */
162  void AppendTool( a2dBaseTool* handler );
163 
164  //!enable the tool with the given name
165  /*!\param tool: classname of the tool
166  \param disableothers: if true other tools in the tool list are disabled
167  */
168  bool EnableTool( const wxString& tool , bool disableothers );
169 
170  //!enable the given tool
171  /*!\param tool: pointer to the tool
172  \param disableothers: if true other tools in the tool list are disabled
173  */
174  bool EnableTool( a2dBaseTool* tool , bool disableothers );
175 
176  //!disable the tool with the given name
177  /*!Disabling a tool means that it will not receive any events.
178  \param tool: classname of the tool
179  */
180  bool DisableTool( const wxString& tool );
181 
182  //!disable the tool with the given name
183  /*!Disabling a tool means that it will not receive any events.
184  \param tool: pointer to the tool
185  */
186  bool DisableTool( a2dBaseTool* tool );
187 
188  //!search for the tools in the tool list with the given name.
189  /*!\param tool: classname of the tool */
190  a2dBaseTool* SearchTool( const wxString& tool );
191 
192  //!(de)activate the first tool in the list.
193  /*! (de)activates the first tool on the stack, and deactivates all others
194  */
195  void ActivateTop( bool active );
196 
197  //!Activate the tool with the given name
198  /*!\remark DIS activating a tool means it will skip mouse events
199  \remark it will still receive other events like Onpaint Onchar.
200  \param tool: pointer to the tool
201  \param disableothers: if true other tools in the tool list are made inactive
202  */
203  bool Activate( const wxString& tool, bool disableothers );
204 
205  //! start editing object using existing corridor to object
206  /*!
207  Start editing the object within the coordinate system defined by the corridor set by for instance
208  a2dIterC::SetCorridorPath() Parent of startobject is defined as last object in corridor.
209 
210  The corridor is used to calculate the editworld matrix, meaning relative to what coordinates system
211  the editing takes place. This becomes important when editing children of objects directly.
212 
213  \remark if a corridor is not set in the a2dCanvasDocument, the ShowObject() of the a2dDrawingPart is used.
214 
215  \remark at the top level (ShowObject of view) the editorWorld is always a2dIDENTITY_MATRIX
216  else it depends on the structure of the document.
217  */
218  virtual bool StartEditingObject( a2dCanvasObject* objectToEdit );
219 
220  //! start editing object using iteration context to define corridor.
221  /*!
222  The editcopy created of the objectToEdit is used to capture the corridor to that object.
223  */
224  virtual bool StartEditingObject( a2dCanvasObject* objectToEdit, a2dIterC& ic );
225 
226  //! trigger restart editing (after undo event or when changing editing mode )
227  /*!
228  An editing tool on a a2dCanvasObject can be restarted in derived controller.
229  */
230  virtual bool TriggerReStartEdit( wxUint16 editmode );
231 
232  //! define corridor for the controller its first tool
233  bool SetCorridor( const a2dCorridor& corridor );
234 
235  //! render the tool chain
236  /*!
237  A tool chain gets rendered when a2dDrawingPart is updating areas that are changed in a document.
238  */
239  virtual void Render();
240 
241  //!set snap on or off.
242  /*!
243  When snapping is on, tools will respect this, and drawing will be on the snap grid.
244  */
245  void SetSnap( bool doSnap );
246 
247  //!get current snap setting ( true or false ).
248  inline bool GetSnap() { return m_snap; }
249 
250  //! see m_eventHandler
251  void SetDefaultToolEvtHandler( a2dObject* handler ) { m_defaultEventHandler = handler; }
252 
253  //! see m_eventHandler
254  a2dObject* GetDefaultToolEventHandler() { return m_defaultEventHandler; }
255 
256  //! see m_defaultEventHandlerFixedStyle
257  void SetDefaultToolEvtHandlerFixedStyle( a2dObject* handler ) { m_defaultEventHandlerFixedStyle = handler; }
258 
259  //! see m_defaultEventHandlerFixedStyle
260  a2dObject* GetDefaultToolEventHandlerFixedStyle() { return m_defaultEventHandlerFixedStyle; }
261 
262 
263 protected:
264 
265  //! Event not handled in this class are redirected to the chain of tools.
266  /*!
267  When there are tools in the tools chain, the first tools receives the event first.
268 
269  If you derive a class from this controller class here, you might not want to use the
270  base event handling for some type of events, even if you do not handle it
271  yourself in your static event callback.
272  Normally handling an event in the baseclass is achieved with event.Skip().
273  ( e.g in OnMouse or OnChar ).
274  But by calling ToolsProcessEvent() function here directly, skipping is not needed, and the event
275  will directly go to the first available tool.
276 
277  \remark If new tools are pushed while handling the event in the currently available tools,
278  and the event itself was skipped ( not handled ), it will be redirect to the pushed tools.
279  This is in a recursive manner, so there may be a chain of extra pushed tools.
280 
281  \remark If a tool is stopped ( \see GetStopTool() ), it is poped from the tools stack.
282  And if the event is not processed yet, it is sent to the next/new first tool.
283  More tools can be stopped in a chain of tools as a respons to one and the same event.
284 
285  \see ProcessEvent
286 
287  \param event the event which will be sent to the tools.
288 
289  \return true if the event was processed and event.Skip() was not called.
290  */
291  bool ToolsProcessEvent( wxEvent& event );
292 
293  //! sets the focus to the display window.
294  void OnEnter( wxMouseEvent& WXUNUSED( event ) );
295 
296  //!window Onpaint is received here before the window Onpaint where this controller is plugged into.
297  /*!In general a flag is set to do the job in Onidle time after the window itself is repainted */
298  void OnPaint( wxPaintEvent& event );
299 
300  void OnIdle( wxIdleEvent& event );
301 
302  //!tool list
304 
305  //!a2dDrawingPart where tool is plugged into
307 
308  //! set when poping a tool is in progress.
309  //! This is used to prevent recursive calls from event sent around in the poping process.
311 
312  //!snap is on or off
313  bool m_snap;
314 
315  //! use to define default handlers in tools.
316  /*!
317  Several tools use a centralized defaultEventHandler,
318  which is called to process events before handling it in the tool itself.
319  Here the default one in those tools can be set.
320  */
322 
323  //! use to define default handlers in tools.
324  /*!
325  Several tools use a centralized defaultEventHandler,
326  which is called to process events before handling it in the tool itself.
327  Here the default one in those tools can be set, for tools having a fixed style.
328  */
330 
331 private:
332  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const { return NULL; };
333 
334  DECLARE_EVENT_TABLE()
335  DECLARE_CLASS( a2dToolContr )
336 };
337 
338 #if defined(WXART2D_USINGDLL)
339 template class A2DCANVASDLLEXP a2dSmrtPtr<a2dToolContr>;
340 #endif
341 
342 //-----------------------------------------------------------
343 // tool modifier on action
344 //-----------------------------------------------------------
345 
346 class A2DCANVASDLLEXP a2dToolFunctor;
347 class A2DCANVASDLLEXP a2dCanvasCommandProcessor;
348 
350 
351 DECLARE_MENU_ITEMID( CmdMenu_NoMenu )
352 
353 //!The a2dBaseTool is used to derive tools from that are controlled by
354 /*! a a2dToolContr derived class.
355 
356  The basetool does not implement default behaviour for events in many cases, instead it is possible to set m_eventHandler to take
357  care of action which are the same for a set of tools. a2dBaseTool::ProcessEvent() first redirect incoming events to
358  m_eventHandler, and if not handled there it goes to the tools its own event handler.
359 
360  - wxEventType sig_toolPushed sent from controller just after this tool is pushed,
361  the tool is the first on the stack. This event can be used to have a master tool push extra tools.
362 
363  - a2dComEvent( GetFirstTool(), poped, &sig_toolPoped ) sent from controller to tool when some
364  other tool is poped from the tool stack. This can be used to control style settings for this tool,
365  based on the last active tool on the top of the tool stack. E.g When style is changed when editing
366  a primitive, the tool that was used to draw this primitive and started the editing tool, normally wants to take over this style.
367  This function is called just after a tool was poped from the stack.
368 
369  - a2dComEvent( GetFirstTool(), poped, &sig_toolBeforePoped ) sent from controller when a new tool is pushed,
370  while the current tool is on the stack. This can be used to control halting or stopping of the current tool.
371  E.g. When a tool allows Zooming while busy, you halt the tool here, but while the new tool is totataly independent,
372  one may terminate the current tool action and close its command group. This function is called just before the new
373  tool is indeed pushed on the stack.
374 
375  \sa a2dToolContr
376 
377  \ingroup tools
378 */
379 class A2DCANVASDLLEXP a2dBaseTool: public a2dObject
380 {
381 public:
382 
383  //! sent to new first tool when tool was pushed
384  static const a2dSignal sig_toolPushed;
385  //! sent to new first tool when last first tool was poped
386  static const a2dSignal sig_toolPoped;
387  //! sent to current firsttool so it can pop itself based on the tool to push.
388  //! Allows the current first tool to react on a the pushing of the new tool.
389  static const a2dSignal sig_toolBeforePush;
390  //! return id after a sig_toolBeforePush, to tell current tool needs to be poped.
391  static const a2dSignal sig_toolDoPopBeforePush;
392  //! not yet used.
393  static const a2dSignal sig_toolComEvent;
394 
395  //! events recieved from controller processed here
396  /*!
397  first m_eventHandler is tried, if not set or not processed, try object itself.
398  */
399  bool ProcessEvent( wxEvent& event );
400 
401  //! to reroute events to this event handler
402  void SetEvtHandler( a2dObject* handler ) { m_eventHandler = handler; }
403 
404  a2dObject* GetEventHandler()
405  {
406  if ( m_eventHandler )
407  return m_eventHandler;
408  return this;
409  }
410 
411  //!construct a new tool for the given controller.
412  a2dBaseTool( a2dToolContr* controller, const a2dMenuIdItem& initiatingMenuId = CmdMenu_NoMenu() );
413 
414  //! constructor initializing partly from other tool
415  a2dBaseTool( const a2dBaseTool& other, CloneOptions options, a2dRefMap* refs );
416 
417  //!destructor
418  virtual ~a2dBaseTool();
419 
420  inline a2dBaseTool* TClone( CloneOptions options, a2dRefMap* refs = NULL ) { return ( a2dBaseTool* ) Clone( options, refs ); }
421 
422  virtual wxString GetToolString() const;
423 
424  //!called to initiate while pushing tool to toolcontroller
425  /*! It also resets the m_stop flag to false.
426  */
427  virtual bool StartTool( a2dBaseTool* currenttool );
428 
429  //!Only one action of the tool, after that it will ask the controller to stop this tool.
430  void SetOneShot() { m_oneshot = true; }
431 
432  //!Is Zooming while the tool is busy Save.
433  /*!If so, the active tool will redraw itself in the new Mapping state */
434  virtual bool ZoomSave() = 0;
435 
436  //! tells if a tool can be poped from the stack.
437  /*!
438  The controller tests if a tool is allowed to be poped from the stack.
439  When a tool returns false here, that tool will stay on the stack until controller
440  is destructed.
441  */
442  virtual bool AllowPop() { return true; }
443 
444  //! call to stop a tool, internal and external.
445  /*! The stop flag within the tool will be set, triggering deletion of the tool
446  from the outside by the a2dToolContr. Stopping one tool often means activating
447  another which is on the tool stack of the a2dToolContr. Therefore the tools
448  are really stopped and removed from the tool stack from the outside.
449 
450  After this call the tool must be left in a state that allows the controller to pop the tool.
451 
452  Override DoStopTool() function, if there is cleaning up to do before stopping a tool.
453  Understand that stopping the tool is something else then (de)activating a tool.
454  A tool can be de-activated, but still in action or at least on the toolstack.
455  Stopping a tools really removes the tool from the stack by the controller.
456 
457  To prevent poping the tool from the outside before it is really stopped,
458  m_bussyStopping is incremented, when recursive calling this function.
459  GetStopTool() only returns true when all recursive StopTool() calls have returned.
460 
461  \remark If a tool can not be stopped right now, the function should return false.
462 
463  \remark Stopping a tools will indirectly lead to the a2dToolContr Popping the
464  tool from the stack, and that action at least de-activates the tool just stopped.
465  So indirectly SetActive( false ) is called on this tool, when it is really stopped.
466 
467  \param abort if true the tool is calling AbortBusyMode() instead FinishBusyMode(),
468  the effect is that the tool does directly Undo what it was doing, but not yet did finish.
469  */
470  void StopTool( bool abort = false );
471 
472  //!checked by controller to see if the tool needs to be stopped e.g. after a oneshot.
473  /*! or when wanted.
474  The stop flag is in general set after a tool has received and handled an event
475  which should stop the tool. A tool should not stop itself, since the tool will be deleted.
476  The StopTool() function is called in such a case to trigger the stopping of the tool.
477  */
478  bool GetStopTool();
479 
480  //!is the tool active?
481  /*! A tool is "active", when it receives mouse input. Usually this is only the top tool
482  on the tool stack. This is something completely different then "busy".
483  A tool is "busy", when it currently focuses on editing a specific object.
484  Toolstates change like this:
485  1. Created
486  2. Pushed on the tool stack -> set active
487  3. User clicks on an object to edit -> set busy
488  4. User starts a different tool (e.g. zoom) -> busy but not active (halted)
489  5. subtool is stopped -> set active again (and busy)
490  6. User continues editing the object selected in 3. -> still busy
491  7. User finishes editing the object selected in 3. -> no longer busy, but still active
492  "One-shot" tools are stopped in this situations, other tools continue.
493  8. User clicks on a different object, repeat step 3..7 -> busy again
494  9. User stops tool (end tool menu or ESC or 2x double-click ...) -> stopped
495  10 Tool gets popped from the tool stack
496  */
497  bool GetActive() { return m_active; }
498 
499  //!set the tool active or inactive.
500  /*!
501  If the tool needs initializing after it was inactive for a while,
502  override this function to re-initialize the tool.
503  This function can be used to distribute its settings for style etc. to the documents
504  \see a2dCanvasDocument::GetCanvasCommandProcessor().
505  The default implementation sets fill, stroke to the commandprocessor,
506  but only when m_doSetStyleToCommandProc is true.
507  If you need more complicated behaviour just override.
508  */
509  virtual void SetActive( bool active = true );
510 
511  //! Check if the tool is busy editing a distinct object */
512  /*! \see GetActive for a discription of various tool states */
513  bool GetBusy() { return m_busy; }
514 
515  //! Called when the user selects a distinct object for editing */
516  /*! \see GetActive for a discription of various tool states
517  You should call the base class (this) version at the END of your function
518  */
519  virtual bool EnterBusyMode();
520 
521  virtual bool EnterBusyModeNoGroup();
522 
523  //! Called when the user finishes editing a distinct object */
524  /*! \see EnterBusyMode, \see GetActive
525  You should call the base class (this) version at the END of your function
526  */
527  virtual void FinishBusyMode( bool closeCommandGroup = true );
528 
529  //! Called when the user aborts editing a distinct object */
530  /*! \see EnterBusyMode
531  This is supposed to undo aeverything the tool did since entering busy mode
532  */
533  virtual void AbortBusyMode();
534 
535  //!set fill if used inside a tool
536  void SetFill( const a2dFill& fill );
537 
538  //!get the current fill
539  /*!
540  Return the current fill
541  */
542  const a2dFill& GetFill() const { return m_fill; }
543 
544  //!set stroke if used inside a tool
545  void SetStroke( const a2dStroke& stroke );
546 
547  //!get the current stroke
548  /*!
549  Return the current stroke
550  */
551  const a2dStroke& GetStroke() const { return m_stroke; }
552 
553  //! layer set for the object that is drawn using a tool
554  void SetLayer( wxUint16 layer );
555 
556  //!layer set for new objects.
557  inline wxUint16 GetLayer() { return m_layer; }
558 
559  //!when true anotation will be shown, if used inside a tool
560  /*! tools can show text when in action (e.g radius of the circle that is drawn)
561  This is called anotation.
562  The flag set by this function can be used to enable or disable the anotation.
563  */
564  void SetShowAnotation( bool show ) { m_anotate = show; }
565 
566  //! font to use for anotation
567  void SetAnotationFont( const wxFont& font ) { m_annotateFont = font; }
568 
569  //! Sets cursor which the tool should use when started
570  /*!
571  You may change the predefined cursor which the tool uses when it
572  becomes active.
573 
574  \remark
575  Many tools are using more than one cursor. These cursors indicate
576  the status of the tool (busy etc.) and only the busy cursor can be
577  changed currently.
578  This cursor only indicate that the tool is active.
579 
580  \param cursor the tool cursor
581  */
582  void SetCursorType( const wxCursor& cursor ) { m_toolcursor = cursor; }
583 
584  //! Sets cursor which the tool should use when busy
585  /*!
586  You may change the predefined cursor which the tool uses when it
587  becomes busy.
588 
589  \param cursor the tool cursor
590  */
591  void SetBusyCursorType( const wxCursor& cursor ) { m_toolBusyCursor = cursor; }
592 
593  //!what cursor is used when tool is started
594  wxCursor GetCursorType() { return m_toolcursor; }
595 
596  //!what cursor is used when tool is busy
597  wxCursor GetBusyCursorType() { return m_toolBusyCursor; }
598 
599  //! general integer to set operation modes for a tool (e.g the way it draws)
600  /*! tools most check the mode and handle in accordance
601  In general Tab should be used to tab/switch/circle between modes
602  understood by a tool.
603  */
604  virtual void SetMode( int mode ) { m_mode = mode; }
605 
606  //! can be used to modify the behaviour of the derived tool.
607  /*!
608  Tools may have several ways of doing the same or simular things.
609  This integer can be used to set this mode, it depends on the implementation
610  what happens.
611  */
612  int GetMode() { return m_mode; }
613 
614  //! a tool is set pending when it needs to be redrawn.
615  void SetPending( bool pending = true ) { m_pending = pending; }
616 
617  //! return if the tool is set pending for redraw.
618  bool GetPending() { return m_pending; }
619 
620  //! render the tool chain
621  /*!
622  A tool chain gets rendered when a2dDrawingPart is updating areas that are changed in a document.
623  */
624  virtual void Render() {};
625 
626  //! to get the tool controller to which this tool is attached.
627  a2dToolContr* GetToolController()
628  {
629  return m_controller;
630  }
631  //! Access to the tool controllers drawer
633  {
634  return m_controller->GetDrawingPart();
635  }
636  //! Access to the tool controllers drawers drawer2d
637  a2dDrawer2D* GetDrawer2D();
638 
639  //! Access to the tool controllers drawers canvas
640  wxWindow* GetDisplayWindow();
641 
642  //!Returns a pointer to the drawing
643  a2dDrawing* GetDrawing();
644 
645  //!Returns a pointer to the command processor associated with this document
646  a2dCanvasCommandProcessor* GetCanvasCommandProcessor();
647 
648  //! Get the hitmargin in world coordinates, base on the pin a2dCanvasGlobals->GetPinSize()/2.0
649  //! If a2dPin its pinsize is pixelbased, it is translated to world calculated based on the active a2dDrawingPart.
650  double GetHitMargin();
651 
652  //!called when starting an editing operation (e.g. on mouse down)
653  /*!\param restart add a hint to the command group name, that this tool was restarted */
654  virtual void OpenCommandGroup( bool restart );
655  //!called when starting an editing operation with another than the default name
656  virtual void OpenCommandGroupNamed( const wxString& name );
657  //!called when ending an editing operation (e.g. mouse up)
658  virtual void CloseCommandGroup();
659  //!return the command group name for commands of a derived class
660  /*!this defaults to the class name */
661  virtual wxString GetCommandGroupName();
662 
663  //! return the command group that is open else NULL.
664  a2dCommandGroup* GetCommandgroup() { return m_commandgroup; }
665 
666  //! to get the current mouse menu of the tool
667  /*! see also RightMouseClick()
668  /return NULL if no menu is set, else the menu.
669  */
670  wxMenu* GetMousePopupMenu() { return m_mousemenu; }
671 
672  //! to set the current mouse menu of the tool
673  /*! see also RightMouseClick()
674  NULL sets the menu to non.
675  */
676  void SetMousePopupMenu( wxMenu* mousemenu );
677 
678  //! parent object relative to which the actions take place.
679  /*!
680  Tools can do there work on child objects of some parent a2dCanvasObject.
681  In such cases the context of the tool is set with SetCorridor(), and the last object in the corridor
682  is the m_parentobject.
683  */
684  a2dCanvasObject* GetParentObject() { return m_parentobject; }
685 
686  //! Add an editcopy object to the tool/document
687  void AddEditobject( a2dCanvasObject* object );
688  //! Remove an editcopy object to the tool/document
689  void RemoveEditobject( a2dCanvasObject* object );
690 
691  //! Add a decoration object to be rendered by the tool.
692  /*! Decoration object are rendered by the tool in the style they have.
693  They are used to add extra drawings to the actual tool object to clarify editing and drawing.*/
694  void AddDecorationObject( a2dCanvasObject* object );
695 
696  //! remove all object that were added as decorations.
697  void RemoveAllDecorations();
698 
699  //! Switches ignorance of pending objects on and off.
700  /*!
701  If set to <code>true</code> pending objects won't be updated.
702  This method is used by several tools (i.e. a2dDragTool) to avoid updates
703  while the tool is working.
704 
705  \see GetUpdatesPending()
706 
707  \param onoff <code>true</code> to ignore pending objects, else <code>false</code>
708  */
709  void SetIgnorePendingObjects( bool onoff );
710 
711  //!get setting of ignore pending objects /sa GetUpdatesPending()
712  bool GetIgnorePendingObjects() { return m_ignorePendingObjects; }
713 
714  //! get reference to the corridor list
715  a2dCorridor& GetCorridor() { return m_corridor; }
716 
717  //! set a corridor from a list of objects
718  void SetCorridor( const a2dCorridor& corridor );
719 
720  void SetContourWidth( double width );
721 
722  //!get the Contour width of the shape
723  double GetContourWidth() const { return m_contourwidth; }
724 
725  //! context like corridor and parentobject are reset
726  void ResetContext();
727 
728  //! rotate object of first tool on the stack, when appropriate.
729  virtual bool RotateObject90LeftRight( bool right ) { return false; }
730 
731  void SetIsEditTool( bool isEditTool ) { m_isEditTool = isEditTool; }
732 
733  bool GetIsEditTool() { return m_isEditTool; }
734 
735  void SetInitiatingMenuId( const a2dMenuIdItem& initiatingMenuId ) { m_initiatingMenuId = &initiatingMenuId; }
736 
737  const a2dMenuIdItem& GetInitiatingMenuId() { return *m_initiatingMenuId; }
738 
739 protected:
740 
741  //! command which initiated the tool, used to seperate commands using the tool
743 
744  //! default handler for a2dComEvent event
745  /*!
746  Event id a2dDrawingPart::sig_changedShowObject makes the tools corridor change to keep the tool active.
747  In derived tools one can implement different behaviour if needed.
748  */
749  void OnComEvent( a2dComEvent& event );
750 
751  void OnDoEvent( a2dCommandProcessorEvent& event );
752  void OnUndoEvent( a2dCommandProcessorEvent& event );
753  void OnRedoEvent( a2dCommandProcessorEvent& event );
754 
755  //! called on mouse events
756  void OnMouseEvent( wxMouseEvent& event );
757  //! called on key events
758  void OnChar( wxKeyEvent& event );
759  //! called on keydown events
760  void OnKeyDown( wxKeyEvent& event );
761  //! called on keyup events
762  void OnKeyUp( wxKeyEvent& event );
763 
764  //! to do tool specific stuff to stop a tool. Called from StopTool().
765  virtual void DoStopTool( bool abort );
766 
767  //! cursor to use
768  wxCursor m_toolcursor;
769 
770  //! cursor to use when the tool is busy doing something.
772 
773  //! under control of this toolcontroller, to give me events.
774  a2dToolContr* m_controller;
775 
776  //! tool is operational
777  bool m_active;
778 
779  //! if > 0, the tool is in the process of stopping, which means it can not be poped yet by controller.
781 
782  //! when set called before own event handler
783  /*!
784  To be able to change the behaviour in a central location for all tools, one can set this event handler.
785  The default handler is the tool itself.
786  */
788 
789  //!if set ignore all setting for pendingobjects
791 
792  //! used in tools that can do nested editing/drawing.
793  //! the corridor is a copy of the a2dCanvasObject in the a2dDocument that form the corridor path.
794  //! re-activating a tool, this list can be used to re-instantiate the corridor path for the tool.
796 
797  //! if tool does change drawing
799 
800 private:
801  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const { return NULL; }
802 
803  //!tool is busy with something (can not interrupt/stop it)
804  /*! This is private, because it should only be changed by Enter/Finish/AbortBusyMode
805  */
806  bool m_busy;
807 
808 public:
809  //! if a tool is deactivated while m_busy is true, this flag is set
810  bool m_halted;
811 
812  //! set when tool needs an redraw (after a a2dCanvas Repaint etc.)
813  /*! this result in redrawing the tool ( e.g after a change ) */
814  bool m_pending;
815 
816  //! do it only once
817  bool m_oneshot;
818 
819  //! stop the tool
820  bool m_stop;
821 
822  //!fill for new object
824 
825  //!stroke for new object
827 
828  //! if != 0 the polygon is contoured at distance m_contourwidth/2
830 
831  //!layer for a new object
832  wxUint16 m_layer;
833 
834  //!used to save the a2dCanvas mouse event setting.
835  /*! when tool is destroyed the original mouse event setting is set for a2dCanvas. */
837 
838  //!when true anotation will be shown, if used inside a tool
839  bool m_anotate;
840 
841  //! font to use for anotation
843 
844  //! general operation mode setting for a tool.
845  int m_mode;
846 
847  //!the command group of the command processor
849 
850  //!popup menu
851  wxMenu* m_mousemenu;
852 
853  //! ( if needed ) parent a2dCanvasObject relative to which the tool actions take place.
855 
856 public:
857  static a2dPropertyIdBool* PROPID_Oneshot;
858  static a2dPropertyIdBool* PROPID_Stop;
859  static a2dPropertyIdFill* PROPID_Fill;
860  static a2dPropertyIdStroke* PROPID_Stroke;
861  static a2dPropertyIdUint16* PROPID_Layer;
862 
864 
865 public:
866  DECLARE_EVENT_TABLE()
867  DECLARE_CLASS( a2dBaseTool )
868 
869 };
870 
871 
872 //-----------------------------------------------------------
873 // tool event handler
874 //-----------------------------------------------------------
875 
876 //! To implement behaviour on a set of tools.
877 /*!
878  A a2dToolEvtHandler is/can be set to a a2dBaseTool as an event handler in between the tool its own event handler.
879  This is the easiest way to make a whole set of tools behave to a certain model.
880 
881  \ingroup tools
882 
883 */
884 class A2DCANVASDLLEXP a2dToolEvtHandler: public a2dObject
885 {
886  DECLARE_EVENT_TABLE()
887 
888 public:
889 
890  //!
892 
893  void OnComEvent( a2dComEvent& event );
894 
895  //! event recieved from tools processed here
896  bool ProcessEvent( wxEvent& event );
897 
898 private:
899  virtual a2dObject* DoClone( CloneOptions options, a2dRefMap* refs ) const { return NULL; }
900 };
901 
902 #endif //__A2DCANVASTOOLS_H__
903 
Display Part of a a2dDrawing, in which a2dCanvasObjects are shown.
Definition: drawer.h:470
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
a2dCanvasObjectPtr m_parentobject
( if needed ) parent a2dCanvasObject relative to which the tool actions take place.
Definition: tools.h:854
bool m_pending
set when tool needs an redraw (after a a2dCanvas Repaint etc.)
Definition: tools.h:814
bool GetActive()
is the tool active?
Definition: tools.h:497
The a2dBaseTool is used to derive tools from that are controlled by.
Definition: tools.h:379
wxUint16 m_layer
layer for a new object
Definition: tools.h:832
void SetShowAnotation(bool show)
when true anotation will be shown, if used inside a tool
Definition: tools.h:564
wxCursor m_toolcursor
cursor to use
Definition: tools.h:768
wxCursor GetBusyCursorType()
what cursor is used when tool is busy
Definition: tools.h:597
bool m_isEditTool
if tool does change drawing
Definition: tools.h:798
a2dCommandGroup * m_commandgroup
the command group of the command processor
Definition: tools.h:848
class to map references to objects stored in XML, in order to make the connection later on...
Definition: gen.h:3462
a2dSmrtPtr< a2dObject > m_eventHandler
when set called before own event handler
Definition: tools.h:787
list for a2dBaseTool&#39;s
Definition: tools.h:57
double m_contourwidth
if != 0 the polygon is contoured at distance m_contourwidth/2
Definition: tools.h:829
a2dDrawingPart * m_drawingPart
a2dDrawingPart where tool is plugged into
Definition: tools.h:306
Ref Counted base object.
Definition: gen.h:1045
void SetOneShot()
Only one action of the tool, after that it will ask the controller to stop this tool.
Definition: tools.h:430
a2dDrawingPart * GetDrawingPart()
Access to the tool controllers drawer.
Definition: tools.h:632
store a menu Id generated by XRCID( menuIdString ) plus a menustring and helpstring ...
Definition: comevt.h:1563
wxMenu * GetMousePopupMenu()
to get the current mouse menu of the tool
Definition: tools.h:670
wxUint16 GetLayer()
layer set for new objects.
Definition: tools.h:557
bool m_anotate
when true anotation will be shown, if used inside a tool
Definition: tools.h:839
a command processor specially designed to work with a a2dCanvasDocument
Definition: drawing.h:1046
int GetMode()
can be used to modify the behaviour of the derived tool.
Definition: tools.h:612
bool m_active
tool is operational
Definition: tools.h:777
wxCursor GetCursorType()
what cursor is used when tool is started
Definition: tools.h:594
a2dToolContr * GetToolController()
to get the tool controller to which this tool is attached.
Definition: tools.h:627
see wx/general/smrtptr.h
#define DECLARE_PROPERTIES()
check if class has the given id as a valid id for this object
Definition: gen.h:835
void SetPending(bool pending=true)
a tool is set pending when it needs to be redrawn.
Definition: tools.h:615
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
a2dDrawingPart * GetDrawingPart()
Get the a2dDrawingPart object that the controller is plugged into.
Definition: tools.h:104
bool GetIgnorePendingObjects()
get setting of ignore pending objects /sa GetUpdatesPending()
Definition: tools.h:712
a2dSmrtPtr< a2dObject > m_defaultEventHandler
use to define default handlers in tools.
Definition: tools.h:321
defenitions an no more
virtual void Render()
render the tool chain
Definition: tools.h:624
void SetEvtHandler(a2dObject *handler)
to reroute events to this event handler
Definition: tools.h:402
a2dStroke m_stroke
stroke for new object
Definition: tools.h:826
wxUint8 m_bussyStopping
if &gt; 0, the tool is in the process of stopping, which means it can not be poped yet by controller...
Definition: tools.h:780
void SetDefaultToolEvtHandlerFixedStyle(a2dObject *handler)
see m_defaultEventHandlerFixedStyle
Definition: tools.h:257
a group of commands, used to group commands together for undo/redo
Definition: comevt.h:360
static const a2dSignal sig_toolComEvent
not yet used.
Definition: tools.h:393
std list compatible list
Definition: a2dlist.h:42
a2dCommandGroup * GetCommandgroup()
return the command group that is open else NULL.
Definition: tools.h:664
a2dFill m_fill
fill for new object
Definition: tools.h:823
bool m_canvas_mouseevents_restore
used to save the a2dCanvas mouse event setting.
Definition: tools.h:836
bool GetSnap()
get current snap setting ( true or false ).
Definition: tools.h:248
wxCursor m_toolBusyCursor
cursor to use when the tool is busy doing something.
Definition: tools.h:771
Drawing context abstraction.
Definition: drawer2d.h:177
static const a2dSignal sig_toolPushed
sent to new first tool when tool was pushed
Definition: tools.h:384
bool m_oneshot
do it only once
Definition: tools.h:817
wxMenu * m_mousemenu
popup menu
Definition: tools.h:851
int m_mode
general operation mode setting for a tool.
Definition: tools.h:845
a2dToolContr * m_controller
under control of this toolcontroller, to give me events.
Definition: tools.h:774
void SetAnotationFont(const wxFont &font)
font to use for anotation
Definition: tools.h:567
bool GetPending()
return if the tool is set pending for redraw.
Definition: tools.h:618
a2dCorridor m_corridor
Definition: tools.h:795
corridor as a direct event path to a a2dCanvasObject
Definition: objlist.h:313
a2dObject * GetDefaultToolEventHandlerFixedStyle()
see m_defaultEventHandlerFixedStyle
Definition: tools.h:260
virtual bool RotateObject90LeftRight(bool right)
rotate object of first tool on the stack, when appropriate.
Definition: tools.h:729
To implement behaviour on a set of tools.
Definition: tools.h:884
a2dSmrtPtr< a2dObject > m_defaultEventHandlerFixedStyle
use to define default handlers in tools.
Definition: tools.h:329
bool m_stop
stop the tool
Definition: tools.h:820
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
bool m_halted
if a tool is deactivated while m_busy is true, this flag is set
Definition: tools.h:810
const a2dStroke & GetStroke() const
get the current stroke
Definition: tools.h:551
void SetDefaultToolEvtHandler(a2dObject *handler)
see m_eventHandler
Definition: tools.h:251
a2dCorridor & GetCorridor()
get reference to the corridor list
Definition: tools.h:715
static const a2dSignal sig_toolPoped
sent to new first tool when last first tool was poped
Definition: tools.h:386
static const a2dSignal sig_toolBeforePush
Definition: tools.h:389
a2dCanvasObject * GetParentObject()
parent object relative to which the actions take place.
Definition: tools.h:684
virtual bool AllowPop()
tells if a tool can be poped from the stack.
Definition: tools.h:442
static const a2dSignal sig_toolDoPopBeforePush
return id after a sig_toolBeforePush, to tell current tool needs to be poped.
Definition: tools.h:391
list for a2dCanvasObject
const a2dFill & GetFill() const
get the current fill
Definition: tools.h:542
double GetContourWidth() const
get the Contour width of the shape
Definition: tools.h:723
smart pointer class and list.
a2dToolList m_tools
tool list
Definition: tools.h:303
Event sent to a2dCommandProcessor.
Definition: comevt.h:701
see a2dComEvent
Definition: gen.h:371
const a2dMenuIdItem * m_initiatingMenuId
command which initiated the tool, used to seperate commands using the tool
Definition: tools.h:742
wxFont m_annotateFont
font to use for anotation
Definition: tools.h:842
bool m_snap
snap is on or off
Definition: tools.h:313
const a2dToolList & GetToolList() const
return reference to tool list
Definition: tools.h:130
The a2dToolContr is the base class for Tool controller classes.
Definition: tools.h:87
void SetCursorType(const wxCursor &cursor)
Sets cursor which the tool should use when started.
Definition: tools.h:582
This template class is for property ids with a known data type.
Definition: id.h:477
bool m_bussyPoping
Definition: tools.h:310
bool GetBusy()
Check if the tool is busy editing a distinct object */.
Definition: tools.h:513
void SetBusyCursorType(const wxCursor &cursor)
Sets cursor which the tool should use when busy.
Definition: tools.h:591
bool m_ignorePendingObjects
if set ignore all setting for pendingobjects
Definition: tools.h:790
a2dObject * GetDefaultToolEventHandler()
see m_eventHandler
Definition: tools.h:254
CloneOptions
options for cloning
Definition: gen.h:1200
Contain one drawing as hierarchical tree of a2dCanvasObject&#39;s.
Definition: drawing.h:434
virtual void SetMode(int mode)
general integer to set operation modes for a tool (e.g the way it draws)
Definition: tools.h:604
tools.h Source File -- Sun Oct 12 2014 17:04:26 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation