KiCad PCB EDA Suite
legacy_wx/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@gmail.com>
6  * Copyright (C) 1992-2018 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 <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:
60  bool m_showCrossHair;
61  int m_cursorLevel;
62  int m_scrollIncrementX;
63  int m_scrollIncrementY;
64 
68 
70  wxTimer *m_ClickTimer;
71 
75 
76  bool m_abortRequest;
77 
80 
81  bool m_enableAutoPan;
82 
83  bool m_requestAutoPan;
84 
85  bool m_ignoreMouseEvents;
86 
87  /* Used to inhibit a response to a mouse left button release, after a double click
88  * (when releasing the left button at the end of the second click. Used in Eeschema
89  * to inhibit a mouse left release command when switching between hierarchical sheets
90  * on a double click.
91  */
93 
95 
103 
106  bool m_PrintIsMirrored;
107 
110 
113 
117  int m_canStartBlock;
118 
120 
121 public:
122 
123  EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id, const wxPoint& pos, const wxSize& size );
124  ~EDA_DRAW_PANEL();
125 
131  void* GetDisplayOptions();
132 
134 
135  EDA_DRAW_FRAME* GetParent() const;
136 
137  void OnPaint( wxPaintEvent& event );
138 
139  EDA_RECT* GetClipBox() { return &m_ClipBox; }
140 
141  void SetClipBox( const EDA_RECT& aRect ) { m_ClipBox = aRect; }
142 
143  bool GetAbortRequest() const { return m_abortRequest; }
144 
145  void SetAbortRequest( bool aAbortRequest ) { m_abortRequest = aAbortRequest; }
146 
148 
149  void SetEnableMousewheelPan( bool aEnable );
150 
152 
153  void SetEnableZoomNoCenter( bool aEnable );
154 
155  bool GetEnableAutoPan() const { return m_enableAutoPan; }
156 
157  void SetEnableAutoPan( bool aEnable );
158 
159  void SetAutoPanRequest( bool aEnable ) { m_requestAutoPan = aEnable; }
160 
161  void SetIgnoreMouseEvents( bool aIgnore ) { m_ignoreMouseEvents = aIgnore; }
162 
163  void SetIgnoreLeftButtonReleaseEvent( bool aIgnore ) { m_ignoreNextLeftButtonRelease = aIgnore; }
164 
165  void SetEnableBlockCommands( bool aEnable ) { m_enableBlockCommands = aEnable; }
166 
167  bool GetPrintMirrored() const { return m_PrintIsMirrored; }
168  void SetPrintMirrored( bool aMirror ) { m_PrintIsMirrored = aMirror; }
169 
170  void SetCanStartBlock( int aStartBlock ) { m_canStartBlock = aStartBlock; }
171 
180  void DrawBackGround( wxDC* DC );
181 
190  void DrawGrid( wxDC* aDC );
191 
199  void DrawAuxiliaryAxis( wxDC* aDC, GR_DRAWMODE aDrawMode );
200 
209  void DrawGridAxis( wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aGridOrigin );
210 
211  void OnEraseBackground( wxEraseEvent& event ) { }
212 
222  void OnActivate( wxActivateEvent& event );
223 
233  void OnTimer( wxTimerEvent& event );
234 
249  virtual void DoPrepareDC( wxDC& aDC ) override;
250 
261  wxRect DeviceToLogical( const wxRect& aRect, wxDC& aDC );
262 
263  /* Mouse and keys events */
264 
274  void OnMouseWheel( wxMouseEvent& event );
275 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
276  void OnMagnify( wxMouseEvent& event );
277 #endif
278  void OnMouseEvent( wxMouseEvent& event );
279  void OnMouseEntering( wxMouseEvent& aEvent );
280  void OnMouseLeaving( wxMouseEvent& event );
281  void OnKeyEvent( wxKeyEvent& event );
282  void OnCharHook( wxKeyEvent& event );
283 
284  void OnPan( wxCommandEvent& event );
285 
286  void EraseScreen( wxDC* DC );
287  void OnScrollWin( wxCommandEvent& event );
288  void OnScroll( wxScrollWinEvent& event );
289 
290  void SetZoom( double mode );
291  double GetZoom();
292 
293  void SetGrid( const wxRealPoint& size );
294  wxRealPoint GetGrid();
295 
301  bool OnRightClick( wxMouseEvent& event );
302 
309  bool IsPointOnDisplay( const wxPoint& aPosition );
310 
327  void SetClipBox( wxDC& aDC, const wxRect* aRect = NULL );
328 
329  void ReDraw( wxDC* aDC, bool aEraseBackground = true );
330 
338  void RefreshDrawingRect( const EDA_RECT& aRect, bool aEraseBackground = true );
339 
341  virtual void Refresh( bool eraseBackground = true, const wxRect* rect = NULL ) override;
342 
348 
353  void MoveCursorToCrossHair();
354 
359  wxPoint ToDeviceXY( const wxPoint& pos );
360 
365  wxPoint ToLogicalXY( const wxPoint& pos );
366 
372  void MoveCursor( const wxPoint& aPosition );
373 
374  /* Cursor functions */
387  void DrawCrossHair( wxDC* aDC, COLOR4D aColor = COLOR4D::WHITE );
388 
389  // Hide the cross hair.
390  void CrossHairOff( wxDC* DC );
391 
392  // Show the cross hair.
393  void CrossHairOn( wxDC* DC );
394 
400  void SetMouseCapture( MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback,
401  END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback )
402  {
403  m_mouseCaptureCallback = aMouseCaptureCallback;
404  m_endMouseCaptureCallback = aEndMouseCaptureCallback;
405  }
406 
407 
408  void SetMouseCaptureCallback( MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback )
409  {
410  m_mouseCaptureCallback = aMouseCaptureCallback;
411  }
412 
413 
426  void EndMouseCapture( int aId = -1, int aCursorId = -1,
427  const wxString& aTitle = wxEmptyString,
428  bool aCallEndFunc = true );
429 
430  inline bool IsMouseCaptured() const { return m_mouseCaptureCallback != NULL; }
431 
442  void CallMouseCapture( wxDC* aDC, const wxPoint& aPosition, bool aErase );
443 
450  void CallEndMouseCapture( wxDC* aDC );
451 
456  void SetCurrentCursor( int aCursor )
457  {
458  m_currentCursor = aCursor;
459  SetCursor( (wxStockCursor) m_currentCursor );
460  }
461 
466  int GetDefaultCursor() const { return m_defaultCursor; }
467 
472  int GetCurrentCursor() const { return m_currentCursor; }
473 
474 
475  DECLARE_EVENT_TABLE()
476 };
477 
478 
484 {
485 public:
486  EDA_CROSS_HAIR_MANAGER( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) :
487  m_panel( aPanel ),
488  m_dc( aDC )
489  {
490  if( aPanel && aDC )
491  aPanel->CrossHairOff( aDC );
492  }
493 
495  {
496  if( m_panel && m_dc )
497  m_panel->CrossHairOn( m_dc );
498  }
499 
500 private:
502  wxDC* m_dc;
503 
504  DECLARE_NO_COPY_CLASS( EDA_CROSS_HAIR_MANAGER )
505 };
506 
507 
508 #endif /* #ifndef PANEL_WXSTRUCT_H */
virtual BASE_SCREEN * GetScreen()=0
bool m_abortRequest
Flag used to abort long commands.
int m_canStartBlock
useful to avoid false start block in certain cases (like switch from a sheet to another sheet >= 0 (o...
virtual wxPoint GetScreenCenterLogicalPosition()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetCurrentCursor(int aCursor)
Function SetCurrentCursor Set the current cursor shape for drawpanel.
virtual wxPoint ToDeviceXY(const wxPoint &pos)
Function ToDeviceXY transforms logical to device coordinates.
bool GetEnableAutoPan() const
wxRealPoint GetGrid()
virtual void SetEnableZoomNoCenter(bool aEnable)
void OnScrollWin(wxCommandEvent &event)
bool m_enableZoomNoCenter
True to enable zooming around the crosshair instead of the center.
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...
bool m_PrintIsMirrored
True when drawing in mirror mode.
virtual void DrawGrid(wxDC *aDC)
Function DrawGrid draws a grid to aDC.
END_MOUSE_CAPTURE_CALLBACK m_endMouseCaptureCallback
Abort mouse capture callback function.
virtual 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)
virtual void RefreshDrawingRect(const EDA_RECT &aRect, bool aEraseBackground=true)
Function RefreshDrawingRect redraws the contents of aRect in drawing units.
wxPoint m_PanStartEventPosition
Initial position of mouse event when pan started.
virtual void MoveCursor(const wxPoint &aPosition)
Function MoveCursor moves the mouse pointer to aPosition in logical (drawing) units.
void OnPan(wxCommandEvent &event)
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
virtual void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
bool m_enableBlockCommands
True enables block commands.
virtual 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.
virtual 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...
virtual EDA_DRAW_FRAME * GetParent() const =0
virtual wxPoint ToLogicalXY(const wxPoint &pos)
Function ToLogicalXY transforms device to logical coordinates.
void OnTimer(wxTimerEvent &event)
Function OnTimer handle timer events.
void OnPaint(wxPaintEvent &event)
virtual bool IsPointOnDisplay(const wxPoint &aPosition)
Function IsPointOnDisplay.
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:37
void OnMouseLeaving(wxMouseEvent &event)
virtual void CrossHairOn(wxDC *DC=nullptr)
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
void(* MOUSE_CAPTURE_CALLBACK)(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Mouse capture callback function prototype.
bool GetEnableZoomNoCenter() const
bool m_ignoreMouseEvents
Ignore mouse events when true.
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
virtual void SetZoom(double mode)
virtual wxRect DeviceToLogical(const wxRect &aRect, wxDC &aDC)
Function DeviceToLogical converts aRect from device to drawing (logical) coordinates.
virtual void DrawCrossHair(wxDC *aDC=nullptr, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
virtual void CrossHairOff(wxDC *DC=nullptr)
void SetAutoPanRequest(bool aEnable)
void OnMouseEntering(wxMouseEvent &aEvent)
void SetMouseCaptureCallback(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback)
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.
void(* END_MOUSE_CAPTURE_CALLBACK)(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
End mouse capture callback function prototype.
wxPoint m_PanStartCenter
Initial scroll center position when pan started.
bool m_showCrossHair
Indicate if cross hair is to be shown.
wxPoint m_CursorClickPos
Used for maintaining click position.
virtual void ReDraw(wxDC *aDC, bool aEraseBackground=true)
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.
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.
Definition: eda_rect.h:44
virtual void SetEnableMousewheelPan(bool aEnable)
void SetGrid(const wxRealPoint &size)
bool OnRightClick(wxMouseEvent &event)
Function OnRightClick builds and displays a context menu on a right mouse button click.
Definition: colors.h:49
void SetPrintMirrored(bool aMirror)
void SetEnableBlockCommands(bool aEnable)
virtual void DrawAuxiliaryAxis(wxDC *aDC, GR_DRAWMODE aDrawMode)
Function DrawAuxiliaryAxis Draw the Auxiliary Axis, used in Pcbnew which as origin coordinates for ge...
int m_minDragEventCount
Count the drag events.
wxPoint m_CursorStartPos
Used for testing the cursor movement.
virtual void DrawBackGround(wxDC *DC)
Function DrawBackGround.
bool m_enableAutoPan
True to enable automatic panning.
virtual void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Basic classes for most KiCad items.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
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.
virtual void EraseScreen(wxDC *DC)
Function OnMouseWheel handles mouse wheel events.
virtual 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.
void OnScroll(wxScrollWinEvent &event)
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)