2007-12-17 20:18:04 +00:00
|
|
|
/****************************/
|
|
|
|
/* readschematicnetlist.cpp */
|
|
|
|
/****************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/* Read a nelist type Eeschema or OrcadPCB2 and build the component list
|
2007-12-17 20:18:04 +00:00
|
|
|
* Manages the lines like :
|
|
|
|
* ( XXXXXX VALEUR|(pin1,pin2,...=newalim) ID VALEUR
|
|
|
|
*/
|
2007-05-06 16:03:28 +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"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "macros.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvpcb.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "protos.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvstruct.h"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
#define SEPARATEUR '|' /* Separator character in NetList */
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
static int ReadPinConnection( FILE* f, COMPONENT* CurrentCmp );
|
2008-08-01 17:41:51 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Sort the list alphabetically by component and and returns
|
|
|
|
* a pointer to the 1st element of list */
|
|
|
|
|
|
|
|
#define BUFFER_CHAR_SIZE 1024 // Size of buffers used to store netlist data
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-08-01 17:41:51 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/**
|
|
|
|
* Function ReadSchematicNetlist
|
2008-08-01 17:41:51 +00:00
|
|
|
* Read a Eeschema (or OrcadPCB) netlist
|
|
|
|
* like:
|
|
|
|
* # EESchema Netlist Version 1.1 created 15/5/2008-12:09:21
|
|
|
|
* (
|
|
|
|
* ( /32568D1E $noname JP1 CONN_8X2 {Lib=CONN_8X2}
|
|
|
|
* ( 1 GND )
|
|
|
|
* ( 2 /REF10 )
|
|
|
|
* ( 3 GND )
|
|
|
|
* ( 4 /REF11 )
|
|
|
|
* ( 5 GND )
|
|
|
|
* ( 6 /REF7 )
|
|
|
|
* ( 7 GND )
|
|
|
|
* ( 8 /REF9 )
|
|
|
|
* ( 9 GND )
|
|
|
|
* ( 10 /REF6 )
|
|
|
|
* ( 11 GND )
|
|
|
|
* ( 12 /REF8 )
|
|
|
|
* ( 13 GND )
|
|
|
|
* ( 14 /REF4 )
|
|
|
|
* ( 15 GND )
|
|
|
|
* ( 16 /REF5 )
|
|
|
|
* )
|
|
|
|
* ( /325679C1 $noname RR1 9x1K {Lib=RR9}
|
|
|
|
* ( 1 VCC )
|
|
|
|
* ( 2 /REF5 )
|
|
|
|
* ( 3 /REF4 )
|
|
|
|
* ( 4 /REF8 )
|
|
|
|
* ( 5 /REF6 )
|
|
|
|
* ( 6 /REF9 )
|
|
|
|
* ( 7 /REF7 )
|
|
|
|
* ( 8 /REF11 )
|
|
|
|
* ( 9 /REF10 )
|
|
|
|
* ( 10 ? )
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* *
|
|
|
|
* { Allowed footprints by component:
|
|
|
|
* $component R5
|
|
|
|
* R?
|
|
|
|
* SM0603
|
|
|
|
* SM0805
|
|
|
|
* $endlist
|
|
|
|
* $component C2
|
|
|
|
* SM*
|
|
|
|
* C?
|
|
|
|
* C1-1
|
|
|
|
* $endlist
|
|
|
|
* $endfootprintlist
|
|
|
|
* }
|
|
|
|
*/
|
2009-04-23 15:02:18 +00:00
|
|
|
int WinEDA_CvpcbFrame::ReadSchematicNetlist()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
char alim[1024];
|
|
|
|
int i, k, l;
|
|
|
|
char* LibName;
|
|
|
|
char Line[BUFFER_CHAR_SIZE + 1];
|
|
|
|
wxString component_reference; /* buffer for component reference (U1, R4...) */
|
|
|
|
wxString schematic_timestamp; /* buffer for component time stamp */
|
|
|
|
wxString footprint_name; /* buffer for component footprint field */
|
|
|
|
wxString component_value; /* buffer for component values (470K, 22nF ...) */
|
|
|
|
char* ptchar;
|
|
|
|
COMPONENT* Cmp;
|
|
|
|
FILE* source;
|
2009-10-26 19:16:18 +00:00
|
|
|
char* result;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
|
|
|
m_modified = false;
|
|
|
|
m_isEESchemaNetlist = false;
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2008-12-08 18:56:43 +00:00
|
|
|
/* Clear components buffer */
|
2009-04-23 15:02:18 +00:00
|
|
|
if( !m_components.empty() )
|
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
m_components.clear();
|
2009-04-23 15:02:18 +00:00
|
|
|
}
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
source = wxFopen( m_NetlistFileName.GetFullPath(), wxT( "rt" ) );
|
|
|
|
|
2007-12-17 20:18:04 +00:00
|
|
|
if( source == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
DisplayError( this, _( "File <" ) + m_NetlistFileName.GetFullPath() +
|
|
|
|
_( "> not found" ) );
|
|
|
|
return -1;
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the file header (must be "( { OrCAD PCB" or "({ OrCAD PCB" )
|
2009-11-05 19:26:52 +00:00
|
|
|
* or "# EESchema Netlist"
|
2007-12-17 20:18:04 +00:00
|
|
|
*/
|
2009-10-26 19:16:18 +00:00
|
|
|
result = fgets( Line, BUFFER_CHAR_SIZE, source );
|
2007-12-17 20:18:04 +00:00
|
|
|
/* test for netlist type PCB2 */
|
|
|
|
i = strnicmp( Line, "( {", 3 );
|
|
|
|
if( i != 0 )
|
|
|
|
i = strnicmp( Line, "({", 2 );
|
|
|
|
if( i != 0 )
|
|
|
|
{
|
|
|
|
i = strnicmp( Line, "# EESchema", 7 ); /* net type EESchema */
|
|
|
|
if( i == 0 )
|
2009-04-23 15:02:18 +00:00
|
|
|
m_isEESchemaNetlist = TRUE;
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( i != 0 )
|
|
|
|
{
|
|
|
|
wxString msg, Lineconv = CONV_FROM_UTF8( Line );
|
|
|
|
msg.Printf( _( "Unknown file format <%s>" ), Lineconv.GetData() );
|
|
|
|
DisplayError( this, msg );
|
2009-05-21 17:42:42 +00:00
|
|
|
fclose( source );
|
|
|
|
return -3;
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetStatusText( _( "Netlist Format: EESchema" ), 0 );
|
|
|
|
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/* Read the netlist */
|
2007-12-17 20:18:04 +00:00
|
|
|
for( ; ; )
|
|
|
|
{
|
|
|
|
/* Search the beginning of a component description */
|
|
|
|
|
|
|
|
if( fgets( Line, BUFFER_CHAR_SIZE, source ) == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Remove blanks */
|
|
|
|
i = 0; while( Line[i] == ' ' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* remove empty lines : */
|
|
|
|
if( Line[i] < ' ' )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( strnicmp( &Line[i], "{ Allowed footprints", 20 ) == 0 )
|
|
|
|
{
|
|
|
|
ReadFootprintFilterList( source );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( &Line[i], "( ", 2 ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*******************************/
|
|
|
|
/* Component description found */
|
|
|
|
/*******************************/
|
|
|
|
while( Line[i] != ' ' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
while( Line[i] == ' ' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* i points the beginning of the schematic time stamp */
|
|
|
|
|
2008-08-01 17:41:51 +00:00
|
|
|
schematic_timestamp.Empty();
|
|
|
|
while( Line[i] != ' ' )
|
|
|
|
schematic_timestamp.Append( Line[i++] );
|
2007-12-17 20:18:04 +00:00
|
|
|
|
|
|
|
/* search val/ref.lib */
|
|
|
|
while( Line[i] == ' ' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* i points the component value */
|
|
|
|
LibName = Line + i;
|
|
|
|
|
2008-08-01 17:41:51 +00:00
|
|
|
component_reference.Empty();
|
|
|
|
footprint_name.Empty();
|
|
|
|
component_value.Empty();
|
2007-12-17 20:18:04 +00:00
|
|
|
memset( alim, 0, sizeof(alim) );
|
|
|
|
|
|
|
|
/* Read value */
|
|
|
|
|
|
|
|
ptchar = strstr( &Line[i], " " ); // Search end of value field (space)
|
|
|
|
if( ptchar == 0 )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Netlist error: %s" ), Line );
|
2008-08-01 17:41:51 +00:00
|
|
|
DisplayError( this, msg );
|
2007-12-17 20:18:04 +00:00
|
|
|
k = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
k = ptchar - Line;
|
|
|
|
|
2008-08-01 17:41:51 +00:00
|
|
|
for( ; i < k; i++ )
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
|
|
|
if( Line[i] == SEPARATEUR )
|
|
|
|
break;
|
2008-08-01 17:41:51 +00:00
|
|
|
footprint_name.Append( Line[i] );
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( (Line[++i] == '(') && (Line[k - 1] == ')' ) )
|
|
|
|
{
|
|
|
|
i++; l = 0; while( k - 1 > i )
|
|
|
|
alim[l++] = Line[i++];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i = k;
|
|
|
|
|
|
|
|
/* Search component reference */
|
|
|
|
while( Line[i] != ' ' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* goto end of value field */
|
|
|
|
while( Line[i] == ' ' )
|
|
|
|
i++;
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* goto beginning of reference */
|
2008-08-01 17:41:51 +00:00
|
|
|
for( ; ; i++ )
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
2009-09-01 10:26:43 +00:00
|
|
|
#if defined(KICAD_GOST)
|
|
|
|
if( Line[i] == ' ' )
|
|
|
|
#else
|
2007-12-17 20:18:04 +00:00
|
|
|
if( Line[i] <= ' ' )
|
2009-09-01 10:26:43 +00:00
|
|
|
#endif
|
2007-12-17 20:18:04 +00:00
|
|
|
break;
|
2008-08-01 17:41:51 +00:00
|
|
|
component_reference.Append( Line[i] );
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Search component value */
|
|
|
|
while( Line[i] == ' ' )
|
|
|
|
i++;
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/** goto beginning of value */
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2008-08-01 17:41:51 +00:00
|
|
|
for( ; ; i++ )
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
2009-09-01 10:26:43 +00:00
|
|
|
#if defined(KICAD_GOST)
|
2009-10-05 05:04:28 +00:00
|
|
|
if( (Line[i] == ' ') || (Line[i] == '\n') || (Line[i] == '\r') )
|
2009-09-01 10:26:43 +00:00
|
|
|
#else
|
2007-12-17 20:18:04 +00:00
|
|
|
if( Line[i] <= ' ' )
|
2009-09-01 10:26:43 +00:00
|
|
|
#endif
|
2007-12-17 20:18:04 +00:00
|
|
|
break;
|
2008-08-01 17:41:51 +00:00
|
|
|
component_value.Append( Line[i] );
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Store info for this component */
|
2009-04-23 15:02:18 +00:00
|
|
|
Cmp = new COMPONENT();
|
2008-08-01 17:41:51 +00:00
|
|
|
Cmp->m_Reference = component_reference;
|
2009-05-06 11:55:36 +00:00
|
|
|
Cmp->m_Value = component_value;
|
2009-04-23 15:02:18 +00:00
|
|
|
m_components.push_back( Cmp );
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
if( m_isEESchemaNetlist ) /* copy footprint name: */
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
|
|
|
if( strnicmp( LibName, "$noname", 7 ) != 0 )
|
|
|
|
{
|
|
|
|
while( *LibName > ' ' )
|
|
|
|
{
|
|
|
|
Cmp->m_Module.Append( *LibName );
|
|
|
|
LibName++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-01 17:41:51 +00:00
|
|
|
Cmp->m_TimeStamp = schematic_timestamp;
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
ReadPinConnection( source, Cmp );
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( source );
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
m_components.sort();
|
2007-12-17 20:18:04 +00:00
|
|
|
|
|
|
|
return 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-12-17 20:18:04 +00:00
|
|
|
|
|
|
|
int WinEDA_CvpcbFrame::ReadFootprintFilterList( FILE* f )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
char Line[BUFFER_CHAR_SIZE + 1];
|
|
|
|
wxString CmpRef;
|
|
|
|
COMPONENT* Cmp = NULL;
|
2007-12-17 20:18:04 +00:00
|
|
|
|
|
|
|
for( ; ; )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fgets( Line, BUFFER_CHAR_SIZE, f ) == 0 )
|
2007-12-17 20:18:04 +00:00
|
|
|
break;
|
|
|
|
if( strnicmp( Line, "$endlist", 8 ) == 0 )
|
|
|
|
{
|
|
|
|
Cmp = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if( strnicmp( Line, "$endfootprintlist", 4 ) == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( strnicmp( Line, "$component", 10 ) == 0 ) // New component ref found
|
|
|
|
{
|
|
|
|
CmpRef = CONV_FROM_UTF8( Line + 11 );
|
2009-04-05 20:49:15 +00:00
|
|
|
CmpRef.Trim( TRUE );
|
|
|
|
CmpRef.Trim( FALSE );
|
2009-04-23 15:02:18 +00:00
|
|
|
|
2007-12-17 20:18:04 +00:00
|
|
|
/* Search the new component in list */
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, m_components )
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
Cmp = &component;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
2007-12-17 20:18:04 +00:00
|
|
|
if( Cmp->m_Reference == CmpRef )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( Cmp )
|
|
|
|
{
|
|
|
|
wxString fp = CONV_FROM_UTF8( Line + 1 );
|
2009-04-05 20:49:15 +00:00
|
|
|
fp.Trim( FALSE );
|
|
|
|
fp.Trim( TRUE );
|
2007-12-17 20:18:04 +00:00
|
|
|
Cmp->m_FootprintFilter.Add( fp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
int ReadPinConnection( FILE* f, COMPONENT* Cmp )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
int i, jj;
|
|
|
|
wxString numpin;
|
|
|
|
wxString net;
|
|
|
|
char Line[BUFFER_CHAR_SIZE + 1];
|
|
|
|
PIN* Pin = NULL;
|
2007-12-17 20:18:04 +00:00
|
|
|
|
|
|
|
for( ; ; )
|
|
|
|
{
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Find beginning of description. */
|
2007-12-17 20:18:04 +00:00
|
|
|
for( ; ; )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fgets( Line, BUFFER_CHAR_SIZE, f ) == 0 )
|
2007-12-17 20:18:04 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Remove blanks from the beginning of the line. */
|
2007-12-17 20:18:04 +00:00
|
|
|
i = 0; while( Line[i] == ' ' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
while( Line[i] == '(' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
while( Line[i] == ' ' )
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* remove empty lines : */
|
|
|
|
if( Line[i] < ' ' )
|
|
|
|
continue;
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* End of description? */
|
2007-12-17 20:18:04 +00:00
|
|
|
if( Line[i] == ')' )
|
|
|
|
return 0;
|
|
|
|
|
2008-08-01 17:41:51 +00:00
|
|
|
net.Empty();
|
|
|
|
numpin.Empty();
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Read pin name, 4 letters */
|
2007-12-17 20:18:04 +00:00
|
|
|
for( jj = 0; jj < 4; jj++, i++ )
|
|
|
|
{
|
|
|
|
if( Line[i] == ' ' )
|
|
|
|
break;
|
2008-08-01 17:41:51 +00:00
|
|
|
numpin.Append( Line[i] );
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read netname */
|
|
|
|
while( Line[i] == ' ' )
|
|
|
|
i++;
|
|
|
|
|
2008-08-01 17:41:51 +00:00
|
|
|
for( ; ; i++ )
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
|
|
|
if( Line[i] <= ' ' )
|
|
|
|
break;
|
2008-08-01 17:41:51 +00:00
|
|
|
net.Append( Line[i] );
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
Pin = new PIN();
|
2009-05-06 11:55:36 +00:00
|
|
|
Pin->m_Number = numpin;
|
|
|
|
Pin->m_Net = net;
|
2009-04-23 15:02:18 +00:00
|
|
|
Cmp->m_Pins.push_back( Pin );
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|