KiCad PCB EDA Suite
class_draw_panel_gal.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) 2013-2018 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 PANELGAL_WXSTRUCT_H
32 #define PANELGAL_WXSTRUCT_H
33 
34 #include <wx/window.h>
35 #include <wx/timer.h>
36 #include <math/box2.h>
37 #include <math/vector2d.h>
38 #include <msgpanel.h>
39 #include <memory>
40 #include <common.h>
41 
42 class BOARD;
43 class EDA_DRAW_FRAME;
44 class TOOL_DISPATCHER;
45 
46 namespace KIGFX
47 {
48 class GAL;
49 class VIEW;
50 class WX_VIEW_CONTROLS;
51 class VIEW_CONTROLS;
52 class PAINTER;
53 class GAL_DISPLAY_OPTIONS;
54 }
55 
56 
57 class EDA_DRAW_PANEL_GAL : public wxScrolledCanvas
58 {
59 public:
60  enum GAL_TYPE {
64  GAL_TYPE_LAST
65  };
66 
67  EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition,
68  const wxSize& aSize, KIGFX::GAL_DISPLAY_OPTIONS& aOptions,
69  GAL_TYPE aGalType = GAL_TYPE_OPENGL );
71 
72  virtual void SetFocus() override;
73 
79  virtual bool SwitchBackend( GAL_TYPE aGalType );
80 
85  inline GAL_TYPE GetBackend() const
86  {
87  return m_backend;
88  }
89 
95  KIGFX::GAL* GetGAL() const
96  {
97  return m_gal;
98  }
99 
106  {
107  return m_view;
108  }
109 
116  {
117  return (KIGFX::VIEW_CONTROLS*)( m_viewControls );
118  }
119 
121  virtual void Refresh( bool aEraseBackground = true, const wxRect* aRect = NULL ) override;
122 
127  void ForceRefresh();
128 
136  void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
137 
142  void StartDrawing();
143 
149  void StopDrawing();
150 
155  virtual void SetHighContrastLayer( int aLayer );
156 
161  virtual void SetTopLayer( int aLayer );
162 
163  virtual void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector<MSG_PANEL_ITEM>& aList )
164  {
165  wxASSERT( false );
166  }
167 
172  double GetLegacyZoom() const;
173 
179  {
180  return m_edaFrame;
181  }
182 
187  virtual void OnShow() {}
188 
194  void SetStealsFocus( bool aStealsFocus )
195  {
196  m_stealsFocus = aStealsFocus;
197  }
198 
202  bool GetStealsFocus() const
203  {
204  return m_stealsFocus;
205  }
206 
207  virtual void SetDefaultCursor();
212  virtual void SetCurrentCursor( int aCursor );
213 
218  virtual int GetDefaultCursor() const { return m_defaultCursor; }
219 
224  int GetCurrentCursor() const { return m_currentCursor; }
225 
232  virtual BOX2I GetDefaultViewBBox() const
233  {
234  return BOX2I();
235  }
236 
240  void OnEvent( wxEvent& aEvent );
241 
242 protected:
243  virtual void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
244  void onSize( wxSizeEvent& aEvent );
245  void onEnter( wxEvent& aEvent );
246  void onLostFocus( wxFocusEvent& aEvent );
247  void onRefreshTimer( wxTimerEvent& aEvent );
248  void onShowTimer( wxTimerEvent& aEvent );
249 
250  static const int MinRefreshPeriod = 17;
251 
256 
258  wxWindow* m_parent;
259 
262 
264  wxLongLong m_lastRefresh;
265 
268 
270  bool m_drawing;
271 
274 
276  wxTimer m_refreshTimer;
277 
279  wxTimer m_onShowTimer;
280 
283 
286 
288  std::unique_ptr<KIGFX::PAINTER> m_painter;
289 
292 
296 
299 
303 
307 };
308 
309 #endif
bool m_pendingRefresh
Is there a redraw event requested?
wxTimer m_refreshTimer
Timer responsible for preventing too frequent refresh.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
GAL_TYPE m_backend
Currently used GAL.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library...
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
EDA_DRAW_FRAME * GetParentEDAFrame() const
Function GetParentEDAFrame() Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
KIGFX::GAL_DISPLAY_OPTIONS & m_options
virtual void OnShow()
Function OnShow() Called when the window is shown for the first time.
int GetCurrentCursor() const
Function GetCurrentCursor.
int m_currentCursor
Current mouse cursor shape id.
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
int m_defaultCursor
The default mouse cursor shape id.
bool m_drawing
True if GAL is currently redrawing the view.
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
wxWindow * m_parent
Pointer to the parent window.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
void SetStealsFocus(bool aStealsFocus)
Set whether focus is taken on certain events (mouseover, keys, etc).
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
bool m_lostFocus
Flag to indicate that focus should be regained on the next mouse event.
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
virtual int GetDefaultCursor() const
Function GetDefaultCursor.
virtual BOX2I GetDefaultViewBBox() const
Returns the bounding box of the view that should be used if model is not valid For example...
Class TOOL_DISPATCHER.
bool GetStealsFocus() const
Get whether focus is taken on certain events (see SetStealsFocus()).
TOOL_DISPATCHER * m_eventDispatcher
Processes and forwards events to tools.
wxTimer m_onShowTimer
Timer used to execute OnShow() when the window finally appears on the screen.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
bool m_drawingEnabled
Flag that determines if VIEW may use GAL for redrawing the screen.
The common library.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel...
wxLongLong m_lastRefresh
Last timestamp when the panel was refreshed.
Class VIEW.
Definition: view.h:61
bool m_stealsFocus
Flag to indicate whether the panel should take focus at certain times (when moused over...
Message panel definition file.
EDA_UNITS_T
Definition: common.h:159
Class GAL is the abstract interface for drawing on a 2D-surface.