@ -656,99 +656,118 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString&
}
bool FOOTPRINT_EDIT_FRAME : : SaveFootprintInLibrary ( const wxString & aLibrary ,
MODULE * aModule ,
bool aOverwrite ,
bool aDisplayDialog )
bool FOOTPRINT_EDIT_FRAME : : SaveFootprintInLibrary ( wxString activeLibrary , MODULE * aModule )
{
if ( aModule = = NULL )
return false ;
FP_LIB_TABLE * tbl = Prj ( ) . PcbFootprintLibs ( ) ;
SetMsgPanel ( aModule ) ;
// For 6.0 Save should silently save the footprint in its own library.
// Save As... should allow a rename and/or reparent to a different library.
//
// However, for 5.0 we need a more limited intervention. We'll always display
// the dialog, but add a Library selection widget that will default to saving
// in the footprint's own library but allow switching to the active library
// (or even some other library).
// Legacy libraries are readable, but modifying legacy format is not allowed
// So prompt the user if he try to add/replace a footprint in a legacy lib
wxString libfullname = Prj ( ) . PcbFootprintLibs ( ) - > FindRow ( aLibrary ) - > GetFullURI ( ) ;
IO_MGR : : PCB_FILE_T piType = IO_MGR : : GuessPluginTypeFromLibPath ( libfullname ) ;
wxString libraryName = aModule - > GetFPID ( ) . GetLibNickname ( ) ;
wxString footprintName = aModule - > GetFPID ( ) . GetLibItemName ( ) ;
if ( piType = = IO_MGR : : LEGACY )
if ( libraryName . IsEmpty ( ) )
libraryName = activeLibrary ;
wxArrayString headers ;
std : : vector < wxArrayString > itemsToDisplay ;
std : : vector < wxString > nicknames = tbl - > GetLogicalLibs ( ) ;
headers . Add ( _ ( " Nickname " ) ) ;
headers . Add ( _ ( " Description " ) ) ;
for ( unsigned i = 0 ; i < nicknames . size ( ) ; i + + )
{
DisplayInfoMessage ( this , INFO_LEGACY_LIB_WARN_EDIT ) ;
return false ;
wxArrayString item ;
item . Add ( nicknames [ i ] ) ;
item . Add ( tbl - > GetDescription ( nicknames [ i ] ) ) ;
itemsToDisplay . push_back ( item ) ;
}
// Ask what to use as the footprint name in the library
wxString footprintName = aModule - > GetFPID ( ) . GetLibItemName ( ) ;
EDA_LIST_DIALOG dlg ( this , FMT_SAVE_MODULE , headers , itemsToDisplay , libraryName ) ;
dlg . SetFilterLabel ( _ ( " Library Filter: " ) ) ;
dlg . SetListLabel ( _ ( " Save in Library: " ) ) ;
if ( aDisplayDialog )
{
wxTextEntryDialog dlg ( this , _ ( " Name: " ) , FMT_SAVE_MODULE , footprintName ) ;
wxSizer * mainSizer = dlg . GetSizer ( ) ;
if ( dlg . ShowModal ( ) ! = wxID_OK )
return false ; // canceled by user
wxStaticLine * separator = new wxStaticLine ( & dlg , wxID_ANY , wxDefaultPosition , wxDefaultSize , wxLI_HORIZONTAL ) ;
mainSizer - > Prepend ( separator , 0 , wxEXPAND | wxBOTTOM | wxTOP , 10 ) ;
footprintName = dlg . GetValue ( ) ;
footprintName . Trim ( true ) ;
footprintName . Trim ( false ) ;
wxTextCtrl * nameTextCtrl = new wxTextCtrl ( & dlg , wxID_ANY , footprintName , wxDefaultPosition , wxDefaultSize , 0 ) ;
mainSizer - > Prepend ( nameTextCtrl , 0 , wxEXPAND | wxBOTTOM | wxRIGHT | wxLEFT , 5 ) ;
if ( footprintName . IsEmpty ( ) )
return false ;
wxTextValidator nameValidator ( wxFILTER_EXCLUDE_CHAR_LIST ) ;
nameValidator . SetCharExcludes ( MODULE : : StringLibNameInvalidChars ( true ) ) ;
nameTextCtrl - > SetValidator ( nameValidator ) ;
if ( ! MODULE : : IsLibNameValid ( footprintName ) )
{
wxString msg = wxString : : Format (
_ ( " Error: \n one of invalid chars \" %s \" found \n in \" %s \" " ) ,
MODULE : : StringLibNameInvalidChars ( true ) ,
GetChars ( footprintName ) ) ;
wxStaticText * label = new wxStaticText ( & dlg , wxID_ANY , _ ( " Footprint Name: " ) , wxDefaultPosition , wxDefaultSize , 0 ) ;
mainSizer - > Prepend ( label , 0 , wxTOP | wxRIGHT | wxLEFT , 5 ) ;
DisplayError ( NULL , msg ) ;
return false ;
}
// Move nameTextCtrl to the head of the tab-order
if ( dlg . GetChildren ( ) . DeleteObject ( nameTextCtrl ) )
dlg . GetChildren ( ) . Insert ( nameTextCtrl ) ;
aModule - > SetFPID ( LIB_ID ( footprintName ) ) ;
}
dlg . Layout ( ) ;
mainSizer - > Fit ( & dlg ) ;
// Ensure this footprint has a libname
if ( footprintName . IsEmpty ( ) )
if ( dlg . ShowModal ( ) ! = wxID_OK )
return false ; // canceled by user
libraryName = dlg . GetTextSelection ( ) ;
if ( libraryName . IsEmpty ( ) )
{
footprintName = wxT ( " noname " ) ;
aModule - > SetFPID ( LIB_ID ( footprintName ) ) ;
DisplayError ( NULL , _ ( " No library specified. Footprint could not be saved. " ) ) ;
return false ;
}
bool module_exists = false ;
footprintName = nameTextCtrl - > GetValue ( ) ;
footprintName . Trim ( true ) ;
footprintName . Trim ( false ) ;
try
if ( foo tp rintName . IsEmpt y( ) )
{
FP_LIB_TABLE * tbl = Prj ( ) . PcbFootprintLibs ( ) ;
DisplayError ( NULL , _ ( " No footprint name specified. Footprint could not be saved. " ) ) ;
return false ;
}
MODULE * m = tbl - > FootprintLoad ( aLibrary , footprintName ) ;
aModule - > SetFPID ( LIB_ID ( footprintName ) ) ;
if ( m )
{
delete m ;
// Legacy libraries are readable, but modifying legacy format is not allowed
// So prompt the user if he try to add/replace a footprint in a legacy lib
wxString libfullname = Prj ( ) . PcbFootprintLibs ( ) - > FindRow ( libraryName ) - > GetFullURI ( ) ;
IO_MGR : : PCB_FILE_T piType = IO_MGR : : GuessPluginTypeFromLibPath ( libfullname ) ;
module_exists = true ;
if ( piType = = IO_MGR : : LEGACY )
{
DisplayInfoMessage ( this , INFO_LEGACY_LIB_WARN_EDIT ) ;
return false ;
}
// an existing footprint is found in current lib
if ( aDisplayDialog )
{
wxString msg = wxString : : Format ( FMT_MOD_EXISTS ,
footprintName . GetData ( ) , aLibrary . GetData ( ) ) ;
bool module_exists = false ;
SetStatusText ( msg ) ;
}
try
{
MODULE * m = tbl - > FootprintLoad ( libraryName , footprintName ) ;
if ( ! aOverwrite )
{
// Do not save the given footprint: an old one exists
return true ;
}
}
module_exists = m ! = nullptr ;
delete m ;
// this always overwrites any existing footprint, but should yell on its
// own if the library or footprint is not writable.
tbl - > FootprintSave ( aLibrary , aModule ) ;
tbl - > FootprintSave ( libraryName , aModule ) ;
}
catch ( const IO_ERROR & ioe )
{
@ -756,15 +775,11 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( const wxString& aLibrary,
return false ;
}
if ( aDisplayDialog )
{
wxString fmt = module_exists ?
_ ( " Component \" %s \" replaced in \" %s \" " ) :
_ ( " Component \" %s \" added in \" %s \" " ) ;
wxString fmt = module_exists ? _ ( " Component \" %s \" replaced in \" %s \" " ) :
_ ( " Component \" %s \" added in \" %s \" " ) ;
wxString msg = wxString : : Format ( fmt , footprintName . GetData ( ) , aLibrary . GetData ( ) ) ;
SetStatusText ( msg ) ;
}
wxString msg = wxString : : Format ( fmt , footprintName . GetData ( ) , libraryName . GetData ( ) ) ;
SetStatusText ( msg ) ;
return true ;
}