Commit ab30fba0 authored by jean-pierre charras's avatar jean-pierre charras

CvPcb: Fix crashes when starting cvPcb (could be Windows Specific) and after...

CvPcb: Fix crashes when starting cvPcb (could be Windows Specific) and after closing the footprint viewer.
parent a7f19392
...@@ -70,15 +70,13 @@ BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME ) ...@@ -70,15 +70,13 @@ BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME )
DISPLAY_FOOTPRINTS_FRAME::OnUpdateLineDrawMode ) DISPLAY_FOOTPRINTS_FRAME::OnUpdateLineDrawMode )
END_EVENT_TABLE() END_EVENT_TABLE()
#define DISPLAY_FOOTPRINTS_FRAME_NAME wxT( "CmpFrame" )
DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, CVPCB_MAINFRAME* aParent ) : DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, CVPCB_MAINFRAME* aParent ) :
PCB_BASE_FRAME( aKiway, aParent, CVPCB_DISPLAY_FRAME_TYPE, _( "Module" ), PCB_BASE_FRAME( aKiway, aParent, CVPCB_DISPLAY_FRAME_TYPE, _( "Footprint Viewer" ),
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
KICAD_DEFAULT_DRAWFRAME_STYLE, DISPLAY_FOOTPRINTS_FRAME_NAME ) KICAD_DEFAULT_DRAWFRAME_STYLE, FOOTPRINTVIEWER_FRAME_NAME )
{ {
m_FrameName = DISPLAY_FOOTPRINTS_FRAME_NAME; m_FrameName = FOOTPRINTVIEWER_FRAME_NAME;
m_showAxis = true; // true to draw axis. m_showAxis = true; // true to draw axis.
// Give an icon // Give an icon
...@@ -147,9 +145,6 @@ DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME() ...@@ -147,9 +145,6 @@ DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME()
{ {
delete GetScreen(); delete GetScreen();
SetScreen( NULL ); // Be sure there is no double deletion SetScreen( NULL ); // Be sure there is no double deletion
// a crash would be better than this uncommented:
// ( (CVPCB_MAINFRAME*) Pgm().GetTopWindow() )->m_DisplayFootprintFrame = NULL;
} }
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <wxBasePcbFrame.h> #include <wxBasePcbFrame.h>
// The name (for wxWidgets) of the footprint viewer frame
#define FOOTPRINTVIEWER_FRAME_NAME wxT( "FootprintViewerFrame" )
class CVPCB_MAINFRAME; class CVPCB_MAINFRAME;
......
...@@ -207,7 +207,7 @@ void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event ) ...@@ -207,7 +207,7 @@ void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
return; return;
// If the footprint view window is displayed, update the footprint. // If the footprint view window is displayed, update the footprint.
if( GetParent()->m_DisplayFootprintFrame ) if( GetParent()->GetFpViewerFrame() )
GetParent()->CreateScreenCmp(); GetParent()->CreateScreenCmp();
GetParent()->DisplayStatus(); GetParent()->DisplayStatus();
......
...@@ -114,7 +114,6 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : ...@@ -114,7 +114,6 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_ListCmp = NULL; m_ListCmp = NULL;
m_FootprintList = NULL; m_FootprintList = NULL;
m_LibraryList = NULL; m_LibraryList = NULL;
m_DisplayFootprintFrame = NULL;
m_mainToolBar = NULL; m_mainToolBar = NULL;
m_modified = false; m_modified = false;
m_isEESchemaNetlist = false; m_isEESchemaNetlist = false;
...@@ -315,8 +314,8 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) ...@@ -315,8 +314,8 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
} }
// Close module display frame // Close module display frame
if( m_DisplayFootprintFrame ) if( GetFpViewerFrame() )
m_DisplayFootprintFrame->Close( true ); GetFpViewerFrame()->Close( true );
m_modified = false; m_modified = false;
...@@ -562,7 +561,7 @@ void CVPCB_MAINFRAME::OnKeepOpenOnSave( wxCommandEvent& event ) ...@@ -562,7 +561,7 @@ void CVPCB_MAINFRAME::OnKeepOpenOnSave( wxCommandEvent& event )
void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event ) void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event )
{ {
CreateScreenCmp(); CreateScreenCmp();
m_DisplayFootprintFrame->RedrawScreen( wxPoint( 0, 0 ), false ); GetFpViewerFrame()->RedrawScreen( wxPoint( 0, 0 ), false );
} }
...@@ -601,7 +600,9 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event ) ...@@ -601,7 +600,9 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
m_FootprintList->SetFootprints( m_footprints, libraryName, component, filter ); m_FootprintList->SetFootprints( m_footprints, libraryName, component, filter );
// Tell AuiMgr that objects are changed ! // Tell AuiMgr that objects are changed !
m_auimgr.Update(); if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
// (could be not the case when starting CvPcb
m_auimgr.Update();
if( component == NULL ) if( component == NULL )
return; return;
...@@ -640,7 +641,7 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event ) ...@@ -640,7 +641,7 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
if ( ii >= 0 ) if ( ii >= 0 )
m_FootprintList->SetSelection( ii, false ); m_FootprintList->SetSelection( ii, false );
if( m_DisplayFootprintFrame ) if( GetFpViewerFrame() )
{ {
CreateScreenCmp(); CreateScreenCmp();
} }
...@@ -919,15 +920,17 @@ bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName ) ...@@ -919,15 +920,17 @@ bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName )
void CVPCB_MAINFRAME::CreateScreenCmp() void CVPCB_MAINFRAME::CreateScreenCmp()
{ {
if( !m_DisplayFootprintFrame ) DISPLAY_FOOTPRINTS_FRAME* fpframe = GetFpViewerFrame();
if( !fpframe )
{ {
m_DisplayFootprintFrame = new DISPLAY_FOOTPRINTS_FRAME( &Kiway(), this ); fpframe = new DISPLAY_FOOTPRINTS_FRAME( &Kiway(), this );
m_DisplayFootprintFrame->Show( true ); fpframe->Show( true );
} }
else else
{ {
if( m_DisplayFootprintFrame->IsIconized() ) if( fpframe->IsIconized() )
m_DisplayFootprintFrame->Iconize( false ); fpframe->Iconize( false );
// The display footprint window might be buried under some other // The display footprint window might be buried under some other
// windows, so CreateScreenCmp() on an existing window would not // windows, so CreateScreenCmp() on an existing window would not
...@@ -935,11 +938,11 @@ void CVPCB_MAINFRAME::CreateScreenCmp() ...@@ -935,11 +938,11 @@ void CVPCB_MAINFRAME::CreateScreenCmp()
// So we want to put it to front, second after our CVPCB_MAINFRAME. // So we want to put it to front, second after our CVPCB_MAINFRAME.
// We do this by a little dance of bringing it to front then the main // We do this by a little dance of bringing it to front then the main
// frame back. // frame back.
m_DisplayFootprintFrame->Raise(); // Make sure that is visible. fpframe->Raise(); // Make sure that is visible.
Raise(); // .. but still we want the focus. Raise(); // .. but still we want the focus.
} }
m_DisplayFootprintFrame->InitDisplay(); fpframe->InitDisplay();
} }
...@@ -1049,3 +1052,10 @@ COMPONENT* CVPCB_MAINFRAME::GetSelectedComponent() ...@@ -1049,3 +1052,10 @@ COMPONENT* CVPCB_MAINFRAME::GetSelectedComponent()
return NULL; return NULL;
} }
DISPLAY_FOOTPRINTS_FRAME* CVPCB_MAINFRAME::GetFpViewerFrame()
{
// returns the Footprint Viewer frame, if exists, or NULL
return (DISPLAY_FOOTPRINTS_FRAME*) wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME );
}
...@@ -63,7 +63,6 @@ public: ...@@ -63,7 +63,6 @@ public:
FOOTPRINTS_LISTBOX* m_FootprintList; FOOTPRINTS_LISTBOX* m_FootprintList;
LIBRARY_LISTBOX* m_LibraryList; LIBRARY_LISTBOX* m_LibraryList;
COMPONENTS_LISTBOX* m_ListCmp; COMPONENTS_LISTBOX* m_ListCmp;
DISPLAY_FOOTPRINTS_FRAME* m_DisplayFootprintFrame;
wxAuiToolBar* m_mainToolBar; wxAuiToolBar* m_mainToolBar;
wxFileName m_NetlistFileName; wxFileName m_NetlistFileName;
wxArrayString m_ModuleLibNames; wxArrayString m_ModuleLibNames;
...@@ -95,6 +94,11 @@ public: ...@@ -95,6 +94,11 @@ public:
*/ */
FP_LIB_TABLE* FootprintLibs() const; FP_LIB_TABLE* FootprintLibs() const;
/**
* @return a pointer on the Footprint Viewer frame, if exists, or NULL
*/
DISPLAY_FOOTPRINTS_FRAME* GetFpViewerFrame();
/** /**
* Function OnSelectComponent * Function OnSelectComponent
* Called when clicking on a component in component list window * Called when clicking on a component in component list window
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment