void InvokePcbLibTableEditor( KIWAY* aKiway, wxWindow* aCaller ) { FP_LIB_TABLE* globalTable = &GFootprintTable; wxString globalTablePath = FP_LIB_TABLE::GetGlobalTableFileName(); FP_LIB_TABLE* projectTable = aKiway->Prj().PcbFootprintLibs(); wxString projectTablePath = aKiway->Prj().FootprintLibTblName(); wxString msg; DIALOG_EDIT_LIBRARY_TABLES dlg( aCaller, _( "Footprint Libraries" ) ); dlg.SetKiway( &dlg, aKiway ); dlg.InstallPanel( new PANEL_FP_LIB_TABLE( &dlg, globalTable, globalTablePath, projectTable, projectTablePath, aKiway->Prj().GetProjectPath() ) ); if( dlg.ShowModal() == wxID_CANCEL ) return; if( dlg.m_GlobalTableChanged ) { try { globalTable->Save( globalTablePath ); } catch( const IO_ERROR& ioe ) { msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() ); wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); } } if( dlg.m_ProjectTableChanged ) { try { projectTable->Save( projectTablePath ); } catch( const IO_ERROR& ioe ) { msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() ); wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); } } auto editor = (FOOTPRINT_EDIT_FRAME*) aKiway->Player( FRAME_PCB_MODULE_EDITOR, false ); if( editor ) editor->SyncLibraryTree( true ); auto viewer = (FOOTPRINT_VIEWER_FRAME*) aKiway->Player( FRAME_PCB_MODULE_VIEWER, false ); if( viewer ) viewer->ReCreateLibraryList(); }
bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR ) { bool tableExists = true; wxFileName fn = GetGlobalTableFileName(); if( !fn.FileExists() ) { tableExists = false; if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) ) { THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ), GetChars( fn.GetPath() ) ) ); } // Attempt to copy the default global file table from the KiCad // template folder to the user's home configuration path. wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name ); // The fallback is to create an empty global footprint table for the user to populate. if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) ) { FP_LIB_TABLE emptyTable; emptyTable.Save( fn.GetFullPath() ); } } aTable.Load( fn.GetFullPath() ); return tableExists; }