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  * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #ifndef PANELGAL_WXSTRUCT_H
29 #define PANELGAL_WXSTRUCT_H
30 
31 #include <wx/window.h>
32 #include <wx/timer.h>
33 #include <wx/grid.h> // needed for MSVC to see wxScrolledCanvas indirectly exported
34 #include <math/box2.h>
35 #include <math/vector2d.h>
36 #include <widgets/msgpanel.h>
37 #include <memory>
38 
39 #include <gal/cursors.h>
40 
41 class BOARD;
42 class EDA_DRAW_FRAME;
43 class TOOL_DISPATCHER;
44 
45 namespace KIGFX
46 {
47 class GAL;
48 class VIEW;
49 class WX_VIEW_CONTROLS;
50 class VIEW_CONTROLS;
51 class PAINTER;
52 class GAL_DISPLAY_OPTIONS;
53 class VIEW_OVERLAY;
54 }
55 
56 
57 class EDA_DRAW_PANEL_GAL : public wxScrolledCanvas
58 {
59 public:
60  enum GAL_TYPE {
66  };
67 
68 #ifdef __WXMAC__
69  // Cairo doesn't work on OSX so we really have no fallback available.
70  static constexpr GAL_TYPE GAL_FALLBACK = GAL_TYPE_OPENGL;
71 #else
72  static constexpr GAL_TYPE GAL_FALLBACK = GAL_TYPE_CAIRO;
73 #endif
74 
83  EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
84  const wxPoint& aPosition, const wxSize& aSize,
86  GAL_TYPE aGalType = GAL_TYPE_OPENGL );
88 
89  virtual void SetFocus() override;
90 
96  virtual bool SwitchBackend( GAL_TYPE aGalType );
97 
101  inline GAL_TYPE GetBackend() const { return m_backend; }
102 
108  KIGFX::GAL* GetGAL() const { return m_gal; }
109 
115  virtual KIGFX::VIEW* GetView() const { return m_view; }
116 
123  {
125  }
126 
128  virtual void Refresh( bool aEraseBackground = true, const wxRect* aRect = nullptr ) override;
129 
133  void ForceRefresh();
134 
143  void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
144 
148  void StartDrawing();
149 
154  void StopDrawing();
155 
159  virtual void SetHighContrastLayer( int aLayer );
160 
164  virtual void SetTopLayer( int aLayer );
165 
166  virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
167  {
168  wxASSERT( false );
169  }
170 
175 
176  bool IsDialogPreview() const { return m_parent != (wxWindow*) m_edaFrame; }
177 
181  virtual void OnShow() {}
182 
189  void SetStealsFocus( bool aStealsFocus ) { m_stealsFocus = aStealsFocus; }
190 
194  void SetCurrentCursor( KICURSOR aCursor );
195 
202  virtual BOX2I GetDefaultViewBBox() const { return BOX2I(); }
203 
207  void OnEvent( wxEvent& aEvent );
208 
216  void DoRePaint();
217 
221  std::shared_ptr<KIGFX::VIEW_OVERLAY> DebugOverlay();
222 
223 
227  void ClearDebugOverlay();
228 
235 
236 protected:
237  virtual void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
238  void onSize( wxSizeEvent& aEvent );
239  void onEnter( wxMouseEvent& aEvent );
240  void onLostFocus( wxFocusEvent& aEvent );
241  void onRefreshTimer( wxTimerEvent& aEvent );
242  void onShowTimer( wxTimerEvent& aEvent );
243 
244  static const int MinRefreshPeriod = 17;
245 
246  wxWindow* m_parent;
248 
249  wxLongLong m_lastRefresh;
251  wxTimer m_refreshTimer;
252 
254  bool m_drawing;
255 
258 
260  wxTimer m_onShowTimer;
261 
264 
267 
269  std::unique_ptr<KIGFX::PAINTER> m_painter;
270 
273 
277 
280 
284 
288 
290  std::shared_ptr<KIGFX::VIEW_OVERLAY> m_debugOverlay;
291 };
292 
293 #endif
bool m_pendingRefresh
Is there a redraw event requested?
wxTimer m_refreshTimer
Timer to prevent too-frequent refreshing.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
BOX2< VECTOR2I > BOX2I
Definition: box2.h:506
virtual void SetHighContrastLayer(int aLayer)
Take care of display settings for the given layer to be displayed in high contrast mode.
void ForceRefresh()
Force a redraw.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
GAL_TYPE m_backend
Currently used GAL.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
An implementation of class VIEW_CONTROLS for wxWidgets library.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
KIGFX::GAL_DISPLAY_OPTIONS & m_options
virtual void OnShow()
Called when the window is shown for the first time.
static constexpr GAL_TYPE GAL_FALLBACK
void onLostFocus(wxFocusEvent &aEvent)
KICURSOR
Definition: cursors.h:33
void DoRePaint()
Repaint the canvas, and fix scrollbar cursors.
Sentinel, do not use as a parameter.
void onShowTimer(wxTimerEvent &aEvent)
The base class for create windows for drawing purpose.
not specified: a GAL engine must be set by the client
void ClearDebugOverlay()
Clear the contents of the debug overlay and removes it from the VIEW.
void onEnter(wxMouseEvent &aEvent)
void onRefreshTimer(wxTimerEvent &aEvent)
bool m_drawing
True if GAL is currently redrawing the view.
wxWindow * m_parent
Pointer to the parent window.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent))
GAL not used (the legacy wxDC engine is used)
static const int MinRefreshPeriod
60 FPS.
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
virtual void SetTopLayer(int aLayer)
Move the selected layer to the top, so it is displayed above all others.
void SetStealsFocus(bool aStealsFocus)
Set whether focus is taken on certain events (mouseover, keys, etc).
An interface for classes handling user events controlling the view behavior such as zooming,...
EDA_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Create a drawing panel that is contained inside aParentWindow.
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
bool m_lostFocus
Flag to indicate that focus should be regained on the next mouse event.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
virtual void SetFocus() override
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
void onSize(wxSizeEvent &aEvent)
void StartDrawing()
Begin drawing if it was stopped previously.
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.
bool m_MouseCapturedLost
used on wxMSW: true after a wxEVT_MOUSE_CAPTURE_LOST was received false after the mouse is recaptured...
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_debugOverlay
Optional overlay for drawing transient debug objects.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
bool m_drawingEnabled
Flag that determines if VIEW may use GAL for redrawing the screen.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxLongLong m_lastRefresh
Last timestamp when the panel was refreshed.
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
bool m_stealsFocus
Flag to indicate whether the panel should take focus at certain times (when moused over,...
Message panel definition file.
std::shared_ptr< KIGFX::VIEW_OVERLAY > DebugOverlay()
Create an overlay for rendering debug graphics.
virtual BOX2I GetDefaultViewBBox() const
Return the bounding box of the view that should be used if model is not valid.
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
Abstract interface for drawing on a 2D-surface.