2009-02-04 15:25:03 +00:00
|
|
|
/***************************/
|
|
|
|
/* writenetlistpcbnew.cpp */
|
|
|
|
/***************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "fctsys.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"
|
|
|
|
#include "appl_wxstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvpcb.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
#define MAX_LEN_NETNAME 16
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
static void ChangePinNet( COMPONENT_LIST& list, wxString& PinNet,
|
|
|
|
int* netNumber, bool rightJustify );
|
2009-04-23 15:02:18 +00:00
|
|
|
static void WriteFootprintFilterInfos( FILE* dest, COMPONENT_LIST& list );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
static void RemoveDuplicatePins( COMPONENT& component )
|
2009-04-23 15:02:18 +00:00
|
|
|
{
|
|
|
|
PIN_LIST::iterator i;
|
|
|
|
PIN *pin1, *pin2;
|
|
|
|
wxString msg;
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
if( component.m_Pins.size() <= 1 )
|
2009-04-23 15:02:18 +00:00
|
|
|
return;
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
i = component.m_Pins.begin();
|
|
|
|
pin1 = &(*i);
|
2009-04-23 15:02:18 +00:00
|
|
|
++i;
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
while( i != component.m_Pins.end() )
|
2009-04-23 15:02:18 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
pin2 = &(*i);
|
2009-04-23 15:02:18 +00:00
|
|
|
|
|
|
|
wxASSERT( pin2 != NULL );
|
|
|
|
|
|
|
|
if( !same_pin_number( pin1, pin2 ) )
|
|
|
|
{
|
|
|
|
pin1 = pin2;
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !same_pin_net( pin1, pin2 ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Component %s %s pin %s : Different Nets" ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( component.m_Reference ),
|
|
|
|
GetChars( component.m_Value ),
|
2009-05-06 11:55:36 +00:00
|
|
|
pin1->m_Number.GetData() );
|
2009-04-23 15:02:18 +00:00
|
|
|
DisplayError( NULL, msg, 60 );
|
|
|
|
}
|
|
|
|
pin1 = pin2;
|
2009-05-06 11:55:36 +00:00
|
|
|
i = component.m_Pins.erase( i );
|
2009-04-23 15:02:18 +00:00
|
|
|
delete pin2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/**
|
|
|
|
* Create Kicad net list file.
|
|
|
|
*
|
|
|
|
* @todo: None of the printf() call return values are checked for failure,
|
|
|
|
* a value less than zero. Check all printf() return values and
|
|
|
|
* return a true(pass) or false(fail) to the caller.
|
|
|
|
*/
|
2009-04-23 15:02:18 +00:00
|
|
|
int GenNetlistPcbnew( FILE* file, COMPONENT_LIST& list, bool isEESchemaNetlist,
|
|
|
|
bool rightJustify )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
#define NETLIST_HEAD_STRING "EESchema Netlist Version 1.1"
|
2009-04-23 15:02:18 +00:00
|
|
|
char Line[1024];
|
|
|
|
int netNumber = 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
DateAndTime( Line );
|
|
|
|
|
|
|
|
if( isEESchemaNetlist )
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "# %s created %s\n(\n", NETLIST_HEAD_STRING, Line );
|
2009-02-04 15:25:03 +00:00
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "( { netlist created %s }\n", Line );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, list )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( file, " ( %s ", CONV_TO_UTF8( component.m_TimeStamp ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
if( !component.m_Module.IsEmpty() )
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( file, "%s", CONV_TO_UTF8( component.m_Module ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "$noname$" );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( file, " %s ", CONV_TO_UTF8( component.m_Reference ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( file, "%s\n", CONV_TO_UTF8( component.m_Value ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
component.m_Pins.sort();
|
|
|
|
RemoveDuplicatePins( component );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( PIN& pin, component.m_Pins )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
if( pin.m_Net.Len() > MAX_LEN_NETNAME )
|
|
|
|
ChangePinNet( list, pin.m_Net, &netNumber, rightJustify );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
if( !pin.m_Net.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, " ( %s %s )\n",
|
2009-05-06 11:55:36 +00:00
|
|
|
CONV_TO_UTF8( pin.m_Number ),
|
|
|
|
CONV_TO_UTF8( pin.m_Net ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
else
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( file, " ( %s ? )\n", CONV_TO_UTF8( pin.m_Number ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, " )\n" );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, ")\n*\n" );
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
if( isEESchemaNetlist )
|
|
|
|
WriteFootprintFilterInfos( file, list );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
fclose( file );
|
2009-02-04 15:25:03 +00:00
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
|
|
|
* Write the allowed footprint list for each component
|
|
|
|
*/
|
|
|
|
void WriteFootprintFilterInfos( FILE* file, COMPONENT_LIST& list )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
bool WriteHeader = FALSE;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, list )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
unsigned int FilterCount;
|
2009-05-06 11:55:36 +00:00
|
|
|
FilterCount = component.m_FootprintFilter.GetCount();
|
2009-02-04 15:25:03 +00:00
|
|
|
if( FilterCount == 0 )
|
|
|
|
continue;
|
|
|
|
if( !WriteHeader )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "{ Allowed footprints by component:\n" );
|
2009-02-04 15:25:03 +00:00
|
|
|
WriteHeader = TRUE;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "$component %s\n",
|
2009-05-06 11:55:36 +00:00
|
|
|
CONV_TO_UTF8( component.m_Reference ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
/* Write the footprint list */
|
|
|
|
for( unsigned int jj = 0; jj < FilterCount; jj++ )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, " %s\n",
|
2009-05-06 11:55:36 +00:00
|
|
|
CONV_TO_UTF8( component.m_FootprintFilter[jj] ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "$endlist\n" );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( WriteHeader )
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, "$endfootprintlist\n}\n" );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-11-23 20:18:47 +00:00
|
|
|
/* ???
|
2009-04-23 15:02:18 +00:00
|
|
|
* Change le NetName PinNet par un nom compose des 8 derniers codes de PinNet
|
|
|
|
* suivi de _Xnnnnn ou nnnnn est un nom de 0 a 99999
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2009-04-23 15:02:18 +00:00
|
|
|
static void ChangePinNet( COMPONENT_LIST& list, wxString& PinNet,
|
|
|
|
int* netNumber, bool rightJustify )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
wxASSERT( netNumber != NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
wxString OldName;
|
|
|
|
wxString NewName;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
OldName = PinNet;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
if( rightJustify ) /* Retain the last 8 letters of the name. */
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
NewName = OldName.Right( 8 );
|
2009-04-23 15:02:18 +00:00
|
|
|
NewName << *netNumber;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2009-11-05 19:26:52 +00:00
|
|
|
else /* Retain the first 8 letters of the name. */
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
NewName = OldName.Left( 8 );
|
2009-04-23 15:02:18 +00:00
|
|
|
NewName << *netNumber;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
*netNumber = *netNumber + 1;
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, list )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( PIN& pin, component.m_Pins )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
if( pin.m_Net != OldName )
|
2009-02-04 15:25:03 +00:00
|
|
|
continue;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
pin.m_Net = NewName;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|