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"
|
2011-02-21 18:27:47 +00:00
|
|
|
#include "cvpcb_mainframe.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2011-02-21 18:27:47 +00:00
|
|
|
int CVPCB_MAINFRAME::GenNetlistPcbnew( FILE* file,bool isEESchemaNetlist )
|
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];
|
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
|
|
|
|
|
|
|
|
2011-02-21 18:27:47 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, m_components )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( file, " ( %s ", 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() )
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( file, "%s", 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
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( file, " %s ", TO_UTF8( component.m_Reference ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( file, "%s\n", 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.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
fprintf( file, " ( %s %s )\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( pin.m_Number ),
|
|
|
|
TO_UTF8( pin.m_Net ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
else
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( file, " ( %s ? )\n", 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 )
|
2011-02-21 18:27:47 +00:00
|
|
|
WriteFootprintFilterInfos( file, m_components );
|
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",
|
2011-02-28 18:36:19 +00:00
|
|
|
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",
|
2011-02-28 18:36:19 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|