Cleanup parentage inside the draw panels

This commit is contained in:
Ian McInerney 2020-05-19 23:54:05 +01:00
parent 89c46e6834
commit 2bc57ade28
8 changed files with 46 additions and 42 deletions

View File

@ -49,24 +49,26 @@
EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
const wxPoint& aPosition, const wxSize& aSize, const wxPoint& aPosition, const wxSize& aSize,
KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : KIGFX::GAL_DISPLAY_OPTIONS& aOptions,
wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ), GAL_TYPE aGalType )
m_options( aOptions ) : 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_parent = aParentWindow;
m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( 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_currentCursor = wxStockCursor( wxCURSOR_ARROW ); m_currentCursor = wxStockCursor( wxCURSOR_ARROW );
SetLayoutDirection( wxLayout_LeftToRight ); SetLayoutDirection( wxLayout_LeftToRight );
m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( m_parent );
// If we're in a dialog, we have to go looking for our parent frame // If we're in a dialog, we have to go looking for our parent frame
if( !m_edaFrame ) if( !m_edaFrame )
{ {

View File

@ -52,12 +52,11 @@
SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
const wxPoint& aPosition, const wxSize& aSize, const wxPoint& aPosition, const wxSize& aSize,
KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType )
EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ), : EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
m_parent( aParentWindow )
{ {
m_currentCursor = wxCURSOR_ARROW; m_currentCursor = wxCURSOR_ARROW;
m_view = new KIGFX::SCH_VIEW( true, dynamic_cast<SCH_BASE_FRAME*>( aParentWindow ) ); m_view = new KIGFX::SCH_VIEW( true, dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() ) );
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );
m_gal->SetWorldUnitLength( SCH_WORLD_UNIT ); m_gal->SetWorldUnitLength( SCH_WORLD_UNIT );
@ -66,7 +65,7 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
COLOR_SETTINGS* cs = nullptr; COLOR_SETTINGS* cs = nullptr;
if( auto frame = dynamic_cast<SCH_BASE_FRAME*>( aParentWindow ) ) if( auto frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() ) )
cs = frame->GetColorSettings(); cs = frame->GetColorSettings();
else else
cs = Pgm().GetSettingsManager().GetColorSettings(); cs = Pgm().GetSettingsManager().GetColorSettings();
@ -145,7 +144,7 @@ bool SCH_DRAW_PANEL::SwitchBackend( GAL_TYPE aGalType )
// Keep grid size and grid visibility: // Keep grid size and grid visibility:
m_gal->SetGridSize( grid_size ); m_gal->SetGridSize( grid_size );
SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParent() ); SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() );
if( frame ) if( frame )
m_gal->SetGridVisibility( frame->IsGridVisible() ); m_gal->SetGridVisibility( frame->IsGridVisible() );
@ -190,7 +189,7 @@ KIGFX::SCH_VIEW* SCH_DRAW_PANEL::GetView() const
void SCH_DRAW_PANEL::OnShow() void SCH_DRAW_PANEL::OnShow()
{ {
SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParent() ); SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() );
try try
{ {

View File

@ -59,9 +59,6 @@ protected:
void setDefaultLayerOrder(); ///> Reassigns layer order to the initial settings. void setDefaultLayerOrder(); ///> Reassigns layer order to the initial settings.
void setDefaultLayerDeps(); ///> Sets rendering targets & dependencies for layers. void setDefaultLayerDeps(); ///> Sets rendering targets & dependencies for layers.
protected:
wxWindow* m_parent;
}; };
#endif #endif

View File

@ -44,8 +44,7 @@ using namespace std::placeholders;
SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
const wxPoint& aPosition, const wxSize& aSize, const wxPoint& aPosition, const wxSize& aSize,
KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ), EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
m_parent( aParentWindow )
{ {
m_view = new KIGFX::SCH_VIEW( true, nullptr ); m_view = new KIGFX::SCH_VIEW( true, nullptr );
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );

View File

@ -66,8 +66,6 @@ protected:
///> Sets rendering targets & dependencies for layers. ///> Sets rendering targets & dependencies for layers.
void setDefaultLayerDeps(); void setDefaultLayerDeps();
wxWindow* m_parent;
}; };
#endif #endif

View File

@ -96,7 +96,7 @@ void GERBVIEW_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
void GERBVIEW_DRAW_PANEL_GAL::OnShow() void GERBVIEW_DRAW_PANEL_GAL::OnShow()
{ {
GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParent() ); GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
if( frame ) 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 // after switching to opengl. Clearing m_view and rebuild it is much faster
if( aGalType == GAL_TYPE_OPENGL ) if( aGalType == GAL_TYPE_OPENGL )
{ {
GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParent() ); GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
if( frame ) if( frame )
{ {

View File

@ -60,8 +60,17 @@ public:
GAL_TYPE_LAST ///< Sentinel, do not use as a parameter 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 ); GAL_TYPE aGalType = GAL_TYPE_OPENGL );
~EDA_DRAW_PANEL_GAL(); ~EDA_DRAW_PANEL_GAL();
@ -208,14 +217,14 @@ protected:
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 wxWindow* m_parent; ///< Pointer to the parent window
EDA_DRAW_FRAME* m_edaFrame; /// Parent EDA_DRAW_FRAME (if available) EDA_DRAW_FRAME* m_edaFrame; ///< Parent EDA_DRAW_FRAME (if available)
wxLongLong m_lastRefresh; /// Last timestamp when the panel was refreshed wxLongLong m_lastRefresh; ///< Last timestamp when the panel was refreshed
bool m_pendingRefresh; /// Is there a redraw event requested? bool m_pendingRefresh; ///< Is there a redraw event requested?
wxTimer m_refreshTimer; /// Timer to prevent too-frequent refreshing wxTimer m_refreshTimer; ///< Timer to prevent too-frequent refreshing
/// True if GAL is currently redrawing the view /// True if GAL is currently redrawing the view
bool m_drawing; bool m_drawing;

View File

@ -361,7 +361,7 @@ void PCB_DRAW_PANEL_GAL::SyncLayersVisibility( const BOARD* aBoard )
void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
std::vector<MSG_PANEL_ITEM>& aList ) std::vector<MSG_PANEL_ITEM>& aList )
{ {
BOARD* board = static_cast<PCB_BASE_FRAME*>( m_parent )->GetBoard(); BOARD* board = static_cast<PCB_BASE_FRAME*>( GetParentEDAFrame() )->GetBoard();
wxString txt; wxString txt;
int viasCount = 0; int viasCount = 0;
int trackSegmentsCount = 0; int trackSegmentsCount = 0;
@ -396,7 +396,7 @@ void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
void PCB_DRAW_PANEL_GAL::OnShow() void PCB_DRAW_PANEL_GAL::OnShow()
{ {
PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( GetParent() ); PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( GetParentEDAFrame() );
try try
{ {
@ -406,7 +406,7 @@ void PCB_DRAW_PANEL_GAL::OnShow()
catch( const std::runtime_error& e ) catch( const std::runtime_error& e )
{ {
// Fallback to software renderer // Fallback to software renderer
DisplayError( frame, e.what() ); DisplayError( GetParent(), e.what() );
SwitchBackend( GAL_TYPE_CAIRO ); SwitchBackend( GAL_TYPE_CAIRO );
if( frame ) if( frame )