diff --git a/cvpcb/class_DisplayFootprintsFrame.cpp b/cvpcb/class_DisplayFootprintsFrame.cpp index 8c3054c6c0..f320465c8b 100644 --- a/cvpcb/class_DisplayFootprintsFrame.cpp +++ b/cvpcb/class_DisplayFootprintsFrame.cpp @@ -70,15 +70,13 @@ BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME ) DISPLAY_FOOTPRINTS_FRAME::OnUpdateLineDrawMode ) END_EVENT_TABLE() -#define DISPLAY_FOOTPRINTS_FRAME_NAME wxT( "CmpFrame" ) - 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, - 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. // Give an icon @@ -147,9 +145,6 @@ DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME() { delete GetScreen(); SetScreen( NULL ); // Be sure there is no double deletion - - // a crash would be better than this uncommented: - // ( (CVPCB_MAINFRAME*) Pgm().GetTopWindow() )->m_DisplayFootprintFrame = NULL; } diff --git a/cvpcb/class_DisplayFootprintsFrame.h b/cvpcb/class_DisplayFootprintsFrame.h index 5c36fa6ef4..b26f372565 100644 --- a/cvpcb/class_DisplayFootprintsFrame.h +++ b/cvpcb/class_DisplayFootprintsFrame.h @@ -29,6 +29,8 @@ #include +// The name (for wxWidgets) of the footprint viewer frame +#define FOOTPRINTVIEWER_FRAME_NAME wxT( "FootprintViewerFrame" ) class CVPCB_MAINFRAME; diff --git a/cvpcb/class_footprints_listbox.cpp b/cvpcb/class_footprints_listbox.cpp index 7c1ab079e4..d09cee580b 100644 --- a/cvpcb/class_footprints_listbox.cpp +++ b/cvpcb/class_footprints_listbox.cpp @@ -207,7 +207,7 @@ void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event ) return; // If the footprint view window is displayed, update the footprint. - if( GetParent()->m_DisplayFootprintFrame ) + if( GetParent()->GetFpViewerFrame() ) GetParent()->CreateScreenCmp(); GetParent()->DisplayStatus(); diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index ae14ead1f2..256e12c641 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -114,7 +114,6 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : m_ListCmp = NULL; m_FootprintList = NULL; m_LibraryList = NULL; - m_DisplayFootprintFrame = NULL; m_mainToolBar = NULL; m_modified = false; m_isEESchemaNetlist = false; @@ -315,8 +314,8 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) } // Close module display frame - if( m_DisplayFootprintFrame ) - m_DisplayFootprintFrame->Close( true ); + if( GetFpViewerFrame() ) + GetFpViewerFrame()->Close( true ); m_modified = false; @@ -562,7 +561,7 @@ void CVPCB_MAINFRAME::OnKeepOpenOnSave( wxCommandEvent& event ) void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event ) { CreateScreenCmp(); - m_DisplayFootprintFrame->RedrawScreen( wxPoint( 0, 0 ), false ); + GetFpViewerFrame()->RedrawScreen( wxPoint( 0, 0 ), false ); } @@ -601,7 +600,9 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event ) m_FootprintList->SetFootprints( m_footprints, libraryName, component, filter ); // 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 ) return; @@ -640,7 +641,7 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event ) if ( ii >= 0 ) m_FootprintList->SetSelection( ii, false ); - if( m_DisplayFootprintFrame ) + if( GetFpViewerFrame() ) { CreateScreenCmp(); } @@ -919,15 +920,17 @@ bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName ) void CVPCB_MAINFRAME::CreateScreenCmp() { - if( !m_DisplayFootprintFrame ) + DISPLAY_FOOTPRINTS_FRAME* fpframe = GetFpViewerFrame(); + + if( !fpframe ) { - m_DisplayFootprintFrame = new DISPLAY_FOOTPRINTS_FRAME( &Kiway(), this ); - m_DisplayFootprintFrame->Show( true ); + fpframe = new DISPLAY_FOOTPRINTS_FRAME( &Kiway(), this ); + fpframe->Show( true ); } else { - if( m_DisplayFootprintFrame->IsIconized() ) - m_DisplayFootprintFrame->Iconize( false ); + if( fpframe->IsIconized() ) + fpframe->Iconize( false ); // The display footprint window might be buried under some other // windows, so CreateScreenCmp() on an existing window would not @@ -935,11 +938,11 @@ void CVPCB_MAINFRAME::CreateScreenCmp() // 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 // frame back. - m_DisplayFootprintFrame->Raise(); // Make sure that is visible. - Raise(); // .. but still we want the focus. + fpframe->Raise(); // Make sure that is visible. + Raise(); // .. but still we want the focus. } - m_DisplayFootprintFrame->InitDisplay(); + fpframe->InitDisplay(); } @@ -1049,3 +1052,10 @@ COMPONENT* CVPCB_MAINFRAME::GetSelectedComponent() 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 ); +} diff --git a/cvpcb/cvpcb_mainframe.h b/cvpcb/cvpcb_mainframe.h index 6a7e00efaa..8cd8f5c322 100644 --- a/cvpcb/cvpcb_mainframe.h +++ b/cvpcb/cvpcb_mainframe.h @@ -63,7 +63,6 @@ public: FOOTPRINTS_LISTBOX* m_FootprintList; LIBRARY_LISTBOX* m_LibraryList; COMPONENTS_LISTBOX* m_ListCmp; - DISPLAY_FOOTPRINTS_FRAME* m_DisplayFootprintFrame; wxAuiToolBar* m_mainToolBar; wxFileName m_NetlistFileName; wxArrayString m_ModuleLibNames; @@ -95,6 +94,11 @@ public: */ FP_LIB_TABLE* FootprintLibs() const; + /** + * @return a pointer on the Footprint Viewer frame, if exists, or NULL + */ + DISPLAY_FOOTPRINTS_FRAME* GetFpViewerFrame(); + /** * Function OnSelectComponent * Called when clicking on a component in component list window