Commit 2ff53e95 authored by Dick Hollenbeck's avatar Dick Hollenbeck

fix some bugs in FOOTPRINT_VIEWER_FRAME, get rid of statics

parent b22aba20
...@@ -142,6 +142,8 @@ public: ...@@ -142,6 +142,8 @@ public:
PCB_LIB_NICKNAME, PCB_LIB_NICKNAME,
VIEWER_3D_PATH, VIEWER_3D_PATH,
PCB_FOOTPRINT, PCB_FOOTPRINT,
PCB_FOOTPRINT_VIEWER_FPNAME,
PCB_FOOTPRINT_VIEWER_NICKNAME,
RSTRING_COUNT RSTRING_COUNT
}; };
......
...@@ -334,7 +334,6 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, ...@@ -334,7 +334,6 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
wxString fpname; wxString fpname;
wxString msg; wxString msg;
wxArrayString libraries; wxArrayString libraries;
FP_LIB_TABLE libTable;
std::vector< wxArrayString > rows; std::vector< wxArrayString > rows;
......
...@@ -60,16 +60,6 @@ ...@@ -60,16 +60,6 @@
#define PREVIOUS_PART -1 #define PREVIOUS_PART -1
/**
* Save previous component library viewer state.
*/
wxString FOOTPRINT_VIEWER_FRAME::m_libraryName;
wxString FOOTPRINT_VIEWER_FRAME::m_footprintName;
/// When the viewer is used to select a component in schematic, the selected component is here.
wxString FOOTPRINT_VIEWER_FRAME::m_selectedFootprintName;
BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME ) BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
// Window events // Window events
EVT_CLOSE( FOOTPRINT_VIEWER_FRAME::OnCloseWindow ) EVT_CLOSE( FOOTPRINT_VIEWER_FRAME::OnCloseWindow )
...@@ -151,8 +141,6 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent ...@@ -151,8 +141,6 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST, m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST,
wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL ); wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL );
m_selectedFootprintName.Empty();
SetBoard( new BOARD() ); SetBoard( new BOARD() );
// Ensure all layers and items are visible: // Ensure all layers and items are visible:
...@@ -173,12 +161,12 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent ...@@ -173,12 +161,12 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
UpdateTitle(); UpdateTitle();
// If a footprint was previously loaded, reload it // If a footprint was previously loaded, reload it
if( !m_libraryName.IsEmpty() && !m_footprintName.IsEmpty() ) if( getCurNickname().size() && getCurFootprintName().size() )
{ {
FPID id; FPID id;
id.SetLibNickname( m_libraryName ); id.SetLibNickname( getCurNickname() );
id.SetFootprintName( m_footprintName ); id.SetFootprintName( getCurFootprintName() );
GetBoard()->Add( loadFootprint( id ) ); GetBoard()->Add( loadFootprint( id ) );
} }
...@@ -315,7 +303,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList() ...@@ -315,7 +303,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList()
m_libList->Append( nicknames[ii] ); m_libList->Append( nicknames[ii] );
// Search for a previous selection: // Search for a previous selection:
int index = m_libList->FindString( m_libraryName ); int index = m_libList->FindString( getCurNickname() );
if( index != wxNOT_FOUND ) if( index != wxNOT_FOUND )
{ {
...@@ -325,8 +313,8 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList() ...@@ -325,8 +313,8 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList()
{ {
// If not found, clear current library selection because it can be // If not found, clear current library selection because it can be
// deleted after a configuration change. // deleted after a configuration change.
m_libraryName = wxEmptyString; setCurNickname( wxEmptyString );
m_footprintName = wxEmptyString; setCurFootprintName( wxEmptyString );
} }
ReCreateFootprintList(); ReCreateFootprintList();
...@@ -340,15 +328,17 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList() ...@@ -340,15 +328,17 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
{ {
m_footprintList->Clear(); m_footprintList->Clear();
if( m_libraryName.IsEmpty() ) if( !getCurNickname() )
{ {
m_footprintName = wxEmptyString; setCurFootprintName( wxEmptyString );
return; return;
} }
FOOTPRINT_LIST fp_info_list; FOOTPRINT_LIST fp_info_list;
fp_info_list.ReadFootprintFiles( Prj().PcbFootprintLibs(), &m_libraryName ); wxString nickname = getCurNickname();
fp_info_list.ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? NULL : &nickname );
if( fp_info_list.GetErrorCount() ) if( fp_info_list.GetErrorCount() )
{ {
...@@ -361,10 +351,10 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList() ...@@ -361,10 +351,10 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
m_footprintList->Append( footprint.GetFootprintName() ); m_footprintList->Append( footprint.GetFootprintName() );
} }
int index = m_footprintList->FindString( m_footprintName ); int index = m_footprintList->FindString( getCurFootprintName() );
if( index == wxNOT_FOUND ) if( index == wxNOT_FOUND )
m_footprintName = wxEmptyString; setCurFootprintName( wxEmptyString );
else else
m_footprintList->SetSelection( index, true ); m_footprintList->SetSelection( index, true );
} }
...@@ -379,10 +369,10 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event ) ...@@ -379,10 +369,10 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
wxString name = m_libList->GetString( ii ); wxString name = m_libList->GetString( ii );
if( m_libraryName == name ) if( getCurNickname() == name )
return; return;
m_libraryName = name; setCurNickname( name );
ReCreateFootprintList(); ReCreateFootprintList();
UpdateTitle(); UpdateTitle();
...@@ -402,17 +392,18 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) ...@@ -402,17 +392,18 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
wxString name = m_footprintList->GetString( ii ); wxString name = m_footprintList->GetString( ii );
if( m_footprintName.CmpNoCase( name ) != 0 ) if( getCurFootprintName().CmpNoCase( name ) != 0 )
{ {
m_footprintName = name; setCurFootprintName( name );
SetCurItem( NULL ); SetCurItem( NULL );
// Delete the current footprint // Delete the current footprint
GetBoard()->m_Modules.DeleteAll(); GetBoard()->m_Modules.DeleteAll();
FPID id; FPID id;
id.SetLibNickname( m_libraryName ); id.SetLibNickname( getCurNickname() );
id.SetFootprintName( m_footprintName ); id.SetFootprintName( getCurFootprintName() );
try try
{ {
...@@ -420,10 +411,12 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) ...@@ -420,10 +411,12 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
wxString msg; wxString msg = wxString::Format(
msg.Printf( _( "Could not load footprint \"%s\" from library \"%s\".\n\n" _( "Could not load footprint \"%s\" from library \"%s\".\n\nError %s." ),
"Error %s." ), GetChars( m_footprintName ), GetChars( m_libraryName ), GetChars( getCurFootprintName() ),
GetChars( getCurNickname() ),
GetChars( ioe.errorText ) ); GetChars( ioe.errorText ) );
DisplayError( this, msg ); DisplayError( this, msg );
} }
...@@ -466,19 +459,15 @@ void FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint( wxCommandEvent& event ) ...@@ -466,19 +459,15 @@ void FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint( wxCommandEvent& event )
{ {
wxString fp_name = m_footprintList->GetString( ii ); wxString fp_name = m_footprintList->GetString( ii );
// @todo(DICK) assign to static now, later PROJECT retained string.
m_selectedFootprintName = fp_name;
FPID fpid; FPID fpid;
fpid.SetLibNickname( GetSelectedLibrary() ); fpid.SetLibNickname( getCurNickname() );
fpid.SetFootprintName( fp_name ); fpid.SetFootprintName( fp_name );
DismissModal( true, fpid.Format() ); DismissModal( true, fpid.Format() );
} }
else else
{ {
m_selectedFootprintName.Empty();
DismissModal( false ); DismissModal( false );
} }
...@@ -498,6 +487,30 @@ void FOOTPRINT_VIEWER_FRAME::SaveSettings( wxConfigBase* aCfg ) ...@@ -498,6 +487,30 @@ void FOOTPRINT_VIEWER_FRAME::SaveSettings( wxConfigBase* aCfg )
} }
const wxString FOOTPRINT_VIEWER_FRAME::getCurNickname()
{
return Prj().GetRString( PROJECT::PCB_FOOTPRINT_VIEWER_NICKNAME );
}
void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
{
Prj().SetRString( PROJECT::PCB_FOOTPRINT_VIEWER_NICKNAME, aNickname );
}
const wxString FOOTPRINT_VIEWER_FRAME::getCurFootprintName()
{
return Prj().GetRString( PROJECT::PCB_FOOTPRINT_VIEWER_FPNAME );
}
void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
{
Prj().SetRString( PROJECT::PCB_FOOTPRINT_VIEWER_FPNAME, aName );
}
void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event ) void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
{ {
EDA_DRAW_FRAME::OnActivate( event ); EDA_DRAW_FRAME::OnActivate( event );
...@@ -506,8 +519,6 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event ) ...@@ -506,8 +519,6 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
if( ! m_FrameIsActive ) if( ! m_FrameIsActive )
return; return;
m_selectedFootprintName.Empty();
// Ensure we have the right library list: // Ensure we have the right library list:
std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs(); std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
...@@ -615,8 +626,10 @@ void FOOTPRINT_VIEWER_FRAME::Update3D_Frame( bool aForceReloadFootprint ) ...@@ -615,8 +626,10 @@ void FOOTPRINT_VIEWER_FRAME::Update3D_Frame( bool aForceReloadFootprint )
if( m_Draw3DFrame == NULL ) if( m_Draw3DFrame == NULL )
return; return;
wxString frm3Dtitle; wxString frm3Dtitle = wxString::Format(
frm3Dtitle.Printf( _( "ModView: 3D Viewer [%s]" ), GetChars( m_footprintName ) ); _( "ModView: 3D Viewer [%s]" ),
GetChars( getCurFootprintName() ) );
m_Draw3DFrame->SetTitle( frm3Dtitle ); m_Draw3DFrame->SetTitle( frm3Dtitle );
if( aForceReloadFootprint ) if( aForceReloadFootprint )
...@@ -675,8 +688,8 @@ void FOOTPRINT_VIEWER_FRAME::UpdateTitle() ...@@ -675,8 +688,8 @@ void FOOTPRINT_VIEWER_FRAME::UpdateTitle()
msg = _( "Library Browser" ); msg = _( "Library Browser" );
msg << wxT( " [" ); msg << wxT( " [" );
if( ! m_libraryName.IsEmpty() ) if( getCurNickname().size() )
msg << m_libraryName; msg << getCurNickname();
else else
msg += _( "no library selected" ); msg += _( "no library selected" );
...@@ -688,16 +701,16 @@ void FOOTPRINT_VIEWER_FRAME::UpdateTitle() ...@@ -688,16 +701,16 @@ void FOOTPRINT_VIEWER_FRAME::UpdateTitle()
void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event ) void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event )
{ {
wxString selection = SelectLibrary( m_libraryName ); wxString selection = SelectLibrary( getCurNickname() );
if( !!selection && selection != m_libraryName ) if( !!selection && selection != getCurNickname() )
{ {
m_libraryName = selection; setCurNickname( selection );
UpdateTitle(); UpdateTitle();
ReCreateFootprintList(); ReCreateFootprintList();
int id = m_libList->FindString( m_libraryName ); int id = m_libList->FindString( getCurNickname() );
if( id >= 0 ) if( id >= 0 )
m_libList->SetSelection( id ); m_libList->SetSelection( id );
...@@ -714,9 +727,9 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event ) ...@@ -714,9 +727,9 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event )
(void*) parent; (void*) parent;
#endif #endif
wxString libname = m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension; wxString nickname = getCurNickname();
MODULE* oldmodule = GetBoard()->m_Modules; MODULE* oldmodule = GetBoard()->m_Modules;
MODULE* module = LoadModuleFromLibrary( libname, Prj().PcbFootprintLibs(), false ); MODULE* module = LoadModuleFromLibrary( nickname, Prj().PcbFootprintLibs(), false );
if( module ) if( module )
{ {
...@@ -729,31 +742,37 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event ) ...@@ -729,31 +742,37 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event )
delete oldmodule; delete oldmodule;
} }
m_footprintName = FROM_UTF8( module->GetFPID().GetFootprintName().c_str() ); setCurFootprintName( module->GetFPID().GetFootprintName() );
wxString nickname = module->GetFPID().GetLibNickname();
if( !getCurNickname() && nickname.size() )
{
// Set the listbox
int index = m_libList->FindString( nickname );
if( index != wxNOT_FOUND )
m_libList->SetSelection( index, true );
setCurNickname( nickname );
}
module->ClearFlags(); module->ClearFlags();
SetCurItem( NULL ); SetCurItem( NULL );
Zoom_Automatique( false ); Zoom_Automatique( false );
m_canvas->Refresh(); m_canvas->Refresh();
Update3D_Frame(); Update3D_Frame();
m_footprintList->SetStringSelection( m_footprintName ); m_footprintList->SetStringSelection( getCurFootprintName() );
} }
} }
const wxString FOOTPRINT_VIEWER_FRAME::GetSelectedLibraryFullName( void )
{
wxString fullname = m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension;
return fullname;
}
void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
{ {
if( !m_libraryName ) if( !getCurNickname() )
return; return;
int selection = m_footprintList->FindString( m_footprintName ); int selection = m_footprintList->FindString( getCurFootprintName() );
if( aMode == NEXT_PART ) if( aMode == NEXT_PART )
{ {
...@@ -770,13 +789,14 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) ...@@ -770,13 +789,14 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
if( selection != wxNOT_FOUND ) if( selection != wxNOT_FOUND )
{ {
m_footprintList->SetSelection( selection ); m_footprintList->SetSelection( selection );
m_footprintName = m_footprintList->GetString( selection ); setCurFootprintName( m_footprintList->GetString( selection ) );
SetCurItem( NULL ); SetCurItem( NULL );
// Delete the current footprint // Delete the current footprint
GetBoard()->m_Modules.DeleteAll(); GetBoard()->m_Modules.DeleteAll();
MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad( m_libraryName, m_footprintName ); MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad(
getCurNickname(), getCurFootprintName() );
if( footprint ) if( footprint )
GetBoard()->Add( footprint, ADD_APPEND ); GetBoard()->Add( footprint, ADD_APPEND );
......
...@@ -59,15 +59,6 @@ public: ...@@ -59,15 +59,6 @@ public:
*/ */
static const wxChar* GetFootprintViewerFrameName(); static const wxChar* GetFootprintViewerFrameName();
wxString& GetSelectedFootprint( void ) const { return m_selectedFootprintName; }
const wxString GetSelectedLibraryFullName();
/**
* Function GetSelectedLibrary
* @return the selected library name from the #FP_LIB_TABLE.
*/
const wxString& GetSelectedLibrary() { return m_libraryName; }
virtual EDA_COLOR_T GetGridColor() const; virtual EDA_COLOR_T GetGridColor() const;
/** /**
...@@ -86,10 +77,11 @@ private: ...@@ -86,10 +77,11 @@ private:
wxString m_configPath; // subpath for configuration wxString m_configPath; // subpath for configuration
static wxString m_libraryName; // Current selected library const wxString getCurNickname();
static wxString m_footprintName; // Current selected footprint void setCurNickname( const wxString& aNickname );
static wxString m_selectedFootprintName; // When the viewer is used to select a footprint
const wxString getCurFootprintName();
void setCurFootprintName( const wxString& aName );
void OnSize( wxSizeEvent& event ); void OnSize( wxSizeEvent& event );
...@@ -123,8 +115,6 @@ private: ...@@ -123,8 +115,6 @@ private:
void LoadSettings( wxConfigBase* aCfg ); // override virtual void LoadSettings( wxConfigBase* aCfg ); // override virtual
void SaveSettings( wxConfigBase* aCfg ); // override virtual void SaveSettings( wxConfigBase* aCfg ); // override virtual
wxString& GetFootprintName( void ) const { return m_footprintName; }
/** /**
* Function OnActivate * Function OnActivate
* is called when the frame frame is activate to reload the libraries and component lists * is called when the frame frame is activate to reload the libraries and component lists
......
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