|
|
|
@ -42,6 +42,7 @@ |
|
|
|
#include <plugins/kicad/kicad_plugin.h>
|
|
|
|
#include <plugins/legacy/legacy_plugin.h>
|
|
|
|
#include <env_paths.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <footprint_editor_settings.h>
|
|
|
|
#include "footprint_viewer_frame.h"
|
|
|
|
@ -375,16 +376,25 @@ wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary( const wxString& aLibName, |
|
|
|
// because the legacy format cannot handle current features.
|
|
|
|
// The footprint library is actually a directory
|
|
|
|
|
|
|
|
FP_LIB_TABLE* table = selectLibTable(); |
|
|
|
|
|
|
|
if( table == nullptr ) |
|
|
|
{ |
|
|
|
return wxEmptyString; |
|
|
|
} |
|
|
|
|
|
|
|
wxString initialPath = aProposedName.IsEmpty() ? Prj().GetProjectPath() : aProposedName; |
|
|
|
wxFileName fn; |
|
|
|
bool doAdd = false; |
|
|
|
bool isGlobal = ( table == &GFootprintTable ); |
|
|
|
|
|
|
|
if( aLibName.IsEmpty() ) |
|
|
|
{ |
|
|
|
fn = initialPath; |
|
|
|
|
|
|
|
if( !LibraryFileBrowser( false, fn, |
|
|
|
KiCadFootprintLibPathWildcard(), KiCadFootprintLibPathExtension ) ) |
|
|
|
if( !LibraryFileBrowser( false, fn, KiCadFootprintLibPathWildcard(), |
|
|
|
KiCadFootprintLibPathExtension, false, isGlobal, |
|
|
|
PATHS::GetDefaultUserFootprintsPath() ) ) |
|
|
|
{ |
|
|
|
return wxEmptyString; |
|
|
|
} |
|
|
|
@ -455,55 +465,89 @@ wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary( const wxString& aLibName, |
|
|
|
} |
|
|
|
|
|
|
|
if( doAdd ) |
|
|
|
AddLibrary( libPath ); |
|
|
|
AddLibrary( libPath, table ); |
|
|
|
|
|
|
|
return libPath; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename ) |
|
|
|
FP_LIB_TABLE* PCB_BASE_EDIT_FRAME::selectLibTable( bool aOptional ) |
|
|
|
{ |
|
|
|
wxFileName fn( aFilename ); |
|
|
|
|
|
|
|
if( aFilename.IsEmpty() ) |
|
|
|
// If no project is loaded, always work with the global table
|
|
|
|
if( Prj().IsNullProject() ) |
|
|
|
{ |
|
|
|
if( !LibraryFileBrowser( true, fn, |
|
|
|
KiCadFootprintLibPathWildcard(), KiCadFootprintLibPathExtension, |
|
|
|
true ) ) |
|
|
|
FP_LIB_TABLE* ret = &GFootprintTable; |
|
|
|
|
|
|
|
if( aOptional ) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
wxMessageDialog dlg( this, _( "Add the library to the global library table?" ), |
|
|
|
_( "Add To Global Library Table" ), wxYES_NO ); |
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK ) |
|
|
|
ret = nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
wxString libPath = fn.GetFullPath(); |
|
|
|
wxString libName = fn.GetName(); |
|
|
|
wxArrayString libTableNames; |
|
|
|
libTableNames.Add( _( "Global" ) ); |
|
|
|
libTableNames.Add( _( "Project" ) ); |
|
|
|
|
|
|
|
if( libName.IsEmpty() ) |
|
|
|
return false; |
|
|
|
wxSingleChoiceDialog dlg( this, _( "Choose the Library Table to add the library to:" ), |
|
|
|
_( "Add To Library Table" ), libTableNames ); |
|
|
|
|
|
|
|
if( aOptional ) |
|
|
|
{ |
|
|
|
dlg.FindWindow( wxID_CANCEL )->SetLabel( _( "Skip" ) ); |
|
|
|
dlg.FindWindow( wxID_OK )->SetLabel( _( "Add" ) ); |
|
|
|
} |
|
|
|
|
|
|
|
bool saveInGlobalTable = false; |
|
|
|
bool saveInProjectTable = false; |
|
|
|
if( dlg.ShowModal() != wxID_OK ) |
|
|
|
return nullptr; |
|
|
|
|
|
|
|
if( Prj().IsNullProject() ) |
|
|
|
switch( dlg.GetSelection() ) |
|
|
|
{ |
|
|
|
saveInGlobalTable = true; |
|
|
|
case 0: return &GFootprintTable; |
|
|
|
case 1: return Prj().PcbFootprintLibs(); |
|
|
|
default: return nullptr; |
|
|
|
} |
|
|
|
else |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename, FP_LIB_TABLE* aTable ) |
|
|
|
{ |
|
|
|
if( aTable == nullptr ) |
|
|
|
{ |
|
|
|
wxArrayString libTableNames; |
|
|
|
aTable = selectLibTable(); |
|
|
|
|
|
|
|
if( aTable == nullptr ) |
|
|
|
{ |
|
|
|
return wxEmptyString; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
libTableNames.Add( _( "Global" ) ); |
|
|
|
libTableNames.Add( _( "Project" ) ); |
|
|
|
bool isGlobal = ( aTable == &GFootprintTable ); |
|
|
|
|
|
|
|
switch( SelectSingleOption( this, _( "Select Library Table" ), |
|
|
|
_( "Choose the Library Table to add the library to:" ), libTableNames ) ) |
|
|
|
wxFileName fn( aFilename ); |
|
|
|
|
|
|
|
if( aFilename.IsEmpty() ) |
|
|
|
{ |
|
|
|
if( !LibraryFileBrowser( true, fn, KiCadFootprintLibPathWildcard(), |
|
|
|
KiCadFootprintLibPathExtension, true, isGlobal, |
|
|
|
PATHS::GetDefaultUserFootprintsPath() ) ) |
|
|
|
{ |
|
|
|
case 0: saveInGlobalTable = true; break; |
|
|
|
case 1: saveInProjectTable = true; break; |
|
|
|
default: return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
wxString libPath = fn.GetFullPath(); |
|
|
|
wxString libName = fn.GetName(); |
|
|
|
|
|
|
|
if( libName.IsEmpty() ) |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
wxString type = IO_MGR::ShowType( IO_MGR::GuessPluginTypeFromLibPath( libPath ) ); |
|
|
|
|
|
|
|
// try to use path normalized to an environmental variable or project path
|
|
|
|
@ -514,16 +558,15 @@ bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename ) |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
if( saveInGlobalTable ) |
|
|
|
auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString ); |
|
|
|
aTable->InsertRow( row ); |
|
|
|
|
|
|
|
if( isGlobal ) |
|
|
|
{ |
|
|
|
auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString ); |
|
|
|
GFootprintTable.InsertRow( row ); |
|
|
|
GFootprintTable.Save( FP_LIB_TABLE::GetGlobalTableFileName() ); |
|
|
|
} |
|
|
|
else if( saveInProjectTable ) |
|
|
|
else |
|
|
|
{ |
|
|
|
auto row = new FP_LIB_TABLE_ROW( libName, normalizedPath, type, wxEmptyString ); |
|
|
|
Prj().PcbFootprintLibs()->InsertRow( row ); |
|
|
|
Prj().PcbFootprintLibs()->Save( Prj().FootprintLibTblName() ); |
|
|
|
} |
|
|
|
} |
|
|
|
|