2009-11-14 22:15:22 +00:00
|
|
|
/****************************************/
|
|
|
|
/* 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"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#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"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
static const wxString ModExportFileWildcard(
|
|
|
|
_( "Kicad foot print export files (*.emp)|*.emp" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
static bool CreateDocLibrary( const wxString& LibName );
|
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 Import_Module
|
|
|
|
* Read a file containing only one footprint.
|
|
|
|
* Used to import (after exporting) a footprint
|
2009-11-14 22:15:22 +00:00
|
|
|
* 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.)
|
|
|
|
* @param DC = Current Device Context (can be NULL)
|
2007-10-30 21:30:58 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
MODULE* WinEDA_ModuleEditFrame::Import_Module( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-15 08:12:03 +00:00
|
|
|
int NbLine = 0;
|
|
|
|
char Line[1024];
|
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;
|
|
|
|
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 );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// Switch the locale to standard C (needed to print floating point numbers
|
|
|
|
// like 1.3)
|
|
|
|
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 */
|
2009-04-05 20:49:15 +00:00
|
|
|
GetLine( file, Line, &NbLine );
|
2007-10-30 21:30:58 +00:00
|
|
|
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
if( strnicmp( Line, "Element", 7 ) == 0 )
|
|
|
|
Footprint_Is_GPCB_Format = true;
|
|
|
|
else
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fclose( file );
|
2008-04-17 16:25:29 +00:00
|
|
|
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
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
while( GetLine( file, Line, &NbLine ) != NULL )
|
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
|
|
|
fclose( file );
|
|
|
|
module->Read_GPCB_Descr( dlg.GetPath() );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
module->ReadDescr( file, &NbLine );
|
|
|
|
fclose( file );
|
2008-04-17 16:25:29 +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 );
|
2007-10-30 21:30:58 +00:00
|
|
|
Place_Module( module, DC );
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2009-06-11 14:26:17 +00:00
|
|
|
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
|
2009-11-14 22:15:22 +00:00
|
|
|
* 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
|
2009-11-14 22:15:22 +00:00
|
|
|
* So Create a new lib (which will contains one module) and export a footprint
|
|
|
|
* is basically the same thing
|
2008-03-12 11:49:16 +00:00
|
|
|
* @param DC = Current Device Context (can be NULL)
|
|
|
|
* @param createlib : true = use default lib path to create lib
|
2009-11-14 22:15:22 +00:00
|
|
|
* false = use current path or last used path to export
|
|
|
|
* footprint
|
2007-10-30 21:30:58 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void WinEDA_ModuleEditFrame::Export_Module( MODULE* ptmod, bool createlib )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
|
|
|
char Line[1025];
|
|
|
|
FILE* file;
|
|
|
|
wxString msg, path, title, wildcard;
|
|
|
|
wxConfig* Config = wxGetApp().m_EDA_Config;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
if( ptmod == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ptmod->m_LibRef = ptmod->m_Reference->m_Text;
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetName( ptmod->m_LibRef );
|
|
|
|
fn.SetExt( createlib ? ModuleFileExtension : ModExportFileExtension );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
if( createlib )
|
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 );
|
2009-11-14 22:15:22 +00:00
|
|
|
title = createlib ? _( "Create New Library" ) : _( "Export Module" );
|
|
|
|
wildcard = createlib ? 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;
|
|
|
|
}
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( !createlib && 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
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// Switch the locale to standard C (needed to read floating point numbers
|
|
|
|
// like 1.3)
|
2009-11-04 19:08:08 +00:00
|
|
|
SetLocaleTo_C_standard();
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "%s %s\n", ENTETE_LIBRAIRIE, DateAndTime( Line ) );
|
|
|
|
fputs( "$INDEX\n", file );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "%s\n", CONV_TO_UTF8( ptmod->m_LibRef ) );
|
|
|
|
fputs( "$EndINDEX\n", file );
|
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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fputs( "$EndLIBRARY\n", file );
|
|
|
|
fclose( file );
|
2009-11-14 22:15:22 +00:00
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2009-11-14 22:15:22 +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
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
void WinEDA_ModuleEditFrame::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;
|
|
|
|
int ii, NoFound = 1, LineNum = 0;
|
|
|
|
char Line[1024], Name[256];
|
|
|
|
FILE* dest, * lib_module;
|
|
|
|
wxString CmpName, msg;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-11-14 22:15:22 +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" ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( CmpName ), GetChars( aLibname ) );
|
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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( lib_module = wxFopen( oldFileName.GetFullPath(),
|
2009-11-14 22:15:22 +00:00
|
|
|
wxT( "rt" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Library " ) + oldFileName.GetFullPath() + _( " not found" );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read header. */
|
2007-10-30 21:30:58 +00:00
|
|
|
GetLine( lib_module, Line, &LineNum );
|
|
|
|
|
|
|
|
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Not a Library file" ) );
|
|
|
|
fclose( lib_module );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read module names. */
|
2007-10-30 21:30:58 +00:00
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
StrPurge( Line );
|
|
|
|
msg = CONV_FROM_UTF8( Line );
|
2009-11-14 22:15:22 +00:00
|
|
|
if( CmpName.CmpNoCase( msg ) == 0 ) /* New module? */
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
NoFound = 0; break;
|
|
|
|
}
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( NoFound )
|
|
|
|
{
|
|
|
|
fclose( lib_module );
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Module [%s] not found" ), GetChars( CmpName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
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 );
|
|
|
|
|
|
|
|
if( ( dest = wxFopen( newFileName.GetFullPath(), wxT( "wt" ) ) ) == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
fclose( lib_module );
|
|
|
|
wxString msg;
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Unable to create " ) + newFileName.GetFullPath();
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxBeginBusyCursor();
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Create header with new date. */
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( dest, ENTETE_LIBRAIRIE );
|
|
|
|
fprintf( dest, " %s\n$INDEX\n", DateAndTime( Line ) );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fseek( lib_module, 0, 0 );
|
|
|
|
GetLine( lib_module, Line, &ii );
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
while( GetLine( lib_module, Line, &ii ) )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$M", 2 ) == 0 )
|
|
|
|
break;
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
|
|
|
while( GetLine( lib_module, Line, &ii ) )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
StrPurge( Line );
|
|
|
|
msg = CONV_FROM_UTF8( Line );
|
|
|
|
if( CmpName.CmpNoCase( msg ) != 0 )
|
|
|
|
fprintf( dest, "%s\n", Line );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( dest, "$EndINDEX\n" );
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Copy modules. */
|
2007-10-30 21:30:58 +00:00
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
StrPurge( Line );
|
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
|
|
|
|
{
|
|
|
|
sscanf( Line + 7, " %s", Name );
|
|
|
|
msg = CONV_FROM_UTF8( Name );
|
|
|
|
if( msg.CmpNoCase( CmpName ) == 0 )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Delete old module. */
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( lib_module );
|
|
|
|
fclose( dest );
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-06-26 12:52:24 +00:00
|
|
|
if( !wxRenameFile( oldFileName.GetFullPath(),
|
2009-11-14 22:15:22 +00:00
|
|
|
backupFileName.GetFullPath() ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "Librairi.cpp: rename .bak err" ) );
|
|
|
|
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
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "Librairi.cpp: rename err 2" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Component %s deleted in library %s" ), GetChars( CmpName ),
|
2009-11-14 22:15:22 +00:00
|
|
|
GetChars( oldFileName.GetFullPath() ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
Affiche_Message( msg );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
CreateDocLibrary( oldFileName.GetFullPath() );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-14 22:15:22 +00:00
|
|
|
* Save library:
|
|
|
|
* All new modules (ie modules not already exist (if NewModulesOnly == true)
|
|
|
|
* all modules (if NewModulesOnly == FALSE)
|
2007-10-30 21:30:58 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void WinEDA_BasePcbFrame::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;
|
|
|
|
float Pas;
|
|
|
|
MODULE* Module;
|
2009-04-14 16:45:22 +00:00
|
|
|
wxString fileName = LibName, 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
|
|
|
{
|
2009-04-17 08:51:02 +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();
|
2009-04-05 20:49:15 +00:00
|
|
|
if( LibName.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,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
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
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( !NewModulesOnly && file_exists )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2009-11-14 22:15:22 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawPanel->m_AbortRequest = FALSE;
|
|
|
|
|
|
|
|
// Create a new, empty library if no old lib, or if archive all modules
|
|
|
|
if( !NewModulesOnly || !file_exists )
|
|
|
|
{
|
|
|
|
FILE* lib_module;
|
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
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString msg = _( "Unable to create " ) + fileName;
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
2009-01-15 08:12:03 +00:00
|
|
|
char Line[256];
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( lib_module, "%s %s\n", ENTETE_LIBRAIRIE, DateAndTime( Line ) );
|
|
|
|
fputs( "$INDEX\n", lib_module );
|
|
|
|
fputs( "$EndINDEX\n", lib_module );
|
|
|
|
fputs( "$EndLIBRARY\n", lib_module );
|
|
|
|
fclose( lib_module );
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculate the number of modules. */
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = (MODULE*) GetBoard()->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
|
2007-10-30 21:30:58 +00:00
|
|
|
NbModules++;
|
|
|
|
|
|
|
|
Pas = (float) 100 / NbModules;
|
|
|
|
DisplayActivity( 0, wxEmptyString );
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = (MODULE*) GetBoard()->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ii = 1; Module != NULL; ii++, Module = (MODULE*) Module->Next() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( Save_Module_In_Library( fileName, Module,
|
2009-11-14 22:15:22 +00:00
|
|
|
NewModulesOnly ? FALSE : true,
|
|
|
|
FALSE, false ) == 0 )
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
2009-01-15 08:12:03 +00:00
|
|
|
DisplayActivity( (int) ( ii * Pas ), wxEmptyString );
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Check for request to stop backup (ESCAPE key actuated) */
|
2007-10-30 21:30:58 +00:00
|
|
|
if( DrawPanel->m_AbortRequest )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
CreateDocLibrary( fileName );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-15 08:12:03 +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
|
2009-11-14 22:15:22 +00:00
|
|
|
* @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
|
2009-01-15 08:12:03 +00:00
|
|
|
* @param aCreateDocFile = true to creates the associated doc file
|
|
|
|
* @return : 1 if OK, 0 if abort
|
2007-10-30 21:30:58 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
int WinEDA_BasePcbFrame::Save_Module_In_Library( const wxString& aLibName,
|
|
|
|
MODULE* aModule,
|
|
|
|
bool aOverwrite,
|
|
|
|
bool aDisplayDialog,
|
|
|
|
bool aCreateDocFile )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName oldFileName;
|
|
|
|
wxFileName newFileName;
|
|
|
|
int newmodule, end;
|
|
|
|
int LineNum = 0, tmp;
|
|
|
|
char Name[256], Line[1024];
|
|
|
|
wxString Name_Cmp;
|
|
|
|
wxString msg;
|
|
|
|
FILE* lib_module, * dest;
|
|
|
|
bool added = true;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
aModule->DisplayInfo( this );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( !wxFileExists( aLibName ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Library %s not found" ), GetChars( aLibName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-01-15 08:12:03 +00:00
|
|
|
Get_Message( _( "Name:" ), _( "Save module" ), Name_Cmp, this );
|
2007-10-30 21:30:58 +00:00
|
|
|
if( Name_Cmp.IsEmpty() )
|
|
|
|
return 0;
|
2009-01-15 08:12:03 +00:00
|
|
|
Name_Cmp.Trim( true );
|
2007-10-30 21:30:58 +00:00
|
|
|
Name_Cmp.Trim( FALSE );
|
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
|
|
|
{
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Unable to open %s" ), GetChars( aLibName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read library file : library header */
|
2007-10-30 21:30:58 +00:00
|
|
|
GetLine( lib_module, Line, &LineNum );
|
|
|
|
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
{
|
|
|
|
fclose( lib_module );
|
2009-11-14 22:15:22 +00:00
|
|
|
msg.Printf( _( "File %s is not a eeschema library" ),
|
|
|
|
GetChars( aLibName ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read footprints in lib: - search for an existing footprint */
|
2007-10-30 21:30:58 +00:00
|
|
|
newmodule = 1; end = 0;
|
|
|
|
while( !end && GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
|
|
|
if( strncmp( Line + 1, "INDEX", 5 ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
if( strncmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
{
|
|
|
|
end = 1; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
StrPurge( Line );
|
|
|
|
msg = CONV_FROM_UTF8( Line );
|
2009-11-14 22:15:22 +00:00
|
|
|
if( Name_Cmp.CmpNoCase( msg ) == 0 ) /* an existing footprint is
|
|
|
|
* found */
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
added = FALSE;
|
|
|
|
newmodule = 0;
|
2009-01-15 08:12:03 +00:00
|
|
|
if( aDisplayDialog )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2008-11-08 21:58:50 +00:00
|
|
|
msg = _( "Module exists\n Line: " );
|
2007-10-30 21:30:58 +00:00
|
|
|
msg << LineNum;
|
|
|
|
Affiche_Message( msg );
|
|
|
|
}
|
2009-11-14 22:15:22 +00:00
|
|
|
if( !aOverwrite ) /* Do not save the given footprint: an old
|
|
|
|
* one exists */
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
fclose( lib_module ); return 1;
|
|
|
|
}
|
|
|
|
end = 1; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( lib_module );
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* Creates the new library */
|
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
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "Librairi.cpp: Error oldlib not found" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +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 );
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Unable to create " ) + newFileName.GetFullPath();
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxBeginBusyCursor();
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// Switch the locale to standard C (needed to print floating point numbers
|
|
|
|
// like 1.3)
|
|
|
|
SetLocaleTo_C_standard();
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* Create the library header with a new date */
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( dest, ENTETE_LIBRAIRIE );
|
|
|
|
fprintf( dest, " %s\n$INDEX\n", DateAndTime( Line ) );
|
|
|
|
|
|
|
|
LineNum = 0;
|
|
|
|
GetLine( lib_module, Line, &LineNum );
|
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
StrPurge( Line );
|
|
|
|
if( strnicmp( Line, "$M", 2 ) == 0 )
|
|
|
|
break;
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
fprintf( dest, "%s\n", Line );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( newmodule )
|
|
|
|
fprintf( dest, "%s\n", CONV_TO_UTF8( Name_Cmp ) );
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 0 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( dest, "$EndINDEX\n" );
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* Copy footprints, until the old footprint to delete */
|
2007-10-30 21:30:58 +00:00
|
|
|
while( GetLine( lib_module, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
StrPurge( Line );
|
|
|
|
if( strnicmp( Line, "$EndLIBRARY", 8 ) == 0 )
|
|
|
|
continue;
|
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) == 0 )
|
|
|
|
{
|
|
|
|
sscanf( Line + 7, " %s", Name );
|
|
|
|
msg = CONV_FROM_UTF8( Name );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf( dest, "%s\n", Line );
|
|
|
|
}
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* Write the new footprint ( append it to the list of footprint ) */
|
|
|
|
tmp = aModule->m_TimeStamp; aModule->m_TimeStamp = 0;
|
|
|
|
aModule->Save( dest );
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( dest, "$EndLIBRARY\n" );
|
2009-01-15 08:12:03 +00:00
|
|
|
aModule->m_TimeStamp = tmp;
|
2007-10-30 21:30:58 +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() ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, wxT( "Librairi.cpp: rename .bak err" ) );
|
|
|
|
|
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
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "Librairi.cpp: rename NewLib err" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
/* creates the new .dcm doc file corresponding to the new library */
|
2009-11-14 22:15:22 +00:00
|
|
|
if( aCreateDocFile )
|
2009-01-15 08:12:03 +00:00
|
|
|
CreateDocLibrary( aLibName );
|
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
|
|
|
{
|
|
|
|
msg = _( "Component " ); msg += Name_Cmp;
|
|
|
|
msg += added ? _( " added in " ) : _( " replaced in " );
|
2009-01-15 08:12:03 +00:00
|
|
|
msg += aLibName;
|
2007-10-30 21:30:58 +00:00
|
|
|
Affiche_Message( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-23 05:53:12 +00:00
|
|
|
/* Create a new module or footprint : A new module contains 2 texts :
|
2008-11-10 20:45:24 +00:00
|
|
|
* First = REFERENCE
|
|
|
|
* Second = VALUE: "VAL**"
|
2009-11-14 22:15:22 +00:00
|
|
|
* the new module is added on beginning of the linked list of modules
|
2007-10-30 21:30:58 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
MODULE* WinEDA_BasePcbFrame::Create_1_Module( wxDC* DC,
|
|
|
|
const wxString& module_name )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-30 21:30:58 +00:00
|
|
|
MODULE* Module;
|
|
|
|
wxString Line;
|
|
|
|
wxPoint newpos;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Ask for the new module reference */
|
2007-10-30 21:30:58 +00:00
|
|
|
if( module_name.IsEmpty() )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( Get_Message( _( "Module Reference:" ),
|
|
|
|
_( "Module Creation" ), Line, this ) != 0 )
|
2008-11-12 17:27:32 +00:00
|
|
|
{
|
2009-04-17 08:51:02 +00:00
|
|
|
DisplayInfoMessage( this, _( "No reference, aborted" ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
return NULL;
|
2008-11-12 17:31:52 +00:00
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Line = module_name;
|
2009-01-15 08:12:03 +00:00
|
|
|
Line.Trim( true );
|
2007-10-30 21:30:58 +00:00
|
|
|
Line.Trim( FALSE );
|
|
|
|
|
2009-11-14 22:15:22 +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 ... */
|
2008-04-17 16:25:29 +00:00
|
|
|
newpos = GetScreen()->m_Curseur;
|
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 */
|
2007-10-30 21:30:58 +00:00
|
|
|
Module->m_LibRef = Line;
|
|
|
|
|
2008-11-10 20:45:24 +00:00
|
|
|
/* Update reference: */
|
2007-10-30 21:30:58 +00:00
|
|
|
Module->m_Reference->m_Text = Line;
|
|
|
|
Module->m_Reference->SetWidth( ModuleTextWidth );
|
|
|
|
Module->m_Reference->m_Size = ModuleTextSize;
|
|
|
|
|
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**" );
|
|
|
|
Module->m_Value->SetWidth( ModuleTextWidth );
|
|
|
|
Module->m_Value->m_Size = ModuleTextSize;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 11:55:46 +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
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
WinEDAListBox* LibListBox = new WinEDAListBox( this, _( "Active Lib:" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
NULL, m_CurrentLib, NULL,
|
|
|
|
wxColour( 200, 200, 255 ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
LibListBox->InsertItems( g_LibName_List );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
int ii = LibListBox->ShowModal();
|
|
|
|
if( ii >= 0 )
|
|
|
|
m_CurrentLib = LibListBox->GetTextSelection();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
LibListBox->Destroy();
|
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;
|
2009-01-15 08:12:03 +00:00
|
|
|
char cbuf[256];
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Write the header of the new library. */
|
2007-10-30 21:30:58 +00:00
|
|
|
if( fprintf( lib_module, ENTETE_LIBRAIRIE ) == 0 )
|
|
|
|
{
|
|
|
|
msg = _( "Create error " ) + LibName;
|
|
|
|
DisplayError( this, msg );
|
|
|
|
fclose( lib_module ); return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( lib_module, " %s\n", DateAndTime( cbuf ) );
|
|
|
|
fputs( "$INDEX\n", lib_module );
|
|
|
|
fputs( "$EndINDEX\n", lib_module );
|
|
|
|
fclose( lib_module );
|
|
|
|
|
|
|
|
return 1;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Synch. Dcm combines a library Libname
|
|
|
|
* (Full file name)
|
2007-10-30 21:30:58 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
static bool CreateDocLibrary( const wxString& LibName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
char Line[1024];
|
|
|
|
char cbuf[256];
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString Name, Doc, KeyWord;
|
|
|
|
wxFileName fn;
|
|
|
|
FILE* LibMod, * LibDoc;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = LibName;
|
|
|
|
fn.SetExt( EXT_DOC );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
LibMod = wxFopen( LibName, wxT( "rt" ) );
|
|
|
|
if( LibMod == NULL )
|
|
|
|
return FALSE;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read library header. */
|
2007-10-30 21:30:58 +00:00
|
|
|
GetLine( LibMod, Line, NULL, sizeof(Line) - 1 );
|
|
|
|
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
{
|
|
|
|
fclose( LibMod );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
LibDoc = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
if( LibDoc == NULL )
|
|
|
|
{
|
|
|
|
fclose( LibMod );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
fprintf( LibDoc, ENTETE_LIBDOC );
|
|
|
|
fprintf( LibDoc, " %s\n", DateAndTime( cbuf ) );
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Read library. */
|
2007-10-30 21:30:58 +00:00
|
|
|
Name = Doc = KeyWord = wxEmptyString;
|
|
|
|
while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
{
|
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
|
|
|
if( strnicmp( Line, "$MODULE", 6 ) == 0 )
|
|
|
|
{
|
|
|
|
while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
{
|
|
|
|
if( Line[0] == '$' )
|
|
|
|
{
|
|
|
|
if( Line[1] == 'E' )
|
|
|
|
break;
|
|
|
|
if( Line[1] == 'P' ) /* Pad Descr */
|
|
|
|
{
|
|
|
|
while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
{
|
|
|
|
if( (Line[0] == '$') && (Line[1] == 'E') )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( Line[0] == 'L' ) /* LibName */
|
|
|
|
Name = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
|
|
|
|
if( Line[0] == 'K' ) /* KeyWords */
|
|
|
|
KeyWord = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
|
|
|
|
if( Line[0] == 'C' ) /* Doc */
|
|
|
|
Doc = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Generate the module the documentation. */
|
|
|
|
if( ( Name != wxEmptyString )
|
|
|
|
&& ( ( Doc != wxEmptyString ) || ( KeyWord != wxEmptyString ) ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
fprintf( LibDoc, "#\n$MODULE %s\n", CONV_TO_UTF8( Name ) );
|
|
|
|
fprintf( LibDoc, "Li %s\n", CONV_TO_UTF8( Name ) );
|
|
|
|
if( Doc != wxEmptyString )
|
|
|
|
fprintf( LibDoc, "Cd %s\n", CONV_TO_UTF8( Doc ) );
|
|
|
|
|
|
|
|
if( KeyWord != wxEmptyString )
|
|
|
|
fprintf( LibDoc, "Kw %s\n", CONV_TO_UTF8( KeyWord ) );
|
|
|
|
|
|
|
|
fprintf( LibDoc, "$EndMODULE\n" );
|
|
|
|
}
|
|
|
|
Name = Doc = KeyWord = wxEmptyString;
|
2009-11-14 22:15:22 +00:00
|
|
|
} /* End read 1 module */
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
|
|
|
while( GetLine( LibMod, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* End read INDEX */
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( LibMod );
|
|
|
|
fprintf( LibDoc, "#\n$EndLIBDOC\n" );
|
|
|
|
fclose( LibDoc );
|
2009-01-15 08:12:03 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|