Move File > Archive Footprints to Tools > Harvest Footprints.

CHANGED.

Also corrects references so they fit the generic pattern.

Fixes https://gitlab.com/kicad/code/kicad/issues/4518
This commit is contained in:
Jeff Young 2020-10-21 11:31:06 +01:00
parent b907f79485
commit adfc9f1288
9 changed files with 81 additions and 52 deletions

View File

@ -61,12 +61,12 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
GetCanvas()->Refresh();
break;
case ID_MENU_ARCHIVE_MODULES_IN_LIBRARY:
ArchiveModulesOnBoard( false );
case ID_MENU_HARVEST_FOOTPRINTS_TO_LIBRARY:
HarvestFootprintsToLibrary( false );
break;
case ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES:
ArchiveModulesOnBoard( true );
case ID_MENU_HARVEST_FOOTPRINTS_TO_NEW_LIBRARY:
HarvestFootprintsToLibrary( true );
break;
default:

View File

@ -1058,7 +1058,7 @@ bool PCB_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
// Extract a footprint library from the design and add it to the fp-lib-table
wxString newLibPath;
ArchiveModulesOnBoard( true, newfilename.GetName(), &newLibPath );
HarvestFootprintsToLibrary( true, newfilename.GetName(), &newLibPath );
if( newLibPath.Length() > 0 )
{

View File

@ -609,17 +609,39 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aC
}
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
void PCB_EDIT_FRAME::HarvestFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName,
wxString* aLibPath )
{
if( GetBoard()->GetFirstModule() == NULL )
{
DisplayInfoMessage( this, _( "No footprints to archive!" ) );
DisplayInfoMessage( this, _( "No footprints to harvest!" ) );
return;
}
wxString footprintName;
auto resetReference =
[]( MODULE* aFootprint )
{
wxString reference;
if( aFootprint->GetAttributes() & MOD_SMD )
{
reference = "REF**";
}
else
{
reference = aFootprint->GetReference();
while( reference.Last() == '*' || wxIsdigit( reference.Last() ) )
reference.RemoveLast();
reference += wxT( "**" );
}
aFootprint->SetReference( reference );
};
if( !aStoreInNewLib )
{
// The footprints are saved in an existing .pretty library in the fp lib table
@ -632,14 +654,20 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString&
prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
for( MODULE* footprint : GetBoard()->Modules() )
{
try
{
FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
for( auto curr_fp : GetBoard()->Modules() )
if( !footprint->GetFPID().GetLibItemName().empty() ) // Handle old boards.
{
if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
tbl->FootprintSave( nickname, curr_fp, false );
MODULE* fpCopy = static_cast<MODULE*>( footprint->Duplicate() );
resetReference( fpCopy );
tbl->FootprintSave( nickname, fpCopy, true );
delete fpCopy;
}
}
catch( const IO_ERROR& ioe )
@ -647,6 +675,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString&
DisplayError( this, ioe.What() );
}
}
}
else
{
// The footprints are saved in a new .pretty library.
@ -662,12 +691,19 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString&
IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP;
PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
for( auto curr_fp : GetBoard()->Modules() )
for( MODULE* footprint : GetBoard()->Modules() )
{
try
{
if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards.
pi->FootprintSave( libPath, curr_fp );
if( !footprint->GetFPID().GetLibItemName().empty() ) // Handle old boards.
{
MODULE* fpCopy = static_cast<MODULE*>( footprint->Duplicate() );
resetReference( fpCopy );
pi->FootprintSave( libPath, fpCopy );
delete fpCopy;
}
}
catch( const IO_ERROR& ioe )
{

View File

@ -173,25 +173,6 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
fileMenu->Add( ACTIONS::print );
fileMenu->Add( ACTIONS::plot );
// Archive submenu
ACTION_MENU* submenuArchive = new ACTION_MENU( false );
submenuArchive->SetTool( selTool );
submenuArchive->SetTitle( _( "Archive Footprints" ) );
submenuArchive->SetIcon( library_archive_xpm );
submenuArchive->Add( _( "&Archive Footprints in Existing Library..." ),
_( "Archive all footprints to existing library in footprint Lib table"
"(does not remove other footprints in this library)" ),
ID_MENU_ARCHIVE_MODULES_IN_LIBRARY, library_archive_xpm );
submenuArchive->Add( _( "&Create New Library and Archive Footprints..." ),
_( "Archive all footprints to a new library\n"
"(if the library already exists it will be replaced)" ),
ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES, library_archive_as_xpm );
fileMenu->AppendSeparator();
fileMenu->Add( submenuArchive );
fileMenu->AppendSeparator();
fileMenu->AddQuitOrClose( &Kiface(), _( "Pcbnew" ) );
@ -396,6 +377,17 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
toolsMenu->Add( PCB_ACTIONS::removeUnusedPads );
toolsMenu->Add( PCB_ACTIONS::repairBoard );
toolsMenu->AppendSeparator();
toolsMenu->Add( _( "&Harvest Footprints to Library..." ),
_( "Add footprints used on board to an existing footprint library\n"
"(does not remove other footprints from this library)" ),
ID_MENU_HARVEST_FOOTPRINTS_TO_LIBRARY, library_archive_xpm );
toolsMenu->Add( _( "&Harvest Footprints to New Library..." ),
_( "Create a new footprint library containing the footprints used on board\n"
"(if the library already exists it will be replaced)" ),
ID_MENU_HARVEST_FOOTPRINTS_TO_NEW_LIBRARY, library_archive_as_xpm );
#if defined(KICAD_SCRIPTING_WXPYTHON)
toolsMenu->AppendSeparator();
toolsMenu->Add( PCB_ACTIONS::showPythonConsole );

View File

@ -128,8 +128,8 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
EVT_MENU( ID_GEN_EXPORT_FILE_STEP, PCB_EDIT_FRAME::OnExportSTEP )
EVT_MENU( ID_GEN_EXPORT_FILE_HYPERLYNX, PCB_EDIT_FRAME::OnExportHyperlynx )
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( ID_MENU_HARVEST_FOOTPRINTS_TO_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions )
EVT_MENU( ID_MENU_HARVEST_FOOTPRINTS_TO_NEW_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions )
EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit )
EVT_MENU( wxID_CLOSE, PCB_EDIT_FRAME::OnQuit )

View File

@ -616,7 +616,7 @@ public:
void RecreateCmpFileFromBoard( wxCommandEvent& aEvent );
/**
* Function ArchiveModulesOnBoard
* Function HarvestFootprintsToLibrary
* Save footprints in a library:
* @param aStoreInNewLib:
* true : save footprints in a existing lib. Existing footprints will be kept
@ -629,7 +629,7 @@ public:
* optional library name to create, stops dialog call.
* must be called with aStoreInNewLib as true
*/
void ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName = wxEmptyString,
void HarvestFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName = wxEmptyString,
wxString* aLibPath = NULL );
/**

View File

@ -78,8 +78,8 @@ enum pcbnew_ids
ID_POPUP_PCB_SELECT_WIDTH_END_RANGE,
ID_MENU_RECOVER_BOARD_AUTOSAVE,
ID_MENU_ARCHIVE_MODULES_IN_LIBRARY,
ID_MENU_CREATE_LIBRARY_AND_ARCHIVE_MODULES,
ID_MENU_HARVEST_FOOTPRINTS_TO_LIBRARY,
ID_MENU_HARVEST_FOOTPRINTS_TO_NEW_LIBRARY,
ID_GEN_EXPORT_FILE_IDF3,
ID_GEN_EXPORT_FILE_VRML,

View File

@ -301,11 +301,11 @@ bool ImportSpecctraSES( wxString& aFullFilename )
}
bool ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath )
bool HarvestFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath )
{
if( s_PcbEditFrame )
{
s_PcbEditFrame->ArchiveModulesOnBoard( aStoreInNewLib, aLibName, aLibPath );
s_PcbEditFrame->HarvestFootprintsToLibrary( aStoreInNewLib, aLibName, aLibPath );
return true;
}
else

View File

@ -98,7 +98,7 @@ bool ExportVRML( const wxString& aFullFileName, double aMMtoWRMLunit,
bool ImportSpecctraSES( wxString& aFullFilename );
/**
* Function ArchiveModulesOnBoard
* Function HarvestFootprintsToLibrary
* Save footprints in a library:
* @param aStoreInNewLib:
* true : save footprints in a existing lib. Existing footprints will be kept
@ -111,8 +111,9 @@ bool ImportSpecctraSES( wxString& aFullFilename );
* optional library name to create, stops dialog call.
* must be called with aStoreInNewLib as true
*/
bool ArchiveModulesOnBoard(
bool aStoreInNewLib, const wxString& aLibName = wxEmptyString, wxString* aLibPath = NULL );
bool HarvestFootprintsToLibrary( bool aStoreInNewLib, const wxString& aLibName = wxEmptyString,
wxString* aLibPath = NULL );
/**
* Update the board display after modifying it by a python script
* (note: it is automatically called by action plugins, after running the plugin,