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,
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<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_parent = aParentWindow;
m_currentCursor = wxStockCursor( wxCURSOR_ARROW );
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( !m_edaFrame )
{

View File

@ -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<SCH_BASE_FRAME*>( aParentWindow ) );
m_view = new KIGFX::SCH_VIEW( true, dynamic_cast<SCH_BASE_FRAME*>( 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<SCH_BASE_FRAME*>( aParentWindow ) )
if( auto frame = dynamic_cast<SCH_BASE_FRAME*>( 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<SCH_BASE_FRAME*>( GetParent() );
SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( 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<SCH_BASE_FRAME*>( GetParent() );
SCH_BASE_FRAME* frame = dynamic_cast<SCH_BASE_FRAME*>( GetParentEDAFrame() );
try
{

View File

@ -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

View File

@ -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 );

View File

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

View File

@ -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<GERBVIEW_FRAME*>( GetParent() );
GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( 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<GERBVIEW_FRAME*>( GetParent() );
GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
if( frame )
{

View File

@ -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

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,
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;
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<PCB_BASE_FRAME*>( GetParent() );
PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( 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 )