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.

This commit is contained in:
jean-pierre charras 2015-09-28 10:46:00 +02:00
parent b504252789
commit 2a4f8db792
8 changed files with 74 additions and 67 deletions

View File

@ -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

View File

@ -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:

View File

@ -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 );
}
}
}
}

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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 )

View File

@ -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,