bool FOOTPRINT_EDIT_FRAME::SaveFootprint( MODULE* aModule ) { wxString libraryName = aModule->GetFPID().GetLibNickname(); wxString footprintName = aModule->GetFPID().GetLibItemName(); bool nameChanged = m_footprintNameWhenLoaded != footprintName; if( aModule->GetLink() ) { if( SaveFootprintToBoard( false ) ) { m_footprintNameWhenLoaded = footprintName; return true; } else return false; } else if( libraryName.IsEmpty() || footprintName.IsEmpty() ) { if( SaveFootprintAs( aModule ) ) { m_footprintNameWhenLoaded = footprintName; SyncLibraryTree( true ); return true; } else return false; } FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs(); // Legacy libraries are readable, but modifying legacy format is not allowed // So prompt the user if he try to add/replace a footprint in a legacy lib wxString libfullname = tbl->FindRow( libraryName )->GetFullURI(); if( IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == IO_MGR::LEGACY ) { DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT ); return false; } if( nameChanged ) { LIB_ID oldFPID( libraryName, m_footprintNameWhenLoaded ); DeleteModuleFromLibrary( oldFPID, false ); } if( !saveFootprintInLibrary( aModule, libraryName ) ) return false; if( nameChanged ) { m_footprintNameWhenLoaded = footprintName; SyncLibraryTree( true ); } return true; }
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(); }
void FOOTPRINT_EDIT_FRAME::HardRedraw() { SyncLibraryTree( true ); GetGalCanvas()->ForceRefresh(); }
bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename ) { wxFileName fn( aFilename ); if( aFilename.IsEmpty() ) { if( !LibraryFileBrowser( true, fn, KiCadFootprintLibPathWildcard(), KiCadFootprintLibPathExtension, true ) ) { return false; } } wxString libPath = fn.GetFullPath(); wxString libName = fn.GetName(); if( libName.IsEmpty() ) return false; bool saveInGlobalTable = false; bool saveInProjectTable = false; wxArrayString libTableNames; libTableNames.Add( _( "Global" ) ); libTableNames.Add( _( "Project" ) ); switch( SelectSingleOption( this, _( "Select Library Table" ), _( "Choose the Library Table to add the library to:" ), libTableNames ) ) { case 0: saveInGlobalTable = true; break; case 1: saveInProjectTable = true; break; default: return false; } wxString type = IO_MGR::ShowType( IO_MGR::GuessPluginTypeFromLibPath( libPath ) ); // try to use path normalized to an environmental variable or project path wxString normalizedPath = NormalizePath( libPath, &Pgm().GetLocalEnvVariables(), &Prj() ); if( normalizedPath.IsEmpty() ) normalizedPath = libPath; try { if( saveInGlobalTable ) { auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString ); GFootprintTable.InsertRow( row ); GFootprintTable.Save( FP_LIB_TABLE::GetGlobalTableFileName() ); } else if( saveInProjectTable ) { auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString ); Prj().PcbFootprintLibs()->InsertRow( row ); Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() ); } } catch( const IO_ERROR& ioe ) { DisplayError( this, ioe.What() ); return false; } auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_PCB_MODULE_EDITOR, false ); if( editor ) editor->SyncLibraryTree( true ); auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_PCB_MODULE_VIEWER, false ); if( viewer ) viewer->ReCreateLibraryList(); return true; }