wxArt2D
mastertool.h
Go to the documentation of this file.
1 /*! \file wx/canvas/mastertool.h
2  \brief master tools are tools on top of other tools.
3 
4  Often it is easier to use a tool which only task is to push other tools onto the tool stack.
5  That way a tool can be designed for one task, while the mastertool does define when which
6  tools becomes active.
7 
8  \author Michael Sögtrop
9  \date Created 02/06/2004
10 
11  Copyright: 2004-2004 (c) Michael Sögtrop
12 
13  Licence: wxWidgets Licence
14 
15  RCS-ID: $Id: mastertool.h,v 1.13 2009/04/23 19:35:23 titato Exp $
16 */
17 
18 // This file contains master tools. This are tools that customize GUI behaviour
19 // by intercepting events and then deligating work to other tools
20 
21 #ifndef __A2DCANVASMASTERTOOL_H__
22 #define __A2DCANVASMASTERTOOL_H__
23 
24 
25 #ifndef WX_PRECOMP
26 #include "wx/wx.h"
27 #endif
28 
29 #include "wx/canvas/canobj.h"
30 #include "wx/canvas/objlist.h"
31 #include "wx/canvas/sttool.h"
32 #include "wx/canvas/edit.h"
33 
34 //!Simple (handle-less) wire editing tool intended as sub-tool for master tools
35 /*!This tool supports the following actions:
36 
37 - Dragging a wire edge
38 
39 - Dragging a vertical/horizontal wire segment: move the segment
40 
41 - Dragging a diagonal wire segment: insert a new point in the segment
42 
43 - Dragging a vertex onto another vertex: delete vertex
44 
45 \ingroup tools
46 */
47 class A2DCANVASDLLEXP a2dSimpleEditPolygonTool: public a2dStTool
48 {
49 public:
50  enum Action
51  {
52  action_movevertex,
53  action_movesegment,
54  action_insertvertex
55  };
56 
57 public:
58  a2dSimpleEditPolygonTool( a2dStToolContr* controller, a2dCanvasObject* hit, int index, int count, Action action );
60 
61 protected:
62  virtual bool EnterBusyMode();
63  virtual void FinishBusyMode();
64  virtual void AbortBusyMode();
65  virtual void DoStopTool( bool abort );
66  virtual bool ZoomSave() { return true;};
67  virtual wxString GetCommandGroupName() { return _( "Edit polygon" ); }
68 
69  void OnChar( wxKeyEvent& event );
70  void OnMouseEvent( wxMouseEvent& event );
71 
72  virtual bool CreateToolObjects();
73  virtual void CleanupToolObjects();
74 
75 public:
76  DECLARE_CLASS( a2dSimpleEditPolygonTool )
77  DECLARE_EVENT_TABLE()
78 
79 protected:
80  //! Index of vertex / segment, that is edited
81  int m_index;
82 
83  //! Number of vertices
84  int m_count;
85 
86  //! what to edit (vertex, segment, ...)
87  Action m_action;
88 
89  //! this is used to simulate a handle attached to the object,
90  //! by adding
92 
93  //! preserve the a2dCANVAS_SELECT flag after editing.
94  /*! selection is cleared in a2dCanvasObject::StartEdit */
95  bool m_preserve_select;
96 
97  bool m_preserve_RouteWhenDrag;
98 
99  //! list of connected wire objects
100  a2dCanvasObjectList m_connectedwirecopies;
101 };
102 
103 
104 
105 //!Draw Master tool for object graphics
106 /*!This tool controls other tools such that simple objects graphics
107 can be edited without manually changing tools. It does this by pushing othere tools on the tool stack when the situation ask for.
108 
109 - When dragging in an empty area, the select tool (with drag box) shall be used
110 
111 - When dragging an existing object, the drag tool shall be used. If multiple object are selected, the drag-multi tool shall be used
112 
113 
114 \ingroup tools
115 */
116 
117 //!Master tool for sub drawing child objects in a2dCanvasObject
118 /*!
119 
120 \ingroup tools
121 */
122 class A2DCANVASDLLEXP a2dSubDrawMasterTool: public a2dStTool
123 {
124 
125 public:
126 
127  a2dSubDrawMasterTool( a2dStToolContr* controller = NULL );
128 
130 
131  void AppendTool( a2dBaseTool* tool, wxMenuItem* menuItem, wxChar key );
132 
133  void OnPostPushTool();
134 
135  void PushToolFromMouseMenu( wxCommandEvent& event );
136 
137 protected:
138 
139  virtual bool ZoomSave();
140  virtual void DoStopTool( bool abort );
141 
142  void OnChar( wxKeyEvent& event );
143 
144  void OnMouseEvent( wxMouseEvent& event );
145 
146  a2dSmrtPtr< a2dBaseTool > m_curTool;
147 
148 
149 public:
150  DECLARE_DYNAMIC_CLASS( a2dSubDrawMasterTool )
151  DECLARE_EVENT_TABLE()
152 
153 protected:
154 };
155 
156 
157 
158 //----------------------------------------------------------------------------
159 // a2dMasterDrawBase
160 //----------------------------------------------------------------------------
161 
162 //! common stuff for several master tools
163 /*!
164  - Pushing tools used form derived master tools.
165  - Cursor hints
166 */
167 class A2DCANVASDLLEXP a2dMasterDrawBase: public a2dStTool
168 {
169 public:
170 
171  //! constructor
172  a2dMasterDrawBase( a2dStToolContr* controller );
173  //! destructor
175 
176  //! tools using inverse drawing will be used.
177  void SetFastTools( bool onOff ) { m_fastTools = onOff; }
178 
179  //! tools using inverse drawing will be used.
180  bool GetFastTools() { return m_fastTools; }
181 
182  //! if set true, Double Click on N selected objects, leads to editing them as a group
183  void SetAllowMultiEdit( bool onOff ) { m_allowMultiEdit = onOff; }
184 
185  //! if true, Double Click on N selected objects, leads to editing them as a group
186  bool GetAllowMultiEdit() { return m_allowMultiEdit; }
187 
188  //! if set true selecting object will be undoable
189  void SetSelectUndo( bool onOff ) { m_select_undo = onOff; }
190 
191  //! if true selecting object is undoable
192  bool GetSelectUndo() { return m_select_undo; }
193 
194  //! if set true pressing escape key, stops current active tool.
195  /*! If escape key is handled by tool itself, that has priority.
196  So if for instance a rectangle drawing tool is active, and busy drawing a rectangle, pressing escape key
197  will and that drawing action, but the drawing tool stays active. If the drawing tool is not busy, the escape key will
198  be handled here. And if this flag is set, the drawing tool will be stopped.
199  If current first tool on the tool stack is this mastertool, there is no tool to stop.
200  */
201  void SetEscapeToStopFirst( bool onOff ) { m_escapeToStopFirst = onOff; }
202 
203  //! \see SetEscapeToStopFirst()
204  bool GetEscapeToStopFirst() { return m_escapeToStopFirst; }
205 
206  //!set select fill
207  void SetSelectFill( const a2dFill& fill ) { m_selectFill = fill; }
208 
209  //!get the select fill
210  /*!
211  Return the select fill
212  */
213  const a2dFill& GetSelectFill() const { return m_selectFill; }
214 
215  //!set select stroke
216  void SetSelectStroke( const a2dStroke& stroke ) { m_selectStroke = stroke; }
217 
218  //!get the select stroke
219  /*!
220  Return the select stroke
221  */
222  const a2dStroke& GetSelectStroke() const { return m_selectStroke; }
223 
224  void SetWiringMode( a2dWiringMode wiringMode ) { m_wiringMode = wiringMode; }
225 
226  void MouseDump( wxMouseEvent& event, wxString strinfo = "" );
227 
228  bool RotateObject90LeftRight( bool right );
229 
230  //! set dlg at Double Left Down if dlgOrEdit == true
231  void SetDlgOrEdit( bool dlgOrEdit ) { m_dlgOrEdit = dlgOrEdit; }
232 
233  //! set dlg at Double Left Down if dlgOrEdit == true
234  bool GetDlgOrEdit() const { return m_dlgOrEdit; }
235 
236  //! set style dlg as modal
237  void SetDlgOrEditModal( bool dlgOrEditModal ) { m_dlgOrEditModal = dlgOrEditModal; }
238 
239  //! get style dlg as modal setting
240  bool GetDlgOrEditModal() const { return m_dlgOrEditModal; }
241 
242  void SetStyleDlgSimple( bool styleDlgSimple ) { m_styleDlgSimple = styleDlgSimple; }
243 
244  //! defines if an object will try to connect at the end of a drag
245  void SetLateConnect( bool lateconnect ) { m_lateconnect = lateconnect; }
246 
247  void SetLastSelected( a2dCanvasObject* lastSelect, bool onOff );
248 
249  //! with this set to 1 or 2 the next point to add to the wire is a two segment piece.
250  //! angle can be altered with the TAB key. Set to 0 is a straight line.
251  void SetEndSegmentMode( a2dNextSeg mode );
252 
253  a2dNextSeg GetEndSegmentMode() { return m_endSegmentMode; }
254 
255 protected:
256 
257  a2dWiringMode m_wiringMode;
258 
259  virtual void PushZoomTool();
260  virtual void PushSelectTool();
261  virtual void PushDeSelectTool();
262  virtual void PushDragTool( a2dCanvasObject* hit );
263  virtual void PushDragMultiTool( a2dCanvasObject* hit, bool onlyKeys = false );
264  virtual void PushCopyTool( a2dCanvasObject* hit );
265  virtual void PushCopyMultiTool( a2dCanvasObject* hit );
266  virtual void PushEditTool( a2dCanvasObject* hit );
267  virtual void PushMultiEditTool( a2dCanvasObject* hit );
268  virtual void PushEditSegmentTool( a2dCanvasObject* hit, int segment );
269  virtual void PushEditWireVertexTool( a2dCanvasObject* hit, int vertex );
270  virtual void PushEditWireSegmentHorizontalTool( a2dCanvasObject* hit, int segment );
271  virtual void PushEditWireSegmentVerticalTool( a2dCanvasObject* hit, int segment );
272  virtual void PushEditWireSegmentInsertTool( a2dCanvasObject* hit, int segment );
273  virtual void PushDrawWireTool( a2dCanvasObject* hit );
274  virtual void PushMovePinTool( a2dCanvasObject* hit );
275  virtual void PushRewirePinTool( a2dCanvasObject* hit );
276 
277  virtual void EditDlgOrHandles( a2dCanvasObject* hit, bool modifier, bool noHandleEditForWire );
278 
279  void SelectedStatus();
280 
281  a2dCanvasObject* GetTopLeftSelected();
282 
283 protected:
284 
285  void SelectHitObject( a2dCanvasObject* hit );
286  virtual bool ZoomSave();
287  virtual void DoStopTool( bool abort );
288 
289  void OnChar( wxKeyEvent& event );
290 
291  void OnKeyDown( wxKeyEvent& event );
292  void OnKeyUp( wxKeyEvent& event );
293 
294  void OnMouseEvent( wxMouseEvent& event );
295 
296  //! generate fack mouse events, based on current mouse event.
297  //! used to set pushed tools in a certain mode e.g. generate LeftDown event when dragging already started in mastertool.
298  void InitMouseEvent(wxMouseEvent& eventnew,
299  int x, int y,
300  wxMouseEvent& event );
301 
302  bool m_hadDoubleClick;
303 
304  bool m_dlgOrEdit;
305 
306  bool m_dlgOrEditModal;
307 
308  bool m_styleDlgSimple;
309 
310  bool m_lateconnect;
311 
312  bool m_escapeToStopFirst;
313 
314  int m_generatedPinX;
315  int m_generatedPinY;
316 
317  a2dNextSeg m_endSegmentMode;
318 
319 public:
320  DECLARE_CLASS( a2dMasterDrawBase )
321  DECLARE_EVENT_TABLE()
322 
323 protected:
324 
325  // the editing mode derived from the object under the cursor
326  enum Mode
327  {
328  mode_none, // no mode
329  mode_edit, // edit object tool
330  mode_multiedit, // edit all selected
331  mode_zoom, // zoom via drag box mode
332  mode_select, // select via drag box mode
333  mode_cntrlselect, // de first and select via drag box mode
334  mode_deselect, // de select via drag box mode
335  mode_drag, // drag object mode
336  mode_dragmulti, // drag selected (multiple) objects mode
337  mode_copy, // drag-copy object mode
338  mode_copymulti, // drag-copy selected (multiple) objects mode
339  mode_zoomdrag, // move view with mouse
340  mode_drawwire, // drawing a connection wire from a pin
341  mode_editwire_segment, // segment shift
342  mode_editwire_segmenthorizontal, // wire editing mode: horizontal segment shift
343  mode_editwire_segmentvertical, // wire editing mode: horizontal segment shift
344  mode_editwire_segmentinsert, // wire editing mode: horizontal segment shift
345  mode_editwire_vertex, // wire editing mode: horizontal segment shift
346  mode_move_pin, // move a pin
347  mode_rewire_pin // disconnect and move a pin and connect at new location if possible.
348  } m_mode;
349 
350  // the object, that was responsible for setting m_mode to what it is
351  a2dCanvasObject* m_modehit;
352 
353  // the hit information for m_modehit
354  a2dHit m_modehitinfo;
355  a2dHitEvent m_hitinfo;
356 
357  bool m_spaceDown;
358  bool m_vertexSegmentEdit;
359  bool m_movePin;
360 
361  bool m_toolBusy;
362  bool m_modehitLastSelectState;
363 
364  bool m_fastTools;
365 
366  bool m_allowMultiEdit;
367 
368  bool m_select_undo;
369 
370  a2dFill m_selectFill;
371  a2dStroke m_selectStroke;
372 };
373 
374 
375 //!Master tool for objects graphics slecting and dragging nd zooming
376 /*!This tool controls other tools such that simple object graphics
377 can be edited without manually changing tools.
378 
379 - Left Down + Drag => select objects in rectangle
380 - Left Down + Drag + Shift Down => select objects in rectangle add to already selected
381 - Left Down + Drag + Alt Down => move selected objects if allowed else editmode
382 - Left Down + Drag + Alt & Ctrl Down => copy selected objects if allowed else editmode
383 - Right Down => Drag canvas view
384 - Right Down + Up => Show Popup
385 - SpaceDown => Zoom area with mouse
386 - Double Click => Edit Selected of hit
387 
388 \ingroup tools
389 */
390 class A2DCANVASDLLEXP a2dMasterDrawSelectFirst: public a2dMasterDrawBase
391 {
392 public:
393 
396 
397 protected:
398 
399  void OnChar( wxKeyEvent& event );
400 
401  void OnMouseEvent( wxMouseEvent& event );
402 
403  void OnKeyDown( wxKeyEvent& event );
404  void OnKeyUp( wxKeyEvent& event );
405 
406  void SelectHitObject( a2dCanvasObject* hit );
407  void DecideMode( a2dCanvasObject* hit, const a2dHitEvent& hitinfo, bool shift, bool control );
408 
409 public:
410  DECLARE_CLASS( a2dMasterDrawSelectFirst )
411  DECLARE_EVENT_TABLE()
412 };
413 
414 //!Master tool for objects graphics slecting and dragging nd zooming
415 /*!This tool controls other tools such that simple object graphics
416 can be edited without manually changing tools.
417 
418 - Left Down + Drag => zoom to rectangle
419 - Left Down + Drag + Shift Down => select objects in rectangle add to already selected
420 - Left Down + Drag + Cntrl Down => select objects in rectangle deselect already selected first
421 - Left Down + Drag + Alt Down => move selected objects if allowed else editmode
422 - Left Down + Drag + Alt & Ctrl Down => copy selected objects if allowed else editmode
423 - Right Down => Drag canvas view
424 - Right Down + Up => Show Popup
425 - Double Click => Edit Selected of hit
426 
427 \ingroup tools
428 */
429 class A2DCANVASDLLEXP a2dMasterDrawZoomFirst: public a2dMasterDrawBase
430 {
431 public:
432 
433  a2dMasterDrawZoomFirst( a2dStToolContr* controller );
435 
436 protected:
437 
438  void DoStopTool( bool abort );
439 
440  void OnChar( wxKeyEvent& event );
441 
442  void OnMouseEvent( wxMouseEvent& event );
443 
444  void OnKeyDown( wxKeyEvent& event );
445  void OnKeyUp( wxKeyEvent& event );
446  void Render();
447 
448 public:
449 
450  void AbortBusyMode();
451 
452  DECLARE_CLASS( a2dMasterDrawZoomFirst )
453  DECLARE_EVENT_TABLE()
454 
455 };
456 
457 //!Master tool for objects+wires graphics
458 /*!This tool controls other tools such that simple objects+wires graphics
459 can be edited without manually changing tools.
460 
461 - When dragging in an empty area, the select tool (with drag box) shall be used
462 
463 - When clicking on a pin, or an object that can create a dynamic pin at the mouse position the draw wire tool shall be used
464 
465 - When dragging an existing object, the drag tool shall be used. If multiple object are selected, the drag-multi tool shall be used
466 
467 - When dragging + Shift a wire edge, call a simple wire editing tool, that moves the edge (without first selecting it in edit mode and without showing handles)
468 
469 - When dragging + Shift a vertical/horizontal wire segment, call a simple tool that moves the segment
470 
471 - When dragging + Shift a diagonal wire segment, insert a new point in the segment
472 
473 \ingroup tools
474 */
475 class A2DCANVASDLLEXP a2dGraphicsMasterTool: public a2dMasterDrawBase
476 {
477 public:
478 
479  a2dGraphicsMasterTool( a2dStToolContr* controller );
481 
482 protected:
483 
484  void OnMouseEvent( wxMouseEvent& event );
485 
486  void SelectHitObject( a2dCanvasObject* hit );
487 
488 public:
489  DECLARE_CLASS( a2dGraphicsMasterTool )
490  DECLARE_EVENT_TABLE()
491 
492 protected:
493 };
494 
495 
496 
497 #endif // __A2DCANVASMASTERTOOL_H__
498 
499 
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
void SetAllowMultiEdit(bool onOff)
if set true, Double Click on N selected objects, leads to editing them as a group ...
Definition: mastertool.h:183
The a2dBaseTool is used to derive tools from that are controlled by.
Definition: tools.h:379
a2dWiringMode
the way a new wire is created
Definition: sttool.h:1882
Master tool for objects graphics slecting and dragging nd zooming.
Definition: mastertool.h:429
The a2dStTool is used to derive tools from.
Definition: sttool.h:115
Simple (handle-less) wire editing tool intended as sub-tool for master tools.
Definition: mastertool.h:47
virtual bool ZoomSave()=0
Is Zooming while the tool is busy Save.
void SetFastTools(bool onOff)
tools using inverse drawing will be used.
Definition: mastertool.h:177
void SetEscapeToStopFirst(bool onOff)
if set true pressing escape key, stops current active tool.
Definition: mastertool.h:201
The base class for all drawable objects in a a2dCanvasDocument.
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
handle holds a pointer to a polygon/polyline segment
Definition: polygon.h:713
bool GetFastTools()
tools using inverse drawing will be used.
Definition: mastertool.h:180
bool GetEscapeToStopFirst()
Definition: mastertool.h:204
void OnMouseEvent(wxMouseEvent &event)
called on mouse events
Definition: sttool.cpp:1203
bool GetDlgOrEditModal() const
get style dlg as modal setting
Definition: mastertool.h:240
virtual wxString GetCommandGroupName()
return the command group name for commands of a derived class
Definition: mastertool.h:67
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
void OnChar(wxKeyEvent &event)
called on key events
Definition: sttool.cpp:1568
void SetDlgOrEditModal(bool dlgOrEditModal)
set style dlg as modal
Definition: mastertool.h:237
void SetSelectUndo(bool onOff)
if set true selecting object will be undoable
Definition: mastertool.h:189
Master tool for objects+wires graphics.
Definition: mastertool.h:475
void SetSelectStroke(const a2dStroke &stroke)
set select stroke
Definition: mastertool.h:216
Master tool for objects graphics slecting and dragging nd zooming.
Definition: mastertool.h:390
virtual bool ZoomSave()
Is Zooming while the tool is busy Save.
Definition: mastertool.h:66
bool GetAllowMultiEdit()
if true, Double Click on N selected objects, leads to editing them as a group
Definition: mastertool.h:186
common stuff for several master tools
Definition: mastertool.h:167
virtual void AbortBusyMode()
Called when the user aborts editing a distinct object */.
Definition: sttool.cpp:1178
const a2dStroke & GetSelectStroke() const
get the select stroke
Definition: mastertool.h:222
struct for how a single object on one layer was hit
Definition: polyver.h:38
void SetSelectFill(const a2dFill &fill)
set select fill
Definition: mastertool.h:207
bool GetDlgOrEdit() const
set dlg at Double Left Down if dlgOrEdit == true
Definition: mastertool.h:234
virtual bool CreateToolObjects()
Create the editcopy and other tool objects (e.g. decorations)
Definition: sttool.cpp:1260
editing tool for a2dCanvasObject&#39;s
virtual void CleanupToolObjects()
Cleanup the editcopy other tool objects (e.g. decorations)
Definition: sttool.cpp:1265
void SetDlgOrEdit(bool dlgOrEdit)
set dlg at Double Left Down if dlgOrEdit == true
Definition: mastertool.h:231
bool GetSelectUndo()
if true selecting object is undoable
Definition: mastertool.h:192
list for a2dCanvasObject
void SetLateConnect(bool lateconnect)
defines if an object will try to connect at the end of a drag
Definition: mastertool.h:245
Draw Master tool for object graphics.
Definition: mastertool.h:122
virtual bool EnterBusyMode()
starts a new action (e.g drawing something ) in a tool that is already pushed.
Definition: sttool.cpp:1147
const a2dFill & GetSelectFill() const
get the select fill
Definition: mastertool.h:213
stack based tools controller and tools for drawing and editing.
A pointer class, that automatically calls SmrtPtrOwn/SmrtPtrRelease.
Definition: a2dlist.h:20
structure to give as parameter to member functions of a2dCanvasObject
Definition: canobj.h:252
mastertool.h Source File -- Sun Oct 12 2014 17:04:22 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation