2011-09-26 20:32:56 +00:00
|
|
|
/**
|
|
|
|
* @file librairi.cpp
|
|
|
|
* @brief Manage module (footprint) libraries.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
|
|
|
#include "filter_reader.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "pcbcommon.h"
|
|
|
|
#include "macros.h"
|
|
|
|
|
|
|
|
#include "class_board.h"
|
|
|
|
#include "class_module.h"
|
|
|
|
|
|
|
|
#include "pcbnew.h"
|
2011-07-06 16:40:54 +00:00
|
|
|
#include "class_footprint_library.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "module_editor_frame.h"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/*
|
2009-11-14 22:15:22 +00:00
|
|
|
* Module library header format:
|
|
|
|
* Array LIBRARY HEADER-datetime
|
|
|
|
* $INDEX
|
|
|
|
* List of modules names (1 name per line)
|
|
|
|
* $EndIndex
|
|
|
|
* List of descriptions of Modules
|
|
|
|
* $EndLIBRARY
|
2007-10-30 21:30:58 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
#define BACKUP_EXT wxT( "bak" )
|
2009-04-05 20:49:15 +00:00
|
|
|
#define FILETMP_EXT wxT( "$$$" )
|
2009-01-15 08:12:03 +00:00
|
|
|
#define EXPORT_IMPORT_LASTPATH_KEY wxT( "import_last_path" )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
const wxString ModExportFileExtension( wxT( "emp" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
static const wxString ModExportFileWildcard( _( "KiCad foot print export files (*.emp)|*.emp" ) );
|
2011-10-13 18:37:43 +00:00
|
|
|
static const wxString ModImportFileWildcard( _( "GPcb foot print files (*)|*" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
2009-04-05 20:49:15 +00:00
|
|
|
FILE* file;
|
2009-01-15 08:12:03 +00:00
|
|
|
MODULE* module = NULL;
|
|
|
|
bool Footprint_Is_GPCB_Format = false;
|
|
|
|
|
|
|
|
wxString LastOpenedPathForLoading;
|
2011-12-16 20:12:49 +00:00
|
|
|
wxConfig* Config = wxGetApp().GetSettings();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2008-03-12 11:49:16 +00:00
|
|
|
if( Config )
|
|
|
|
Config->Read( EXPORT_IMPORT_LASTPATH_KEY, &LastOpenedPathForLoading );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2011-10-13 18:37:43 +00:00
|
|
|
wxString importWildCard = ModExportFileWildcard + wxT("|") + ModImportFileWildcard;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileDialog dlg( this, _( "Import Footprint Module" ),
|
|
|
|
LastOpenedPathForLoading, wxEmptyString,
|
2011-10-13 18:37:43 +00:00
|
|
|
importWildCard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
file = wxFopen( dlg.GetPath(), wxT( "rt" ) );
|
|
|
|
|
|
|
|
if( file == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "File <%s> not found" ), GetChars( dlg.GetPath() ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
FILE_LINE_READER fileReader( file, dlg.GetPath() );
|
|
|
|
|
|
|
|
FILTER_READER reader( fileReader );
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( Config ) // Save file path
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
LastOpenedPathForLoading = wxPathOnly( dlg.GetPath() );
|
2008-03-12 11:49:16 +00:00
|
|
|
Config->Write( EXPORT_IMPORT_LASTPATH_KEY, LastOpenedPathForLoading );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_C_standard();
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2008-03-12 11:49:16 +00:00
|
|
|
/* Read header and test file type */
|
2011-01-14 17:43:30 +00:00
|
|
|
reader.ReadLine();
|
|
|
|
Line = reader.Line();
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-09-24 18:33:28 +00:00
|
|
|
if( strnicmp( Line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) != 0 )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
if( strnicmp( Line, "Element", 7 ) == 0 )
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
Footprint_Is_GPCB_Format = true;
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Not a module file" ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2008-03-12 11:49:16 +00:00
|
|
|
/* Read file: Search the description starting line (skip lib header)*/
|
2009-01-15 08:12:03 +00:00
|
|
|
if( !Footprint_Is_GPCB_Format )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
module = new MODULE( GetBoard() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( Footprint_Is_GPCB_Format )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
module->Read_GPCB_Descr( dlg.GetPath() );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
module->ReadDescr( &reader );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2008-03-12 11:49:16 +00:00
|
|
|
/* Insert footprint in list*/
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Add( module );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2008-03-12 11:49:16 +00:00
|
|
|
/* Display info : */
|
2009-04-17 08:51:02 +00:00
|
|
|
module->DisplayInfo( this );
|
2011-09-16 14:13:02 +00:00
|
|
|
PlaceModule( module, NULL );
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->BuildListOfNets();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule, bool aCreateSysLib )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
|
|
|
FILE* file;
|
|
|
|
wxString msg, path, title, wildcard;
|
2011-12-16 20:12:49 +00:00
|
|
|
wxConfig* Config = wxGetApp().GetSettings();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aModule == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
fn.SetName( aModule->m_LibRef );
|
|
|
|
fn.SetExt( aCreateSysLib ? ModuleFileExtension : ModExportFileExtension );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aCreateSysLib )
|
2009-04-14 16:45:22 +00:00
|
|
|
path = wxGetApp().ReturnLastVisitedLibraryPath();
|
2008-04-17 16:25:29 +00:00
|
|
|
else if( Config )
|
2008-03-12 11:49:16 +00:00
|
|
|
Config->Read( EXPORT_IMPORT_LASTPATH_KEY, &path );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetPath( path );
|
2010-12-29 17:47:32 +00:00
|
|
|
title = aCreateSysLib ? _( "Create New Library" ) : _( "Export Module" );
|
|
|
|
wildcard = aCreateSysLib ? ModuleFileWildcard : ModExportFileWildcard;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileDialog dlg( this, msg, fn.GetPath(), fn.GetFullName(), wildcard,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = dlg.GetPath();
|
2009-04-14 16:45:22 +00:00
|
|
|
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( file = wxFopen( fn.GetFullPath(), wxT( "wt" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Unable to create <%s>" ), GetChars( fn.GetFullPath() ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( !aCreateSysLib && Config ) // Save file path
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
Config->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
2008-03-12 11:49:16 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
// Switch the locale to standard C (needed to read/write floating point numbers like 1.3)
|
2009-11-04 19:08:08 +00:00
|
|
|
SetLocaleTo_C_standard();
|
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
FOOTPRINT_LIBRARY libexport( file );
|
|
|
|
libexport.WriteHeader();
|
|
|
|
libexport.m_List.Add(aModule->m_LibRef);
|
|
|
|
libexport.WriteSectionIndex();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
GetBoard()->m_Modules->Save( file );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
libexport.WriteEndOfFile();
|
2009-04-05 20:49:15 +00:00
|
|
|
fclose( file );
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
msg.Printf( _( "Module exported in file <%s>" ), GetChars( fn.GetFullPath() ) );
|
2009-04-17 08:51:02 +00:00
|
|
|
DisplayInfoMessage( this, msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::Delete_Module_In_Library( const wxString& aLibname )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName newFileName;
|
|
|
|
wxFileName oldFileName;
|
2011-07-06 16:40:54 +00:00
|
|
|
int LineNum = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
char Line[1024], Name[256];
|
2011-07-06 16:40:54 +00:00
|
|
|
FILE* out_file, * lib_module;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString CmpName, msg;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
CmpName = Select_1_Module_From_List( this, aLibname, wxEmptyString, wxEmptyString );
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( CmpName == wxEmptyString )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Confirmation */
|
|
|
|
msg.Printf( _( "Ok to delete module %s in library %s" ),
|
2011-08-26 17:01:17 +00:00
|
|
|
GetChars( CmpName ), GetChars( aLibname ) );
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
oldFileName = aLibname;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( ( lib_module = wxFopen( oldFileName.GetFullPath(), wxT( "rt" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Library <%s> not found" ), GetChars(oldFileName.GetFullPath() ) );
|
|
|
|
DisplayError( NULL, msg );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
FOOTPRINT_LIBRARY input_lib( lib_module );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
/* Read header. */
|
|
|
|
if( ! input_lib.IsLibrary() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
fclose( lib_module );
|
2011-07-06 16:40:54 +00:00
|
|
|
wxString msg;
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "<%s> is not a valid footprint library file" ),
|
2011-09-26 20:32:56 +00:00
|
|
|
GetChars( oldFileName.GetFullPath() ) );
|
2011-10-16 08:02:36 +00:00
|
|
|
DisplayError( NULL, msg );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read module names. */
|
2011-07-06 16:40:54 +00:00
|
|
|
input_lib.RebuildIndex();
|
|
|
|
bool found = input_lib.FindInList( CmpName );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( !found )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
fclose( lib_module );
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Module [%s] not found" ), GetChars( CmpName ) );
|
2011-10-16 08:02:36 +00:00
|
|
|
DisplayError( NULL, msg );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Create new library. */
|
2009-04-05 20:49:15 +00:00
|
|
|
newFileName = oldFileName;
|
|
|
|
newFileName.SetExt( FILETMP_EXT );
|
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( ( out_file = wxFopen( newFileName.GetFullPath(), wxT( "wt" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
fclose( lib_module );
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Unable to create %s" ), GetChars( newFileName.GetFullPath() ) );
|
|
|
|
DisplayError( NULL, msg );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxBeginBusyCursor();
|
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
FOOTPRINT_LIBRARY output_lib( out_file );
|
|
|
|
output_lib.m_List = input_lib.m_List;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
output_lib.WriteHeader();
|
2011-08-26 17:01:17 +00:00
|
|
|
output_lib.RemoveFromList( CmpName );
|
2011-07-06 16:40:54 +00:00
|
|
|
output_lib.SortList();
|
|
|
|
output_lib.WriteSectionIndex();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Copy modules. */
|
2011-07-06 16:40:54 +00:00
|
|
|
rewind( lib_module );
|
|
|
|
LineNum = input_lib.m_LineNum;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
bool copylines = false;
|
2007-10-30 21:30:58 +00:00
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
StrPurge( Line );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
|
|
|
|
{
|
2011-07-06 16:40:54 +00:00
|
|
|
copylines = true;
|
2007-10-30 21:30:58 +00:00
|
|
|
sscanf( Line + 7, " %s", Name );
|
2011-02-28 18:36:19 +00:00
|
|
|
msg = FROM_UTF8( Name );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( msg.CmpNoCase( CmpName ) == 0 )
|
|
|
|
{
|
2011-07-06 16:40:54 +00:00
|
|
|
/* Delete old module (i.e. do not copy description to out_file). */
|
2007-10-30 21:30:58 +00:00
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$EndMODULE", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( copylines )
|
|
|
|
fprintf( out_file, "%s\n", Line );
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( lib_module );
|
2011-07-06 16:40:54 +00:00
|
|
|
fclose( out_file );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
wxEndBusyCursor();
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* The old library file is renamed .bak */
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName backupFileName = oldFileName;
|
2009-06-26 12:52:24 +00:00
|
|
|
backupFileName.SetExt( BACKUP_EXT );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( backupFileName.FileExists() )
|
|
|
|
wxRemoveFile( backupFileName.GetFullPath() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( !wxRenameFile( oldFileName.GetFullPath(), backupFileName.GetFullPath() ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Could not create library back up file <%s>." ),
|
|
|
|
GetChars( backupFileName.GetFullName() ) );
|
|
|
|
DisplayError( this, msg );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* The temporary file is renamed as the previous library. */
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !wxRenameFile( newFileName.GetFullPath(), oldFileName.GetFullPath() ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _("Could not create temporary library file <%s>."),
|
|
|
|
GetChars( oldFileName.GetFullName() ) );
|
|
|
|
DisplayError( this, msg );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Component %s deleted in library %s" ), GetChars( CmpName ),
|
2011-08-26 17:01:17 +00:00
|
|
|
GetChars( oldFileName.GetFullPath() ) );
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-06 19:00:59 +00:00
|
|
|
/* Save modules in a library:
|
|
|
|
* param aNewModulesOnly:
|
|
|
|
* true : save modules not already existing in this lib
|
|
|
|
* false: save all modules
|
|
|
|
*/
|
|
|
|
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( const wxString& aLibName, bool aNewModulesOnly )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-01-06 19:00:59 +00:00
|
|
|
wxString fileName = aLibName;
|
|
|
|
wxString path;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-09-26 20:32:56 +00:00
|
|
|
DisplayInfoMessage( this, _( "No modules to archive!" ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
path = wxGetApp().ReturnLastVisitedLibraryPath();
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-01-06 19:00:59 +00:00
|
|
|
if( aLibName.IsEmpty() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2009-04-14 16:45:22 +00:00
|
|
|
wxFileDialog dlg( this, _( "Library" ), path,
|
2009-04-05 20:49:15 +00:00
|
|
|
wxEmptyString, ModuleFileWildcard,
|
2012-01-06 20:32:19 +00:00
|
|
|
wxFD_SAVE );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
fileName = dlg.GetPath();
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
wxFileName fn( fileName );
|
2009-04-14 16:45:22 +00:00
|
|
|
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
2009-11-14 22:15:22 +00:00
|
|
|
bool file_exists = wxFileExists( fileName );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-01-06 19:00:59 +00:00
|
|
|
if( !aNewModulesOnly && file_exists )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2011-08-26 17:01:17 +00:00
|
|
|
msg.Printf( _( "File %s exists, OK to replace ?" ), GetChars( fileName ) );
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAbortRequest( false );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
// Create a new, empty library if no old lib, or if archive all modules
|
2012-01-06 19:00:59 +00:00
|
|
|
if( !aNewModulesOnly || !file_exists )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
FILE* lib_module;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( lib_module = wxFopen( fileName, wxT( "w+t" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Unable to create <%s>" ), GetChars(fileName) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
FOOTPRINT_LIBRARY new_lib( lib_module );
|
|
|
|
new_lib.WriteHeader();
|
|
|
|
new_lib.WriteSectionIndex();
|
|
|
|
new_lib.WriteEndOfFile();
|
2007-10-30 21:30:58 +00:00
|
|
|
fclose( lib_module );
|
|
|
|
}
|
|
|
|
|
2012-01-06 20:32:19 +00:00
|
|
|
MODULE* module = (MODULE*) GetBoard()->m_Modules;
|
|
|
|
for( int ii = 1; module != NULL; ii++, module = module->Next() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-01-06 20:32:19 +00:00
|
|
|
// 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 )
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Check for request to stop backup (ESCAPE key actuated) */
|
2011-12-29 20:11:42 +00:00
|
|
|
if( m_canvas->GetAbortRequest() )
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibName,
|
|
|
|
MODULE* aModule,
|
|
|
|
bool aOverwrite,
|
|
|
|
bool aDisplayDialog )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName oldFileName;
|
|
|
|
wxFileName newFileName;
|
|
|
|
int LineNum = 0, tmp;
|
|
|
|
char Name[256], Line[1024];
|
|
|
|
wxString Name_Cmp;
|
|
|
|
wxString msg;
|
|
|
|
FILE* lib_module, * dest;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-07-05 12:46:14 +00:00
|
|
|
if( aModule == NULL )
|
|
|
|
return false;
|
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
aModule->DisplayInfo( this );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
newFileName = aLibName;
|
|
|
|
|
|
|
|
if( !newFileName.FileExists( aLibName ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Library <%s> not found." ), GetChars( aLibName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
2011-02-22 20:59:16 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( !IsWritable( newFileName ) )
|
|
|
|
return false;
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* Ask for the footprint name in lib */
|
|
|
|
Name_Cmp = aModule->m_LibRef;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( aDisplayDialog )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2010-07-20 18:11:34 +00:00
|
|
|
wxTextEntryDialog dlg( this, _( "Name:" ), _( "Save module" ), Name_Cmp );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2011-09-16 14:13:02 +00:00
|
|
|
return false; // canceled by user
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
Name_Cmp = dlg.GetValue();
|
2009-01-15 08:12:03 +00:00
|
|
|
Name_Cmp.Trim( true );
|
2010-07-20 18:11:34 +00:00
|
|
|
Name_Cmp.Trim( false );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( Name_Cmp.IsEmpty() )
|
2011-07-08 07:12:28 +00:00
|
|
|
return false;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-07-08 07:12:28 +00:00
|
|
|
aModule->m_LibRef = Name_Cmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure this footprint has a libname
|
|
|
|
if( Name_Cmp.IsEmpty() )
|
|
|
|
{
|
|
|
|
Name_Cmp = wxT("noname");
|
2009-01-15 08:12:03 +00:00
|
|
|
aModule->m_LibRef = Name_Cmp;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( ( lib_module = wxFopen( aLibName, wxT( "rt" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Unable to open <%s>" ), GetChars( aLibName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
2011-02-22 20:59:16 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
/* Read library file */
|
|
|
|
FOOTPRINT_LIBRARY input_lib( lib_module );
|
|
|
|
|
|
|
|
if( ! input_lib.IsLibrary() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
fclose( lib_module );
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "File <%s> is not an Eeschema library" ), GetChars( aLibName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
2011-02-22 20:59:16 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read footprints in lib: - search for an existing footprint */
|
2011-07-06 16:40:54 +00:00
|
|
|
input_lib.RebuildIndex();
|
|
|
|
bool module_exists = input_lib.FindInList( Name_Cmp );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( module_exists )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-07-06 16:40:54 +00:00
|
|
|
// an existing footprint is found in current lib
|
|
|
|
if( aDisplayDialog )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-07-06 16:40:54 +00:00
|
|
|
msg = _( "Module exists\n Line: " );
|
|
|
|
msg << LineNum;
|
|
|
|
SetStatusText( msg );
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( !aOverwrite ) // Do not save the given footprint: an old one exists
|
|
|
|
{
|
|
|
|
fclose( lib_module );
|
2011-07-08 07:12:28 +00:00
|
|
|
return true;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* Creates the new library */
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
newFileName.SetExt( FILETMP_EXT );
|
|
|
|
|
|
|
|
if( ( dest = wxFopen( newFileName.GetFullPath(), wxT( "w+t" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
fclose( lib_module );
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Unable to create <%s>" ), GetChars( newFileName.GetFullPath() ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
2011-02-22 20:59:16 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxBeginBusyCursor();
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
// Switch the locale to standard C (needed to print floating point numbers like 1.3)
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_C_standard();
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
FOOTPRINT_LIBRARY output_lib( dest );
|
|
|
|
output_lib.m_List = input_lib.m_List;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( ! module_exists )
|
|
|
|
output_lib.m_List.Add( Name_Cmp );
|
|
|
|
|
|
|
|
output_lib.SortList();
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* Create the library header with a new date */
|
2011-07-06 16:40:54 +00:00
|
|
|
output_lib.WriteHeader();
|
|
|
|
output_lib.WriteSectionIndex();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
LineNum = 0;
|
2011-07-06 16:40:54 +00:00
|
|
|
rewind( lib_module);
|
|
|
|
|
2011-07-08 07:12:28 +00:00
|
|
|
// Copy footprints, until the old footprint to delete
|
|
|
|
bool skip_header = true;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
StrPurge( Line );
|
|
|
|
if( strnicmp( Line, "$EndLIBRARY", 8 ) == 0 )
|
|
|
|
continue;
|
2011-07-08 07:12:28 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
// Search for the beginning of module section:
|
2011-07-08 07:12:28 +00:00
|
|
|
if( skip_header )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
|
|
|
|
skip_header = false;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
|
|
|
|
{
|
|
|
|
sscanf( Line + 7, " %s", Name );
|
2011-02-28 18:36:19 +00:00
|
|
|
msg = FROM_UTF8( Name );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( msg.CmpNoCase( Name_Cmp ) == 0 )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
/* skip old footprint descr (delete from the lib) */
|
2007-10-30 21:30:58 +00:00
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$EndMODULE", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( dest, "%s\n", Line );
|
|
|
|
}
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* Write the new footprint ( append it to the list of footprint ) */
|
2012-01-06 19:00:59 +00:00
|
|
|
tmp = aModule->GetTimeStamp();
|
|
|
|
aModule->SetTimeStamp( 0 );
|
2009-01-15 08:12:03 +00:00
|
|
|
aModule->Save( dest );
|
2011-12-12 08:37:05 +00:00
|
|
|
aModule->SetTimeStamp( tmp );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
output_lib.WriteEndOfFile();
|
|
|
|
|
2011-01-16 05:11:17 +00:00
|
|
|
fclose( dest );
|
|
|
|
fclose( lib_module );
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
wxEndBusyCursor();
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* The old library file is renamed .bak */
|
2009-04-05 20:49:15 +00:00
|
|
|
oldFileName = aLibName;
|
2009-06-26 12:52:24 +00:00
|
|
|
oldFileName.SetExt( BACKUP_EXT );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( oldFileName.FileExists() )
|
|
|
|
wxRemoveFile( oldFileName.GetFullPath() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !wxRenameFile( aLibName, oldFileName.GetFullPath() ) )
|
2011-10-16 08:02:36 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "Could not create library back up file <%s>." ),
|
|
|
|
GetChars( oldFileName.GetFullName() ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* The new library file is renamed */
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !wxRenameFile( newFileName.GetFullPath(), aLibName ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Could not create temporary library file <%s>." ),
|
|
|
|
GetChars( aLibName ) );
|
|
|
|
DisplayError( this, msg );
|
2011-02-22 20:59:16 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( aDisplayDialog )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
wxString fmt = module_exists ?
|
|
|
|
_( "Component [%s] replaced in <%s>" ) :
|
|
|
|
_( "Component [%s] added in <%s>" );
|
|
|
|
msg.Printf( fmt, GetChars( Name_Cmp ), GetChars( aLibName ) );
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( msg );
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::Create_1_Module( const wxString& aModuleName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-30 21:30:58 +00:00
|
|
|
MODULE* Module;
|
2010-07-20 18:11:34 +00:00
|
|
|
wxString moduleName;
|
2007-10-30 21:30:58 +00:00
|
|
|
wxPoint newpos;
|
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
moduleName = aModuleName;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Ask for the new module reference */
|
2010-07-20 18:11:34 +00:00
|
|
|
if( moduleName.IsEmpty() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2010-07-20 18:11:34 +00:00
|
|
|
wxTextEntryDialog dlg( this, _( "Module Reference:" ),
|
2011-08-26 17:01:17 +00:00
|
|
|
_( "Module Creation" ), moduleName );
|
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2010-07-20 18:11:34 +00:00
|
|
|
return NULL; //Aborted by user
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
moduleName = dlg.GetValue();
|
2010-07-20 18:11:34 +00:00
|
|
|
}
|
2011-09-26 20:32:56 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
moduleName.Trim( true );
|
|
|
|
moduleName.Trim( false );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( moduleName.IsEmpty( ) )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, _( "No reference, aborted" ) );
|
|
|
|
return NULL;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
// Creates the new module and add it to the head of the linked list of modules
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = new MODULE( GetBoard() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Add( Module );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2008-11-10 20:45:24 +00:00
|
|
|
/* Update parameters: position, timestamp ... */
|
2011-02-11 20:48:13 +00:00
|
|
|
newpos = GetScreen()->GetCrossHairPosition();
|
2007-10-30 21:30:58 +00:00
|
|
|
Module->SetPosition( newpos );
|
|
|
|
Module->m_LastEdit_Time = time( NULL );
|
|
|
|
|
2008-11-10 20:45:24 +00:00
|
|
|
/* Update its name in lib */
|
2010-07-20 18:11:34 +00:00
|
|
|
Module->m_LibRef = moduleName;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2008-11-10 20:45:24 +00:00
|
|
|
/* Update reference: */
|
2010-07-20 18:11:34 +00:00
|
|
|
Module->m_Reference->m_Text = moduleName;
|
2011-01-09 11:17:28 +00:00
|
|
|
Module->m_Reference->SetThickness( g_ModuleTextWidth );
|
|
|
|
Module->m_Reference->SetSize( g_ModuleTextSize );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2008-11-10 20:45:24 +00:00
|
|
|
/* Set the value field to a default value */
|
2007-10-30 21:30:58 +00:00
|
|
|
Module->m_Value->m_Text = wxT( "VAL**" );
|
2011-01-09 11:17:28 +00:00
|
|
|
Module->m_Value->SetThickness( g_ModuleTextWidth );
|
|
|
|
Module->m_Value->SetSize( g_ModuleTextSize );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
Module->SetPosition( wxPoint( 0, 0 ) );
|
2008-11-10 20:45:24 +00:00
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
Module->DisplayInfo( this );
|
2007-10-30 21:30:58 +00:00
|
|
|
return Module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::Select_Active_Library()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-08-26 17:01:17 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2011-09-27 20:43:18 +00:00
|
|
|
if( g_LibraryNames.GetCount() == 0 )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-27 20:43:18 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Select Active Library:" ), g_LibraryNames, m_CurrentLib );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
wxFileName fileName = wxFileName( wxEmptyString, dlg.GetTextSelection(), ModuleFileExtension );
|
|
|
|
fileName = wxGetApp().FindLibraryPath( fileName );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( fileName.IsOk() && fileName.FileExists() )
|
|
|
|
{
|
|
|
|
m_CurrentLib = dlg.GetTextSelection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "The footprint library <%s> could not be found in any of the search paths." ),
|
|
|
|
GetChars( dlg.GetTextSelection() ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
m_CurrentLib.Empty();
|
|
|
|
}
|
2011-08-08 15:44:43 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
UpdateTitle();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-26 20:32:56 +00:00
|
|
|
int FOOTPRINT_EDIT_FRAME::CreateLibrary( const wxString& aLibName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-30 21:30:58 +00:00
|
|
|
FILE* lib_module;
|
|
|
|
wxString msg;
|
2011-08-26 17:01:17 +00:00
|
|
|
wxFileName fileName = aLibName;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( fileName.FileExists() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-08-26 17:01:17 +00:00
|
|
|
msg.Printf( _( "Library <%s> already exists." ), GetChars( fileName.GetFullPath() ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( !IsWritable( fileName ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( ( lib_module = wxFopen( fileName.GetFullPath(), wxT( "wt" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
msg.Printf( _( "Unable to create library <%s>" ), GetChars( fileName.GetFullPath() ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
FOOTPRINT_LIBRARY new_lib( lib_module );
|
|
|
|
new_lib.WriteHeader();
|
|
|
|
new_lib.WriteSectionIndex();
|
|
|
|
new_lib.WriteEndOfFile();
|
2007-10-30 21:30:58 +00:00
|
|
|
fclose( lib_module );
|
|
|
|
|
|
|
|
return 1;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|