From 2bc57ade28a0e1e1aab1fd2fe6503ac4e5fbd623 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Tue, 19 May 2020 23:54:05 +0100 Subject: [PATCH] Cleanup parentage inside the draw panels --- common/draw_panel_gal.cpp | 28 ++++++++++++++------------- eeschema/sch_draw_panel.cpp | 13 ++++++------- eeschema/sch_draw_panel.h | 3 --- eeschema/sch_preview_panel.cpp | 3 +-- eeschema/sch_preview_panel.h | 2 -- gerbview/gerbview_draw_panel_gal.cpp | 4 ++-- include/class_draw_panel_gal.h | 29 ++++++++++++++++++---------- pcbnew/pcb_draw_panel_gal.cpp | 6 +++--- 8 files changed, 46 insertions(+), 42 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index a3c7f602a5..11b277f378 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -49,24 +49,26 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, const wxSize& aSize, - KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : - wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ), - m_options( aOptions ) + KIGFX::GAL_DISPLAY_OPTIONS& aOptions, + GAL_TYPE aGalType ) + : wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ), + m_edaFrame( nullptr ), + m_gal( nullptr ), + m_view( nullptr ), + m_painter( nullptr ), + m_backend( GAL_TYPE_NONE ), + m_options( aOptions ), + m_eventDispatcher( nullptr ), + m_lostFocus( false ), + m_stealsFocus( true ) { - m_parent = aParentWindow; - m_edaFrame = dynamic_cast( aParentWindow ); - m_gal = NULL; - m_backend = GAL_TYPE_NONE; - m_view = NULL; - m_painter = NULL; - m_eventDispatcher = NULL; - m_lostFocus = false; - m_stealsFocus = true; - + m_parent = aParentWindow; m_currentCursor = wxStockCursor( wxCURSOR_ARROW ); SetLayoutDirection( wxLayout_LeftToRight ); + m_edaFrame = dynamic_cast( m_parent ); + // If we're in a dialog, we have to go looking for our parent frame if( !m_edaFrame ) { diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index e1a7484702..2bb5d6d8b2 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -52,12 +52,11 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, const wxSize& aSize, - KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : - EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ), - m_parent( aParentWindow ) + KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) + : EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ) { m_currentCursor = wxCURSOR_ARROW; - m_view = new KIGFX::SCH_VIEW( true, dynamic_cast( aParentWindow ) ); + m_view = new KIGFX::SCH_VIEW( true, dynamic_cast( GetParentEDAFrame() ) ); m_view->SetGAL( m_gal ); m_gal->SetWorldUnitLength( SCH_WORLD_UNIT ); @@ -66,7 +65,7 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, COLOR_SETTINGS* cs = nullptr; - if( auto frame = dynamic_cast( aParentWindow ) ) + if( auto frame = dynamic_cast( GetParentEDAFrame() ) ) cs = frame->GetColorSettings(); else cs = Pgm().GetSettingsManager().GetColorSettings(); @@ -145,7 +144,7 @@ bool SCH_DRAW_PANEL::SwitchBackend( GAL_TYPE aGalType ) // Keep grid size and grid visibility: m_gal->SetGridSize( grid_size ); - SCH_BASE_FRAME* frame = dynamic_cast( GetParent() ); + SCH_BASE_FRAME* frame = dynamic_cast( GetParentEDAFrame() ); if( frame ) m_gal->SetGridVisibility( frame->IsGridVisible() ); @@ -190,7 +189,7 @@ KIGFX::SCH_VIEW* SCH_DRAW_PANEL::GetView() const void SCH_DRAW_PANEL::OnShow() { - SCH_BASE_FRAME* frame = dynamic_cast( GetParent() ); + SCH_BASE_FRAME* frame = dynamic_cast( GetParentEDAFrame() ); try { diff --git a/eeschema/sch_draw_panel.h b/eeschema/sch_draw_panel.h index e5a993870d..92050270a5 100644 --- a/eeschema/sch_draw_panel.h +++ b/eeschema/sch_draw_panel.h @@ -59,9 +59,6 @@ protected: void setDefaultLayerOrder(); ///> Reassigns layer order to the initial settings. void setDefaultLayerDeps(); ///> Sets rendering targets & dependencies for layers. - -protected: - wxWindow* m_parent; }; #endif diff --git a/eeschema/sch_preview_panel.cpp b/eeschema/sch_preview_panel.cpp index 6f358b669f..da6a3e240e 100644 --- a/eeschema/sch_preview_panel.cpp +++ b/eeschema/sch_preview_panel.cpp @@ -44,8 +44,7 @@ using namespace std::placeholders; SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, const wxSize& aSize, KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : - EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ), - m_parent( aParentWindow ) + EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ) { m_view = new KIGFX::SCH_VIEW( true, nullptr ); m_view->SetGAL( m_gal ); diff --git a/eeschema/sch_preview_panel.h b/eeschema/sch_preview_panel.h index 13d1aed541..78df79617e 100644 --- a/eeschema/sch_preview_panel.h +++ b/eeschema/sch_preview_panel.h @@ -66,8 +66,6 @@ protected: ///> Sets rendering targets & dependencies for layers. void setDefaultLayerDeps(); - - wxWindow* m_parent; }; #endif diff --git a/gerbview/gerbview_draw_panel_gal.cpp b/gerbview/gerbview_draw_panel_gal.cpp index e15a318b79..09d55fc78a 100644 --- a/gerbview/gerbview_draw_panel_gal.cpp +++ b/gerbview/gerbview_draw_panel_gal.cpp @@ -96,7 +96,7 @@ void GERBVIEW_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, void GERBVIEW_DRAW_PANEL_GAL::OnShow() { - GERBVIEW_FRAME* frame = dynamic_cast( GetParent() ); + GERBVIEW_FRAME* frame = dynamic_cast( GetParentEDAFrame() ); if( frame ) { @@ -118,7 +118,7 @@ bool GERBVIEW_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) // after switching to opengl. Clearing m_view and rebuild it is much faster if( aGalType == GAL_TYPE_OPENGL ) { - GERBVIEW_FRAME* frame = dynamic_cast( GetParent() ); + GERBVIEW_FRAME* frame = dynamic_cast( GetParentEDAFrame() ); if( frame ) { diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index 639972c890..ad8ef0c383 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -60,8 +60,17 @@ public: GAL_TYPE_LAST ///< Sentinel, do not use as a parameter }; - EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, - const wxSize& aSize, KIGFX::GAL_DISPLAY_OPTIONS& aOptions, + /** + * Create a drawing panel that is contained inside \p aParentWindow. + * + * If \p aParentWindow is not an EDA frame, a search through all the parents + * of the parent window will be done to find the frame. + * + * @param aParentWindow is the window immeidately containing this panel + */ + 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 ); ~EDA_DRAW_PANEL_GAL(); @@ -206,16 +215,16 @@ protected: void onShowTimer( wxTimerEvent& aEvent ); void onSetCursor( wxSetCursorEvent& event ); - static const int MinRefreshPeriod = 17; ///< 60 FPS. + static const int MinRefreshPeriod = 17; ///< 60 FPS. - wxCursor m_currentCursor; /// Current mouse cursor shape id. + wxCursor m_currentCursor; ///< Current mouse cursor shape id. - wxWindow* m_parent; /// Pointer to the parent window - EDA_DRAW_FRAME* m_edaFrame; /// Parent EDA_DRAW_FRAME (if available) + wxWindow* m_parent; ///< Pointer to the parent window + EDA_DRAW_FRAME* m_edaFrame; ///< Parent EDA_DRAW_FRAME (if available) - wxLongLong m_lastRefresh; /// Last timestamp when the panel was refreshed - bool m_pendingRefresh; /// Is there a redraw event requested? - wxTimer m_refreshTimer; /// Timer to prevent too-frequent refreshing + wxLongLong m_lastRefresh; ///< Last timestamp when the panel was refreshed + bool m_pendingRefresh; ///< Is there a redraw event requested? + wxTimer m_refreshTimer; ///< Timer to prevent too-frequent refreshing /// True if GAL is currently redrawing the view bool m_drawing; @@ -239,7 +248,7 @@ protected: KIGFX::WX_VIEW_CONTROLS* m_viewControls; /// Currently used GAL - GAL_TYPE m_backend; + GAL_TYPE m_backend; KIGFX::GAL_DISPLAY_OPTIONS& m_options; /// Processes and forwards events to tools diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index cde9016208..d62837835f 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -361,7 +361,7 @@ void PCB_DRAW_PANEL_GAL::SyncLayersVisibility( const BOARD* aBoard ) void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) { - BOARD* board = static_cast( m_parent )->GetBoard(); + BOARD* board = static_cast( GetParentEDAFrame() )->GetBoard(); wxString txt; int viasCount = 0; int trackSegmentsCount = 0; @@ -396,7 +396,7 @@ void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, void PCB_DRAW_PANEL_GAL::OnShow() { - PCB_BASE_FRAME* frame = dynamic_cast( GetParent() ); + PCB_BASE_FRAME* frame = dynamic_cast( GetParentEDAFrame() ); try { @@ -406,7 +406,7 @@ void PCB_DRAW_PANEL_GAL::OnShow() catch( const std::runtime_error& e ) { // Fallback to software renderer - DisplayError( frame, e.what() ); + DisplayError( GetParent(), e.what() ); SwitchBackend( GAL_TYPE_CAIRO ); if( frame )