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:
parent
b504252789
commit
2a4f8db792
|
@ -937,11 +937,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* Function ArchiveModulesOnBoard
|
* Function ArchiveModulesOnBoard
|
||||||
* Save modules in a library:
|
* Save modules in a library:
|
||||||
* @param aNewModulesOnly:
|
* @param aStoreInNewLib:
|
||||||
* true : save modules not already existing in this lib
|
* true : save modules in a existing lib. Existing footprints will be kept
|
||||||
* false: save all modules
|
* 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
|
* Function RecreateBOMFileFromBoard
|
||||||
|
|
|
@ -1235,12 +1235,12 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_MENU_ARCHIVE_NEW_MODULES:
|
case ID_MENU_ARCHIVE_MODULES_IN_LIBRARY:
|
||||||
ArchiveModulesOnBoard( true );
|
ArchiveModulesOnBoard( false );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_MENU_ARCHIVE_ALL_MODULES:
|
case ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES:
|
||||||
ArchiveModulesOnBoard( false );
|
ArchiveModulesOnBoard( true );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_GEN_IMPORT_DXF_FILE:
|
case ID_GEN_IMPORT_DXF_FILE:
|
||||||
|
|
|
@ -384,7 +384,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveCurrentModule( const wxString* aLibPath )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary()
|
wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary()
|
||||||
{
|
{
|
||||||
// Kicad cannot write legacy format libraries, only .pretty new format
|
// Kicad cannot write legacy format libraries, only .pretty new format
|
||||||
// because the legacy format cannot handle current features.
|
// 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 )
|
if( GetBoard()->m_Modules == NULL )
|
||||||
{
|
{
|
||||||
|
@ -522,57 +522,59 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PROJECT& prj = Prj();
|
wxString footprintName;
|
||||||
|
|
||||||
wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
|
if( !aStoreInNewLib )
|
||||||
|
|
||||||
wxString nickname = SelectLibrary( last_nickname );
|
|
||||||
|
|
||||||
if( !nickname )
|
|
||||||
return;
|
|
||||||
|
|
||||||
prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
|
|
||||||
|
|
||||||
if( !aNewModulesOnly )
|
|
||||||
{
|
{
|
||||||
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;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
m_canvas->SetAbortRequest( false );
|
prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
|
||||||
FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
|
|
||||||
|
|
||||||
// Delete old library if we're replacing it entirely.
|
|
||||||
if( !aNewModulesOnly )
|
|
||||||
{
|
{
|
||||||
tbl->FootprintLibDelete( nickname );
|
FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
|
||||||
tbl->FootprintLibCreate( nickname );
|
|
||||||
|
|
||||||
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() )
|
DisplayError( this, ioe.errorText );
|
||||||
{
|
|
||||||
tbl->FootprintSave( nickname, m, false );
|
|
||||||
|
|
||||||
// Check for request to stop backup (ESCAPE key actuated)
|
|
||||||
if( m_canvas->GetAbortRequest() )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,14 +252,16 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
|
||||||
//----- archive submenu -----------------------------------------------------
|
//----- archive submenu -----------------------------------------------------
|
||||||
wxMenu* submenuarchive = new wxMenu();
|
wxMenu* submenuarchive = new wxMenu();
|
||||||
|
|
||||||
AddMenuItem( submenuarchive, ID_MENU_ARCHIVE_NEW_MODULES,
|
AddMenuItem( submenuarchive, ID_MENU_ARCHIVE_MODULES_IN_LIBRARY,
|
||||||
_( "&Archive New Footprints" ),
|
_( "&Archive Footprints in a Project Library" ),
|
||||||
_( "Archive new footprints only in a library (keep other footprints in this lib)" ),
|
_( "Archive footprints in an existing library in footprint Lib table"
|
||||||
|
"(do not remove other footprints in this lib)" ),
|
||||||
KiBitmap( library_update_xpm ) );
|
KiBitmap( library_update_xpm ) );
|
||||||
|
|
||||||
AddMenuItem( submenuarchive, ID_MENU_ARCHIVE_ALL_MODULES,
|
AddMenuItem( submenuarchive, ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES,
|
||||||
_( "&Create Footprint Archive" ),
|
_( "&Create Library and Archive Footprints" ),
|
||||||
_( "Archive all footprints in a library (old library will be deleted)" ),
|
_( "Archive all footprints in a new library\n"
|
||||||
|
"(if this library already exists, it will be deleted)" ),
|
||||||
KiBitmap( library_xpm ) );
|
KiBitmap( library_xpm ) );
|
||||||
|
|
||||||
AddMenuItem( filesMenu, submenuarchive,
|
AddMenuItem( filesMenu, submenuarchive,
|
||||||
|
|
|
@ -347,17 +347,6 @@ public:
|
||||||
*/
|
*/
|
||||||
MODULE* Import_Module();
|
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
|
* Function SaveCurrentModule
|
||||||
* saves the module which is currently being edited into aLibPath or into the
|
* saves the module which is currently being edited into aLibPath or into the
|
||||||
|
|
|
@ -42,6 +42,17 @@ public:
|
||||||
|
|
||||||
virtual ~PCB_BASE_EDIT_FRAME() {};
|
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
|
* Function OnEditItemRequest
|
||||||
* Install the corresponding dialog editor for the given item
|
* Install the corresponding dialog editor for the given item
|
||||||
|
|
|
@ -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_SPECCTRA_DESIGN, PCB_EDIT_FRAME::ImportSpecctraDesign )
|
||||||
EVT_MENU( ID_GEN_IMPORT_DXF_FILE, PCB_EDIT_FRAME::Process_Special_Functions )
|
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_MODULES_IN_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions )
|
||||||
EVT_MENU( ID_MENU_ARCHIVE_ALL_MODULES, 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 )
|
EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit )
|
||||||
|
|
||||||
|
|
|
@ -256,8 +256,8 @@ enum pcbnew_ids
|
||||||
ID_MENU_READ_BOARD_BACKUP_FILE,
|
ID_MENU_READ_BOARD_BACKUP_FILE,
|
||||||
ID_MENU_RECOVER_BOARD_AUTOSAVE,
|
ID_MENU_RECOVER_BOARD_AUTOSAVE,
|
||||||
ID_MENU_ARCHIVE_MODULES,
|
ID_MENU_ARCHIVE_MODULES,
|
||||||
ID_MENU_ARCHIVE_NEW_MODULES,
|
ID_MENU_ARCHIVE_MODULES_IN_LIBRARY,
|
||||||
ID_MENU_ARCHIVE_ALL_MODULES,
|
ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES,
|
||||||
ID_MENU_MICELLANOUS,
|
ID_MENU_MICELLANOUS,
|
||||||
ID_MENU_LIST_NETS,
|
ID_MENU_LIST_NETS,
|
||||||
ID_MENU_PCB_CLEAN,
|
ID_MENU_PCB_CLEAN,
|
||||||
|
|
Loading…
Reference in New Issue