2009-11-05 19:26:52 +00:00
|
|
|
/****************/
|
|
|
|
/* savecmp.cpp */
|
|
|
|
/****************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "wxstruct.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
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
int CVPCB_MAINFRAME::SaveComponentList( const wxString& aFullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
FILE* dest;
|
2011-08-24 19:44:05 +00:00
|
|
|
wxFileName fn( aFullFileName );
|
2009-04-23 15:02:18 +00:00
|
|
|
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" ) );
|
2011-08-24 19:44:05 +00:00
|
|
|
|
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 ) );
|
2011-11-08 16:37:25 +00:00
|
|
|
fprintf( dest, " date = %s\n", TO_UTF8( DateAndTime() ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
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" );
|
2011-08-24 19:44:05 +00:00
|
|
|
fprintf( dest, "TimeStamp = %s;\n", TO_UTF8( component.m_TimeStamp ) );
|
|
|
|
fprintf( dest, "Reference = %s;\n", TO_UTF8( component.m_Reference ) );
|
|
|
|
fprintf( dest, "ValeurCmp = %s;\n", TO_UTF8( component.m_Value ) );
|
|
|
|
fprintf( dest, "IdModule = %s;\n", 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
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
bool CVPCB_MAINFRAME::LoadComponentFile( const wxString& aFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
wxString timestamp, valeur, ilib, namecmp, msg;
|
2011-08-24 19:44:05 +00:00
|
|
|
bool read_cmp_data = false, eof = false;
|
2009-04-23 15:02:18 +00:00
|
|
|
char Line[1024], * ident, * data;
|
|
|
|
FILE* source;
|
2011-08-24 19:44:05 +00:00
|
|
|
wxFileName fn = aFileName;
|
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 )
|
|
|
|
{
|
2011-08-29 19:50:05 +00:00
|
|
|
msg.Printf( _( "Cannot open CvPcb component file <%s>." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2011-08-24 19:44:05 +00:00
|
|
|
msg << wxT( "\n" ) << _( "This is normal if you are opening a new netlist file" );
|
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
|
|
|
{
|
2011-09-30 18:15:37 +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;
|
2011-08-24 19:44:05 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
timestamp.Empty();
|
|
|
|
valeur.Empty();
|
|
|
|
ilib.Empty();
|
|
|
|
namecmp.Empty();
|
2011-08-24 19:44:05 +00:00
|
|
|
read_cmp_data = true;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
while( !eof && read_cmp_data )
|
|
|
|
{
|
|
|
|
if( fgets( Line, 1024, source ) == 0 )
|
|
|
|
{
|
2011-08-24 19:44:05 +00:00
|
|
|
eof = true;
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "EndCmp", 6 ) == 0 )
|
|
|
|
{
|
2011-08-24 19:44:05 +00:00
|
|
|
read_cmp_data = true;
|
2009-04-05 20:49:15 +00:00
|
|
|
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 );
|
2011-08-24 19:44:05 +00:00
|
|
|
timestamp.Trim( true );
|
|
|
|
timestamp.Trim( false );
|
2009-02-04 15:25:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "Reference", 9 ) == 0 )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
namecmp = FROM_UTF8( data );
|
2011-08-24 19:44:05 +00:00
|
|
|
namecmp.Trim( true );
|
|
|
|
namecmp.Trim( false );
|
2009-02-04 15:25:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "ValeurCmp", 9 ) == 0 )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
valeur = FROM_UTF8( data );
|
2011-08-24 19:44:05 +00:00
|
|
|
valeur.Trim( true );
|
|
|
|
valeur.Trim( false );
|
2009-02-04 15:25:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "IdModule", 8 ) == 0 )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
ilib = FROM_UTF8( data );
|
2011-08-24 19:44:05 +00:00
|
|
|
ilib.Trim( true );
|
|
|
|
ilib.Trim( false );
|
2009-02-04 15:25:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-11-05 19:26:52 +00:00
|
|
|
} /* End reading component description. */
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-08-24 19:44:05 +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
|
|
|
}
|