PcbNew Eagle Import: Archives footprints in pretty library automatically on eagle project import.

This commit is contained in:
Russell Oliver 2017-08-26 22:04:56 +10:00 committed by Maciej Suminski
parent 869743d573
commit b9973a1c67
4 changed files with 39 additions and 12 deletions

View File

@ -878,6 +878,8 @@ bool PCB_EDIT_FRAME::ImportFile( const wxString aFileName )
GetBoard()->SetFileName( newfilename.GetFullPath() );
UpdateTitle();
ArchiveModulesOnBoard( true, newfilename.GetName() );
return true;
}

View File

@ -441,24 +441,43 @@ bool FOOTPRINT_EDIT_FRAME::SaveCurrentModule( const wxString* aLibPath )
return true;
}
wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary()
wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary(const wxString& aLibName )
{
// Kicad cannot write legacy format libraries, only .pretty new format
// because the legacy format cannot handle current features.
// The footprint library is actually a directory
// prompt user for footprint library name, ending by ".pretty"
// if a library name is not given, prompt user for footprint library name, ending by ".pretty"
// Because there are constraints for the directory name to create,
// (the name should have the extension ".pretty", and the folder cannot be inside
// a footprint library), we do not use the standard wxDirDialog.
wxString initialPath = wxPathOnly( Prj().GetProjectFullName() );
DIALOG_SELECT_PRETTY_LIB dlg( this, initialPath );
if( dlg.ShowModal() != wxID_OK )
return wxEmptyString;
wxString libPath;
if( aLibName.IsEmpty() )
{
DIALOG_SELECT_PRETTY_LIB dlg( this, initialPath );
if( dlg.ShowModal() != wxID_OK )
return wxEmptyString;
libPath = dlg.GetFullPrettyLibName();
}
else
{
wxFileName fn = aLibName;
if( !fn.IsAbsolute() )
fn.MakeAbsolute( initialPath );
// Enforce the extension:
fn.SetExt( KiCadFootprintLibPathExtension );
libPath = fn.GetFullPath();
}
wxString libPath = dlg.GetFullPrettyLibName();
// We can save fp libs only using IO_MGR::KICAD format (.pretty libraries)
IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD;
@ -570,7 +589,7 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary()
}
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib )
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName )
{
if( GetBoard()->m_Modules == NULL )
{
@ -611,7 +630,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib )
{
// The footprints are saved in a new .pretty library.
// If this library already exists, all previous footprints will be deleted
wxString libPath = CreateNewLibrary();
wxString libPath = CreateNewLibrary( aLibName );
if( libPath.IsEmpty() ) // Aborted
return;

View File

@ -52,14 +52,16 @@ public:
/**
* 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
* If a library name is given, creates a new footprint library in the project folder
* with the given name. If no library name is given it 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();
wxString CreateNewLibrary(const wxString& aLibName = wxEmptyString);
/**
* Function OnEditItemRequest

View File

@ -939,8 +939,12 @@ public:
* 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
*
* @param aLibName:
* optional library name to create, stops dialog call.
* must be called with aStoreInNewLib as true
*/
void ArchiveModulesOnBoard( bool aStoreInNewLib );
void ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName = wxEmptyString );
/**
* Function RecreateBOMFileFromBoard