From 2a4f8db79270bc2564fc9d3f3d3389923fced287 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 28 Sep 2015 10:46:00 +0200 Subject: [PATCH] Pcbnew, archive footprints: fix bug #1495321. The user can now save the footprints in a library in fp lib table, or in a new library. --- include/wxPcbStruct.h | 11 +++-- pcbnew/edit.cpp | 8 ++-- pcbnew/librairi.cpp | 78 ++++++++++++++++++------------------ pcbnew/menubar_pcbframe.cpp | 14 ++++--- pcbnew/module_editor_frame.h | 11 ----- pcbnew/pcb_base_edit_frame.h | 11 +++++ pcbnew/pcbframe.cpp | 4 +- pcbnew/pcbnew_id.h | 4 +- 8 files changed, 74 insertions(+), 67 deletions(-) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 81aa4ac917..9ce7651859 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -937,11 +937,14 @@ public: /** * Function ArchiveModulesOnBoard * Save modules in a library: - * @param aNewModulesOnly: - * true : save modules not already existing in this lib - * false: save all modules + * @param aStoreInNewLib: + * true : save modules in a existing lib. Existing footprints will be kept + * or updated. + * This lib should be in fp lib table, and is type is .pretty + * false: save modules in a new lib. It it is an existing lib, + * previous footprints will be removed */ - void ArchiveModulesOnBoard( bool aNewModulesOnly ); + void ArchiveModulesOnBoard( bool aStoreInNewLib ); /** * Function RecreateBOMFileFromBoard diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index b12b10cddc..d12d1e5c1f 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -1235,12 +1235,12 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) } break; - case ID_MENU_ARCHIVE_NEW_MODULES: - ArchiveModulesOnBoard( true ); + case ID_MENU_ARCHIVE_MODULES_IN_LIBRARY: + ArchiveModulesOnBoard( false ); break; - case ID_MENU_ARCHIVE_ALL_MODULES: - ArchiveModulesOnBoard( false ); + case ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES: + ArchiveModulesOnBoard( true ); break; case ID_GEN_IMPORT_DXF_FILE: diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index 362c340f40..2fb89e0c7e 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -384,7 +384,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveCurrentModule( const wxString* aLibPath ) return true; } -wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary() +wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary() { // Kicad cannot write legacy format libraries, only .pretty new format // because the legacy format cannot handle current features. @@ -514,7 +514,7 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary() } -void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly ) +void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib ) { if( GetBoard()->m_Modules == NULL ) { @@ -522,57 +522,59 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly ) return; } - PROJECT& prj = Prj(); + wxString footprintName; - wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME ); - - wxString nickname = SelectLibrary( last_nickname ); - - if( !nickname ) - return; - - prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname ); - - if( !aNewModulesOnly ) + if( !aStoreInNewLib ) { - wxString msg = wxString::Format( FMT_OK_OVERWRITE, GetChars( nickname ) ); + // The footprints are saved in an existing .pretty library in the fp lib table + PROJECT& prj = Prj(); + wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME ); + wxString nickname = SelectLibrary( last_nickname ); - if( !IsOK( this, msg ) ) + if( !nickname ) // Aborted return; - } - m_canvas->SetAbortRequest( false ); + prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname ); - try - { - FP_LIB_TABLE* tbl = prj.PcbFootprintLibs(); - - // Delete old library if we're replacing it entirely. - if( !aNewModulesOnly ) + try { - tbl->FootprintLibDelete( nickname ); - tbl->FootprintLibCreate( nickname ); + FP_LIB_TABLE* tbl = prj.PcbFootprintLibs(); - for( MODULE* m = GetBoard()->m_Modules; m; m = m->Next() ) + for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() ) { - tbl->FootprintSave( nickname, m, true ); + if( !curr_fp->GetFPID().GetFootprintName().empty() ) // Can happen with old boards. + tbl->FootprintSave( nickname, curr_fp, false ); } } - else + catch( const IO_ERROR& ioe ) { - for( MODULE* m = GetBoard()->m_Modules; m; m = m->Next() ) - { - tbl->FootprintSave( nickname, m, false ); - - // Check for request to stop backup (ESCAPE key actuated) - if( m_canvas->GetAbortRequest() ) - break; - } + DisplayError( this, ioe.errorText ); } } - catch( const IO_ERROR& ioe ) + else { - DisplayError( this, ioe.errorText ); + // The footprints are saved in a new .pretty library. + // If this library already exists, all previous footprints will be deleted + wxString libPath = CreateNewLibrary(); + + if( libPath.IsEmpty() ) // Aborted + return; + + IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD; + PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) ); + + for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() ) + { + try + { + if( !curr_fp->GetFPID().GetFootprintName().empty() ) // Can happen with old boards. + pi->FootprintSave( libPath, curr_fp ); + } + catch( const IO_ERROR& ioe ) + { + DisplayError( this, ioe.errorText ); + } + } } } diff --git a/pcbnew/menubar_pcbframe.cpp b/pcbnew/menubar_pcbframe.cpp index 1c291ff538..ca426c632b 100644 --- a/pcbnew/menubar_pcbframe.cpp +++ b/pcbnew/menubar_pcbframe.cpp @@ -252,14 +252,16 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() //----- archive submenu ----------------------------------------------------- wxMenu* submenuarchive = new wxMenu(); - AddMenuItem( submenuarchive, ID_MENU_ARCHIVE_NEW_MODULES, - _( "&Archive New Footprints" ), - _( "Archive new footprints only in a library (keep other footprints in this lib)" ), + AddMenuItem( submenuarchive, ID_MENU_ARCHIVE_MODULES_IN_LIBRARY, + _( "&Archive Footprints in a Project Library" ), + _( "Archive footprints in an existing library in footprint Lib table" + "(do not remove other footprints in this lib)" ), KiBitmap( library_update_xpm ) ); - AddMenuItem( submenuarchive, ID_MENU_ARCHIVE_ALL_MODULES, - _( "&Create Footprint Archive" ), - _( "Archive all footprints in a library (old library will be deleted)" ), + AddMenuItem( submenuarchive, ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES, + _( "&Create Library and Archive Footprints" ), + _( "Archive all footprints in a new library\n" + "(if this library already exists, it will be deleted)" ), KiBitmap( library_xpm ) ); AddMenuItem( filesMenu, submenuarchive, diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index 08cb17fe3d..ce32a2ef18 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -347,17 +347,6 @@ public: */ MODULE* Import_Module(); - /** - * Function CreateNewLibrary - * prompts user for a library path, then creates a new footprint library at that - * location. If library exists, user is warned about that, and is given a chance - * to abort the new creation, and in that case existing library is first deleted. - * - * @return wxString - the newly created library path if library was successfully - * created, else wxEmptyString because user aborted or error. - */ - wxString CreateNewLibrary(); - /** * Function SaveCurrentModule * saves the module which is currently being edited into aLibPath or into the diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 7a3574c4a5..15332ac5e6 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -42,6 +42,17 @@ public: virtual ~PCB_BASE_EDIT_FRAME() {}; + /** + * Function CreateNewLibrary + * prompts user for a library path, then creates a new footprint library at that + * location. If library exists, user is warned about that, and is given a chance + * to abort the new creation, and in that case existing library is first deleted. + * + * @return wxString - the newly created library path if library was successfully + * created, else wxEmptyString because user aborted or error. + */ + wxString CreateNewLibrary(); + /** * Function OnEditItemRequest * Install the corresponding dialog editor for the given item diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index f842a74d52..0579115a3b 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -127,8 +127,8 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_MENU( ID_GEN_IMPORT_SPECCTRA_DESIGN, PCB_EDIT_FRAME::ImportSpecctraDesign ) EVT_MENU( ID_GEN_IMPORT_DXF_FILE, PCB_EDIT_FRAME::Process_Special_Functions ) - EVT_MENU( ID_MENU_ARCHIVE_NEW_MODULES, PCB_EDIT_FRAME::Process_Special_Functions ) - EVT_MENU( ID_MENU_ARCHIVE_ALL_MODULES, PCB_EDIT_FRAME::Process_Special_Functions ) + EVT_MENU( ID_MENU_ARCHIVE_MODULES_IN_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions ) + EVT_MENU( ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit ) diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 9b7aa94eca..90bdc66ca9 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -256,8 +256,8 @@ enum pcbnew_ids ID_MENU_READ_BOARD_BACKUP_FILE, ID_MENU_RECOVER_BOARD_AUTOSAVE, ID_MENU_ARCHIVE_MODULES, - ID_MENU_ARCHIVE_NEW_MODULES, - ID_MENU_ARCHIVE_ALL_MODULES, + ID_MENU_ARCHIVE_MODULES_IN_LIBRARY, + ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES, ID_MENU_MICELLANOUS, ID_MENU_LIST_NETS, ID_MENU_PCB_CLEAN,