2009-11-05 19:26:52 +00:00
|
|
|
/****************/
|
|
|
|
/* savecmp.cpp */
|
|
|
|
/****************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "appl_wxstruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "cvpcb.h"
|
2011-02-05 16:15:48 +00:00
|
|
|
#include "cvpcb_mainframe.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2010-01-05 08:48:49 +00:00
|
|
|
#include "build_version.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* File header. */
|
2009-02-04 15:25:03 +00:00
|
|
|
char EnteteCmpMod[] = { "Cmp-Mod V01" };
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-21 18:27:47 +00:00
|
|
|
#define titleComponentLibErr _( "Component Library Error" )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
2009-11-05 19:26:52 +00:00
|
|
|
* Backup modules file.
|
|
|
|
*
|
|
|
|
* @param NetlistFullFileName - Name of net list file to save.
|
|
|
|
* @returns - 1 if OK, 0 if error.
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2011-02-05 16:15:48 +00:00
|
|
|
int CVPCB_MAINFRAME::SaveComponentList( const wxString& NetlistFullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
FILE* dest;
|
|
|
|
wxFileName fn( NetlistFullFileName );
|
|
|
|
char Line[1024];
|
|
|
|
wxString Title = wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( ComponentFileExtension );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
dest = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
if( dest == NULL )
|
2009-11-05 19:26:52 +00:00
|
|
|
return 0;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
fprintf( dest, "%s", EnteteCmpMod );
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( dest, " Created by %s", TO_UTF8( Title ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
fprintf( dest, " date = %s\n", DateAndTime( Line ) );
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, m_components )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
fprintf( dest, "\nBeginCmp\n" );
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( dest, "TimeStamp = %s;\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( component.m_TimeStamp ) );
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( dest, "Reference = %s;\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( component.m_Reference ) );
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( dest, "ValeurCmp = %s;\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( component.m_Value ) );
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( dest, "IdModule = %s;\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( component.m_Module ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
fprintf( dest, "EndCmp\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( dest, "\nEndListe\n" );
|
|
|
|
fclose( dest );
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
2009-11-05 19:26:52 +00:00
|
|
|
* Load list of associated components and footprints.
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2011-02-21 18:27:47 +00:00
|
|
|
bool CVPCB_MAINFRAME::LoadComponentFile( const wxString& fileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
wxString timestamp, valeur, ilib, namecmp, msg;
|
|
|
|
bool read_cmp_data = FALSE, eof = FALSE;
|
|
|
|
char Line[1024], * ident, * data;
|
|
|
|
FILE* source;
|
|
|
|
wxFileName fn = fileName;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( ComponentFileExtension );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
source = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
if( source == NULL )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg.Printf( _( "Cannot open component library <%s>." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
|
|
|
|
return false;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Identification of the type of file CmpMod */
|
2009-02-04 15:25:03 +00:00
|
|
|
if( fgets( Line, 79, source ) == 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( " <%s> does not appear to be a valid Kicad component library." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
|
|
|
|
fclose( source );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( strnicmp( Line, EnteteCmpMod, 11 ) != 0 ) /* old file version*/
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg.Printf( _( "<%s> is an old version component file." ) );
|
|
|
|
wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
|
2009-02-04 15:25:03 +00:00
|
|
|
fclose( source );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while( !eof && fgets( Line, 79, source ) != 0 )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "EndListe", 8 ) == 0 )
|
|
|
|
break;
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Search the beginning of the component description. */
|
2009-02-04 15:25:03 +00:00
|
|
|
if( strnicmp( Line, "BeginCmp", 8 ) != 0 )
|
|
|
|
continue;
|
|
|
|
timestamp.Empty();
|
|
|
|
valeur.Empty();
|
|
|
|
ilib.Empty();
|
|
|
|
namecmp.Empty();
|
|
|
|
read_cmp_data = TRUE;
|
|
|
|
|
|
|
|
while( !eof && read_cmp_data )
|
|
|
|
{
|
|
|
|
if( fgets( Line, 1024, source ) == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
eof = TRUE;
|
|
|
|
break;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "EndCmp", 6 ) == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
read_cmp_data = TRUE;
|
|
|
|
break;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ident = strtok( Line, "=;\n\r" );
|
|
|
|
data = strtok( NULL, ";\n\r" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( strnicmp( ident, "TimeStamp", 9 ) == 0 )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
timestamp = FROM_UTF8( data );
|
2009-02-04 15:25:03 +00:00
|
|
|
timestamp.Trim( TRUE );
|
|
|
|
timestamp.Trim( FALSE );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "Reference", 9 ) == 0 )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
namecmp = FROM_UTF8( data );
|
2009-02-04 15:25:03 +00:00
|
|
|
namecmp.Trim( TRUE );
|
|
|
|
namecmp.Trim( FALSE );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "ValeurCmp", 9 ) == 0 )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
valeur = FROM_UTF8( data );
|
2009-02-04 15:25:03 +00:00
|
|
|
valeur.Trim( TRUE );
|
|
|
|
valeur.Trim( FALSE );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "IdModule", 8 ) == 0 )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
ilib = FROM_UTF8( data );
|
2009-02-04 15:25:03 +00:00
|
|
|
ilib.Trim( TRUE );
|
|
|
|
ilib.Trim( FALSE );
|
|
|
|
continue;
|
|
|
|
}
|
2009-11-05 19:26:52 +00:00
|
|
|
} /* End reading component description. */
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Search corresponding component and NetList
|
|
|
|
* Update its parameters. */
|
2011-02-21 18:27:47 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, m_components )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
if( namecmp != component.m_Reference )
|
2009-04-05 20:49:15 +00:00
|
|
|
continue;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Copy the name of the corresponding module. */
|
2009-05-06 11:55:36 +00:00
|
|
|
component.m_Module = ilib;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( source );
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|