@ -20,9 +20,9 @@
# include <class_module.h>
# include <pcbnew.h>
# include <class_footprint_library.h>
# include <module_editor_frame.h>
# include <wildcards_and_files_ext.h>
# include <legacy_plugin.h> // temporarily, for LoadMODULE()
/*
@ -46,26 +46,24 @@ static const wxString ModImportFileWildcard( _( "GPcb foot print files (*)|*" )
MODULE * FOOTPRINT_EDIT_FRAME : : Import_Module ( )
{
char * Line ;
FILE * file ;
MODULE * module = NULL ;
bool Footprint_Is_GPCB_Format = false ;
// use the clipboard for this in the future?
wxString L astOpenedPathForLoading;
wxConfig * C onfig = wxGetApp ( ) . GetSettings ( ) ;
wxString lastOpenedPathForLoading ;
wxConfig * config = wxGetApp ( ) . GetSettings ( ) ;
if ( C onfig )
C onfig- > Read ( EXPORT_IMPORT_LASTPATH_KEY , & L astOpenedPathForLoading ) ;
if ( c onfig )
c onfig- > Read ( EXPORT_IMPORT_LASTPATH_KEY , & l astOpenedPathForLoading ) ;
wxString importWildCard = ModExportFileWildcard + wxT ( " | " ) + ModImportFileWildcard ;
wxFileDialog dlg ( this , _ ( " Import Footprint Module " ) ,
L astOpenedPathForLoading, wxEmptyString ,
l astOpenedPathForLoading, wxEmptyString ,
importWildCard , wxFD_OPEN | wxFD_FILE_MUST_EXIST ) ;
if ( dlg . ShowModal ( ) = = wxID_CANCEL )
return NULL ;
file = wxFopen ( dlg . GetPath ( ) , wxT ( " rt " ) ) ;
FILE * file = wxFopen ( dlg . GetPath ( ) , wxT ( " rt " ) ) ;
if ( file = = NULL )
{
@ -75,28 +73,29 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
return NULL ;
}
FILE_LINE_READER fileReader ( file , dlg . GetPath ( ) ) ;
FILTER_READER reader ( fileReader ) ;
if ( Config ) // Save file path
if ( config ) // Save file path
{
L astOpenedPathForLoading = wxPathOnly ( dlg . GetPath ( ) ) ;
C onfig- > Write ( EXPORT_IMPORT_LASTPATH_KEY , L astOpenedPathForLoading ) ;
lastOpenedPathForLoading = wxPathOnly ( dlg . GetPath ( ) ) ;
config - > Write ( EXPORT_IMPORT_LASTPATH_KEY , lastOpenedPathForLoading ) ;
}
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
SetLocaleTo_C_standard ( ) ;
LOCALE_IO toggle ;
FILE_LINE_READER fileReader ( file , dlg . GetPath ( ) ) ;
FILTER_READER reader ( fileReader ) ;
// Read header and test file type
reader . ReadLine ( ) ;
L ine = reader . Line ( ) ;
char * l ine = reader . Line ( ) ;
if ( strnicmp ( Line , FOOTPRINT_LIBRARY_HEADER , FOOTPRINT_LIBRARY_HEADER_CNT ) ! = 0 )
bool footprint_Is_GPCB_Format = false ;
if ( strnicmp ( line , FOOTPRINT_LIBRARY_HEADER , FOOTPRINT_LIBRARY_HEADER_CNT ) ! = 0 )
{
if ( strnicmp ( Line , " Element " , 7 ) = = 0 )
if ( strnicmp ( l ine, " Element " , 7 ) = = 0 )
{
F ootprint_Is_GPCB_Format = true ;
f ootprint_Is_GPCB_Format = true ;
}
else
{
@ -106,27 +105,41 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
}
// Read file: Search the description starting line (skip lib header)
if ( ! F ootprint_Is_GPCB_Format )
if ( ! f ootprint_Is_GPCB_Format )
{
while ( reader . ReadLine ( ) )
{
if ( strnicmp ( L ine, " $MODULE " , 7 ) = = 0 )
if ( strnicmp ( l ine, " $MODULE " , 7 ) = = 0 )
break ;
}
}
module = new MODULE ( GetBoard ( ) ) ;
MODULE * module ;
if ( F ootprint_Is_GPCB_Format )
if ( f ootprint_Is_GPCB_Format )
{
// @todo GEDA plugin
module = new MODULE ( GetBoard ( ) ) ;
module - > Read_GPCB_Descr ( dlg . GetPath ( ) ) ;
}
else
{
module - > ReadDescr ( & reader ) ;
}
try
{
PLUGIN : : RELEASER pi ( IO_MGR : : PluginFind ( IO_MGR : : LEGACY ) ) ;
LEGACY_PLUGIN * lp = ( LEGACY_PLUGIN * ) ( PLUGIN * ) pi ;
lp - > SetReader ( & reader ) ;
SetLocaleTo_Default ( ) ; // revert to the current locale
module = lp - > LoadMODULE ( ) ;
}
catch ( IO_ERROR ioe )
{
DisplayError ( this , ioe . errorText ) ;
return NULL ;
}
}
// Insert footprint in list
GetBoard ( ) - > Add ( module ) ;
@ -144,9 +157,8 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
void FOOTPRINT_EDIT_FRAME : : Export_Module ( MODULE * aModule , bool aCreateSysLib )
{
wxFileName fn ;
FILE * file ;
wxString msg , path , title , wildcard ;
wxConfig * C onfig = wxGetApp ( ) . GetSettings ( ) ;
wxConfig * c onfig = wxGetApp ( ) . GetSettings ( ) ;
if ( aModule = = NULL )
return ;
@ -156,12 +168,14 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule, bool aCreateSysLib )
if ( aCreateSysLib )
path = wxGetApp ( ) . ReturnLastVisitedLibraryPath ( ) ;
else if ( C onfig )
C onfig- > Read ( EXPORT_IMPORT_LASTPATH_KEY , & path ) ;
else if ( c onfig )
c onfig- > Read ( EXPORT_IMPORT_LASTPATH_KEY , & path ) ;
fn . SetPath ( path ) ;
title = aCreateSysLib ? _ ( " Create New Library " ) : _ ( " Export Module " ) ;
wildcard = aCreateSysLib ? FootprintLibFileWildcard : ModExportFileWildcard ;
fn . SetPath ( path ) ;
wxFileDialog dlg ( this , msg , fn . GetPath ( ) , fn . GetFullName ( ) ,
wxGetTranslation ( wildcard ) ,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT ) ;
@ -172,180 +186,63 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule, bool aCreateSysLib )
fn = dlg . GetPath ( ) ;
wxGetApp ( ) . SaveLastVisitedLibraryPath ( fn . GetPath ( ) ) ;
if ( ( file = wxFopen ( fn . GetFullPath ( ) , wxT ( " wt " ) ) ) = = NULL )
if ( ! aCreateSysLib & & config ) // Save file path
{
msg . Printf ( _ ( " Unable to create <%s> " ) , GetChars ( fn . GetFullPath ( ) ) ) ;
DisplayError ( this , msg ) ;
return ;
config - > Write ( EXPORT_IMPORT_LASTPATH_KEY , fn . GetPath ( ) ) ;
}
if ( ! aCreateSysLib & & Config ) // Save file path
{
Config - > Write ( EXPORT_IMPORT_LASTPATH_KEY , fn . GetPath ( ) ) ;
}
// Switch the locale to standard C (needed to read/write floating point numbers like 1.3)
SetLocaleTo_C_standard ( ) ;
FOOTPRINT_LIBRARY libexport ( file ) ;
libexport . WriteHeader ( ) ;
libexport . m_List . Add ( aModule - > m_LibRef ) ;
libexport . WriteSectionIndex ( ) ;
GetBoard ( ) - > m_Modules - > Save ( file ) ;
wxString libName = fn . GetFullPath ( ) ;
libexport . WriteEndOfFile ( ) ;
fclose ( file ) ;
try
{
// @todo : hard code this as IO_MGR::KICAD plugin, what would be the reason to "export"
// any other single footprint type, with clipboard support coming?
// Use IO_MGR::LEGACY for now, until the IO_MGR::KICAD plugin is ready.
PLUGIN : : RELEASER pi ( IO_MGR : : PluginFind ( IO_MGR : : LEGACY ) ) ;
SetLocaleTo_Default ( ) ; // revert to the current locale
pi - > FootprintLibCreate ( libName ) ;
pi - > FootprintSave ( libName , aModule ) ;
}
catch ( IO_ERROR ioe )
{
DisplayError ( this , ioe . errorText ) ;
return ;
}
msg . Printf ( _ ( " Module exported in file <%s> " ) , GetChars ( fn . GetFullPath ( ) ) ) ;
msg . Printf ( _ ( " Module exported in file <%s> " ) , libName . GetData ( ) ) ;
DisplayInfoMessage ( this , msg ) ;
}
void FOOTPRINT_EDIT_FRAME : : Delete_Module_In_Library ( const wxString & aLibname )
void FOOTPRINT_EDIT_FRAME : : Delete_Module_In_Library ( const wxString & aLibN ame )
{
wxFileName newFileName ;
wxFileName oldFileName ;
int LineNum = 0 ;
char Line [ 1024 ] , Name [ 256 ] ;
FILE * out_file , * lib_module ;
wxString CmpName , msg ;
wxString footprintName = Select_1_Module_From_List ( this , aLibName , wxEmptyString , wxEmptyString ) ;
CmpName = Select_1_Module_From_List ( this , aLibname , wxEmptyString , wxEmptyString ) ;
if ( CmpName = = wxEmptyString )
if ( footprintName = = wxEmptyString )
return ;
// Confirmation
msg . Printf ( _ ( " Ok to delete module %s in library %s " ) ,
GetChars ( CmpName ) , GetChars ( aLibname ) ) ;
wxString msg = wxString : : Format ( _ ( " Ok to delete module ' %s' in library ' %s' " ) ,
footprintName . GetData ( ) , aLibName . GetData ( ) ) ;
if ( ! IsOK ( this , msg ) )
return ;
oldFileName = aLibname ;
if ( ( lib_module = wxFopen ( oldFileName . GetFullPath ( ) , wxT ( " rt " ) ) ) = = NULL )
{
wxString msg ;
msg . Printf ( _ ( " Library <%s> not found " ) , GetChars ( oldFileName . GetFullPath ( ) ) ) ;
DisplayError ( NULL , msg ) ;
return ;
}
FOOTPRINT_LIBRARY input_lib ( lib_module ) ;
// Read header.
if ( ! input_lib . IsLibrary ( ) )
{
fclose ( lib_module ) ;
wxString msg ;
msg . Printf ( _ ( " <%s> is not a valid footprint library file " ) ,
GetChars ( oldFileName . GetFullPath ( ) ) ) ;
DisplayError ( NULL , msg ) ;
return ;
}
// Read module names.
input_lib . RebuildIndex ( ) ;
bool found = input_lib . FindInList ( CmpName ) ;
if ( ! found )
{
fclose ( lib_module ) ;
msg . Printf ( _ ( " Module [%s] not found " ) , GetChars ( CmpName ) ) ;
DisplayError ( NULL , msg ) ;
return ;
}
// Create new library.
newFileName = oldFileName ;
newFileName . SetExt ( FILETMP_EXT ) ;
if ( ( out_file = wxFopen ( newFileName . GetFullPath ( ) , wxT ( " wt " ) ) ) = = NULL )
{
fclose ( lib_module ) ;
msg . Printf ( _ ( " Unable to create %s " ) , GetChars ( newFileName . GetFullPath ( ) ) ) ;
DisplayError ( NULL , msg ) ;
return ;
}
wxBeginBusyCursor ( ) ;
FOOTPRINT_LIBRARY output_lib ( out_file ) ;
output_lib . m_List = input_lib . m_List ;
output_lib . WriteHeader ( ) ;
output_lib . RemoveFromList ( CmpName ) ;
output_lib . SortList ( ) ;
output_lib . WriteSectionIndex ( ) ;
// Copy modules.
rewind ( lib_module ) ;
LineNum = input_lib . m_LineNum ;
bool copylines = false ;
while ( GetLine ( lib_module , Line , & LineNum ) )
{
StrPurge ( Line ) ;
if ( strnicmp ( Line , " $MODULE " , 7 ) = = 0 )
try
{
copylines = true ;
sscanf ( Line + 7 , " %s " , Name ) ;
msg = FROM_UTF8 ( Name ) ;
PLUGIN : : RELEASER pi ( IO_MGR : : PluginFind ( IO_MGR : : LEGACY ) ) ;
if ( msg . CmpNoCase ( CmpName ) = = 0 )
{
// Delete old module (i.e. do not copy description to out_file).
while ( GetLine ( lib_module , Line , & LineNum ) )
{
if ( strnicmp ( Line , " $EndMODULE " , 9 ) = = 0 )
break ;
}
continue ;
pi - > FootprintDelete ( aLibName , footprintName ) ;
}
}
if ( copylines )
fprintf ( out_file , " %s \n " , Line ) ;
}
fclose ( lib_module ) ;
fclose ( out_file ) ;
wxEndBusyCursor ( ) ;
// The old library file is renamed .bak
wxFileName backupFileName = oldFileName ;
backupFileName . SetExt ( BACKUP_EXT ) ;
if ( backupFileName . FileExists ( ) )
wxRemoveFile ( backupFileName . GetFullPath ( ) ) ;
if ( ! wxRenameFile ( oldFileName . GetFullPath ( ) , backupFileName . GetFullPath ( ) ) )
catch ( IO_ERROR ioe )
{
msg . Printf ( _ ( " Could not create library back up file <%s>. " ) ,
GetChars ( backupFileName . GetFullName ( ) ) ) ;
DisplayError ( this , msg ) ;
DisplayError ( NULL , ioe . errorText ) ;
return ;
}
// The temporary file is renamed as the previous library.
if ( ! wxRenameFile ( newFileName . GetFullPath ( ) , oldFileName . GetFullPath ( ) ) )
{
msg . Printf ( _ ( " Could not create temporary library file <%s>. " ) ,
GetChars ( oldFileName . GetFullName ( ) ) ) ;
DisplayError ( this , msg ) ;
return ;
}
msg . Printf ( _ ( " Component '%s' deleted from library '%s' " ) ,
footprintName . GetData ( ) , aLibName . GetData ( ) ) ;
msg . Printf ( _ ( " Component %s deleted in library %s " ) , GetChars ( CmpName ) ,
GetChars ( oldFileName . GetFullPath ( ) ) ) ;
SetStatusText ( msg ) ;
}
@ -368,7 +265,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( const wxString& aLibName, bool aNewM
path = wxGetApp ( ) . ReturnLastVisitedLibraryPath ( ) ;
if ( aLibName . IsEmpty ( ) )
if ( ! aLibName )
{
wxFileDialog dlg ( this , _ ( " Library " ) , path ,
wxEmptyString ,
@ -383,12 +280,12 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( const wxString& aLibName, bool aNewM
wxFileName fn ( fileName ) ;
wxGetApp ( ) . SaveLastVisitedLibraryPath ( fn . GetPath ( ) ) ;
bool file _exists = wxFileExists ( fileName ) ;
bool lib _exists = wxFileExists ( fileName ) ;
if ( ! aNewModulesOnly & & file _exists )
if ( ! aNewModulesOnly & & lib _exists )
{
wxString msg ;
msg . Printf ( _ ( " File %s exists, OK to replace ?" ) , GetChars ( fileName ) ) ;
msg . Printf ( _ ( " Library %s exists, OK to replace ?" ) , GetChars ( fileName ) ) ;
if ( ! IsOK ( this , msg ) )
return ;
@ -396,52 +293,47 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( const wxString& aLibName, bool aNewM
m_canvas - > SetAbortRequest ( false ) ;
// Create a new, empty library if no old lib, or if archive all modules
if ( ! aNewModulesOnly | | ! file_exists )
try
{
FILE * lib_module ;
PLUGIN : : RELEASER pi ( IO_MGR : : PluginFind ( IO_MGR : : LEGACY ) ) ;
if ( ( lib_module = wxFopen ( fileName , wxT ( " w+t " ) ) ) = = NULL )
// Delete old library if we're replacing it entirely.
if ( lib_exists & & ! aNewModulesOnly )
{
wxString msg ;
msg . Printf ( _ ( " Unable to create <%s> " ) , GetChars ( fileName ) ) ;
DisplayError ( this , msg ) ;
return ;
pi - > FootprintLibDelete ( fileName ) ;
lib_exists = false ;
}
FOOTPRINT_LIBRARY new_lib ( lib_module ) ;
new_lib . WriteHeader ( ) ;
new_lib . WriteSectionIndex ( ) ;
new_lib . WriteEndOfFile ( ) ;
fclose ( lib_module ) ;
if ( ! lib_exists )
{
pi - > FootprintLibCreate ( fileName ) ;
}
MODULE * module = ( MODULE * ) GetBoard ( ) - > m_Modules ;
for ( int ii = 1 ; module ! = NULL ; ii + + , module = module - > Next ( ) )
if ( ! aNewModulesOnly )
{
// Save footprints in default orientation (0.0) and default layer (FRONT layer)
int orient = module - > GetOrientation ( ) ;
if ( orient ! = 0 )
module - > SetOrientation ( 0 ) ;
int layer = module - > GetLayer ( ) ;
if ( layer ! = LAYER_N_FRONT )
module - > Flip ( module - > m_Pos ) ;
bool success = Save_Module_In_Library ( fileName , module ,
aNewModulesOnly ? false : true , false ) ;
// Restore previous orientation and/or side
if ( layer ! = module - > GetLayer ( ) )
module - > Flip ( module - > m_Pos ) ;
if ( orient ! = 0 )
module - > SetOrientation ( orient ) ;
if ( ! success )
for ( MODULE * m = GetBoard ( ) - > m_Modules ; m ; m = m - > Next ( ) )
{
pi - > FootprintSave ( fileName , m ) ;
}
}
else
{
for ( MODULE * m = GetBoard ( ) - > m_Modules ; m ; m = m - > Next ( ) )
{
if ( ! Save_Module_In_Library ( fileName , m , false , false ) )
break ;
// Check for request to stop backup (ESCAPE key actuated)
if ( m_canvas - > GetAbortRequest ( ) )
break ;
}
}
}
catch ( IO_ERROR ioe )
{
DisplayError ( this , ioe . errorText ) ;
return ;
}
}
@ -450,202 +342,84 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibName,
bool aOverwrite ,
bool aDisplayDialog )
{
wxFileName oldFileName ;
wxFileName newFileName ;
int LineNum = 0 , tmp ;
char Name [ 256 ] , Line [ 1024 ] ;
wxString Name_Cmp ;
wxString msg ;
FILE * lib_module , * dest ;
if ( aModule = = NULL )
return false ;
aModule - > DisplayInfo ( this ) ;
newFileName = aLibName ;
if ( ! newFileName . FileExists ( aLibName ) )
if ( ! wxFileExists ( aLibName ) )
{
msg . Printf ( _ ( " Library <%s> not found. " ) , GetChars ( aLibName ) ) ;
wxString msg = wxString : : Format ( _ ( " Library <%s> not found. " ) ,
aLibName . GetData ( ) ) ;
DisplayError ( this , msg ) ;
return false ;
}
if ( ! IsWritable ( newFile Name ) )
if ( ! IsWritable ( aLib Name ) )
return false ;
// Ask for the footprint name in lib
Name_Cmp = aModule - > m_LibRef ;
// Ask what to use as the footprint name in the library
wxString footprint Name = aModule - > GetLibRef ( ) ;
if ( aDisplayDialog )
{
wxTextEntryDialog dlg ( this , _ ( " Name: " ) , _ ( " Save m odule " ) , Name_Cmp ) ;
wxTextEntryDialog dlg ( this , _ ( " Name: " ) , _ ( " Save M odule " ) , footprint Name ) ;
if ( dlg . ShowModal ( ) ! = wxID_OK )
return false ; // canceled by user
Name_Cmp = dlg . GetValue ( ) ;
Name_Cmp . Trim ( true ) ;
Name_Cmp . Trim ( false ) ;
footprint Name = dlg . GetValue ( ) ;
footprint Name. Trim ( true ) ;
footprint Name. Trim ( false ) ;
if ( Name_Cmp . IsEmpty ( ) )
if ( footprint Name. IsEmpty ( ) )
return false ;
aModule - > m_LibRef = Name_Cmp ;
aModule - > SetLibRef ( footprintName ) ;
}
// Ensure this footprint has a libname
if ( Name_Cmp . IsEmpty ( ) )
if ( footprint Name. IsEmpty ( ) )
{
Name_Cmp = wxT ( " noname " ) ;
aModule - > m_LibRef = Name_Cmp ;
footprint Name = wxT ( " noname " ) ;
aModule - > SetLibRef ( footprintName ) ;
}
if ( ( lib_module = wxFopen ( aLibName , wxT ( " rt " ) ) ) = = NULL )
{
msg . Printf ( _ ( " Unable to open <%s> " ) , GetChars ( aLibName ) ) ;
DisplayError ( this , msg ) ;
return false ;
}
// Read library file
FOOTPRINT_LIBRARY input_lib ( lib_module ) ;
MODULE * module_exists = NULL ;
if ( ! inpu t_lib . IsLibra ry( ) )
try
{
fclose ( lib_module ) ;
msg . Printf ( _ ( " File <%s> is not an Eeschema library " ) , GetChars ( aLibName ) ) ;
DisplayError ( this , msg ) ;
return false ;
}
PLUGIN : : RELEASER pi ( IO_MGR : : PluginFind ( IO_MGR : : LEGACY ) ) ;
// Read footprints in lib: - search for an existing footprint
input_lib . RebuildIndex ( ) ;
bool module_exists = input_lib . FindInList ( Name_Cmp ) ;
module_exists = pi - > FootprintLoad ( aLibName , footprintName ) ;
if ( module_exists )
{
delete module_exists ;
// an existing footprint is found in current lib
if ( aDisplayDialog )
{
msg = _ ( " Module exists \n Line: " ) ;
msg < < LineNum ;
wxString msg = wxString : : Format (
_ ( " Footprint '%s' already exists in library '%s' " ) ,
footprintName . GetData ( ) , aLibName . GetData ( ) ) ;
SetStatusText ( msg ) ;
}
if ( ! aOverwrite ) // Do not save the given footprint: an old one exists
if ( ! aOverwrite )
{
fclose ( lib_module ) ;
// Do not save the given footprint: an old one exists
return true ;
}
}
// Creates the new library
newFileName . SetExt ( FILETMP_EXT ) ;
if ( ( dest = wxFopen ( newFileName . GetFullPath ( ) , wxT ( " w+t " ) ) ) = = NULL )
{
fclose ( lib_module ) ;
msg . Printf ( _ ( " Unable to create <%s> " ) , GetChars ( newFileName . GetFullPath ( ) ) ) ;
DisplayError ( this , msg ) ;
return false ;
}
wxBeginBusyCursor ( ) ;
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
SetLocaleTo_C_standard ( ) ;
FOOTPRINT_LIBRARY output_lib ( dest ) ;
output_lib . m_List = input_lib . m_List ;
if ( ! module_exists )
output_lib . m_List . Add ( Name_Cmp ) ;
output_lib . SortList ( ) ;
// Create the library header with a new date
output_lib . WriteHeader ( ) ;
output_lib . WriteSectionIndex ( ) ;
LineNum = 0 ;
rewind ( lib_module ) ;
// Copy footprints, until the old footprint to delete
bool skip_header = true ;
while ( GetLine ( lib_module , Line , & LineNum ) )
{
StrPurge ( Line ) ;
if ( strnicmp ( Line , " $EndLIBRARY " , 8 ) = = 0 )
continue ;
// Search for the beginning of module section:
if ( skip_header )
{
if ( strnicmp ( Line , " $MODULE " , 7 ) = = 0 )
skip_header = false ;
else
continue ;
}
if ( strnicmp ( Line , " $MODULE " , 7 ) = = 0 )
{
sscanf ( Line + 7 , " %s " , Name ) ;
msg = FROM_UTF8 ( Name ) ;
if ( msg . CmpNoCase ( Name_Cmp ) = = 0 )
{
// skip old footprint descr (delete from the lib)
while ( GetLine ( lib_module , Line , & LineNum ) )
{
if ( strnicmp ( Line , " $EndMODULE " , 9 ) = = 0 )
break ;
}
continue ;
}
}
fprintf ( dest , " %s \n " , Line ) ;
}
// Write the new footprint ( append it to the list of footprint )
tmp = aModule - > GetTimeStamp ( ) ;
aModule - > SetTimeStamp ( 0 ) ;
aModule - > Save ( dest ) ;
aModule - > SetTimeStamp ( tmp ) ;
output_lib . WriteEndOfFile ( ) ;
fclose ( dest ) ;
fclose ( lib_module ) ;
SetLocaleTo_Default ( ) ; // revert to the current locale
wxEndBusyCursor ( ) ;
// The old library file is renamed .bak
oldFileName = aLibName ;
oldFileName . SetExt ( BACKUP_EXT ) ;
if ( oldFileName . FileExists ( ) )
wxRemoveFile ( oldFileName . GetFullPath ( ) ) ;
if ( ! wxRenameFile ( aLibName , oldFileName . GetFullPath ( ) ) )
{
msg . Printf ( _ ( " Could not create library back up file <%s>. " ) ,
GetChars ( oldFileName . GetFullName ( ) ) ) ;
DisplayError ( this , msg ) ;
// this always overwrites any existing footprint
pi - > FootprintSave ( aLibName , aModule ) ;
}
// The new library file is renamed
if ( ! wxRenameFile ( newFileName . GetFullPath ( ) , aLibName ) )
catch ( IO_ERROR ioe )
{
msg . Printf ( _ ( " Could not create temporary library file <%s>. " ) ,
GetChars ( aLibName ) ) ;
DisplayError ( this , msg ) ;
DisplayError ( this , ioe . errorText ) ;
return false ;
}
@ -654,7 +428,8 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibName,
wxString fmt = module_exists ?
_ ( " Component [%s] replaced in <%s> " ) :
_ ( " Component [%s] added in <%s> " ) ;
msg . Printf ( fmt , GetChars ( Name_Cmp ) , GetChars ( aLibName ) ) ;
wxString msg = wxString : : Format ( fmt , footprintName . GetData ( ) , aLibName . GetData ( ) ) ;
SetStatusText ( msg ) ;
}
@ -755,13 +530,14 @@ void FOOTPRINT_EDIT_FRAME::Select_Active_Library()
int FOOTPRINT_EDIT_FRAME : : CreateLibrary ( const wxString & aLibName )
{
FILE * lib_module ;
wxString msg ;
wxFileName fileName = aLibName ;
if ( fileName . FileExists ( ) )
{
msg . Printf ( _ ( " Library <%s> already exists. " ) , GetChars ( fileName . GetFullPath ( ) ) ) ;
wxString msg = wxString : : Format (
_ ( " Library <%s> already exists. " ) ,
aLibName . GetData ( ) ) ;
DisplayError ( this , msg ) ;
return 0 ;
}
@ -769,18 +545,18 @@ int FOOTPRINT_EDIT_FRAME::CreateLibrary( const wxString& aLibName )
if ( ! IsWritable ( fileName ) )
return 0 ;
if ( ( lib_module = wxFopen ( fileName . GetFullPath ( ) , wxT ( " wt " ) ) ) = = NULL )
try
{
msg . Printf ( _ ( " Unable to create library <%s> " ) , GetChars ( fileName . GetFullPath ( ) ) ) ;
DisplayError ( this , msg ) ;
return - 1 ;
}
PLUGIN : : RELEASER pi ( IO_MGR : : PluginFind ( IO_MGR : : LEGACY ) ) ;
FOOTPRINT_LIBRARY new_lib ( lib_module ) ;
new_lib . WriteHeader ( ) ;
new_lib . WriteSectionIndex ( ) ;
new_lib . WriteEndOfFile ( ) ;
fclose ( lib_module ) ;
pi - > FootprintLibCreate ( aLibName ) ;
}
catch ( IO_ERROR ioe )
{
DisplayError ( this , ioe . errorText ) ;
return 0 ;
}
return 1 ;
return 1 ; // remember how many times we succeeded
}