KiCad PCB EDA Suite
class_drawpanel.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef PANEL_WXSTRUCT_H
32 #define PANEL_WXSTRUCT_H
33 
34 #include <base_struct.h>
35 #include <gr_basic.h>
36 #include <class_eda_rect.h>
37 
38 
39 class BASE_SCREEN;
40 class PCB_SCREEN;
41 
42 
46 typedef void ( *MOUSE_CAPTURE_CALLBACK )( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
47  const wxPoint& aPosition, bool aErase );
48 
52 typedef void ( *END_MOUSE_CAPTURE_CALLBACK )( EDA_DRAW_PANEL* aPanel, wxDC* aDC );
53 
54 
55 class EDA_DRAW_PANEL : public wxScrolledWindow
56 {
57 private:
64 
68 
72 
74 
77 
79 
81 
83 
84  /* Used to inhibit a response to a mouse left button release, after a double click
85  * (when releasing the left button at the end of the second click. Used in Eeschema
86  * to inhibit a mouse left release command when switching between hierarchical sheets
87  * on a double click.
88  */
90 
92 
100 
104 
107 
110 
115 
116 public:
117 
118  EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id, const wxPoint& pos, const wxSize& size );
119  ~EDA_DRAW_PANEL();
120 
126  void* GetDisplayOptions();
127 
129 
130  EDA_DRAW_FRAME* GetParent() const;
131 
132  void OnPaint( wxPaintEvent& event );
133 
134  EDA_RECT* GetClipBox() { return &m_ClipBox; }
135 
136  void SetClipBox( const EDA_RECT& aRect ) { m_ClipBox = aRect; }
137 
138  bool GetAbortRequest() const { return m_abortRequest; }
139 
140  void SetAbortRequest( bool aAbortRequest ) { m_abortRequest = aAbortRequest; }
141 
143 
144  void SetEnableMousewheelPan( bool aEnable );
145 
147 
148  void SetEnableZoomNoCenter( bool aEnable );
149 
150  bool GetEnableAutoPan() const { return m_enableAutoPan; }
151 
152  void SetEnableAutoPan( bool aEnable ) { m_enableAutoPan = aEnable; }
153 
154  void SetAutoPanRequest( bool aEnable ) { m_requestAutoPan = aEnable; }
155 
156  void SetIgnoreMouseEvents( bool aIgnore ) { m_ignoreMouseEvents = aIgnore; }
157 
158  void SetIgnoreLeftButtonReleaseEvent( bool aIgnore ) { m_ignoreNextLeftButtonRelease = aIgnore; }
159 
160  void SetEnableBlockCommands( bool aEnable ) { m_enableBlockCommands = aEnable; }
161 
162  bool GetPrintMirrored() const { return m_PrintIsMirrored; }
163  void SetPrintMirrored( bool aMirror ) { m_PrintIsMirrored = aMirror; }
164 
165  void SetCanStartBlock( int aStartBlock ) { m_canStartBlock = aStartBlock; }
166 
175  void DrawBackGround( wxDC* DC );
176 
185  void DrawGrid( wxDC* aDC );
186 
194  void DrawAuxiliaryAxis( wxDC* aDC, GR_DRAWMODE aDrawMode );
195 
204  void DrawGridAxis( wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aGridOrigin );
205 
206  void OnEraseBackground( wxEraseEvent& event ) { }
207 
217  void OnActivate( wxActivateEvent& event );
218 
233  virtual void DoPrepareDC( wxDC& aDC ) override;
234 
245  wxRect DeviceToLogical( const wxRect& aRect, wxDC& aDC );
246 
247  /* Mouse and keys events */
248 
258  void OnMouseWheel( wxMouseEvent& event );
259 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
260  void OnMagnify( wxMouseEvent& event );
261 #endif
262  void OnMouseEvent( wxMouseEvent& event );
263  void OnMouseEntering( wxMouseEvent& aEvent );
264  void OnMouseLeaving( wxMouseEvent& event );
265  void OnKeyEvent( wxKeyEvent& event );
266  void OnCharHook( wxKeyEvent& event );
267 
268  void OnPan( wxCommandEvent& event );
269 
270  void EraseScreen( wxDC* DC );
271  void OnScrollWin( wxCommandEvent& event );
272  void OnScroll( wxScrollWinEvent& event );
273 
274  void SetZoom( double mode );
275  double GetZoom();
276 
277  void SetGrid( const wxRealPoint& size );
278  wxRealPoint GetGrid();
279 
285  bool OnRightClick( wxMouseEvent& event );
286 
293  bool IsPointOnDisplay( const wxPoint& aPosition );
294 
311  void SetClipBox( wxDC& aDC, const wxRect* aRect = NULL );
312 
313  void ReDraw( wxDC* aDC, bool aEraseBackground = true );
314 
322  void RefreshDrawingRect( const EDA_RECT& aRect, bool aEraseBackground = true );
323 
325  virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ) override;
326 
332 
337  void MoveCursorToCrossHair();
338 
343  wxPoint ToDeviceXY( const wxPoint& pos );
344 
349  wxPoint ToLogicalXY( const wxPoint& pos );
350 
356  void MoveCursor( const wxPoint& aPosition );
357 
358  /* Cursor functions */
371  void DrawCrossHair( wxDC* aDC, COLOR4D aColor = COLOR4D::WHITE );
372 
373  // Hide the cross hair.
374  void CrossHairOff( wxDC* DC );
375 
376  // Show the cross hair.
377  void CrossHairOn( wxDC* DC );
378 
384  void SetMouseCapture( MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback,
385  END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback )
386  {
387  m_mouseCaptureCallback = aMouseCaptureCallback;
388  m_endMouseCaptureCallback = aEndMouseCaptureCallback;
389  }
390 
391 
392  void SetMouseCaptureCallback( MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback )
393  {
394  m_mouseCaptureCallback = aMouseCaptureCallback;
395  }
396 
397 
410  void EndMouseCapture( int aId = -1, int aCursorId = -1,
411  const wxString& aTitle = wxEmptyString,
412  bool aCallEndFunc = true );
413 
414  inline bool IsMouseCaptured() const { return m_mouseCaptureCallback != NULL; }
415 
426  void CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase );
427 
434  void CallEndMouseCapture( wxDC* aDC );
435 
440  void SetCurrentCursor( int aCursor )
441  {
442  m_currentCursor = aCursor;
443  SetCursor( (wxStockCursor) m_currentCursor );
444  }
445 
450  int GetDefaultCursor() const { return m_defaultCursor; }
451 
456  int GetCurrentCursor() const { return m_currentCursor; }
457 
458 
459  DECLARE_EVENT_TABLE()
460 };
461 
462 
468 {
469 public:
470  EDA_CROSS_HAIR_MANAGER( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) :
471  m_panel( aPanel ),
472  m_dc( aDC )
473  {
474  if( aPanel && aDC )
475  aPanel->CrossHairOff( aDC );
476  }
477 
479  {
480  if( m_panel && m_dc )
482  }
483 
484 private:
486  wxDC* m_dc;
487 
488  DECLARE_NO_COPY_CLASS( EDA_CROSS_HAIR_MANAGER )
489 };
490 
491 
492 #endif /* #ifndef PANEL_WXSTRUCT_H */
bool m_abortRequest
Flag used to abort long commands.
double GetZoom()
Definition: draw_panel.cpp:270
int m_canStartBlock
useful to avoid false start block in certain cases (like switch from a sheet to an other sheet >= 0 (...
wxPoint GetScreenCenterLogicalPosition()
Function GetScreenCenterLogicalPosition.
Definition: draw_panel.cpp:339
void SetCurrentCursor(int aCursor)
Function SetCurrentCursor Set the current cursor shape for drawpanel.
void(* MOUSE_CAPTURE_CALLBACK)(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Mouse capture callback function prototype.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
wxPoint ToDeviceXY(const wxPoint &pos)
Function ToDeviceXY transforms logical to device coordinates.
Definition: draw_panel.cpp:196
bool GetEnableAutoPan() const
wxRealPoint GetGrid()
Definition: draw_panel.cpp:282
void SetEnableZoomNoCenter(bool aEnable)
Definition: draw_panel.cpp:657
void OnScrollWin(wxCommandEvent &event)
bool m_enableZoomNoCenter
True to enable zooming around the crosshair instead of the center.
EDA_DRAW_PANEL * m_panel
int m_scrollIncrementX
X axis scroll increment in pixels per unit.
int GetCurrentCursor() const
Function GetCurrentCursor.
bool m_requestAutoPan
true to request an auto pan. Valid only when m_enableAutoPan = true.
EDA_RECT m_ClipBox
The drawing area used to redraw the screen which is usually the visible area of the drawing in intern...
EDA_DRAW_PANEL(EDA_DRAW_FRAME *parent, int id, const wxPoint &pos, const wxSize &size)
Definition: draw_panel.cpp:99
void DrawCrossHair(wxDC *aDC, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
Definition: draw_panel.cpp:216
bool m_PrintIsMirrored
True when drawing in mirror mode.
void DrawGrid(wxDC *aDC)
Function DrawGrid draws a grid to aDC.
Definition: draw_panel.cpp:695
END_MOUSE_CAPTURE_CALLBACK m_endMouseCaptureCallback
Abort mouse capture callback function.
void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
void OnKeyEvent(wxKeyEvent &event)
EDA_CROSS_HAIR_MANAGER(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
void SetCanStartBlock(int aStartBlock)
void(* END_MOUSE_CAPTURE_CALLBACK)(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
End mouse capture callback function prototype.
void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
Definition: draw_panel.cpp:306
wxPoint m_PanStartEventPosition
Initial position of mouse event when pan started.
wxRect DeviceToLogical(const wxRect &aRect, wxDC &aDC)
Function DeviceToLogical converts aRect from device to drawing (logical) coordinates.
void MoveCursor(const wxPoint &aPosition)
Function MoveCursor moves the mouse pointer to aPosition in logical (drawing) units.
Definition: draw_panel.cpp:354
void OnPan(wxCommandEvent &event)
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:348
bool m_enableBlockCommands
True enables block commands.
void CallEndMouseCapture(wxDC *aDC)
Function CallEndMouseCapture calls the end mouse capture callback.
void OnMouseEvent(wxMouseEvent &event)
void SetClipBox(const EDA_RECT &aRect)
MOUSE_CAPTURE_CALLBACK m_mouseCaptureCallback
Mouse capture move callback function.
void DrawGridAxis(wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aGridOrigin)
Function DrawGridAxis Draw on auxiliary axis, used in Pcbnew to show grid origin, when the grid origi...
Definition: draw_panel.cpp:834
wxPoint ToLogicalXY(const wxPoint &pos)
Function ToLogicalXY transforms device to logical coordinates.
Definition: draw_panel.cpp:206
void OnPaint(wxPaintEvent &event)
Definition: draw_panel.cpp:592
bool IsPointOnDisplay(const wxPoint &aPosition)
Function IsPointOnDisplay.
Definition: draw_panel.cpp:288
void OnEraseBackground(wxEraseEvent &event)
Class EDA_CROSS_HAIR_MANAGER is used to hide the cross hair and restore it when the class goes out of...
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
void OnMouseLeaving(wxMouseEvent &event)
Definition: draw_panel.cpp:916
bool IsMouseCaptured() const
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
bool GetEnableZoomNoCenter() const
bool m_ignoreMouseEvents
Ignore mouse events when true.
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
void SetZoom(double mode)
Definition: draw_panel.cpp:276
EDA_RECT * GetClipBox()
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
void SetAutoPanRequest(bool aEnable)
void OnMouseEntering(wxMouseEvent &aEvent)
Definition: draw_panel.cpp:905
void SetMouseCaptureCallback(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback)
void CrossHairOff(wxDC *DC)
Definition: draw_panel.cpp:253
bool m_ignoreNextLeftButtonRelease
Ignore the next mouse left button release when true.
void SetAbortRequest(bool aAbortRequest)
void OnMouseWheel(wxMouseEvent &event)
Function OnMouseWheel handles mouse wheel events.
Definition: draw_panel.cpp:950
wxPoint m_PanStartCenter
Initial scroll center position when pan started.
bool m_showCrossHair
Indicate if cross hair is to be shown.
bool GetAbortRequest() const
void CrossHairOn(wxDC *DC)
Definition: draw_panel.cpp:260
void ReDraw(wxDC *aDC, bool aEraseBackground=true)
Definition: draw_panel.cpp:608
void OnCharHook(wxKeyEvent &event)
bool GetPrintMirrored() const
bool GetEnableMousewheelPan() const
bool m_enableMousewheelPan
True to enable mousewheel panning by default.
void OnActivate(wxActivateEvent &event)
Function OnActivate handles window activation events.
Definition: draw_panel.cpp:401
int m_currentCursor
Current mouse cursor shape id.
int m_defaultCursor
The default mouse cursor shape id.
void SetIgnoreMouseEvents(bool aIgnore)
Class EDA_RECT handles the component boundary box.
void SetEnableMousewheelPan(bool aEnable)
Definition: draw_panel.cpp:648
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
void SetGrid(const wxRealPoint &size)
bool OnRightClick(wxMouseEvent &event)
Function OnRightClick builds and displays a context menu on a right mouse button click.
Definition: draw_panel.cpp:870
Definition: colors.h:49
void SetPrintMirrored(bool aMirror)
void SetEnableBlockCommands(bool aEnable)
void DrawAuxiliaryAxis(wxDC *aDC, GR_DRAWMODE aDrawMode)
Function DrawAuxiliaryAxis Draw the Auxiliary Axis, used in Pcbnew which as origin coordinates for ge...
Definition: draw_panel.cpp:796
int m_minDragEventCount
Count the drag events.
wxPoint m_CursorStartPos
Used for testing the cursor movement.
void DrawBackGround(wxDC *DC)
Function DrawBackGround.
Definition: draw_panel.cpp:666
bool m_enableAutoPan
True to enable automatic panning.
void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_panel.cpp:182
Basic classes for most KiCad items.
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
int GetDefaultCursor() const
Function GetDefaultCursor.
void EraseScreen(wxDC *DC)
Definition: draw_panel.cpp:554
void SetEnableAutoPan(bool aEnable)
int m_cursorLevel
Index for cursor redraw in XOR mode.
virtual void DoPrepareDC(wxDC &aDC) override
Function DoPrepareDC sets up the device context aDC for drawing.
Definition: draw_panel.cpp:573
void OnScroll(wxScrollWinEvent &event)
Definition: draw_panel.cpp:408
int m_scrollIncrementY
Y axis scroll increment in pixels per unit.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
void SetIgnoreLeftButtonReleaseEvent(bool aIgnore)