2009-11-04 20:46:53 +00:00
|
|
|
/*****************************/
|
|
|
|
/* Net list generation code. */
|
|
|
|
/*****************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "appl_wxstruct.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "netlist.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/**
|
|
|
|
* @bug - Every place in this file where fprintf() is used and the return
|
|
|
|
* is not checked is a bug. The fprintf() function can fail and
|
|
|
|
* returns a value less than 0 when it does.
|
|
|
|
*/
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
static void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame,
|
2009-11-04 20:46:53 +00:00
|
|
|
const wxString& FullFileName );
|
2007-09-21 13:23:51 +00:00
|
|
|
static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f,
|
|
|
|
bool with_pcbnew );
|
|
|
|
static void WriteNetListCADSTAR( WinEDA_SchematicFrame* frame, FILE* f );
|
2009-07-12 15:29:42 +00:00
|
|
|
static void WriteListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
|
2009-09-29 18:38:21 +00:00
|
|
|
static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f,
|
|
|
|
bool use_netnames );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
static void WriteGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
|
2009-12-02 21:44:03 +00:00
|
|
|
static void AddPinToComponentPinList( SCH_COMPONENT* Component,
|
|
|
|
SCH_SHEET_PATH* sheet,
|
|
|
|
LIB_PIN* PinEntry );
|
|
|
|
static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component,
|
|
|
|
LIB_COMPONENT* Entry,
|
|
|
|
SCH_SHEET_PATH* Sheet_in );
|
2009-07-12 15:29:42 +00:00
|
|
|
static bool SortPinsByNum( NETLIST_OBJECT* Pin1, NETLIST_OBJECT* Pin2 );
|
|
|
|
static void EraseDuplicatePins( NETLIST_OBJECT_LIST& aPinList );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
static void ClearUsedFlags( void );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
static NETLIST_OBJECT_LIST s_SortedComponentPinList;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
// list of references already found for multi part per packages components
|
2008-05-15 11:20:19 +00:00
|
|
|
// (used to avoid to used more than one time a component)
|
|
|
|
static wxArrayString s_ReferencesAlreadyFound;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2009-04-29 17:09:00 +00:00
|
|
|
/* Create the netlist file ( Format is given by frame->m_NetlistFormat )
|
2007-09-21 13:23:51 +00:00
|
|
|
* bool use_netnames is used only for Spice netlist
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void WriteNetList( WinEDA_SchematicFrame* frame, const wxString& FileNameNL,
|
|
|
|
bool use_netnames )
|
|
|
|
{
|
2009-07-05 12:09:41 +00:00
|
|
|
FILE* f = NULL;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-04-29 17:09:00 +00:00
|
|
|
if( frame->m_NetlistFormat < NET_TYPE_CUSTOM1 )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
if( ( f = wxFopen( FileNameNL, wxT( "wt" ) ) ) == NULL )
|
|
|
|
{
|
|
|
|
wxString msg = _( "Failed to create file " ) + FileNameNL;
|
|
|
|
DisplayError( frame, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxBusyCursor Busy;
|
|
|
|
|
2009-04-29 17:09:00 +00:00
|
|
|
switch( frame->m_NetlistFormat )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
case NET_TYPE_PCBNEW:
|
|
|
|
WriteNetListPCBNEW( frame, f, TRUE );
|
|
|
|
fclose( f );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_ORCADPCB2:
|
|
|
|
WriteNetListPCBNEW( frame, f, FALSE );
|
|
|
|
fclose( f );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_CADSTAR:
|
|
|
|
WriteNetListCADSTAR( frame, f );
|
|
|
|
fclose( f );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_SPICE:
|
|
|
|
WriteNetListPspice( frame, f, use_netnames );
|
|
|
|
fclose( f );
|
|
|
|
break;
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
default:
|
|
|
|
Write_GENERIC_NetList( frame, FileNameNL );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
2008-05-15 11:20:19 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/* Find a "suitable" component from the DrawList
|
2007-09-21 13:23:51 +00:00
|
|
|
* build its pin list s_SortedComponentPinList.
|
|
|
|
* The list is sorted by pin num
|
2009-09-29 18:38:21 +00:00
|
|
|
* A suitable component is a "new" real component (power symbols are not
|
|
|
|
* considered)
|
2007-09-21 13:23:51 +00:00
|
|
|
* Must be deallocated by the user
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static SCH_COMPONENT* FindNextComponentAndCreatPinList(
|
|
|
|
EDA_BaseStruct* DrawList,
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
SCH_COMPONENT* Component = NULL;
|
|
|
|
LIB_COMPONENT* Entry;
|
2009-11-04 20:46:53 +00:00
|
|
|
LIB_PIN* Pin;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
s_SortedComponentPinList.clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
for( ; DrawList != NULL; DrawList = DrawList->Next() )
|
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
if( DrawList->Type() != TYPE_SCH_COMPONENT )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2008-03-20 01:50:21 +00:00
|
|
|
Component = (SCH_COMPONENT*) DrawList;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Power symbol and other component which have the reference starting
|
|
|
|
* by "#" are not included in netlist (pseudo or virtual components) */
|
2008-05-15 11:20:19 +00:00
|
|
|
wxString str = Component->GetRef( sheet );
|
|
|
|
if( str[0] == '#' ) // ignore it
|
|
|
|
continue;
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
//if( Component->m_FlagControlMulti == 1 )
|
|
|
|
// continue; /* yes */
|
2008-03-20 01:50:21 +00:00
|
|
|
// removed because with multiple instances of one schematic
|
2009-09-29 18:38:21 +00:00
|
|
|
// (several sheets pointing to 1 screen), this will be erroneously be
|
|
|
|
// toggled.
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
Entry = CMP_LIBRARY::FindLibraryComponent( Component->m_ChipName );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
if( Entry == NULL )
|
|
|
|
continue;
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
// Multi parts per package: test if already visited:
|
2009-10-05 17:52:41 +00:00
|
|
|
if( Entry->GetPartCount() > 1 )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
|
|
|
bool found = false;
|
2009-11-04 20:46:53 +00:00
|
|
|
for( unsigned jj = 0;
|
|
|
|
jj < s_ReferencesAlreadyFound.GetCount();
|
|
|
|
jj++ )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
|
|
|
if( str == s_ReferencesAlreadyFound[jj] ) // Already visited
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( found )
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_ReferencesAlreadyFound.Add( str ); // Mark as visited
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
if( Entry->GetPartCount() <= 1 ) // One part per package
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-10-14 19:43:31 +00:00
|
|
|
LIB_PIN_LIST pins;
|
|
|
|
|
|
|
|
Entry->GetPins( pins, Component->GetUnitSelection( sheet ),
|
|
|
|
Component->m_Convert );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < pins.size(); i++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-10-14 19:43:31 +00:00
|
|
|
Pin = pins[i];
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
wxASSERT( Pin->Type() == COMPONENT_PIN_DRAW_TYPE );
|
2009-09-29 18:38:21 +00:00
|
|
|
|
|
|
|
AddPinToComponentPinList( Component, sheet, Pin );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
else // Multiple parts per package: Collect all parts ans pins for
|
|
|
|
// this reference
|
2008-05-15 11:20:19 +00:00
|
|
|
FindAllsInstancesOfComponent( Component, Entry, sheet );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
/* Sort Pins in s_SortedComponentPinList by pin number */
|
2009-09-29 18:38:21 +00:00
|
|
|
sort( s_SortedComponentPinList.begin(),
|
|
|
|
s_SortedComponentPinList.end(), SortPinsByNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
/* Remove duplicate Pins in s_SortedComponentPinList */
|
2009-07-12 15:29:42 +00:00
|
|
|
EraseDuplicatePins( s_SortedComponentPinList );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
return Component;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Return the net name for the pin Pin.
|
2007-09-21 13:23:51 +00:00
|
|
|
* Net name is:
|
|
|
|
* "?" if pin not connected
|
|
|
|
* "netname" for global net (like gnd, vcc ..
|
|
|
|
* "netname_sheetnumber" for the usual nets
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static wxString ReturnPinNetName( NETLIST_OBJECT* Pin,
|
|
|
|
const wxString& DefaultFormatNetname )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
int netcode = Pin->GetNet();
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString NetName;
|
|
|
|
|
2008-01-05 17:30:56 +00:00
|
|
|
if( (netcode == 0 ) || ( Pin->m_FlagOfConnection != PAD_CONNECT ) )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
return NetName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
unsigned jj;
|
|
|
|
for( jj = 0; jj < g_NetObjectslist.size(); jj++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
if( g_NetObjectslist[jj]->GetNet() != netcode )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-07-12 15:29:42 +00:00
|
|
|
if( ( g_NetObjectslist[jj]->m_Type != NET_HIERLABEL)
|
|
|
|
&& ( g_NetObjectslist[jj]->m_Type != NET_LABEL)
|
|
|
|
&& ( g_NetObjectslist[jj]->m_Type != NET_PINLABEL) )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
NetName = *g_NetObjectslist[jj]->m_Label;
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !NetName.IsEmpty() )
|
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
if( g_NetObjectslist[jj]->m_Type != NET_PINLABEL )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
wxString lnet = NetName;
|
2009-07-12 15:29:42 +00:00
|
|
|
NetName = g_NetObjectslist[jj]->m_SheetList.PathHumanReadable();
|
2009-07-05 12:09:41 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// If sheet path is too long, use the time stamp name instead
|
2009-07-05 12:09:41 +00:00
|
|
|
if( NetName.Length() > 32 )
|
2009-07-12 15:29:42 +00:00
|
|
|
NetName = g_NetObjectslist[jj]->m_SheetList.Path();
|
2008-07-31 15:30:57 +00:00
|
|
|
NetName += lnet;
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NetName.Printf( DefaultFormatNetname.GetData(), netcode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NetName;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Create a generic netlist, and call an external netlister
|
2007-09-21 13:23:51 +00:00
|
|
|
* to change the netlist syntax and create the file
|
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame,
|
|
|
|
const wxString& FullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
wxString Line, FootprintName;
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet;
|
2008-05-15 11:20:19 +00:00
|
|
|
EDA_BaseStruct* SchItem;
|
|
|
|
SCH_COMPONENT* Component;
|
|
|
|
wxString netname;
|
|
|
|
FILE* tmpfile;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn = FullFileName;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( wxT( "tmp" ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( tmpfile = wxFopen( fn.GetFullPath(), wxT( "wt" ) ) ) == NULL )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString msg = _( "Failed to create file " ) + fn.GetFullPath();
|
2007-09-21 13:23:51 +00:00
|
|
|
DisplayError( frame, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
ClearUsedFlags(); /* Reset the flags FlagControlMulti in all schematic
|
|
|
|
* files*/
|
2007-09-21 13:23:51 +00:00
|
|
|
fprintf( tmpfile, "$BeginNetlist\n" );
|
|
|
|
|
|
|
|
/* Create netlist module section */
|
|
|
|
fprintf( tmpfile, "$BeginComponentList\n" );
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
for( SchItem = sheet->LastDrawList();
|
|
|
|
SchItem != NULL;
|
|
|
|
SchItem = SchItem->Next() )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SchItem = Component = FindNextComponentAndCreatPinList( SchItem,
|
|
|
|
sheet );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
if( Component == NULL )
|
2009-11-04 20:46:53 +00:00
|
|
|
break; // No component left
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
FootprintName.Empty();
|
2008-10-06 05:44:29 +00:00
|
|
|
if( !Component->GetField( FOOTPRINT )->IsVoid() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
FootprintName = Component->GetField( FOOTPRINT )->m_Text;
|
2007-09-21 13:23:51 +00:00
|
|
|
FootprintName.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( tmpfile, "\n$BeginComponent\n" );
|
|
|
|
fprintf( tmpfile, "TimeStamp=%8.8lX\n", Component->m_TimeStamp );
|
|
|
|
fprintf( tmpfile, "Footprint=%s\n", CONV_TO_UTF8( FootprintName ) );
|
2009-11-04 20:46:53 +00:00
|
|
|
Line = wxT( "Reference=" ) + Component->GetRef( sheet ) + wxT(
|
|
|
|
"\n" );
|
2007-09-21 13:23:51 +00:00
|
|
|
Line.Replace( wxT( " " ), wxT( "_" ) );
|
2009-05-05 17:32:07 +00:00
|
|
|
fputs( CONV_TO_UTF8( Line ), tmpfile );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
Line = Component->GetField( VALUE )->m_Text;
|
2007-09-21 13:23:51 +00:00
|
|
|
Line.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
fprintf( tmpfile, "Value=%s\n", CONV_TO_UTF8( Line ) );
|
|
|
|
|
|
|
|
Line = Component->m_ChipName;
|
|
|
|
Line.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
fprintf( tmpfile, "Libref=%s\n", CONV_TO_UTF8( Line ) );
|
|
|
|
|
|
|
|
// Write pin list:
|
|
|
|
fprintf( tmpfile, "$BeginPinList\n" );
|
2009-07-12 15:29:42 +00:00
|
|
|
for( unsigned ii = 0; ii < s_SortedComponentPinList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
NETLIST_OBJECT* Pin = s_SortedComponentPinList[ii];
|
2007-09-21 13:23:51 +00:00
|
|
|
if( !Pin )
|
|
|
|
continue;
|
|
|
|
netname = ReturnPinNetName( Pin, wxT( "$-%.6d" ) );
|
|
|
|
if( netname.IsEmpty() )
|
|
|
|
netname = wxT( "?" );
|
|
|
|
fprintf( tmpfile, "%.4s=%s\n", (char*) &Pin->m_PinNum,
|
|
|
|
CONV_TO_UTF8( netname ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( tmpfile, "$EndPinList\n" );
|
|
|
|
fprintf( tmpfile, "$EndComponent\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( tmpfile, "$EndComponentList\n" );
|
|
|
|
|
|
|
|
fprintf( tmpfile, "\n$BeginNets\n" );
|
2009-07-12 15:29:42 +00:00
|
|
|
WriteGENERICListOfNets( tmpfile, g_NetObjectslist );
|
2007-09-21 13:23:51 +00:00
|
|
|
fprintf( tmpfile, "$EndNets\n" );
|
|
|
|
fprintf( tmpfile, "\n$EndNetlist\n" );
|
|
|
|
fclose( tmpfile );
|
|
|
|
|
|
|
|
// Call the external module (plug in )
|
|
|
|
|
|
|
|
if( g_NetListerCommandLine.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString CommandFile;
|
|
|
|
if( wxIsAbsolutePath( g_NetListerCommandLine ) )
|
|
|
|
CommandFile = g_NetListerCommandLine;
|
|
|
|
else
|
|
|
|
CommandFile = FindKicadFile( g_NetListerCommandLine );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
CommandFile += wxT( " " ) + fn.GetFullPath();
|
2007-09-21 13:23:51 +00:00
|
|
|
CommandFile += wxT( " " ) + FullFileName;
|
|
|
|
|
2008-04-24 16:55:35 +00:00
|
|
|
ProcessExecute( CommandFile, wxEXEC_SYNC );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-12 18:39:20 +00:00
|
|
|
/* Clear flag list, used in netlist generation */
|
2009-11-04 20:46:53 +00:00
|
|
|
static void ClearUsedFlags( void )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
s_ReferencesAlreadyFound.Clear();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Routine generation of the netlist file (Format PSPICE)
|
|
|
|
* = TRUE if use_netnames
|
|
|
|
* Nodes are identified by the netname
|
|
|
|
* If the nodes are identified by the netnumber
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2009-11-04 20:46:53 +00:00
|
|
|
* All graphics text commentary by a [.-+] PSpice or [.-+] gnucap
|
|
|
|
* Are considered in placing orders in the netlist
|
|
|
|
* [.-] Or PSpice gnucap are beginning
|
|
|
|
* + + Gnucap and PSpice are ultimately NetList
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f,
|
|
|
|
bool use_netnames )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
char Line[1024];
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet;
|
2008-05-15 11:20:19 +00:00
|
|
|
EDA_BaseStruct* DrawList;
|
|
|
|
SCH_COMPONENT* Component;
|
2009-07-12 15:29:42 +00:00
|
|
|
int nbitems;
|
2008-05-15 11:20:19 +00:00
|
|
|
wxString text;
|
|
|
|
wxArrayString SpiceCommandAtBeginFile, SpiceCommandAtEndFile;
|
|
|
|
wxString msg;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#define BUFYPOS_LEN 4
|
2008-05-15 11:20:19 +00:00
|
|
|
wxChar bufnum[BUFYPOS_LEN + 1];
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
DateAndTime( Line );
|
2009-11-04 20:46:53 +00:00
|
|
|
fprintf( f,
|
|
|
|
"* %s (Spice format) creation date: %s\n\n",
|
|
|
|
NETLIST_HEAD_STRING,
|
|
|
|
Line );
|
|
|
|
|
|
|
|
/* Create text list starting by [.-]pspice , or [.-]gnucap (simulator
|
|
|
|
* commands) and create text list starting by [+]pspice , or [+]gnucap
|
|
|
|
* (simulator commands) */
|
2007-09-21 13:23:51 +00:00
|
|
|
bufnum[BUFYPOS_LEN] = 0;
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
for( DrawList = sheet->LastDrawList();
|
|
|
|
DrawList != NULL;
|
|
|
|
DrawList = DrawList->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
wxChar ident;
|
2008-03-20 01:50:21 +00:00
|
|
|
if( DrawList->Type() != TYPE_SCH_TEXT )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2008-03-20 01:50:21 +00:00
|
|
|
#define DRAWTEXT ( (SCH_TEXT*) DrawList )
|
2008-05-15 11:20:19 +00:00
|
|
|
text = DRAWTEXT->m_Text; if( text.IsEmpty() )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
ident = text.GetChar( 0 );
|
|
|
|
if( ident != '.' && ident != '-' && ident != '+' )
|
|
|
|
continue;
|
2009-11-04 20:46:53 +00:00
|
|
|
text.Remove( 0, 1 ); // Remove the first char.
|
|
|
|
text.Remove( 6 ); // text contains 6 char.
|
2008-06-18 09:18:51 +00:00
|
|
|
text.MakeLower();
|
2007-09-21 13:23:51 +00:00
|
|
|
if( ( text == wxT( "pspice" ) ) || ( text == wxT( "gnucap" ) ) )
|
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Put the Y position as an ascii string, for sort by vertical
|
|
|
|
* position, using usual sort string by alphabetic value */
|
2007-09-21 13:23:51 +00:00
|
|
|
int ypos = DRAWTEXT->m_Pos.y;
|
2009-07-12 15:29:42 +00:00
|
|
|
for( int ii = 0; ii < BUFYPOS_LEN; ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
bufnum[BUFYPOS_LEN - 1 -
|
|
|
|
ii] = (ypos & 63) + ' '; ypos >>= 6;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
text = DRAWTEXT->m_Text.AfterFirst( ' ' );
|
2009-11-04 20:46:53 +00:00
|
|
|
// First BUFYPOS_LEN char are the Y position.
|
|
|
|
msg.Printf( wxT( "%s %s" ), bufnum, text.GetData() );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( ident == '+' )
|
|
|
|
SpiceCommandAtEndFile.Add( msg );
|
|
|
|
else
|
|
|
|
SpiceCommandAtBeginFile.Add( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Print texts starting by [.-]pspice , ou [.-]gnucap (of course, without
|
|
|
|
* the Y position string)*/
|
2007-09-21 13:23:51 +00:00
|
|
|
nbitems = SpiceCommandAtBeginFile.GetCount();
|
|
|
|
if( nbitems )
|
|
|
|
{
|
|
|
|
SpiceCommandAtBeginFile.Sort();
|
2009-07-12 15:29:42 +00:00
|
|
|
for( int ii = 0; ii < nbitems; ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
SpiceCommandAtBeginFile[ii].Remove( 0, BUFYPOS_LEN );
|
|
|
|
SpiceCommandAtBeginFile[ii].Trim( TRUE );
|
|
|
|
SpiceCommandAtBeginFile[ii].Trim( FALSE );
|
|
|
|
fprintf( f, "%s\n", CONV_TO_UTF8( SpiceCommandAtBeginFile[ii] ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
|
|
|
|
|
|
|
|
/* Create component list */
|
2009-11-04 20:46:53 +00:00
|
|
|
ClearUsedFlags(); /* Reset the flags FlagControlMulti in all schematic
|
|
|
|
* files*/
|
|
|
|
for( sheet = SheetList.GetFirst();
|
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
for( DrawList = sheet->LastDrawList();
|
|
|
|
DrawList != NULL;
|
|
|
|
DrawList = DrawList->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
DrawList = Component = FindNextComponentAndCreatPinList( DrawList,
|
|
|
|
sheet );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( Component == NULL )
|
|
|
|
break;
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
fprintf( f, "%s ", CONV_TO_UTF8( Component->GetRef( sheet ) ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
// Write pin list:
|
2009-07-12 15:29:42 +00:00
|
|
|
for( unsigned ii = 0; ii < s_SortedComponentPinList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
NETLIST_OBJECT* Pin = s_SortedComponentPinList[ii];
|
2007-09-21 13:23:51 +00:00
|
|
|
if( !Pin )
|
|
|
|
continue;
|
2009-11-04 20:46:53 +00:00
|
|
|
wxString NetName = ReturnPinNetName( Pin, wxT( "N-%.6d" ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( NetName.IsEmpty() )
|
|
|
|
NetName = wxT( "?" );
|
|
|
|
if( use_netnames )
|
|
|
|
fprintf( f, " %s", CONV_TO_UTF8( NetName ) );
|
2009-11-04 20:46:53 +00:00
|
|
|
else // Use number for net names (with net number = 0 for
|
|
|
|
// "GND"
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
// NetName = "0" is "GND" net for Spice
|
|
|
|
if( NetName == wxT( "0" ) || NetName == wxT( "GND" ) )
|
|
|
|
fprintf( f, " 0" );
|
|
|
|
else
|
2007-10-13 06:18:44 +00:00
|
|
|
fprintf( f, " %d", Pin->GetNet() );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
fprintf( f, " %s\n",
|
|
|
|
CONV_TO_UTF8( Component->GetField( VALUE )->m_Text ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
s_SortedComponentPinList.clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
/* Print texts starting by [+]pspice , ou [+]gnucap */
|
|
|
|
nbitems = SpiceCommandAtEndFile.GetCount();
|
|
|
|
if( nbitems )
|
|
|
|
{
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
SpiceCommandAtEndFile.Sort();
|
2009-07-12 15:29:42 +00:00
|
|
|
for( int ii = 0; ii < nbitems; ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
SpiceCommandAtEndFile[ii].Remove( 0, +BUFYPOS_LEN );
|
|
|
|
SpiceCommandAtEndFile[ii].Trim( TRUE );
|
|
|
|
SpiceCommandAtEndFile[ii].Trim( FALSE );
|
|
|
|
fprintf( f, "%s\n", CONV_TO_UTF8( SpiceCommandAtEndFile[ii] ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( f, "\n.end\n" );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Generate net list file (Format 2 improves ORCAD PCB)
|
|
|
|
* = TRUE if with_pcbnew
|
|
|
|
* Format Pcbnew (OrcadPcb2 + reviews and lists of net)
|
|
|
|
* = FALSE if with_pcbnew
|
|
|
|
* Format ORCADPCB2 strict
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame,
|
|
|
|
FILE* f,
|
|
|
|
bool with_pcbnew )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString Line, FootprintName;
|
|
|
|
char Buf[256];
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet;
|
2007-09-21 13:23:51 +00:00
|
|
|
EDA_BaseStruct* DrawList;
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_COMPONENT* Component;
|
2008-12-10 16:49:53 +00:00
|
|
|
OBJ_CMP_TO_LIST* CmpList = NULL;
|
2007-09-21 13:23:51 +00:00
|
|
|
int CmpListCount = 0, CmpListSize = 1000;
|
|
|
|
|
|
|
|
DateAndTime( Buf );
|
|
|
|
if( with_pcbnew )
|
|
|
|
fprintf( f, "# %s created %s\n(\n", NETLIST_HEAD_STRING, Buf );
|
|
|
|
else
|
|
|
|
fprintf( f, "( { %s created %s }\n", NETLIST_HEAD_STRING, Buf );
|
|
|
|
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
/* Create netlist module section */
|
2009-11-04 20:46:53 +00:00
|
|
|
ClearUsedFlags(); /* Reset the flags FlagControlMulti in all schematic
|
2009-12-02 21:44:03 +00:00
|
|
|
* files*/
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
for( DrawList = sheet->LastDrawList();
|
|
|
|
DrawList != NULL;
|
|
|
|
DrawList = DrawList->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
DrawList = Component = FindNextComponentAndCreatPinList( DrawList,
|
|
|
|
sheet );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( Component == NULL )
|
|
|
|
break;
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Get the Component FootprintFilter and put the component in
|
2009-12-02 21:44:03 +00:00
|
|
|
* CmpList if filter is not void */
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* Entry =
|
|
|
|
CMP_LIBRARY::FindLibraryComponent( Component->m_ChipName );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
if( Entry != NULL )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
if( Entry->m_FootprintList.GetCount() != 0 ) /* Put in list */
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
if( CmpList == NULL )
|
|
|
|
{
|
2008-12-10 16:49:53 +00:00
|
|
|
CmpList = (OBJ_CMP_TO_LIST*)
|
2009-11-04 20:46:53 +00:00
|
|
|
MyZMalloc( sizeof(OBJ_CMP_TO_LIST) *
|
|
|
|
CmpListSize );
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
if( CmpListCount >= CmpListSize )
|
|
|
|
{
|
|
|
|
CmpListSize += 1000;
|
2009-11-04 20:46:53 +00:00
|
|
|
CmpList =
|
|
|
|
(OBJ_CMP_TO_LIST*) realloc( CmpList,
|
|
|
|
sizeof(OBJ_CMP_TO_LIST)
|
|
|
|
* CmpListSize );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2008-12-10 16:49:53 +00:00
|
|
|
CmpList[CmpListCount].m_RootCmp = Component;
|
2009-11-04 20:46:53 +00:00
|
|
|
strcpy( CmpList[CmpListCount].m_Reference,
|
|
|
|
Component->GetRef( sheet ).mb_str() );
|
2007-09-21 13:23:51 +00:00
|
|
|
CmpListCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
if( !Component->GetField( FOOTPRINT )->IsVoid() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
FootprintName = Component->GetField( FOOTPRINT )->m_Text;
|
2007-09-21 13:23:51 +00:00
|
|
|
FootprintName.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FootprintName = wxT( "$noname" );
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
Line = Component->GetRef( sheet );
|
2008-02-12 21:12:46 +00:00
|
|
|
fprintf( f, " ( %s %s",
|
2009-11-04 20:46:53 +00:00
|
|
|
CONV_TO_UTF8( Component->GetPath( sheet ) ),
|
|
|
|
CONV_TO_UTF8( FootprintName ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
fprintf( f, " %s", CONV_TO_UTF8( Line ) );
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
Line = Component->GetField( VALUE )->m_Text;
|
2007-09-21 13:23:51 +00:00
|
|
|
Line.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
fprintf( f, " %s", CONV_TO_UTF8( Line ) );
|
|
|
|
|
|
|
|
if( with_pcbnew ) // Add the lib name for this component
|
|
|
|
{
|
|
|
|
Line = Component->m_ChipName;
|
|
|
|
Line.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
fprintf( f, " {Lib=%s}", CONV_TO_UTF8( Line ) );
|
|
|
|
}
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
|
|
|
|
// Write pin list:
|
2009-07-12 15:29:42 +00:00
|
|
|
for( unsigned ii = 0; ii < s_SortedComponentPinList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
NETLIST_OBJECT* Pin = s_SortedComponentPinList[ii];
|
2007-09-21 13:23:51 +00:00
|
|
|
if( !Pin )
|
|
|
|
continue;
|
|
|
|
wxString netname = ReturnPinNetName( Pin, wxT( "N-%.6d" ) );
|
|
|
|
if( netname.IsEmpty() )
|
2008-07-31 15:30:57 +00:00
|
|
|
netname = wxT( "?" );
|
|
|
|
netname.Replace( wxT( " " ), wxT( "_" ) );
|
2009-07-12 15:29:42 +00:00
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
fprintf( f, " ( %4.4s %s )\n", (char*) &Pin->m_PinNum,
|
2009-11-04 20:46:53 +00:00
|
|
|
CONV_TO_UTF8( netname ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( f, " )\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( f, ")\n*\n" );
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
s_SortedComponentPinList.clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
/* Write the allowed footprint list for each component */
|
|
|
|
if( with_pcbnew && CmpList )
|
|
|
|
{
|
|
|
|
fprintf( f, "{ Allowed footprints by component:\n" );
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* Entry;
|
2009-07-12 15:29:42 +00:00
|
|
|
for( int ii = 0; ii < CmpListCount; ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2008-12-10 16:49:53 +00:00
|
|
|
Component = CmpList[ii].m_RootCmp;
|
2009-09-18 14:56:05 +00:00
|
|
|
Entry = CMP_LIBRARY::FindLibraryComponent( Component->m_ChipName );
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
//Line.Printf(_("%s"), CmpList[ii].m_Ref);
|
2008-02-12 21:12:46 +00:00
|
|
|
//Line.Replace( wxT( " " ), wxT( "_" ) );
|
2009-11-04 20:46:53 +00:00
|
|
|
for( unsigned nn = 0;
|
|
|
|
nn<sizeof(CmpList[ii].m_Reference)
|
|
|
|
&& CmpList[ii].m_Reference[nn];
|
|
|
|
nn++ )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
if( CmpList[ii].m_Reference[nn] == ' ' )
|
|
|
|
CmpList[ii].m_Reference[nn] = '_';
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
fprintf( f, "$component %s\n", CmpList[ii].m_Reference );
|
2007-09-21 13:23:51 +00:00
|
|
|
/* Write the footprint list */
|
2009-07-12 15:29:42 +00:00
|
|
|
for( unsigned jj = 0; jj < Entry->m_FootprintList.GetCount(); jj++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
fprintf( f, " %s\n",
|
|
|
|
CONV_TO_UTF8( Entry->m_FootprintList[jj] ) );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( f, "$endlist\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( f, "$endfootprintlist\n}\n" );
|
|
|
|
}
|
|
|
|
if( CmpList )
|
|
|
|
free( CmpList );
|
|
|
|
|
|
|
|
if( with_pcbnew )
|
|
|
|
{
|
|
|
|
fprintf( f, "{ Pin List by Nets\n" );
|
2009-07-12 15:29:42 +00:00
|
|
|
WriteGENERICListOfNets( f, g_NetObjectslist );
|
2007-09-21 13:23:51 +00:00
|
|
|
fprintf( f, "}\n" );
|
|
|
|
fprintf( f, "#End\n" );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/*
|
|
|
|
* Add a new pin description in the pin list s_SortedComponentPinList
|
|
|
|
* a pin description is a pointer to the corresponding structure
|
|
|
|
* created by BuildNetList() in the table g_NetObjectslist
|
|
|
|
*/
|
2008-03-20 01:50:21 +00:00
|
|
|
static void AddPinToComponentPinList( SCH_COMPONENT* Component,
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheetlist, LIB_PIN* Pin )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
/* Search the PIN description for Pin in g_NetObjectslist*/
|
|
|
|
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
if( g_NetObjectslist[ii]->m_Type != NET_PIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-07-12 15:29:42 +00:00
|
|
|
if( g_NetObjectslist[ii]->m_Link != Component )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-07-12 15:29:42 +00:00
|
|
|
if( g_NetObjectslist[ii]->m_SheetList != *sheetlist )
|
2008-03-20 01:50:21 +00:00
|
|
|
continue;
|
2009-07-12 15:29:42 +00:00
|
|
|
if( g_NetObjectslist[ii]->m_PinNum != Pin->m_PinNum )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-07-12 15:29:42 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
s_SortedComponentPinList.push_back( g_NetObjectslist[ii] );
|
2009-07-12 15:29:42 +00:00
|
|
|
if( s_SortedComponentPinList.size() >= MAXPIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
/* Log message for Internal error */
|
2009-11-04 20:46:53 +00:00
|
|
|
DisplayError( NULL,
|
|
|
|
wxT( "AddPinToComponentPinList err: MAXPIN reached" ) );
|
2009-07-12 15:29:42 +00:00
|
|
|
return;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-21 07:25:31 +00:00
|
|
|
/** Function EraseDuplicatePins
|
2008-05-15 11:20:19 +00:00
|
|
|
* Function to remove duplicate Pins in the TabPin pin list
|
2009-11-04 20:46:53 +00:00
|
|
|
* (This is a list of pins found in the whole schematic, for a given
|
|
|
|
* component)
|
2008-05-15 11:20:19 +00:00
|
|
|
* These duplicate pins were put in list because some pins (powers... )
|
2009-11-04 20:46:53 +00:00
|
|
|
* are found more than one time when we have a multiple parts per package
|
|
|
|
* component
|
|
|
|
* for instance, a 74ls00 has 4 parts, and therefore the VCC pin and GND pin
|
|
|
|
* appears 4 times
|
2008-05-15 11:20:19 +00:00
|
|
|
* in the list.
|
2009-11-04 20:46:53 +00:00
|
|
|
* @param aPinList = a NETLIST_OBJECT_LIST that contains the list of pins for a
|
|
|
|
* given component.
|
2009-07-21 07:25:31 +00:00
|
|
|
* Note: this list *MUST* be sorted by pin number (.m_PinNum member value)
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static void EraseDuplicatePins( NETLIST_OBJECT_LIST& aPinList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
if( aPinList.size() == 0 ) // Trivial case: component with no pin
|
2009-07-21 07:25:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aPinList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-21 07:25:31 +00:00
|
|
|
if( aPinList[ii] == NULL ) /* already deleted */
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-07-21 07:25:31 +00:00
|
|
|
/* Search for duplicated pins
|
2009-11-04 20:46:53 +00:00
|
|
|
* If found, remove duplicates. The priority is to keep connected pins
|
|
|
|
* and remove unconnected
|
2009-07-21 07:25:31 +00:00
|
|
|
* - So this allows (for instance when using multi op amps per package
|
|
|
|
* - to connect only one op amp to power
|
2009-11-04 20:46:53 +00:00
|
|
|
* Because the pin list is sorted by m_PinNum value, duplicated pins
|
|
|
|
* are necessary successive in list
|
|
|
|
*/
|
2009-07-05 12:09:41 +00:00
|
|
|
int idxref = ii;
|
2009-07-12 15:29:42 +00:00
|
|
|
for( unsigned jj = ii + 1; jj < aPinList.size(); jj++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
if( aPinList[jj] == NULL ) // Already removed
|
2009-07-20 17:00:55 +00:00
|
|
|
continue;
|
2009-11-04 20:46:53 +00:00
|
|
|
// other pin num end of duplicate list.
|
|
|
|
if( aPinList[idxref]->m_PinNum != aPinList[jj]->m_PinNum )
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
2009-11-04 20:46:53 +00:00
|
|
|
if( aPinList[idxref]->m_FlagOfConnection == PAD_CONNECT )
|
2009-07-12 15:29:42 +00:00
|
|
|
aPinList[jj] = NULL;
|
2009-11-04 20:46:53 +00:00
|
|
|
else /* the reference pin is not connected: remove this pin if the
|
|
|
|
* other pin is connected */
|
|
|
|
{
|
|
|
|
if( aPinList[jj]->m_FlagOfConnection == PAD_CONNECT )
|
2009-07-05 12:09:41 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
aPinList[idxref] = NULL;
|
2009-07-05 12:09:41 +00:00
|
|
|
idxref = jj;
|
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
else // the 2 pins are not connected: remove the tested pin,
|
|
|
|
// and continue ...
|
2009-07-12 15:29:42 +00:00
|
|
|
aPinList[jj] = NULL;
|
2009-07-05 12:09:41 +00:00
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
/**
|
2009-09-29 18:38:21 +00:00
|
|
|
* Used for multiple parts per package components.
|
|
|
|
*
|
2008-05-15 11:20:19 +00:00
|
|
|
* Search all instances of Component_in,
|
2009-09-29 18:38:21 +00:00
|
|
|
* Calls AddPinToComponentPinList() to and pins founds to the current
|
|
|
|
* component pin list
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component_in,
|
|
|
|
LIB_COMPONENT* Entry,
|
|
|
|
SCH_SHEET_PATH* Sheet_in )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
EDA_BaseStruct* SchItem;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* Component2;
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_PIN* pin;
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet;
|
2008-05-15 11:20:19 +00:00
|
|
|
wxString str, Reference = Component_in->GetRef( Sheet_in );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
for( sheet = SheetList.GetFirst(); sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-09-29 18:38:21 +00:00
|
|
|
for( SchItem = sheet->LastDrawList(); SchItem;
|
|
|
|
SchItem = SchItem->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
if( SchItem->Type() != TYPE_SCH_COMPONENT )
|
|
|
|
continue;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
Component2 = (SCH_COMPONENT*) SchItem;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
str = Component2->GetRef( sheet );
|
|
|
|
if( str.CmpNoCase( Reference ) != 0 )
|
|
|
|
continue;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
if( Entry == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( pin = Entry->GetNextPin(); pin != NULL;
|
|
|
|
pin = Entry->GetNextPin( pin ) )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
wxASSERT( pin->Type() == COMPONENT_PIN_DRAW_TYPE );
|
2009-09-29 18:38:21 +00:00
|
|
|
|
|
|
|
if( pin->m_Unit
|
2009-11-04 20:46:53 +00:00
|
|
|
&& ( pin->m_Unit != Component2->GetUnitSelection( sheet ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pin->m_Convert
|
2009-11-04 20:46:53 +00:00
|
|
|
&& ( pin->m_Convert != Component2->m_Convert ) )
|
|
|
|
continue;
|
2009-07-05 12:09:41 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
// A suitable pin in found: add it to the current list
|
|
|
|
AddPinToComponentPinList( Component2, sheet, pin );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Comparison routine for sorting by pin numbers.
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2009-09-29 18:38:21 +00:00
|
|
|
static bool SortPinsByNum( NETLIST_OBJECT* Pin1, NETLIST_OBJECT* Pin2 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-21 13:23:51 +00:00
|
|
|
int Num1, Num2;
|
|
|
|
char Line[5];
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
Num1 = Pin1->m_PinNum;
|
|
|
|
Num2 = Pin2->m_PinNum;
|
2009-07-12 15:29:42 +00:00
|
|
|
Line[4] = 0;
|
|
|
|
memcpy( Line, &Num1, 4 ); Num1 = atoi( Line );
|
2007-09-21 13:23:51 +00:00
|
|
|
memcpy( Line, &Num2, 4 ); Num2 = atoi( Line );
|
2009-07-12 15:29:42 +00:00
|
|
|
return Num1 < Num2;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Written in the file / net list (ranked by Netcode), and elements that are
|
|
|
|
* connected
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static void WriteGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-21 13:23:51 +00:00
|
|
|
int NetCode, LastNetCode = -1;
|
|
|
|
int SameNetcodeCount = 0;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* Cmp;
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString NetName, CmpRef;
|
|
|
|
wxString NetcodeName;
|
|
|
|
char FirstItemInNet[1024];
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
for( unsigned ii = 0; ii < aObjectsList.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
// New net found, write net id;
|
|
|
|
if( ( NetCode = aObjectsList[ii]->GetNet() ) != LastNetCode )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SameNetcodeCount = 0; // Items count for this net
|
2007-09-21 13:23:51 +00:00
|
|
|
NetName.Empty();
|
2009-07-12 15:29:42 +00:00
|
|
|
unsigned jj;
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
// Find a label (if exists) for this net.
|
|
|
|
for( jj = 0; jj < aObjectsList.size(); jj++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[jj]->GetNet() != NetCode )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-07-12 15:29:42 +00:00
|
|
|
if( ( aObjectsList[jj]->m_Type != NET_HIERLABEL)
|
|
|
|
&& ( aObjectsList[jj]->m_Type != NET_LABEL)
|
|
|
|
&& ( aObjectsList[jj]->m_Type != NET_PINLABEL) )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
NetName = *aObjectsList[jj]->m_Label;
|
2009-07-05 12:09:41 +00:00
|
|
|
break;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NetcodeName.Printf( wxT( "Net %d " ), NetCode );
|
|
|
|
NetcodeName += wxT( "\"" );
|
|
|
|
if( !NetName.IsEmpty() )
|
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[jj]->m_Type != NET_PINLABEL )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2008-10-25 10:21:46 +00:00
|
|
|
// usual net name, prefix it by the sheet path
|
2009-11-04 20:46:53 +00:00
|
|
|
NetcodeName +=
|
|
|
|
aObjectsList[jj]->m_SheetList.PathHumanReadable();
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2008-10-25 10:21:46 +00:00
|
|
|
NetcodeName += NetName;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
NetcodeName += wxT( "\"" );
|
2009-07-05 12:09:41 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// Add the netname without prefix, in cases we need only the
|
|
|
|
// "short" netname
|
2008-10-25 10:21:46 +00:00
|
|
|
NetcodeName += wxT( " \"" ) + NetName + wxT( "\"" );
|
2007-09-21 13:23:51 +00:00
|
|
|
LastNetCode = NetCode;
|
|
|
|
}
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[ii]->m_Type != NET_PIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
Cmp = (SCH_COMPONENT*) aObjectsList[ii]->m_Link;
|
|
|
|
|
|
|
|
// Get the reference for the net name and the main parent component
|
|
|
|
CmpRef = Cmp->GetRef( &aObjectsList[ii]->m_SheetList );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( CmpRef.StartsWith( wxT( "#" ) ) )
|
2009-11-04 20:46:53 +00:00
|
|
|
continue; // Pseudo component (Like Power symbol)
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
// Print the pin list for this net, if 2 or more items are connected:
|
|
|
|
SameNetcodeCount++;
|
|
|
|
if( SameNetcodeCount == 1 ) /* first item for this net found,
|
2009-11-04 20:46:53 +00:00
|
|
|
* Print this connection, when a
|
|
|
|
* second item will be found */
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
sprintf( FirstItemInNet, " %s %.4s\n", CONV_TO_UTF8( CmpRef ),
|
2009-07-12 15:29:42 +00:00
|
|
|
(const char*) &aObjectsList[ii]->m_PinNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
// Second item for this net found, Print the Net name, and the
|
|
|
|
// first item
|
|
|
|
if( SameNetcodeCount == 2 )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
fprintf( f, "%s\n", CONV_TO_UTF8( NetcodeName ) );
|
|
|
|
fputs( FirstItemInNet, f );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( SameNetcodeCount >= 2 )
|
|
|
|
fprintf( f, " %s %.4s\n", CONV_TO_UTF8( CmpRef ),
|
2009-07-12 15:29:42 +00:00
|
|
|
(const char*) &aObjectsList[ii]->m_PinNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Generate CADSTAR net list. */
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString StartLine( wxT( "." ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
/* Routine generation of the netlist file (CADSTAR Format)
|
|
|
|
* Header:
|
|
|
|
* HEA ..
|
|
|
|
* TIM .. 2004 07 29 16 22 17
|
|
|
|
* APA .. "Cadstar RINF Output - Version 6.0.2.3"
|
|
|
|
* INCH UNI .. 1000.0 in
|
|
|
|
* FULL TYP ..
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2009-11-04 20:46:53 +00:00
|
|
|
* List of components:
|
|
|
|
* .. ADD_COM X1 "CNT D41612 (48pts CONTOUR TM)"
|
|
|
|
* .. ADD_COM U2 "74HCT245D" "74HCT245D"
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Connections:
|
|
|
|
* .. ADD_TER RR2 * 6 "$ 42"
|
|
|
|
* .. B U1 100
|
|
|
|
* 6 CA
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2009-11-04 20:46:53 +00:00
|
|
|
* ADD_TER .. U2 * 6 "$ 59"
|
|
|
|
* .. B * U7 39
|
|
|
|
* U6 17
|
|
|
|
* U1 * 122
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2009-11-04 20:46:53 +00:00
|
|
|
* .. ADD_TER P2 * 1 "$ 9"
|
|
|
|
* .. B * T3 1
|
|
|
|
*U1 * 14
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static void WriteNetListCADSTAR( WinEDA_SchematicFrame* frame, FILE* f )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
|
|
|
|
wxString msg;
|
|
|
|
wxString FootprintName;
|
|
|
|
char Line[1024];
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet;
|
2007-09-21 13:23:51 +00:00
|
|
|
EDA_BaseStruct* DrawList;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* Component;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString Title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
fprintf( f, "%sHEA\n", CONV_TO_UTF8( StartLine ) );
|
|
|
|
DateAndTime( Line );
|
|
|
|
fprintf( f, "%sTIM %s\n", CONV_TO_UTF8( StartLine ), Line );
|
|
|
|
fprintf( f, "%sAPP ", CONV_TO_UTF8( StartLine ) );
|
|
|
|
fprintf( f, "\"%s\"\n", CONV_TO_UTF8( Title ) );
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
|
|
|
|
/* Create netlist module section */
|
2009-11-04 20:46:53 +00:00
|
|
|
ClearUsedFlags(); /* Reset the flags FlagControlMulti in all schematic
|
|
|
|
*files*/
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
for( DrawList = sheet->LastDrawList();
|
|
|
|
DrawList != NULL;
|
|
|
|
DrawList = DrawList->Next() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
DrawList = Component = FindNextComponentAndCreatPinList( DrawList,
|
|
|
|
sheet );
|
2007-09-21 13:23:51 +00:00
|
|
|
if( Component == NULL )
|
|
|
|
break;
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
if( !Component->GetField( FOOTPRINT )->IsVoid() )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
FootprintName = Component->GetField( FOOTPRINT )->m_Text;
|
2007-09-21 13:23:51 +00:00
|
|
|
FootprintName.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FootprintName = wxT( "$noname" );
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
msg = Component->GetRef( sheet );
|
2007-09-21 13:23:51 +00:00
|
|
|
fprintf( f, "%s ", CONV_TO_UTF8( StartCmpDesc ) );
|
|
|
|
fprintf( f, "%s", CONV_TO_UTF8( msg ) );
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
msg = Component->GetField( VALUE )->m_Text;
|
2007-09-21 13:23:51 +00:00
|
|
|
msg.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
fprintf( f, " \"%s\"", CONV_TO_UTF8( msg ) );
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( f, "\n" );
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
s_SortedComponentPinList.clear();
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
WriteListOfNetsCADSTAR( f, g_NetObjectslist );
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
fprintf( f, "\n%sEND\n", CONV_TO_UTF8( StartLine ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/*
|
|
|
|
* Written in the file / net list (ranked by Netcode), and
|
|
|
|
* Pins connected to it
|
|
|
|
* Format:
|
|
|
|
*. ADD_TER RR2 6 "$ 42"
|
|
|
|
*. B U1 100
|
|
|
|
* 6 CA
|
2007-09-21 13:23:51 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static void WriteListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
|
|
|
|
wxString StartNetDesc = StartLine + wxT( "TER" );
|
|
|
|
wxString NetcodeName, InitNetDescLine;
|
2009-07-12 15:29:42 +00:00
|
|
|
unsigned ii, jj;
|
|
|
|
int print_ter = 0;
|
2007-09-21 13:23:51 +00:00
|
|
|
int NetCode, LastNetCode = -1;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* Cmp;
|
2007-09-21 13:23:51 +00:00
|
|
|
wxString NetName;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
for( ii = 0; ii < aObjectsList.size(); ii++ )
|
|
|
|
aObjectsList[ii]->m_Flag = 0;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
for( ii = 0; ii < g_NetObjectslist.size(); ii++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
// Get the NetName of the current net :
|
2009-07-12 15:29:42 +00:00
|
|
|
if( ( NetCode = aObjectsList[ii]->GetNet() ) != LastNetCode )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
NetName.Empty();
|
2009-07-12 15:29:42 +00:00
|
|
|
for( jj = 0; jj < aObjectsList.size(); jj++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[jj]->GetNet() != NetCode )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2009-07-12 15:29:42 +00:00
|
|
|
if( ( aObjectsList[jj]->m_Type != NET_HIERLABEL)
|
|
|
|
&& ( aObjectsList[jj]->m_Type != NET_LABEL)
|
|
|
|
&& ( aObjectsList[jj]->m_Type != NET_PINLABEL) )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
NetName = *aObjectsList[jj]->m_Label; break;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NetcodeName = wxT( "\"" );
|
|
|
|
if( !NetName.IsEmpty() )
|
|
|
|
{
|
|
|
|
NetcodeName += NetName;
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[jj]->m_Type != NET_PINLABEL )
|
2008-05-15 11:20:19 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
NetcodeName =
|
|
|
|
aObjectsList[jj]->m_SheetList.PathHumanReadable()
|
|
|
|
+ NetcodeName;
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
//NetcodeName << wxT("_") <<
|
2009-11-04 20:46:53 +00:00
|
|
|
// g_NetObjectslist[jj].m_SheetList.PathHumanReadable();
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
else // this net has no name: create a default name $<net number>
|
|
|
|
NetcodeName << wxT( "$" ) << NetCode;
|
|
|
|
NetcodeName += wxT( "\"" );
|
|
|
|
LastNetCode = NetCode;
|
|
|
|
print_ter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[ii]->m_Type != NET_PIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[ii]->m_Flag != 0 )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
Cmp = (SCH_COMPONENT*) aObjectsList[ii]->m_Link;
|
|
|
|
wxString refstr = Cmp->GetRef( &(aObjectsList[ii]->m_SheetList) );
|
2008-02-12 21:12:46 +00:00
|
|
|
if( refstr[0] == '#' )
|
2009-11-04 20:46:53 +00:00
|
|
|
continue; // Power supply symbols.
|
2007-09-21 13:23:51 +00:00
|
|
|
|
|
|
|
switch( print_ter )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
char buf[5];
|
|
|
|
wxString str_pinnum;
|
2009-07-12 15:29:42 +00:00
|
|
|
strncpy( buf, (char*) &aObjectsList[ii]->m_PinNum, 4 );
|
2009-11-04 20:46:53 +00:00
|
|
|
buf[4] = 0;
|
2007-09-21 13:23:51 +00:00
|
|
|
str_pinnum = CONV_FROM_UTF8( buf );
|
|
|
|
InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
|
2009-11-04 20:46:53 +00:00
|
|
|
InitNetDesc.GetData(),
|
|
|
|
refstr.GetData(),
|
|
|
|
str_pinnum.GetData(),
|
|
|
|
NetcodeName.GetData() );
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
print_ter++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
fprintf( f, "%s\n", CONV_TO_UTF8( InitNetDescLine ) );
|
|
|
|
fprintf( f, "%s %s %.4s\n",
|
|
|
|
CONV_TO_UTF8( StartNetDesc ),
|
2008-02-12 21:12:46 +00:00
|
|
|
CONV_TO_UTF8( refstr ),
|
2009-07-12 15:29:42 +00:00
|
|
|
(char*) &aObjectsList[ii]->m_PinNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
print_ter++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf( f, " %s %.4s\n",
|
2008-02-12 21:12:46 +00:00
|
|
|
CONV_TO_UTF8( refstr ),
|
2009-07-12 15:29:42 +00:00
|
|
|
(char*) &aObjectsList[ii]->m_PinNum );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
aObjectsList[ii]->m_Flag = 1;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// Search for redundant pins to avoid generation the same connection
|
|
|
|
// more than once.
|
2009-07-12 15:29:42 +00:00
|
|
|
for( jj = ii + 1; jj < aObjectsList.size(); jj++ )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[jj]->GetNet() != NetCode )
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[jj]->m_Type != NET_PIN )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* tstcmp =
|
2009-07-12 15:29:42 +00:00
|
|
|
(SCH_COMPONENT*) aObjectsList[jj]->m_Link;
|
|
|
|
wxString p = Cmp->GetPath( &( aObjectsList[ii]->m_SheetList ) );
|
|
|
|
wxString tstp = tstcmp->GetPath( &( aObjectsList[jj]->m_SheetList ) );
|
2008-05-15 11:20:19 +00:00
|
|
|
if( p.Cmp( tstp ) != 0 )
|
2007-09-21 13:23:51 +00:00
|
|
|
continue;
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
if( aObjectsList[jj]->m_PinNum == aObjectsList[ii]->m_PinNum )
|
|
|
|
aObjectsList[jj]->m_Flag = 1;
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|