kicad/pcbnew/librairi.cpp

762 lines
21 KiB
C++
Raw Normal View History

/****************************************/
/* Manage module (footprint) libraries. */
/****************************************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "appl_wxstruct.h"
2007-05-06 16:03:28 +00:00
#include "common.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "kicad_string.h"
#include "gestfich.h"
2007-05-06 16:03:28 +00:00
#include "pcbnew.h"
2009-07-30 11:04:07 +00:00
#include "wxPcbStruct.h"
#include "module_editor_frame.h"
2010-11-18 21:16:28 +00:00
#include "dialog_helpers.h"
#include "richio.h"
#include "filter_reader.h"
#include "class_footprint_library.h"
2007-05-06 16:03:28 +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
*/
#define BACKUP_EXT wxT( "bak" )
#define FILETMP_EXT wxT( "$$$" )
#define EXPORT_IMPORT_LASTPATH_KEY wxT( "import_last_path" )
2007-05-06 16:03:28 +00:00
const wxString ModExportFileExtension( wxT( "emp" ) );
static const wxString ModExportFileWildcard(
_( "Kicad foot print export files (*.emp)|*.emp" ) );
2010-12-29 17:47:32 +00:00
/*
2008-03-12 11:49:16 +00:00
* Function Import_Module
* Read a file containing only one footprint.
* Used to import (after exporting) a footprint
* Exported files have the standard ext .emp
2008-03-12 11:49:16 +00:00
* This is the same format as .mod files but restricted to only one footprint
* The import function can also read gpcb footprint file, in Newlib format
* (One footprint per file, Newlib files have no special ext.)
2007-10-30 21:30:58 +00:00
*/
2010-07-20 18:11:34 +00:00
MODULE* WinEDA_ModuleEditFrame::Import_Module( )
2007-05-06 16:03:28 +00:00
{
char* Line;
FILE* file;
MODULE* module = NULL;
bool Footprint_Is_GPCB_Format = false;
wxString LastOpenedPathForLoading;
wxConfig* Config = wxGetApp().m_EDA_Config;
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 );
wxFileDialog dlg( this, _( "Import Footprint Module" ),
LastOpenedPathForLoading, wxEmptyString,
ModExportFileWildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL )
2007-10-30 21:30:58 +00:00
return NULL;
file = wxFopen( dlg.GetPath(), wxT( "rt" ) );
if( file == NULL )
2007-10-30 21:30:58 +00:00
{
wxString msg;
msg.Printf( _( "File <%s> not found" ), GetChars( dlg.GetPath() ) );
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return NULL;
}
FILE_LINE_READER fileReader( file, dlg.GetPath() );
FILTER_READER reader( fileReader );
if( Config ) // Save file path
{
LastOpenedPathForLoading = wxPathOnly( dlg.GetPath() );
2008-03-12 11:49:16 +00:00
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();
2008-03-12 11:49:16 +00:00
/* Read header and test file type */
reader.ReadLine();
Line = reader.Line();
2007-10-30 21:30:58 +00:00
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{
if( strnicmp( Line, "Element", 7 ) == 0 )
Footprint_Is_GPCB_Format = true;
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)*/
if( !Footprint_Is_GPCB_Format )
{
while( reader.ReadLine() )
{
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
break;
}
}
2007-10-30 21:30:58 +00:00
module = new MODULE( GetBoard() );
2007-10-30 21:30:58 +00:00
if( Footprint_Is_GPCB_Format )
{
module->Read_GPCB_Descr( dlg.GetPath() );
}
else
{
module->ReadDescr( &reader );
}
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*/
GetBoard()->Add( module );
2007-10-30 21:30:58 +00:00
2008-03-12 11:49:16 +00:00
/* Display info : */
module->DisplayInfo( this );
2010-07-20 18:11:34 +00:00
Place_Module( module, NULL );
GetBoard()->m_Status_Pcb = 0;
GetBoard()->m_NetInfo->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
2008-03-12 11:49:16 +00:00
/**
* Function Export_Module
* Create a file containing only one footprint.
* Used to export a footprint
* Exported files have the standard ext .emp
2008-03-12 11:49:16 +00:00
* This is the same format as .mod files but restricted to only one footprint
* So Create a new lib (which will contains one module) and export a footprint
* is basically the same thing
2010-12-29 17:47:32 +00:00
* @param aModule = the module to export
* @param aCreateSysLib : true = use default lib path to create lib
* false = use current path or last used path to export the footprint
2007-10-30 21:30:58 +00:00
*/
2010-12-29 17:47:32 +00:00
void WinEDA_ModuleEditFrame::Export_Module( MODULE* aModule, bool aCreateSysLib )
2007-05-06 16:03:28 +00:00
{
wxFileName fn;
FILE* file;
wxString msg, path, title, wildcard;
wxConfig* Config = wxGetApp().m_EDA_Config;
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 )
path = wxGetApp().ReturnLastVisitedLibraryPath();
else if( Config )
2008-03-12 11:49:16 +00:00
Config->Read( EXPORT_IMPORT_LASTPATH_KEY, &path );
fn.SetPath( path );
2010-12-29 17:47:32 +00:00
title = aCreateSysLib ? _( "Create New Library" ) : _( "Export Module" );
wildcard = aCreateSysLib ? ModuleFileWildcard : ModExportFileWildcard;
wxFileDialog dlg( this, msg, fn.GetPath(), fn.GetFullName(), wildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL )
2007-10-30 21:30:58 +00:00
return;
fn = dlg.GetPath();
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
2007-10-30 21:30:58 +00:00
if( ( file = wxFopen( fn.GetFullPath(), wxT( "wt" ) ) ) == NULL )
2007-10-30 21:30:58 +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
{
Config->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
}
2008-03-12 11:49:16 +00:00
// 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();
2007-10-30 21:30:58 +00:00
GetBoard()->m_Modules->Save( file );
2007-10-30 21:30:58 +00:00
libexport.WriteEndOfFile();
fclose( file );
2011-01-16 05:11:17 +00:00
SetLocaleTo_Default(); // revert to the current locale
msg.Printf( _( "Module exported in file <%s>" ),
GetChars( fn.GetFullPath() ) );
DisplayInfoMessage( this, msg );
2007-05-06 16:03:28 +00:00
}
2007-10-30 21:30:58 +00:00
void WinEDA_ModuleEditFrame::Delete_Module_In_Library( const wxString& aLibname )
2007-05-06 16:03:28 +00:00
{
wxFileName newFileName;
wxFileName oldFileName;
int LineNum = 0;
char Line[1024], Name[256];
FILE* out_file, * lib_module;
wxString CmpName, msg;
2007-10-30 21:30:58 +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" ),
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;
oldFileName = aLibname;
2007-10-30 21:30:58 +00:00
if( ( lib_module = wxFopen( oldFileName.GetFullPath(),
wxT( "rt" ) ) ) == NULL )
2007-10-30 21:30:58 +00:00
{
wxString msg;
msg.Printf( _( "Library %s not found" ), GetChars(oldFileName.GetFullPath()) );
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return;
}
FOOTPRINT_LIBRARY input_lib( lib_module );
2007-10-30 21:30:58 +00:00
/* Read header. */
if( ! input_lib.IsLibrary() )
2007-10-30 21:30:58 +00:00
{
fclose( lib_module );
wxString msg;
msg.Printf( _( "%s is not a Library file" ), GetChars(oldFileName.GetFullPath()) );
DisplayError( this, msg );
2007-10-30 21:30:58 +00:00
return;
}
/* Read module names. */
input_lib.RebuildIndex();
bool found = input_lib.FindInList( CmpName );
if( !found )
2007-10-30 21:30:58 +00:00
{
fclose( lib_module );
msg.Printf( _( "Module [%s] not found" ), GetChars( CmpName ) );
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return;
}
/* Create new library. */
newFileName = oldFileName;
newFileName.SetExt( FILETMP_EXT );
if( ( out_file = wxFopen( newFileName.GetFullPath(), wxT( "wt" ) ) ) == NULL )
2007-10-30 21:30:58 +00:00
{
fclose( lib_module );
wxString msg;
msg = _( "Unable to create " ) + newFileName.GetFullPath();
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return;
}
wxBeginBusyCursor();
FOOTPRINT_LIBRARY output_lib( out_file );
output_lib.m_List = input_lib.m_List;
2007-10-30 21:30:58 +00:00
output_lib.WriteHeader();
output_lib.RemoveFromList(CmpName);
output_lib.SortList();
output_lib.WriteSectionIndex();
2007-10-30 21:30:58 +00:00
/* Copy modules. */
rewind( lib_module );
LineNum = input_lib.m_LineNum;
bool copylines = false;
2007-10-30 21:30:58 +00:00
while( GetLine( lib_module, Line, &LineNum ) )
{
StrPurge( Line );
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
{
copylines = true;
2007-10-30 21:30:58 +00:00
sscanf( Line + 7, " %s", Name );
msg = FROM_UTF8( Name );
2007-10-30 21:30:58 +00:00
if( msg.CmpNoCase( CmpName ) == 0 )
{
/* 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;
}
}
if( copylines )
fprintf( out_file, "%s\n", Line );
2007-10-30 21:30:58 +00:00
}
fclose( lib_module );
fclose( out_file );
2007-10-30 21:30:58 +00:00
wxEndBusyCursor();
/* The old library file is renamed .bak */
wxFileName backupFileName = oldFileName;
backupFileName.SetExt( BACKUP_EXT );
2007-10-30 21:30:58 +00:00
if( backupFileName.FileExists() )
wxRemoveFile( backupFileName.GetFullPath() );
2007-10-30 21:30:58 +00:00
if( !wxRenameFile( oldFileName.GetFullPath(),
backupFileName.GetFullPath() ) )
2007-10-30 21:30:58 +00:00
{
DisplayError( this, wxT( "Librairi.cpp: rename .bak err" ) );
return;
}
/* The temporary file is renamed as the previous library. */
if( !wxRenameFile( newFileName.GetFullPath(), oldFileName.GetFullPath() ) )
2007-10-30 21:30:58 +00:00
{
DisplayError( this, wxT( "Librairi.cpp: rename err 2" ) );
return;
}
msg.Printf( _( "Component %s deleted in library %s" ), GetChars( CmpName ),
GetChars( oldFileName.GetFullPath() ) );
SetStatusText( msg );
2007-05-06 16:03:28 +00:00
}
/**
* Function Archive_Modules
* Save in the library:
* All new modules (ie modules not found in this lib) (if NewModulesOnly == true)
2010-07-20 18:11:34 +00:00
* all modules (if NewModulesOnly == false)
2007-10-30 21:30:58 +00:00
*/
void PCB_BASE_FRAME::Archive_Modules( const wxString& LibName, bool NewModulesOnly )
2007-05-06 16:03:28 +00:00
{
2007-10-30 21:30:58 +00:00
int ii, NbModules = 0;
MODULE* Module;
wxString fileName = LibName, path;
2007-10-30 21:30:58 +00:00
if( GetBoard()->m_Modules == NULL )
2007-10-30 21:30:58 +00:00
{
DisplayInfoMessage( this, _( " No modules to archive!" ) );
2007-10-30 21:30:58 +00:00
return;
}
path = wxGetApp().ReturnLastVisitedLibraryPath();
if( LibName.IsEmpty() )
2007-10-30 21:30:58 +00:00
{
wxFileDialog dlg( this, _( "Library" ), path,
wxEmptyString, ModuleFileWildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
2007-10-30 21:30:58 +00:00
if( dlg.ShowModal() == wxID_CANCEL )
2007-10-30 21:30:58 +00:00
return;
fileName = dlg.GetPath();
2007-10-30 21:30:58 +00:00
}
wxFileName fn( fileName );
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
bool file_exists = wxFileExists( fileName );
2007-10-30 21:30:58 +00:00
if( !NewModulesOnly && file_exists )
{
wxString msg;
msg.Printf( _( "File %s exists, OK to replace ?" ),
GetChars( fileName ) );
2007-10-30 21:30:58 +00:00
if( !IsOK( this, msg ) )
return;
}
2010-07-20 18:11:34 +00:00
DrawPanel->m_AbortRequest = false;
2007-10-30 21:30:58 +00:00
// Create a new, empty library if no old lib, or if archive all modules
if( !NewModulesOnly || !file_exists )
{
FILE* lib_module;
if( ( lib_module = wxFopen( fileName, wxT( "w+t" ) ) ) == NULL )
2007-10-30 21:30:58 +00:00
{
wxString msg = _( "Unable to create " ) + fileName;
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return;
}
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 );
}
/* Calculate the number of modules. */
Module = (MODULE*) GetBoard()->m_Modules;
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
2007-10-30 21:30:58 +00:00
NbModules++;
double step = 100.0 / NbModules;
2007-10-30 21:30:58 +00:00
DisplayActivity( 0, wxEmptyString );
Module = (MODULE*) GetBoard()->m_Modules;
for( ii = 1; Module != NULL; ii++, Module = (MODULE*) Module->Next() )
2007-10-30 21:30:58 +00:00
{
if( Save_Module_In_Library( fileName, Module,
2010-07-20 18:11:34 +00:00
NewModulesOnly ? false : true,
false ) == 0 )
2007-10-30 21:30:58 +00:00
break;
DisplayActivity( (int) ( ii * step ), wxEmptyString );
/* Check for request to stop backup (ESCAPE key actuated) */
2007-10-30 21:30:58 +00:00
if( DrawPanel->m_AbortRequest )
break;
}
2007-05-06 16:03:28 +00:00
}
/**
* Function Save_Module_In_Library
* Save in an existing library a given footprint
* @param aLibName = name of the library to use
* @param aModule = the given footprint
* @param aOverwrite = true to overwrite an existing footprint, false to abort
* an existing footprint is found
* @param aDisplayDialog = true to display a dialog to enter or confirm the
* footprint name
* @return : true if OK, false if abort
2007-10-30 21:30:58 +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
{
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
if( aModule == NULL )
return false;
aModule->DisplayInfo( this );
2007-10-30 21:30:58 +00:00
if( !wxFileExists( aLibName ) )
2007-10-30 21:30:58 +00:00
{
msg.Printf( _( "Library %s not found" ), GetChars( aLibName ) );
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return false;
2007-10-30 21:30:58 +00:00
}
/* Ask for the footprint name in lib */
Name_Cmp = aModule->m_LibRef;
2007-10-30 21:30:58 +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 );
if( dlg.ShowModal() != wxID_OK )
return false; // cancelled by user
Name_Cmp = dlg.GetValue();
Name_Cmp.Trim( true );
2010-07-20 18:11:34 +00:00
Name_Cmp.Trim( false );
if( Name_Cmp.IsEmpty() )
return false;
aModule->m_LibRef = Name_Cmp;
}
// Ensure this footprint has a libname
if( Name_Cmp.IsEmpty() )
{
Name_Cmp = wxT("noname");
aModule->m_LibRef = Name_Cmp;
2007-10-30 21:30:58 +00:00
}
if( ( lib_module = wxFopen( aLibName, wxT( "rt" ) ) ) == NULL )
2007-10-30 21:30:58 +00:00
{
msg.Printf( _( "Unable to open %s" ), GetChars( aLibName ) );
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return false;
2007-10-30 21:30:58 +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 );
msg.Printf( _( "File %s is not a eeschema library" ),
GetChars( aLibName ) );
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return false;
2007-10-30 21:30:58 +00:00
}
/* Read footprints in lib: - search for an existing footprint */
input_lib.RebuildIndex();
bool module_exists = input_lib.FindInList( Name_Cmp );
if( module_exists )
2007-10-30 21:30:58 +00:00
{
// an existing footprint is found in current lib
if( aDisplayDialog )
2007-10-30 21:30:58 +00:00
{
msg = _( "Module exists\n Line: " );
msg << LineNum;
SetStatusText( msg );
}
if( !aOverwrite ) // Do not save the given footprint: an old one exists
{
fclose( lib_module );
return true;
2007-10-30 21:30:58 +00:00
}
}
/* Creates the new library */
2007-10-30 21:30:58 +00:00
newFileName = aLibName;
newFileName.SetExt( FILETMP_EXT );
if( ( dest = wxFopen( newFileName.GetFullPath(), wxT( "w+t" ) ) ) == NULL )
2007-10-30 21:30:58 +00:00
{
fclose( lib_module );
msg = _( "Unable to create " ) + newFileName.GetFullPath();
2007-10-30 21:30:58 +00:00
DisplayError( this, msg );
return false;
2007-10-30 21:30:58 +00:00
}
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();
2007-10-30 21:30:58 +00:00
LineNum = 0;
rewind( lib_module);
// Copy footprints, until the old footprint to delete
bool skip_header = true;
2007-10-30 21:30:58 +00:00
while( GetLine( lib_module, Line, &LineNum ) )
{
StrPurge( Line );
if( strnicmp( Line, "$EndLIBRARY", 8 ) == 0 )
continue;
// Search fo the beginning of module section:
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 );
msg = FROM_UTF8( Name );
2007-10-30 21:30:58 +00:00
if( msg.CmpNoCase( Name_Cmp ) == 0 )
{
/* 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;
}
}
fprintf( dest, "%s\n", Line );
}
/* Write the new footprint ( append it to the list of footprint ) */
tmp = aModule->m_TimeStamp; aModule->m_TimeStamp = 0;
aModule->Save( dest );
aModule->m_TimeStamp = tmp;
2007-10-30 21:30:58 +00:00
output_lib.WriteEndOfFile();
2011-01-16 05:11:17 +00:00
fclose( dest );
fclose( lib_module );
SetLocaleTo_Default(); // revert to the current locale
2007-10-30 21:30:58 +00:00
wxEndBusyCursor();
/* The old library file is renamed .bak */
oldFileName = aLibName;
oldFileName.SetExt( BACKUP_EXT );
2007-10-30 21:30:58 +00:00
if( oldFileName.FileExists() )
wxRemoveFile( oldFileName.GetFullPath() );
2007-10-30 21:30:58 +00:00
if( !wxRenameFile( aLibName, oldFileName.GetFullPath() ) )
2007-10-30 21:30:58 +00:00
DisplayError( this, wxT( "Librairi.cpp: rename .bak err" ) );
/* The new library file is renamed */
if( !wxRenameFile( newFileName.GetFullPath(), aLibName ) )
2007-10-30 21:30:58 +00:00
{
DisplayError( this, wxT( "Librairi.cpp: rename NewLib err" ) );
return false;
2007-10-30 21:30:58 +00:00
}
if( aDisplayDialog )
2007-10-30 21:30:58 +00:00
{
msg = _( "Component " ); msg += Name_Cmp;
msg += module_exists ? _( " replaced in " ) : _( " added in " );
msg += aLibName;
SetStatusText( msg );
2007-10-30 21:30:58 +00:00
}
return true;
2007-05-06 16:03:28 +00:00
}
/**
* Function Create_1_Module
2010-07-20 18:11:34 +00:00
* Creates a new module or footprint : A new module contains 2 texts :
* First = REFERENCE
* Second = VALUE: "VAL**"
* the new module is added to the board module list
* @param aModuleName = name of the new footprint
* (will the component reference in board)
* @return a pointer to the new module
2007-10-30 21:30:58 +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;
/* 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:" ),
_( "Module Creation" ), moduleName );
if( dlg.ShowModal() != wxID_OK )
2010-07-20 18:11:34 +00:00
return NULL; //Aborted by user
moduleName = dlg.GetValue();
2010-07-20 18:11:34 +00:00
}
moduleName.Trim( true );
moduleName.Trim( false );
if( moduleName.IsEmpty( ) )
{
DisplayInfoMessage( this, _( "No reference, aborted" ) );
return NULL;
2007-10-30 21:30:58 +00:00
}
// Creates the new module and add it to the head of the linked list of
// modules
Module = new MODULE( GetBoard() );
2007-10-30 21:30:58 +00:00
GetBoard()->Add( Module );
2007-10-30 21:30:58 +00:00
/* Update parameters: position, timestamp ... */
newpos = GetScreen()->GetCrossHairPosition();
2007-10-30 21:30:58 +00:00
Module->SetPosition( newpos );
Module->m_LastEdit_Time = time( NULL );
/* 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
/* Update reference: */
2010-07-20 18:11:34 +00:00
Module->m_Reference->m_Text = moduleName;
Module->m_Reference->SetThickness( g_ModuleTextWidth );
Module->m_Reference->SetSize( g_ModuleTextSize );
2007-10-30 21:30:58 +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**" );
Module->m_Value->SetThickness( g_ModuleTextWidth );
Module->m_Value->SetSize( g_ModuleTextSize );
2007-10-30 21:30:58 +00:00
Module->SetPosition( wxPoint( 0, 0 ) );
Module->DisplayInfo( this );
2007-10-30 21:30:58 +00:00
return Module;
2007-05-06 16:03:28 +00:00
}
void WinEDA_ModuleEditFrame::Select_Active_Library()
2007-05-06 16:03:28 +00:00
{
2007-10-30 21:30:58 +00:00
if( g_LibName_List.GetCount() == 0 )
return;
2007-05-06 16:03:28 +00:00
2010-11-19 18:50:23 +00:00
WinEDAListBox dlg( this, _( "Active Lib:" ), g_LibName_List, 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
2010-11-19 18:50:23 +00:00
m_CurrentLib = dlg.GetTextSelection();
2007-05-06 16:03:28 +00:00
2007-10-30 21:30:58 +00:00
SetTitle( _( "Module Editor (lib: " ) + m_CurrentLib + wxT( ")" ) );
return;
2007-05-06 16:03:28 +00:00
}
2007-10-30 21:30:58 +00:00
int WinEDA_ModuleEditFrame::Create_Librairie( const wxString& LibName )
2007-05-06 16:03:28 +00:00
{
2007-10-30 21:30:58 +00:00
FILE* lib_module;
wxString msg;
if( wxFileExists( LibName ) )
{
msg = _( "Library exists " ) + LibName;
DisplayError( this, msg );
return 0;
}
if( ( lib_module = wxFopen( LibName, wxT( "wt" ) ) ) == NULL )
{
msg = _( "Unable to create " ) + LibName;
DisplayError( this, msg );
return -1;
}
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
}