Commit aa9e61ed authored by charras's avatar charras

Code cleanup about netlist, ERC and markers in eeschema ( work in progress )

parent a97a2b4b
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "appl_wxstruct.h" #include "appl_wxstruct.h"
#define BUILD_VERSION "(20090708-unstable)" #define BUILD_VERSION "(20090712-unstable)"
#ifdef HAVE_SVN_VERSION #ifdef HAVE_SVN_VERSION
......
...@@ -23,6 +23,7 @@ set(EESCHEMA_SRCS ...@@ -23,6 +23,7 @@ set(EESCHEMA_SRCS
class_libentry_fields.cpp class_libentry_fields.cpp
class_library.cpp class_library.cpp
class_marker_sch.cpp class_marker_sch.cpp
class_netlist_object.cpp
class_pin.cpp class_pin.cpp
class_sch_cmp_field.cpp class_sch_cmp_field.cpp
class_schematic_items.cpp class_schematic_items.cpp
......
...@@ -675,10 +675,6 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert ) ...@@ -675,10 +675,6 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )
bBox.Merge( DrawEntry->GetBoundingBox() ); bBox.Merge( DrawEntry->GetBoundingBox() );
} }
wxRect r = bBox;
wxLogDebug( wxT( "New boundary box = (%d, %d, %d, %d)" ), r.GetLeft(),
r.GetRight(), r.GetBottom(), r.GetTop() );
return bBox; return bBox;
} }
......
/*************************************************************************************/
/* Class NETLIST_OBJECT to handle 1 item connected (in netlist and erc calculations) */
/*************************************************************************************/
#include "fctsys.h"
#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"
#include "class_netlist_object.h"
#if defined(DEBUG)
#include <iostream>
const char* ShowType( NetObjetType aType )
{
const char* ret;
switch( aType )
{
case NET_SEGMENT:
ret = "segment"; break;
case NET_BUS:
ret = "bus"; break;
case NET_JONCTION:
ret = "junction"; break;
case NET_LABEL:
ret = "label"; break;
case NET_HIERLABEL:
ret = "hierlabel"; break;
case NET_GLOBLABEL:
ret = "glabel"; break;
case NET_BUSLABELMEMBER:
ret = "buslblmember"; break;
case NET_HIERBUSLABELMEMBER:
ret = "hierbuslblmember"; break;
case NET_GLOBBUSLABELMEMBER:
ret = "gbuslblmember"; break;
case NET_SHEETBUSLABELMEMBER:
ret = "sbuslblmember"; break;
case NET_SHEETLABEL:
ret = "sheetlabel"; break;
case NET_PINLABEL:
ret = "pinlabel"; break;
case NET_PIN:
ret = "pin"; break;
case NET_NOCONNECT:
ret = "noconnect"; break;
default:
ret = "??"; break;
}
return ret;
}
void NETLIST_OBJECT::Show( std::ostream& out, int ndx )
{
wxString path = m_SheetList.PathHumanReadable();
out << "<netItem ndx=\"" << ndx << '"' <<
" type=\"" << ShowType( m_Type ) << '"' <<
" netCode=\"" << GetNet() << '"' <<
" sheet=\"" << CONV_TO_UTF8( path ) << '"' <<
">\n";
out << " <start " << m_Start << "/> <end " << m_End << "/>\n";
if( m_Label )
out << " <label>" << m_Label->mb_str() << "</label>\n";
if( m_Comp )
m_Comp->Show( 1, out );
else
out << " m_Comp==NULL\n";
out << "</netItem>\n";
}
#endif
NETLIST_OBJECT::NETLIST_OBJECT()
{
m_Type = NET_ITEM_UNSPECIFIED; /* Type of this item (see NetObjetType enum) */
m_Comp = NULL; /* Pointer on the library item that created this net object (the parent)*/
m_Link = NULL; /* For Hierarchical_PIN_Sheet_Struct:
* Pointer to the hierarchy sheet that contains this Hierarchical_PIN_Sheet_Struct
* For Pins: pointer to the component that contains this pin
*/
m_Flag = 0; /* flag used in calculations */
m_ElectricalType = 0; /* Has meaning only for Pins and hierachical pins: electrical type */
m_NetCode = 0; /* net code for all items except BUS labels because a BUS label has
* as many net codes as bus members
*/
m_BusNetCode = 0; /* Used for BUS connections */
m_Member = 0; /* for labels type NET_BUSLABELMEMBER ( bus member created from the BUS label )
* member number
*/
m_FlagOfConnection = UNCONNECTED;
m_PinNum = 0; /* pin number ( 1 long = 4 bytes -> 4 ascii codes) */
m_Label = 0; /* For all labels:pointer on the text label */
}
// Copy constructor
NETLIST_OBJECT::NETLIST_OBJECT( NETLIST_OBJECT& aSource )
{
}
NETLIST_OBJECT::~NETLIST_OBJECT()
{
/* NETLIST_OBJECT is owner of m_Label only if its type is
* NET_HIERBUSLABELMEMBER, NET_GLOBBUSLABELMEMBER, NET_SHEETBUSLABELMEMBER or NET_BUSLABELMEMBER
* So we must delete m_Label only for these cases
* ( see the note in ConvertBustToMembers)
*/
switch( m_Type )
{
default:
break;
case NET_HIERBUSLABELMEMBER:
case NET_GLOBBUSLABELMEMBER:
case NET_SHEETBUSLABELMEMBER:
case NET_BUSLABELMEMBER:
SAFE_DELETE( m_Label );
break;
}
}
/*************************************************************************************/
/* Class NETLIST_OBJECT to handle 1 item connected (in netlist and erc calculations) */
/*************************************************************************************/
#ifndef _CLASS_NETLIST_OBJECT_H_
#define _CLASS_NETLIST_OBJECT_H_
/* Type of Net objects (wires, labels, pins...) */
enum NetObjetType {
NET_ITEM_UNSPECIFIED, // only for not yet initialized instances
NET_SEGMENT, // connection by wire
NET_BUS, // connection by bus
NET_JONCTION, // connection by junction: can connect to or more crossing wires
NET_LABEL, // this is a local label
NET_GLOBLABEL, // this is a global label that connect all others global label in whole hierrachy
NET_HIERLABEL, // element to indicate connection to a higher-level sheet
NET_SHEETLABEL, // element to indicate connection to a lower-level sheet.
NET_BUSLABELMEMBER, /* created when a bus label is found:
* the bus label (like DATA[0..7] is converted to n single labels like DATA0, DATA1 ...
*/
NET_GLOBBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a global bus label is found
NET_HIERBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a hierarchical bus label is found
NET_SHEETBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a pin sheet label using bus notation is found
NET_PINLABEL, /* created when a pin is POWER (IN or OUT) with invisible attribute is found:
* these pins are equivalent to a global label and are automatically connected
*/
NET_PIN, // this is an usual pin
NET_NOCONNECT // this is a no connect symbol
};
/* Values for .m_FlagOfConnection member */
enum ConnectType {
UNCONNECTED = 0, /* Pin or Label not connected (error) */
NOCONNECT_SYMBOL_PRESENT, /* Pin not connected but have a NoConnect symbol on it (no error) */
PAD_CONNECT /* Normal connection (no error) */
};
class NETLIST_OBJECT
{
public:
NetObjetType m_Type; /* Type of this item (see NetObjetType enum) */
EDA_BaseStruct* m_Comp; /* Pointer on the library item that created this net object (the parent)*/
SCH_ITEM* m_Link; /* For Hierarchical_PIN_Sheet_Struct:
* Pointer to the hierarchy sheet that contains this Hierarchical_PIN_Sheet_Struct
* For Pins: pointer to the component that contains this pin
*/
int m_Flag; /* flag used in calculations */
DrawSheetPath m_SheetList;
int m_ElectricalType; /* Has meaning only for Pins and hierachical pins: electrical type */
private:
int m_NetCode; /* net code for all items except BUS labels because a BUS label has
* as many net codes as bus members
*/
public:
int m_BusNetCode; /* Used for BUS connections */
int m_Member; /* for labels type NET_BUSLABELMEMBER ( bus member created from the BUS label )
* member number
*/
ConnectType m_FlagOfConnection;
DrawSheetPath m_SheetListInclude; /* sheet that the hierarchal label connects to.*/
long m_PinNum; /* pin number ( 1 long = 4 bytes -> 4 ascii codes) */
const wxString* m_Label; /* For all labels:pointer on the text label */
wxPoint m_Start; // Position of object or for segments: starting point
wxPoint m_End; // For segments (wire and busses): ending point
#if defined(DEBUG)
void Show( std::ostream& out, int ndx );
#endif
NETLIST_OBJECT();
NETLIST_OBJECT( NETLIST_OBJECT& aSource ); // Copy constructor
~NETLIST_OBJECT();
void SetNet( int aNetCode ) { m_NetCode = aNetCode; }
int GetNet() const { return m_NetCode; }
};
#endif // _CLASS_NETLIST_OBJECT_H_
...@@ -30,15 +30,15 @@ ...@@ -30,15 +30,15 @@
/* fonctions locales */ /* fonctions locales */
static bool WriteDiagnosticERC( const wxString& FullFileName ); static bool WriteDiagnosticERC( const wxString& FullFileName );
static void Diagnose( WinEDA_DrawPanel* panel, static void Diagnose( WinEDA_DrawPanel* panel,
ObjetNetListStruct* NetItemRef, NETLIST_OBJECT* NetItemRef,
ObjetNetListStruct* NetItemTst, int MinConnexion, int Diag ); NETLIST_OBJECT* NetItemTst, int MinConnexion, int Diag );
static void TestOthersItems( WinEDA_DrawPanel* panel, static void TestOthersItems( WinEDA_DrawPanel* panel,
ObjetNetListStruct* NetItemRef, unsigned NetItemRef,
ObjetNetListStruct* NetStart, unsigned NetStart,
int* NetNbItems, int* MinConnexion ); int* NetNbItems, int* MinConnexion );
static void TestLabel( WinEDA_DrawPanel* panel, static void TestLabel( WinEDA_DrawPanel* panel,
ObjetNetListStruct* NetItemRef, unsigned NetItemRef,
ObjetNetListStruct* StartNet ); unsigned StartNet );
/* Local variables */ /* Local variables */
int WriteFichierERC = FALSE; int WriteFichierERC = FALSE;
...@@ -166,7 +166,7 @@ static int MinimalReq[PIN_NMAX][PIN_NMAX] = ...@@ -166,7 +166,7 @@ static int MinimalReq[PIN_NMAX][PIN_NMAX] =
/**Function TestDuplicateSheetNames( ) /** Function TestDuplicateSheetNames( )
* inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated). * inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).
*/ */
int TestDuplicateSheetNames( ) int TestDuplicateSheetNames( )
...@@ -217,10 +217,9 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) ...@@ -217,10 +217,9 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
/**************************************************/ /**************************************************/
{ {
wxFileName fn; wxFileName fn;
ObjetNetListStruct* NetItemRef; unsigned NetItemRef;
ObjetNetListStruct* OldItem; unsigned OldItem;
ObjetNetListStruct* StartNet; unsigned StartNet;
ObjetNetListStruct* Lim;
int NetNbItems, MinConn; int NetNbItems, MinConn;
...@@ -273,30 +272,28 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) ...@@ -273,30 +272,28 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
m_Parent->BuildNetListBase(); m_Parent->BuildNetListBase();
/* Analyse de la table des connexions : */
Lim = g_TabObjNet + g_NbrObjNet;
/* Reset the flag m_FlagOfConnection, that will be used next, in calculations */ /* Reset the flag m_FlagOfConnection, that will be used next, in calculations */
for( NetItemRef = g_TabObjNet; NetItemRef < Lim; NetItemRef++ ) for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
NetItemRef->m_FlagOfConnection = UNCONNECTED; g_NetObjectslist[ii]->m_FlagOfConnection = UNCONNECTED;
StartNet = OldItem = 0;
NetNbItems = 0; NetNbItems = 0;
MinConn = NOC; MinConn = NOC;
StartNet = OldItem = NetItemRef = g_TabObjNet; for( NetItemRef = 0; NetItemRef < g_NetObjectslist.size(); NetItemRef++ )
for( ; NetItemRef < Lim; NetItemRef++ )
{ {
/* Tst changement de net */ /* Tst changement de net */
if( OldItem->GetNet() != NetItemRef->GetNet() ) if( g_NetObjectslist[OldItem]->GetNet() != g_NetObjectslist[NetItemRef]->GetNet() )
{ {
MinConn = NOC; MinConn = NOC;
NetNbItems = 0; NetNbItems = 0;
StartNet = NetItemRef; StartNet = NetItemRef;
} }
switch( NetItemRef->m_Type ) switch( g_NetObjectslist[NetItemRef]->m_Type )
{ {
case NET_ITEM_UNSPECIFIED:
case NET_SEGMENT: case NET_SEGMENT:
case NET_BUS: case NET_BUS:
case NET_JONCTION: case NET_JONCTION:
...@@ -325,7 +322,8 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) ...@@ -325,7 +322,8 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
// ERC problems when a noconnect symbol is connected to more than one pin. // ERC problems when a noconnect symbol is connected to more than one pin.
MinConn = NET_NC; MinConn = NET_NC;
if( NetNbItems != 0 ) if( NetNbItems != 0 )
Diagnose( m_Parent->DrawPanel, NetItemRef, NULL, MinConn, UNC ); Diagnose( m_Parent->DrawPanel,
g_NetObjectslist[NetItemRef], NULL, MinConn, UNC );
break; break;
case NET_PIN: case NET_PIN:
...@@ -339,8 +337,6 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) ...@@ -339,8 +337,6 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
OldItem = NetItemRef; OldItem = NetItemRef;
} }
FreeTabNetList( g_TabObjNet, g_NbrObjNet );
// Displays global results: // Displays global results:
wxString num; wxString num;
num.Printf( wxT( "%d" ), g_EESchemaVar.NbErrorErc ); num.Printf( wxT( "%d" ), g_EESchemaVar.NbErrorErc );
...@@ -383,8 +379,8 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) ...@@ -383,8 +379,8 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
/********************************************************/ /********************************************************/
static void Diagnose( WinEDA_DrawPanel* aPanel, static void Diagnose( WinEDA_DrawPanel* aPanel,
ObjetNetListStruct* aNetItemRef, NETLIST_OBJECT* aNetItemRef,
ObjetNetListStruct* aNetItemTst, NETLIST_OBJECT* aNetItemTst,
int aMinConn, int aDiag ) int aMinConn, int aDiag )
/********************************************************/ /********************************************************/
...@@ -515,8 +511,8 @@ static void Diagnose( WinEDA_DrawPanel* aPanel, ...@@ -515,8 +511,8 @@ static void Diagnose( WinEDA_DrawPanel* aPanel,
/********************************************************************/ /********************************************************************/
static void TestOthersItems( WinEDA_DrawPanel* panel, static void TestOthersItems( WinEDA_DrawPanel* panel,
ObjetNetListStruct* NetItemRef, unsigned NetItemRef,
ObjetNetListStruct* netstart, unsigned netstart,
int* NetNbItems, int* MinConnexion ) int* NetNbItems, int* MinConnexion )
/********************************************************************/ /********************************************************************/
...@@ -525,15 +521,13 @@ static void TestOthersItems( WinEDA_DrawPanel* panel, ...@@ -525,15 +521,13 @@ static void TestOthersItems( WinEDA_DrawPanel* panel,
* et les autres items du meme net * et les autres items du meme net
*/ */
{ {
ObjetNetListStruct* NetItemTst; unsigned NetItemTst;
ObjetNetListStruct* Lim;
int ref_elect_type, jj, erc = OK, local_minconn; int ref_elect_type, jj, erc = OK, local_minconn;
/* Analyse de la table des connexions : */ /* Analyse de la table des connexions : */
Lim = g_TabObjNet + g_NbrObjNet; // pointe la fin de la liste
ref_elect_type = NetItemRef->m_ElectricalType; ref_elect_type = g_NetObjectslist[NetItemRef]->m_ElectricalType;
NetItemTst = netstart; NetItemTst = netstart;
local_minconn = NOC; local_minconn = NOC;
...@@ -545,49 +539,50 @@ static void TestOthersItems( WinEDA_DrawPanel* panel, ...@@ -545,49 +539,50 @@ static void TestOthersItems( WinEDA_DrawPanel* panel,
continue; continue;
/* We examine only a given net. We stop the search if the net changes */ /* We examine only a given net. We stop the search if the net changes */
if( (NetItemTst >= Lim) // End of list if( (NetItemTst >= g_NetObjectslist.size()) // End of list
|| ( NetItemRef->GetNet() != NetItemTst->GetNet() ) ) // End of net || ( g_NetObjectslist[NetItemRef]->GetNet() != g_NetObjectslist[NetItemTst]->GetNet() ) ) // End of net
{ {
/* Fin de netcode trouve: Tst connexion minimum */ /* Fin de netcode trouve: Tst connexion minimum */
if( (*MinConnexion < NET_NC ) && (local_minconn < NET_NC ) ) /* Not connected or not driven pin */ if( (*MinConnexion < NET_NC ) && (local_minconn < NET_NC ) ) /* Not connected or not driven pin */
{ {
bool seterr = true; bool seterr = true;
if( local_minconn == NOC && NetItemRef->m_Type == NET_PIN) if( local_minconn == NOC && g_NetObjectslist[NetItemRef]->m_Type == NET_PIN)
{ {
/* This pin is not connected: for multiple part per package, and duplicated pin, /* This pin is not connected: for multiple part per package, and duplicated pin,
* search for an other instance of this pin * search for an other instance of this pin
* this will be flagged only is all instances of this pin are not connected * this will be flagged only is all instances of this pin are not connected
* TODO test also if instances connected are connected to the same net * TODO test also if instances connected are connected to the same net
*/ */
for ( ObjetNetListStruct *duppin = g_TabObjNet; duppin < Lim; duppin ++ ) for ( unsigned duppin = 0; duppin < g_NetObjectslist.size(); duppin ++ )
{ {
if ( duppin->m_Type != NET_PIN ) if ( g_NetObjectslist[duppin]->m_Type != NET_PIN )
continue; continue;
if( duppin == NetItemRef ) if( duppin == NetItemRef )
continue; continue;
if ( NetItemRef->m_PinNum != duppin->m_PinNum ) if ( g_NetObjectslist[NetItemRef]->m_PinNum != g_NetObjectslist[duppin]->m_PinNum )
continue; continue;
if( ( (SCH_COMPONENT*) NetItemRef->m_Link )->GetRef(&NetItemRef->m_SheetList) != if( ( (SCH_COMPONENT*) g_NetObjectslist[NetItemRef]->m_Link )->GetRef(&g_NetObjectslist[NetItemRef]->m_SheetList) !=
((SCH_COMPONENT*) duppin->m_Link )->GetRef(&duppin->m_SheetList) ) ((SCH_COMPONENT*) g_NetObjectslist[duppin]->m_Link )->GetRef(&g_NetObjectslist[duppin]->m_SheetList) )
continue; continue;
// Same component and same pin. Do dot create error for this pin // Same component and same pin. Do dot create error for this pin
// if the other pin is connected (i.e. if duppin net has an other item) // if the other pin is connected (i.e. if duppin net has an other item)
if ( (duppin > g_TabObjNet) && (duppin->GetNet() == (duppin-1)->GetNet())) if ( (duppin > 0) && (g_NetObjectslist[duppin]->GetNet() == g_NetObjectslist[duppin-1]->GetNet()))
seterr = false; seterr = false;
if ( (duppin < Lim-1) && (duppin->GetNet() == (duppin+1)->GetNet()) ) if ( (duppin < g_NetObjectslist.size()-1) && (g_NetObjectslist[duppin]->GetNet() == g_NetObjectslist[duppin+1]->GetNet()) )
seterr = false; seterr = false;
} }
} }
if ( seterr ) if ( seterr )
Diagnose( panel, NetItemRef, NULL, local_minconn, WAR ); Diagnose( panel, g_NetObjectslist[NetItemRef], NULL, local_minconn, WAR );
*MinConnexion = DRV; // inhibition autres messages de ce type pour ce net *MinConnexion = DRV; // inhibition autres messages de ce type pour ce net
} }
return; return;
} }
switch( NetItemTst->m_Type ) switch( g_NetObjectslist[NetItemTst]->m_Type )
{ {
case NET_ITEM_UNSPECIFIED:
case NET_SEGMENT: case NET_SEGMENT:
case NET_BUS: case NET_BUS:
case NET_JONCTION: case NET_JONCTION:
...@@ -607,7 +602,7 @@ static void TestOthersItems( WinEDA_DrawPanel* panel, ...@@ -607,7 +602,7 @@ static void TestOthersItems( WinEDA_DrawPanel* panel,
break; break;
case NET_PIN: case NET_PIN:
jj = NetItemTst->m_ElectricalType; jj = g_NetObjectslist[NetItemTst]->m_ElectricalType;
local_minconn = MAX( MinimalReq[ref_elect_type][jj], local_minconn ); local_minconn = MAX( MinimalReq[ref_elect_type][jj], local_minconn );
if( NetItemTst <= NetItemRef ) if( NetItemTst <= NetItemRef )
...@@ -619,10 +614,10 @@ static void TestOthersItems( WinEDA_DrawPanel* panel, ...@@ -619,10 +614,10 @@ static void TestOthersItems( WinEDA_DrawPanel* panel,
erc = DiagErc[ref_elect_type][jj]; erc = DiagErc[ref_elect_type][jj];
if( erc != OK ) if( erc != OK )
{ {
if( NetItemTst->m_FlagOfConnection == 0 ) if( g_NetObjectslist[NetItemTst]->m_FlagOfConnection == 0 )
{ {
Diagnose( panel, NetItemRef, NetItemTst, 0, erc ); Diagnose( panel, g_NetObjectslist[NetItemRef], g_NetObjectslist[NetItemTst], 0, erc );
NetItemTst->m_FlagOfConnection = NOCONNECT; g_NetObjectslist[NetItemTst]->m_FlagOfConnection = NOCONNECT_SYMBOL_PRESENT;
} }
} }
} }
...@@ -692,7 +687,7 @@ static bool WriteDiagnosticERC( const wxString& FullFileName ) ...@@ -692,7 +687,7 @@ static bool WriteDiagnosticERC( const wxString& FullFileName )
} }
static bool IsLabelsConnected( ObjetNetListStruct* a, ObjetNetListStruct* b ) static bool IsLabelsConnected( NETLIST_OBJECT* a, NETLIST_OBJECT* b )
{ {
int at = a->m_Type; int at = a->m_Type;
int bt = b->m_Type; int bt = b->m_Type;
...@@ -711,19 +706,17 @@ static bool IsLabelsConnected( ObjetNetListStruct* a, ObjetNetListStruct* b ) ...@@ -711,19 +706,17 @@ static bool IsLabelsConnected( ObjetNetListStruct* a, ObjetNetListStruct* b )
/***********************************************************************/ /***********************************************************************/
void TestLabel( WinEDA_DrawPanel* panel, void TestLabel( WinEDA_DrawPanel* panel,
ObjetNetListStruct* NetItemRef, unsigned NetItemRef,
ObjetNetListStruct* StartNet ) unsigned StartNet )
/***********************************************************************/ /***********************************************************************/
/* Routine controlant qu'un sheetLabel est bien connecte a un Glabel de la /* Routine controlant qu'un sheetLabel est bien connecte a un Glabel de la
* sous-feuille correspondante * sous-feuille correspondante
*/ */
{ {
ObjetNetListStruct* NetItemTst, * Lim; unsigned NetItemTst;
int erc = 1; int erc = 1;
/* Analyse de la table des connexions : */
Lim = g_TabObjNet + g_NbrObjNet;
NetItemTst = StartNet; NetItemTst = StartNet;
...@@ -734,22 +727,22 @@ void TestLabel( WinEDA_DrawPanel* panel, ...@@ -734,22 +727,22 @@ void TestLabel( WinEDA_DrawPanel* panel,
continue; continue;
/* Est - on toujours dans le meme net ? */ /* Est - on toujours dans le meme net ? */
if( ( NetItemTst == Lim ) if( ( NetItemTst == g_NetObjectslist.size() )
|| ( NetItemRef->GetNet() != NetItemTst->GetNet() ) ) || ( g_NetObjectslist[NetItemRef]->GetNet() != g_NetObjectslist[NetItemTst]->GetNet() ) )
{ {
/* Fin de netcode trouve */ /* Fin de netcode trouve */
if( erc ) if( erc )
{ {
/* GLabel ou SheetLabel orphelin */ /* GLabel ou SheetLabel orphelin */
Diagnose( panel, NetItemRef, NULL, -1, WAR ); Diagnose( panel, g_NetObjectslist[NetItemRef], NULL, -1, WAR );
} }
return; return;
} }
if( IsLabelsConnected( NetItemRef, NetItemTst ) ) if( IsLabelsConnected( g_NetObjectslist[NetItemRef], g_NetObjectslist[NetItemTst] ) )
erc = 0; erc = 0;
//same thing, different order. //same thing, different order.
if( IsLabelsConnected( NetItemTst, NetItemRef ) ) if( IsLabelsConnected( g_NetObjectslist[NetItemTst], g_NetObjectslist[NetItemRef] ) )
erc = 0; erc = 0;
} }
} }
...@@ -21,27 +21,26 @@ static void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame, const wxString& ...@@ -21,27 +21,26 @@ static void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame, const wxString&
static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f,
bool with_pcbnew ); bool with_pcbnew );
static void WriteNetListCADSTAR( WinEDA_SchematicFrame* frame, FILE* f ); static void WriteNetListCADSTAR( WinEDA_SchematicFrame* frame, FILE* f );
static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet ); static void WriteListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, bool use_netnames ); static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, bool use_netnames );
static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet ); static void WriteGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
static void AddPinToComponentPinList( SCH_COMPONENT* Component, static void AddPinToComponentPinList( SCH_COMPONENT* Component,
DrawSheetPath* sheet, DrawSheetPath* sheet,
LibDrawPin* PinEntry ); LibDrawPin* PinEntry );
static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component, static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component,
EDA_LibComponentStruct* Entry, EDA_LibComponentStruct* Entry,
DrawSheetPath* Sheet_in ); DrawSheetPath* Sheet_in );
static int SortPinsByNum( ObjetNetListStruct** Pin1, ObjetNetListStruct** Pin2 ); static bool SortPinsByNum( NETLIST_OBJECT* Pin1, NETLIST_OBJECT* Pin2 );
static void EraseDuplicatePins( ObjetNetListStruct** TabPin, int NbrPin ); static void EraseDuplicatePins( NETLIST_OBJECT_LIST& aPinList );
static void ClearUsedFlags( void ); static void ClearUsedFlags( void );
/* Local variables */ /* Local variables */
static int s_SortedPinCount; static NETLIST_OBJECT_LIST s_SortedComponentPinList;
static ObjetNetListStruct** s_SortedComponentPinList;
// list of references arready found for multi part per packages components // list of references already found for multi part per packages components
// (used to avoid to used more than one time a component) // (used to avoid to used more than one time a component)
static wxArrayString s_ReferencesAlreadyFound; static wxArrayString s_ReferencesAlreadyFound;
...@@ -106,8 +105,6 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( ...@@ -106,8 +105,6 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList(
* build its pin list s_SortedComponentPinList. * build its pin list s_SortedComponentPinList.
* The list is sorted by pin num * The list is sorted by pin num
* A suitable component is a "new" real component (power symbols are not considered) * A suitable component is a "new" real component (power symbols are not considered)
*
* alloc memory for s_SortedComponentPinList if s_SortedComponentPinList == NULL
* Must be deallocated by the user * Must be deallocated by the user
*/ */
{ {
...@@ -115,8 +112,7 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( ...@@ -115,8 +112,7 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList(
EDA_LibComponentStruct* Entry; EDA_LibComponentStruct* Entry;
LibEDA_BaseStruct* DEntry; LibEDA_BaseStruct* DEntry;
s_SortedPinCount = 0; s_SortedComponentPinList.clear();
for( ; DrawList != NULL; DrawList = DrawList->Next() ) for( ; DrawList != NULL; DrawList = DrawList->Next() )
{ {
if( DrawList->Type() != TYPE_SCH_COMPONENT ) if( DrawList->Type() != TYPE_SCH_COMPONENT )
...@@ -158,13 +154,6 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( ...@@ -158,13 +154,6 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList(
} }
} }
/* Create the pin table for this component */
int ii = sizeof(ObjetNetListStruct*) * MAXPIN;
if( s_SortedComponentPinList == NULL )
s_SortedComponentPinList = (ObjetNetListStruct**) MyMalloc( ii );
memset( s_SortedComponentPinList, 0, ii );
DEntry = Entry->m_Drawings; DEntry = Entry->m_Drawings;
if( Entry->m_UnitCount <= 1 ) // One part per package if( Entry->m_UnitCount <= 1 ) // One part per package
{ {
...@@ -187,11 +176,10 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( ...@@ -187,11 +176,10 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList(
FindAllsInstancesOfComponent( Component, Entry, sheet ); FindAllsInstancesOfComponent( Component, Entry, sheet );
/* Sort Pins in s_SortedComponentPinList by pin number */ /* Sort Pins in s_SortedComponentPinList by pin number */
qsort( s_SortedComponentPinList, s_SortedPinCount, sizeof(ObjetNetListStruct*), sort( s_SortedComponentPinList.begin(), s_SortedComponentPinList.end(),SortPinsByNum );
( int( * ) ( const void*, const void* ) )SortPinsByNum );
/* Remove duplicate Pins in s_SortedComponentPinList */ /* Remove duplicate Pins in s_SortedComponentPinList */
EraseDuplicatePins( s_SortedComponentPinList, s_SortedPinCount ); EraseDuplicatePins( s_SortedComponentPinList );
return Component; return Component;
} }
...@@ -201,7 +189,7 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( ...@@ -201,7 +189,7 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList(
/**************************************************************************************/ /**************************************************************************************/
static wxString ReturnPinNetName( ObjetNetListStruct* Pin, static wxString ReturnPinNetName( NETLIST_OBJECT* Pin,
const wxString& DefaultFormatNetname ) const wxString& DefaultFormatNetname )
/**************************************************************************************/ /**************************************************************************************/
...@@ -221,30 +209,30 @@ static wxString ReturnPinNetName( ObjetNetListStruct* Pin, ...@@ -221,30 +209,30 @@ static wxString ReturnPinNetName( ObjetNetListStruct* Pin,
} }
else else
{ {
int jj; unsigned jj;
for( jj = 0; jj < g_NbrObjNet; jj++ ) for( jj = 0; jj < g_NetObjectslist.size(); jj++ )
{ {
if( g_TabObjNet[jj].GetNet() != netcode ) if( g_NetObjectslist[jj]->GetNet() != netcode )
continue; continue;
if( ( g_TabObjNet[jj].m_Type != NET_HIERLABEL) if( ( g_NetObjectslist[jj]->m_Type != NET_HIERLABEL)
&& ( g_TabObjNet[jj].m_Type != NET_LABEL) && ( g_NetObjectslist[jj]->m_Type != NET_LABEL)
&& ( g_TabObjNet[jj].m_Type != NET_PINLABEL) ) && ( g_NetObjectslist[jj]->m_Type != NET_PINLABEL) )
continue; continue;
NetName = *g_TabObjNet[jj].m_Label; NetName = *g_NetObjectslist[jj]->m_Label;
break; break;
} }
if( !NetName.IsEmpty() ) if( !NetName.IsEmpty() )
{ {
if( g_TabObjNet[jj].m_Type != NET_PINLABEL ) if( g_NetObjectslist[jj]->m_Type != NET_PINLABEL )
{ {
wxString lnet = NetName; wxString lnet = NetName;
NetName = g_TabObjNet[jj].m_SheetList.PathHumanReadable(); NetName = g_NetObjectslist[jj]->m_SheetList.PathHumanReadable();
// If sheet path is too long, use the time stamp name insteed // If sheet path is too long, use the time stamp name insteed
if( NetName.Length() > 32 ) if( NetName.Length() > 32 )
NetName = g_TabObjNet[jj].m_SheetList.Path(); NetName = g_NetObjectslist[jj]->m_SheetList.Path();
NetName += lnet; NetName += lnet;
} }
} }
...@@ -271,7 +259,6 @@ void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame, ...@@ -271,7 +259,6 @@ void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame,
EDA_BaseStruct* SchItem; EDA_BaseStruct* SchItem;
SCH_COMPONENT* Component; SCH_COMPONENT* Component;
wxString netname; wxString netname;
int ii;
FILE* tmpfile; FILE* tmpfile;
wxFileName fn = FullFileName; wxFileName fn = FullFileName;
...@@ -324,9 +311,9 @@ void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame, ...@@ -324,9 +311,9 @@ void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame,
// Write pin list: // Write pin list:
fprintf( tmpfile, "$BeginPinList\n" ); fprintf( tmpfile, "$BeginPinList\n" );
for( ii = 0; ii < s_SortedPinCount; ii++ ) for( unsigned ii = 0; ii < s_SortedComponentPinList.size(); ii++ )
{ {
ObjetNetListStruct* Pin = s_SortedComponentPinList[ii]; NETLIST_OBJECT* Pin = s_SortedComponentPinList[ii];
if( !Pin ) if( !Pin )
continue; continue;
netname = ReturnPinNetName( Pin, wxT( "$-%.6d" ) ); netname = ReturnPinNetName( Pin, wxT( "$-%.6d" ) );
...@@ -341,13 +328,10 @@ void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame, ...@@ -341,13 +328,10 @@ void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame,
} }
} }
MyFree( s_SortedComponentPinList );
s_SortedComponentPinList = NULL;
fprintf( tmpfile, "$EndComponentList\n" ); fprintf( tmpfile, "$EndComponentList\n" );
fprintf( tmpfile, "\n$BeginNets\n" ); fprintf( tmpfile, "\n$BeginNets\n" );
WriteGENERICListOfNets( tmpfile, g_TabObjNet ); WriteGENERICListOfNets( tmpfile, g_NetObjectslist );
fprintf( tmpfile, "$EndNets\n" ); fprintf( tmpfile, "$EndNets\n" );
fprintf( tmpfile, "\n$EndNetlist\n" ); fprintf( tmpfile, "\n$EndNetlist\n" );
fclose( tmpfile ); fclose( tmpfile );
...@@ -399,7 +383,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, ...@@ -399,7 +383,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f,
DrawSheetPath* sheet; DrawSheetPath* sheet;
EDA_BaseStruct* DrawList; EDA_BaseStruct* DrawList;
SCH_COMPONENT* Component; SCH_COMPONENT* Component;
int ii, nbitems; int nbitems;
wxString text; wxString text;
wxArrayString SpiceCommandAtBeginFile, SpiceCommandAtEndFile; wxArrayString SpiceCommandAtBeginFile, SpiceCommandAtEndFile;
wxString msg; wxString msg;
...@@ -436,7 +420,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, ...@@ -436,7 +420,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f,
/* Put the Y position as an ascii string, for sort by vertical position, /* Put the Y position as an ascii string, for sort by vertical position,
* using usual sort string by alphabetic value */ * using usual sort string by alphabetic value */
int ypos = DRAWTEXT->m_Pos.y; int ypos = DRAWTEXT->m_Pos.y;
for( ii = 0; ii < BUFYPOS_LEN; ii++ ) for( int ii = 0; ii < BUFYPOS_LEN; ii++ )
{ {
bufnum[BUFYPOS_LEN - 1 - ii] = (ypos & 63) + ' '; ypos >>= 6; bufnum[BUFYPOS_LEN - 1 - ii] = (ypos & 63) + ' '; ypos >>= 6;
} }
...@@ -456,7 +440,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, ...@@ -456,7 +440,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f,
if( nbitems ) if( nbitems )
{ {
SpiceCommandAtBeginFile.Sort(); SpiceCommandAtBeginFile.Sort();
for( ii = 0; ii < nbitems; ii++ ) for( int ii = 0; ii < nbitems; ii++ )
{ {
SpiceCommandAtBeginFile[ii].Remove( 0, BUFYPOS_LEN ); SpiceCommandAtBeginFile[ii].Remove( 0, BUFYPOS_LEN );
SpiceCommandAtBeginFile[ii].Trim( TRUE ); SpiceCommandAtBeginFile[ii].Trim( TRUE );
...@@ -480,9 +464,9 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, ...@@ -480,9 +464,9 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f,
fprintf( f, "%s ", CONV_TO_UTF8( Component->GetRef( sheet ) ) ); fprintf( f, "%s ", CONV_TO_UTF8( Component->GetRef( sheet ) ) );
// Write pin list: // Write pin list:
for( ii = 0; ii < s_SortedPinCount; ii++ ) for( unsigned ii = 0; ii < s_SortedComponentPinList.size(); ii++ )
{ {
ObjetNetListStruct* Pin = s_SortedComponentPinList[ii]; NETLIST_OBJECT* Pin = s_SortedComponentPinList[ii];
if( !Pin ) if( !Pin )
continue; continue;
wxString NetName = ReturnPinNetName( Pin, wxT( "N-%.6d" ) ); wxString NetName = ReturnPinNetName( Pin, wxT( "N-%.6d" ) );
...@@ -504,8 +488,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, ...@@ -504,8 +488,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f,
} }
} }
MyFree( s_SortedComponentPinList ); s_SortedComponentPinList.clear();
s_SortedComponentPinList = NULL;
/* Print texts starting by [+]pspice , ou [+]gnucap */ /* Print texts starting by [+]pspice , ou [+]gnucap */
nbitems = SpiceCommandAtEndFile.GetCount(); nbitems = SpiceCommandAtEndFile.GetCount();
...@@ -513,7 +496,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, ...@@ -513,7 +496,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f,
{ {
fprintf( f, "\n" ); fprintf( f, "\n" );
SpiceCommandAtEndFile.Sort(); SpiceCommandAtEndFile.Sort();
for( ii = 0; ii < nbitems; ii++ ) for( int ii = 0; ii < nbitems; ii++ )
{ {
SpiceCommandAtEndFile[ii].Remove( 0, +BUFYPOS_LEN ); SpiceCommandAtEndFile[ii].Remove( 0, +BUFYPOS_LEN );
SpiceCommandAtEndFile[ii].Trim( TRUE ); SpiceCommandAtEndFile[ii].Trim( TRUE );
...@@ -542,7 +525,6 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with ...@@ -542,7 +525,6 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
DrawSheetPath* sheet; DrawSheetPath* sheet;
EDA_BaseStruct* DrawList; EDA_BaseStruct* DrawList;
SCH_COMPONENT* Component; SCH_COMPONENT* Component;
int ii;
OBJ_CMP_TO_LIST* CmpList = NULL; OBJ_CMP_TO_LIST* CmpList = NULL;
int CmpListCount = 0, CmpListSize = 1000; int CmpListCount = 0, CmpListSize = 1000;
...@@ -618,15 +600,16 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with ...@@ -618,15 +600,16 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
fprintf( f, "\n" ); fprintf( f, "\n" );
// Write pin list: // Write pin list:
for( ii = 0; ii < s_SortedPinCount; ii++ ) for( unsigned ii = 0; ii < s_SortedComponentPinList.size(); ii++ )
{ {
ObjetNetListStruct* Pin = s_SortedComponentPinList[ii]; NETLIST_OBJECT* Pin = s_SortedComponentPinList[ii];
if( !Pin ) if( !Pin )
continue; continue;
wxString netname = ReturnPinNetName( Pin, wxT( "N-%.6d" ) ); wxString netname = ReturnPinNetName( Pin, wxT( "N-%.6d" ) );
if( netname.IsEmpty() ) if( netname.IsEmpty() )
netname = wxT( "?" ); netname = wxT( "?" );
netname.Replace( wxT( " " ), wxT( "_" ) ); netname.Replace( wxT( " " ), wxT( "_" ) );
fprintf( f, " ( %4.4s %s )\n", (char*) &Pin->m_PinNum, fprintf( f, " ( %4.4s %s )\n", (char*) &Pin->m_PinNum,
CONV_TO_UTF8( netname ) ); CONV_TO_UTF8( netname ) );
} }
...@@ -637,31 +620,29 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with ...@@ -637,31 +620,29 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
fprintf( f, ")\n*\n" ); fprintf( f, ")\n*\n" );
MyFree( s_SortedComponentPinList ); s_SortedComponentPinList.clear();
s_SortedComponentPinList = NULL;
/* Write the allowed footprint list for each component */ /* Write the allowed footprint list for each component */
if( with_pcbnew && CmpList ) if( with_pcbnew && CmpList )
{ {
fprintf( f, "{ Allowed footprints by component:\n" ); fprintf( f, "{ Allowed footprints by component:\n" );
EDA_LibComponentStruct* Entry; EDA_LibComponentStruct* Entry;
for( ii = 0; ii < CmpListCount; ii++ ) for( int ii = 0; ii < CmpListCount; ii++ )
{ {
Component = CmpList[ii].m_RootCmp; Component = CmpList[ii].m_RootCmp;
Entry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); Entry = FindLibPart( Component->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
//Line.Printf(_("%s"), CmpList[ii].m_Ref); //Line.Printf(_("%s"), CmpList[ii].m_Ref);
//Line.Replace( wxT( " " ), wxT( "_" ) ); //Line.Replace( wxT( " " ), wxT( "_" ) );
unsigned int i; for( unsigned nn = 0; nn<sizeof(CmpList[ii].m_Reference) && CmpList[ii].m_Reference[nn]; nn++ )
for( i = 0; i<sizeof(CmpList[ii].m_Reference) && CmpList[ii].m_Reference[i]; i++ )
{ {
if( CmpList[ii].m_Reference[i] == ' ' ) if( CmpList[ii].m_Reference[nn] == ' ' )
CmpList[ii].m_Reference[i] = '_'; CmpList[ii].m_Reference[nn] = '_';
} }
fprintf( f, "$component %s\n", CmpList[ii].m_Reference ); fprintf( f, "$component %s\n", CmpList[ii].m_Reference );
/* Write the footprint list */ /* Write the footprint list */
for( unsigned int jj = 0; jj < Entry->m_FootprintList.GetCount(); jj++ ) for( unsigned jj = 0; jj < Entry->m_FootprintList.GetCount(); jj++ )
{ {
fprintf( f, " %s\n", CONV_TO_UTF8( Entry->m_FootprintList[jj] ) ); fprintf( f, " %s\n", CONV_TO_UTF8( Entry->m_FootprintList[jj] ) );
} }
...@@ -677,7 +658,7 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with ...@@ -677,7 +658,7 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with
if( with_pcbnew ) if( with_pcbnew )
{ {
fprintf( f, "{ Pin List by Nets\n" ); fprintf( f, "{ Pin List by Nets\n" );
WriteGENERICListOfNets( f, g_TabObjNet ); WriteGENERICListOfNets( f, g_NetObjectslist );
fprintf( f, "}\n" ); fprintf( f, "}\n" );
fprintf( f, "#End\n" ); fprintf( f, "#End\n" );
} }
...@@ -691,38 +672,35 @@ static void AddPinToComponentPinList( SCH_COMPONENT* Component, ...@@ -691,38 +672,35 @@ static void AddPinToComponentPinList( SCH_COMPONENT* Component,
/* Add a new pin description in the pin list s_SortedComponentPinList /* Add a new pin description in the pin list s_SortedComponentPinList
* a pin description is a pointer to the corresponding structure * a pin description is a pointer to the corresponding structure
* created by BuildNetList() in the table g_TabObjNet * created by BuildNetList() in the table g_NetObjectslist
*/ */
{ {
int ii; /* Search the PIN description for Pin in g_NetObjectslist*/
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
/* Search the PIN description for Pin in g_TabObjNet*/
for( ii = 0; ii < g_NbrObjNet; ii++ )
{ {
if( g_TabObjNet[ii].m_Type != NET_PIN ) if( g_NetObjectslist[ii]->m_Type != NET_PIN )
continue; continue;
if( g_TabObjNet[ii].m_Link != Component ) if( g_NetObjectslist[ii]->m_Link != Component )
continue; continue;
if( g_TabObjNet[ii].m_SheetList != *sheetlist ) if( g_NetObjectslist[ii]->m_SheetList != *sheetlist )
continue; continue;
if( g_TabObjNet[ii].m_PinNum != Pin->m_PinNum ) if( g_NetObjectslist[ii]->m_PinNum != Pin->m_PinNum )
continue; continue;
s_SortedComponentPinList.push_back(g_NetObjectslist[ii]);
if( s_SortedComponentPinList.size() >= MAXPIN )
{ {
s_SortedComponentPinList[s_SortedPinCount] = &g_TabObjNet[ii]; /* Log message for Internal error */
s_SortedPinCount++; DisplayError( NULL, wxT( "AddPinToComponentPinList err: MAXPIN reached" ) );
if( s_SortedPinCount >= MAXPIN ) return;
{
/* Log message for Internal error */
DisplayError( NULL, wxT( "AddPinToComponentPinList err: MAXPIN reached" ) );
return;
}
} }
} }
} }
/**********************************************************************/ /**********************************************************************/
static void EraseDuplicatePins( ObjetNetListStruct** TabPin, int NbrPin ) static void EraseDuplicatePins( NETLIST_OBJECT_LIST& aPinList )
/**********************************************************************/ /**********************************************************************/
/* /*
...@@ -734,11 +712,13 @@ static void EraseDuplicatePins( ObjetNetListStruct** TabPin, int NbrPin ) ...@@ -734,11 +712,13 @@ static void EraseDuplicatePins( ObjetNetListStruct** TabPin, int NbrPin )
* in the list. * in the list.
*/ */
{ {
for( int ii = 0; ii < NbrPin - 1; ii++ ) for( unsigned ii = 0; ii < aPinList.size() - 1; ii++ )
{ {
if( TabPin[ii] == NULL ) if( aPinList[ii] == NULL )
continue; /* already deleted */ continue; /* already deleted */
if( TabPin[ii]->m_PinNum != TabPin[ii + 1]->m_PinNum ) if( aPinList[ii+1] == NULL )
continue; /* already tested and deleted */
if( aPinList[ii]->m_PinNum != aPinList[ii + 1]->m_PinNum )
continue; continue;
/* Duplicated Pins /* Duplicated Pins
* remove duplicates. The priority is to keep connected pins and remove unconnected * remove duplicates. The priority is to keep connected pins and remove unconnected
...@@ -746,23 +726,22 @@ static void EraseDuplicatePins( ObjetNetListStruct** TabPin, int NbrPin ) ...@@ -746,23 +726,22 @@ static void EraseDuplicatePins( ObjetNetListStruct** TabPin, int NbrPin )
* to connect only one op amp to power * to connect only one op amp to power
*/ */
int idxref = ii; int idxref = ii;
for( int jj = ii + 1; jj < NbrPin; jj++ ) for( unsigned jj = ii + 1; jj < aPinList.size(); jj++ )
{ {
if( TabPin[idxref]->m_PinNum != TabPin[jj]->m_PinNum ) if( aPinList[idxref]->m_PinNum != aPinList[jj]->m_PinNum )
break; break;
if ( TabPin[idxref]->GetNet() ) if ( aPinList[idxref]->m_FlagOfConnection == PAD_CONNECT )
TabPin[jj] = NULL; aPinList[jj] = NULL;
else else
{ /* the refernce pin is not connected: remove this pin if the other pin is connected */ { /* the reference pin is not connected: remove this pin if the other pin is connected */
if ( TabPin[jj]->GetNet() ) if ( aPinList[jj]->m_FlagOfConnection == PAD_CONNECT )
{ {
TabPin[idxref] = NULL; aPinList[idxref] = NULL;
idxref = jj; idxref = jj;
} }
else // the 2 pins are not connected: remove the tested pin, and continue ... else // the 2 pins are not connected: remove the tested pin, and continue ...
TabPin[jj] = NULL; aPinList[jj] = NULL;
} }
} }
} }
} }
...@@ -825,34 +804,33 @@ static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component_in, ...@@ -825,34 +804,33 @@ static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component_in,
/**************************************************************************/ /**************************************************************************/
static int SortPinsByNum( ObjetNetListStruct** Pin1, ObjetNetListStruct** Pin2 ) static bool SortPinsByNum( NETLIST_OBJECT* Pin1, NETLIST_OBJECT* Pin2 )
/**************************************************************************/ /**************************************************************************/
/* Routine de comparaison pour le tri des pins par numero croissant /* Routine de comparaison pour le tri des pins par numero croissant
* du tableau des pins s_SortedComponentPinList par qsort() * du tableau des pins s_SortedComponentPinList par qsort()
*/ */
{ {
ObjetNetListStruct* Obj1, * Obj2;
int Num1, Num2; int Num1, Num2;
char Line[5]; char Line[5];
Obj1 = *Pin1; Obj2 = *Pin2; Num1 = Pin1->m_PinNum;
Num1 = Obj1->m_PinNum; Num2 = Obj2->m_PinNum; Num2 = Pin2->m_PinNum;
Line[4] = 0; memcpy( Line, &Num1, 4 ); Num1 = atoi( Line ); Line[4] = 0;
memcpy( Line, &Num1, 4 ); Num1 = atoi( Line );
memcpy( Line, &Num2, 4 ); Num2 = atoi( Line ); memcpy( Line, &Num2, 4 ); Num2 = atoi( Line );
return Num1 - Num2; return Num1 < Num2;
} }
/*************************************************************************/ /*************************************************************************/
static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet ) static void WriteGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList )
/*************************************************************************/ /*************************************************************************/
/* Ecrit dans le fichier f la liste des nets ( classee par NetCodes ), et des /* Ecrit dans le fichier f la liste des nets ( classee par NetCodes ), et des
* elements qui y sont connectes * elements qui y sont connectes
*/ */
{ {
int ii, jj;
int NetCode, LastNetCode = -1; int NetCode, LastNetCode = -1;
int SameNetcodeCount = 0; int SameNetcodeCount = 0;
SCH_COMPONENT* Cmp; SCH_COMPONENT* Cmp;
...@@ -860,22 +838,23 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -860,22 +838,23 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet )
wxString NetcodeName; wxString NetcodeName;
char FirstItemInNet[1024]; char FirstItemInNet[1024];
for( ii = 0; ii < g_NbrObjNet; ii++ ) for( unsigned ii = 0; ii < aObjectsList.size(); ii++ )
{ {
if( ( NetCode = ObjNet[ii].GetNet() ) != LastNetCode ) // New net found, write net id; if( ( NetCode = aObjectsList[ii]->GetNet() ) != LastNetCode ) // New net found, write net id;
{ {
SameNetcodeCount = 0; // Items count for this net SameNetcodeCount = 0; // Items count for this net
NetName.Empty(); NetName.Empty();
for( jj = 0; jj < g_NbrObjNet; jj++ ) // Find a label (if exists) for this net unsigned jj;
for( jj = 0; jj < aObjectsList.size(); jj++ ) // Find a label (if exists) for this net
{ {
if( ObjNet[jj].GetNet() != NetCode ) if( aObjectsList[jj]->GetNet() != NetCode )
continue; continue;
if( ( ObjNet[jj].m_Type != NET_HIERLABEL) if( ( aObjectsList[jj]->m_Type != NET_HIERLABEL)
&& ( ObjNet[jj].m_Type != NET_LABEL) && ( aObjectsList[jj]->m_Type != NET_LABEL)
&& ( ObjNet[jj].m_Type != NET_PINLABEL) ) && ( aObjectsList[jj]->m_Type != NET_PINLABEL) )
continue; continue;
NetName = *g_TabObjNet[jj].m_Label; NetName = *aObjectsList[jj]->m_Label;
break; break;
} }
...@@ -883,10 +862,10 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -883,10 +862,10 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet )
NetcodeName += wxT( "\"" ); NetcodeName += wxT( "\"" );
if( !NetName.IsEmpty() ) if( !NetName.IsEmpty() )
{ {
if( g_TabObjNet[jj].m_Type != NET_PINLABEL ) if( aObjectsList[jj]->m_Type != NET_PINLABEL )
{ {
// usual net name, prefix it by the sheet path // usual net name, prefix it by the sheet path
NetcodeName += g_TabObjNet[jj].m_SheetList.PathHumanReadable(); NetcodeName += aObjectsList[jj]->m_SheetList.PathHumanReadable();
} }
NetcodeName += NetName; NetcodeName += NetName;
} }
...@@ -897,11 +876,11 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -897,11 +876,11 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet )
LastNetCode = NetCode; LastNetCode = NetCode;
} }
if( ObjNet[ii].m_Type != NET_PIN ) if( aObjectsList[ii]->m_Type != NET_PIN )
continue; continue;
Cmp = (SCH_COMPONENT*) ObjNet[ii].m_Link; Cmp = (SCH_COMPONENT*) aObjectsList[ii]->m_Link;
CmpRef = Cmp->GetRef( &ObjNet[ii].m_SheetList ); //is this correct? CmpRef = Cmp->GetRef( &aObjectsList[ii]->m_SheetList ); // Get the reference for thenetname and the main parent component
if( CmpRef.StartsWith( wxT( "#" ) ) ) if( CmpRef.StartsWith( wxT( "#" ) ) )
continue; // Pseudo component (Like Power symbol) continue; // Pseudo component (Like Power symbol)
...@@ -911,7 +890,7 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -911,7 +890,7 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet )
* Print this connection, when a second item will be found */ * Print this connection, when a second item will be found */
{ {
sprintf( FirstItemInNet, " %s %.4s\n", CONV_TO_UTF8( CmpRef ), sprintf( FirstItemInNet, " %s %.4s\n", CONV_TO_UTF8( CmpRef ),
(const char*) &ObjNet[ii].m_PinNum ); (const char*) &aObjectsList[ii]->m_PinNum );
} }
if( SameNetcodeCount == 2 ) // Second item for this net found, Print the Net name, and the first item if( SameNetcodeCount == 2 ) // Second item for this net found, Print the Net name, and the first item
{ {
...@@ -921,7 +900,7 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -921,7 +900,7 @@ static void WriteGENERICListOfNets( FILE* f, ObjetNetListStruct* ObjNet )
if( SameNetcodeCount >= 2 ) if( SameNetcodeCount >= 2 )
fprintf( f, " %s %.4s\n", CONV_TO_UTF8( CmpRef ), fprintf( f, " %s %.4s\n", CONV_TO_UTF8( CmpRef ),
(const char*) &ObjNet[ii].m_PinNum ); (const char*) &aObjectsList[ii]->m_PinNum );
} }
} }
...@@ -1009,17 +988,16 @@ static void WriteNetListCADSTAR( WinEDA_SchematicFrame* frame, FILE* f ) ...@@ -1009,17 +988,16 @@ static void WriteNetListCADSTAR( WinEDA_SchematicFrame* frame, FILE* f )
fprintf( f, "\n" ); fprintf( f, "\n" );
MyFree( s_SortedComponentPinList ); s_SortedComponentPinList.clear();
s_SortedComponentPinList = NULL;
WriteListOfNetsCADSTAR( f, g_TabObjNet ); WriteListOfNetsCADSTAR( f, g_NetObjectslist );
fprintf( f, "\n%sEND\n", CONV_TO_UTF8( StartLine ) ); fprintf( f, "\n%sEND\n", CONV_TO_UTF8( StartLine ) );
} }
/*************************************************************************/ /*************************************************************************/
static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet ) static void WriteListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList )
/*************************************************************************/ /*************************************************************************/
/* Ecrit dans le fichier f la liste des nets ( classee par NetCodes ), et des /* Ecrit dans le fichier f la liste des nets ( classee par NetCodes ), et des
...@@ -1033,43 +1011,44 @@ static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -1033,43 +1011,44 @@ static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet )
wxString InitNetDesc = StartLine + wxT( "ADD_TER" ); wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
wxString StartNetDesc = StartLine + wxT( "TER" ); wxString StartNetDesc = StartLine + wxT( "TER" );
wxString NetcodeName, InitNetDescLine; wxString NetcodeName, InitNetDescLine;
int ii, jj, print_ter = 0; unsigned ii, jj;
int print_ter = 0;
int NetCode, LastNetCode = -1; int NetCode, LastNetCode = -1;
SCH_COMPONENT* Cmp; SCH_COMPONENT* Cmp;
wxString NetName; wxString NetName;
for( ii = 0; ii < g_NbrObjNet; ii++ ) for( ii = 0; ii < aObjectsList.size(); ii++ )
ObjNet[ii].m_Flag = 0; aObjectsList[ii]->m_Flag = 0;
for( ii = 0; ii < g_NbrObjNet; ii++ ) for( ii = 0; ii < g_NetObjectslist.size(); ii++ )
{ {
// Get the NetName of the current net : // Get the NetName of the current net :
if( ( NetCode = ObjNet[ii].GetNet() ) != LastNetCode ) if( ( NetCode = aObjectsList[ii]->GetNet() ) != LastNetCode )
{ {
NetName.Empty(); NetName.Empty();
for( jj = 0; jj < g_NbrObjNet; jj++ ) for( jj = 0; jj < aObjectsList.size(); jj++ )
{ {
if( ObjNet[jj].GetNet() != NetCode ) if( aObjectsList[jj]->GetNet() != NetCode )
continue; continue;
if( ( ObjNet[jj].m_Type != NET_HIERLABEL) if( ( aObjectsList[jj]->m_Type != NET_HIERLABEL)
&& ( ObjNet[jj].m_Type != NET_LABEL) && ( aObjectsList[jj]->m_Type != NET_LABEL)
&& ( ObjNet[jj].m_Type != NET_PINLABEL) ) && ( aObjectsList[jj]->m_Type != NET_PINLABEL) )
continue; continue;
NetName = *ObjNet[jj].m_Label; break; NetName = *aObjectsList[jj]->m_Label; break;
} }
NetcodeName = wxT( "\"" ); NetcodeName = wxT( "\"" );
if( !NetName.IsEmpty() ) if( !NetName.IsEmpty() )
{ {
NetcodeName += NetName; NetcodeName += NetName;
if( g_TabObjNet[jj].m_Type != NET_PINLABEL ) if( aObjectsList[jj]->m_Type != NET_PINLABEL )
{ {
NetcodeName = g_TabObjNet[jj].m_SheetList.PathHumanReadable() NetcodeName = aObjectsList[jj]->m_SheetList.PathHumanReadable()
+ NetcodeName; + NetcodeName;
//NetcodeName << wxT("_") << //NetcodeName << wxT("_") <<
// g_TabObjNet[jj].m_SheetList.PathHumanReadable(); // g_NetObjectslist[jj].m_SheetList.PathHumanReadable();
} }
} }
else // this net has no name: create a default name $<net number> else // this net has no name: create a default name $<net number>
...@@ -1080,14 +1059,14 @@ static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -1080,14 +1059,14 @@ static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet )
} }
if( ObjNet[ii].m_Type != NET_PIN ) if( aObjectsList[ii]->m_Type != NET_PIN )
continue; continue;
if( ObjNet[ii].m_Flag != 0 ) if( aObjectsList[ii]->m_Flag != 0 )
continue; continue;
Cmp = (SCH_COMPONENT*) ObjNet[ii].m_Link; Cmp = (SCH_COMPONENT*) aObjectsList[ii]->m_Link;
wxString refstr = Cmp->GetRef( &(ObjNet[ii].m_SheetList) ); wxString refstr = Cmp->GetRef( &(aObjectsList[ii]->m_SheetList) );
if( refstr[0] == '#' ) if( refstr[0] == '#' )
continue; // Pseudo composant (symboles d'alims) continue; // Pseudo composant (symboles d'alims)
...@@ -1097,7 +1076,8 @@ static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -1097,7 +1076,8 @@ static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet )
{ {
char buf[5]; char buf[5];
wxString str_pinnum; wxString str_pinnum;
strncpy( buf, (char*) &ObjNet[ii].m_PinNum, 4 ); buf[4] = 0; strncpy( buf, (char*) &aObjectsList[ii]->m_PinNum, 4 );
buf[4] = 0;
str_pinnum = CONV_FROM_UTF8( buf ); str_pinnum = CONV_FROM_UTF8( buf );
InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ), InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
InitNetDesc.GetData(), InitNetDesc.GetData(),
...@@ -1112,36 +1092,36 @@ static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet ) ...@@ -1112,36 +1092,36 @@ static void WriteListOfNetsCADSTAR( FILE* f, ObjetNetListStruct* ObjNet )
fprintf( f, "%s %s %.4s\n", fprintf( f, "%s %s %.4s\n",
CONV_TO_UTF8( StartNetDesc ), CONV_TO_UTF8( StartNetDesc ),
CONV_TO_UTF8( refstr ), CONV_TO_UTF8( refstr ),
(char*) &ObjNet[ii].m_PinNum ); (char*) &aObjectsList[ii]->m_PinNum );
print_ter++; print_ter++;
break; break;
default: default:
fprintf( f, " %s %.4s\n", fprintf( f, " %s %.4s\n",
CONV_TO_UTF8( refstr ), CONV_TO_UTF8( refstr ),
(char*) &ObjNet[ii].m_PinNum ); (char*) &aObjectsList[ii]->m_PinNum );
break; break;
} }
ObjNet[ii].m_Flag = 1; aObjectsList[ii]->m_Flag = 1;
// Recherche des pins redondantes et mise a 1 de m_Flag, // Recherche des pins redondantes et mise a 1 de m_Flag,
// pour ne pas generer plusieurs fois la connexion // pour ne pas generer plusieurs fois la connexion
for( jj = ii + 1; jj < g_NbrObjNet; jj++ ) for( jj = ii + 1; jj < aObjectsList.size(); jj++ )
{ {
if( ObjNet[jj].GetNet() != NetCode ) if( aObjectsList[jj]->GetNet() != NetCode )
break; break;
if( ObjNet[jj].m_Type != NET_PIN ) if( aObjectsList[jj]->m_Type != NET_PIN )
continue; continue;
SCH_COMPONENT* tstcmp = SCH_COMPONENT* tstcmp =
(SCH_COMPONENT*) ObjNet[jj].m_Link; (SCH_COMPONENT*) aObjectsList[jj]->m_Link;
wxString p = Cmp->GetPath( &( ObjNet[ii].m_SheetList ) ); wxString p = Cmp->GetPath( &( aObjectsList[ii]->m_SheetList ) );
wxString tstp = tstcmp->GetPath( &( ObjNet[jj].m_SheetList ) ); wxString tstp = tstcmp->GetPath( &( aObjectsList[jj]->m_SheetList ) );
if( p.Cmp( tstp ) != 0 ) if( p.Cmp( tstp ) != 0 )
continue; continue;
if( ObjNet[jj].m_PinNum == ObjNet[ii].m_PinNum ) if( aObjectsList[jj]->m_PinNum == aObjectsList[ii]->m_PinNum )
ObjNet[jj].m_Flag = 1; aObjectsList[jj]->m_Flag = 1;
} }
} }
} }
...@@ -13,330 +13,203 @@ ...@@ -13,330 +13,203 @@
#include "netlist.h" /* Definitions generales liees au calcul de netliste */ #include "netlist.h" /* Definitions generales liees au calcul de netliste */
#include "protos.h" #include "protos.h"
int g_NbrObjNet; #include "algorithm"
ObjetNetListStruct* g_TabObjNet = NULL;
// Buffer to build the list of items used in netlist and erc calculations
NETLIST_OBJECT_LIST g_NetObjectslist;
//#define NETLIST_DEBUG //#define NETLIST_DEBUG
/* Routines locales */ /* Routines locales */
static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus ); static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus );
static void SheetLabelConnect( ObjetNetListStruct* SheetLabel ); static void SheetLabelConnect( NETLIST_OBJECT* SheetLabel );
static int ListeObjetConnection( DrawSheetPath* sheetlist, static void ListeObjetConnection( DrawSheetPath* sheetlist,
ObjetNetListStruct* ObjNet ); NETLIST_OBJECT_LIST& aNetItemBuffer );
static int ConvertBusToMembers( ObjetNetListStruct* ObjNet ); static int ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer,
static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, NETLIST_OBJECT& ObjNet );
static void PointToPointConnect( NETLIST_OBJECT* Ref, int IsBus,
int start ); int start );
static void SegmentToPointConnect( ObjetNetListStruct* Jonction, int IsBus, static void SegmentToPointConnect( NETLIST_OBJECT* Jonction, int IsBus,
int start ); int start );
static void LabelConnect( ObjetNetListStruct* Label ); static void LabelConnect( NETLIST_OBJECT* Label );
static int TriNetCode( const void* o1, const void* o2 ); static void ConnectBusLabels( NETLIST_OBJECT_LIST& aNetItemBuffer );
static void ConnectBusLabels( ObjetNetListStruct* Label, int NbItems ); static void SetUnconnectedFlag( NETLIST_OBJECT_LIST& aNetItemBuffer );
static void SetUnconnectedFlag( ObjetNetListStruct* ObjNet, int NbItems );
static int TriBySheet( const void* o1, const void* o2 ); // Sort functions used here:
static bool SortItemsbyNetcode( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 );
static bool SortItemsBySheet( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 );
/* Variable locales */ /* Variable locales */
static int FirstNumWireBus, LastNumWireBus, RootBusNameLength; static int FirstNumWireBus, LastNumWireBus, RootBusNameLength;
static int LastNetCode, LastBusNetCode; static int LastNetCode, LastBusNetCode;
static int s_PassNumber;
#if defined (DEBUG)
#include <iostream>
const char* ShowType( NetObjetType aType )
{
const char* ret;
switch( aType )
{
case NET_SEGMENT:
ret = "segment"; break;
case NET_BUS:
ret = "bus"; break;
case NET_JONCTION:
ret = "junction"; break;
case NET_LABEL:
ret = "label"; break;
case NET_HIERLABEL:
ret = "hierlabel"; break;
case NET_GLOBLABEL:
ret = "glabel"; break;
case NET_BUSLABELMEMBER:
ret = "buslblmember"; break;
case NET_HIERBUSLABELMEMBER:
ret = "hierbuslblmember"; break;
case NET_GLOBBUSLABELMEMBER:
ret = "gbuslblmember"; break;
case NET_SHEETBUSLABELMEMBER:
ret = "sbuslblmember"; break;
case NET_SHEETLABEL:
ret = "sheetlabel"; break;
case NET_PINLABEL:
ret = "pinlabel"; break;
case NET_PIN:
ret = "pin"; break;
case NET_NOCONNECT:
ret = "noconnect"; break;
default:
ret = "??"; break;
}
return ret;
}
void ObjetNetListStruct::Show( std::ostream& out, int ndx )
{
wxString path = m_SheetList.PathHumanReadable();
out << "<netItem ndx=\"" << ndx << '"' <<
" type=\"" << ShowType( m_Type ) << '"' <<
" netCode=\"" << GetNet() << '"' <<
" sheet=\"" << CONV_TO_UTF8( path ) << '"' <<
">\n";
out << " <start " << m_Start << "/> <end " << m_End << "/>\n";
if( m_Label )
out << " <label>" << m_Label->mb_str() << "</label>\n";
if( m_Comp )
m_Comp->Show( 1, out );
else
out << " m_Comp==NULL\n";
out << "</netItem>\n";
}
#if defined(DEBUG)
void dumpNetTable() void dumpNetTable()
{ {
for( int i = 0; i<g_NbrObjNet; ++i ) for( unsigned idx = 0; idx < g_NetObjectslist.size(); ++idx )
{ {
g_TabObjNet[i].Show( std::cout, i ); g_NetObjectslist[idx]->Show( std::cout, idx );
} }
} }
#endif #endif
/*********************************************************************/
/***********************************************************************/ void FreeNetObjectsList( NETLIST_OBJECT_LIST& aNetObjectsBuffer )
void FreeTabNetList( ObjetNetListStruct* TabNetItems, int NbrNetItems ) /*********************************************************************/
/***********************************************************************/
/* /*
* Routine de liberation memoire des tableaux utilises pour le calcul * Routine de liberation memoire des tableaux utilises pour le calcul
* de la netliste * de la netliste
* TabNetItems = pointeur sur le tableau principal (liste des items ) * TabNetItems = pointeur sur le tableau principal (liste des items )
* NbrNetItems = nombre d'elements
*/ */
{ {
int i; for( unsigned i = 0; i < aNetObjectsBuffer.size(); i++ )
delete aNetObjectsBuffer[i];
/* Liberation memoire des strings du champ Label reserve par ConvertBusToMembers */
for( i = 0; i < NbrNetItems; i++ )
{
switch( TabNetItems[i].m_Type )
{
case NET_PIN:
case NET_SHEETLABEL:
case NET_SEGMENT:
case NET_JONCTION:
case NET_BUS:
case NET_LABEL:
case NET_HIERLABEL:
case NET_GLOBLABEL:
case NET_PINLABEL:
case NET_NOCONNECT:
break;
case NET_HIERBUSLABELMEMBER: aNetObjectsBuffer.clear();
case NET_GLOBBUSLABELMEMBER:
case NET_SHEETBUSLABELMEMBER:
case NET_BUSLABELMEMBER:
SAFE_DELETE( TabNetItems[i].m_Label );
//see the note in ConvertBustToMembers
break;
}
}
MyFree( TabNetItems );
} }
/*****************************************************/ /************************************************************************/
void* WinEDA_SchematicFrame::BuildNetListBase() void WinEDA_SchematicFrame::BuildNetListBase()
/*****************************************************/ /************************************************************************/
/* Routine qui construit le tableau des elements connectes du projet /* Routine qui construit le tableau des elements connectes du projet
* met a jour: * met a jour:
* g_TabObjNet * g_NetObjectslist
* g_NbrObjNet * g_NetObjectslist
*/ */
{ {
int NetNumber; int NetNumber;
int i, istart, NetCode; int i, NetCode;
DrawSheetPath* sheet; DrawSheetPath* sheet;
wxString msg, activity; wxString msg, activity;
wxBusyCursor Busy; wxBusyCursor Busy;
NetNumber = 1; NetNumber = 1;
s_PassNumber = 0;
activity = _( "List" ); activity = _( "List" );
SetStatusText( activity ); SetStatusText( activity );
FreeNetObjectsList( g_NetObjectslist );
/* Build the sheet (not screen) list (flattened)*/ /* Build the sheet (not screen) list (flattened)*/
EDA_SheetList SheetListList; EDA_SheetList SheetListList;
i = 0; i = 0;
/* first pass : count objects used in connectivty calculation */
g_NbrObjNet = 0;
g_TabObjNet = NULL; /* Init pour le 1er passage dans ListeObjetConnection */
/* count nelist items */
for( sheet = SheetListList.GetFirst(); sheet != NULL; sheet = SheetListList.GetNext() )
{
g_NbrObjNet += ListeObjetConnection( sheet, NULL );
}
if( g_NbrObjNet == 0 )
{
DisplayError( this, _( "No component" ), 20 );
return NULL;
}
i = sizeof(ObjetNetListStruct) * g_NbrObjNet;
g_TabObjNet = (ObjetNetListStruct*) MyZMalloc( i );
if( g_TabObjNet == NULL )
return NULL;
/* second pass: fill the fields of the structures used in connectivty calculation */ /* Fill g_NetObjectslist with items used in connectivity calculation */
s_PassNumber++;
ObjetNetListStruct* tabObjNet = g_TabObjNet;
sheet = SheetListList.GetFirst(); sheet = SheetListList.GetFirst();
for( ; sheet != NULL; sheet = SheetListList.GetNext() ) for( ; sheet != NULL; sheet = SheetListList.GetNext() )
{ ListeObjetConnection( sheet, g_NetObjectslist );
int icnt = ListeObjetConnection( sheet, tabObjNet );
tabObjNet += icnt; // tabObjNet points the first free location in g_TabObjNet if( g_NetObjectslist.size() == 0 )
} return; // no objects
activity.Empty(); activity.Empty();
activity << wxT( " " ) << _( "NbItems" ) << wxT( " " ) << g_NbrObjNet; activity << wxT( " " ) << _( "NbItems" ) << wxT( " " ) << g_NetObjectslist.size();
SetStatusText( activity ); SetStatusText( activity );
/* Sort objects by Sheet */ /* Sort objects by Sheet */
qsort( g_TabObjNet, g_NbrObjNet, sizeof(ObjetNetListStruct), TriBySheet ); sort( g_NetObjectslist.begin(), g_NetObjectslist.end(), SortItemsBySheet );
activity << wxT( "; " ) << _( "Conn" ); activity << wxT( "; " ) << _( "Conn" );
SetStatusText( activity ); SetStatusText( activity );
sheet = &(g_TabObjNet[0].m_SheetList); sheet = &(g_NetObjectslist[0]->m_SheetList);
LastNetCode = LastBusNetCode = 1; LastNetCode = LastBusNetCode = 1;
for( i = istart = 0; i<g_NbrObjNet; i++ ) for( unsigned i = 0, istart = 0; i < g_NetObjectslist.size(); i++ )
{ {
if( g_TabObjNet[i].m_SheetList != *sheet ) if( g_NetObjectslist[i]->m_SheetList != *sheet )
{ {
sheet = &(g_TabObjNet[i].m_SheetList); sheet = &(g_NetObjectslist[i]->m_SheetList);
istart = i;
} }
switch( g_TabObjNet[i].m_Type ) switch( g_NetObjectslist[i]->m_Type )
{ {
case NET_ITEM_UNSPECIFIED:
wxMessageBox(wxT("BuildNetListBase() error"));
break;
case NET_PIN: case NET_PIN:
case NET_PINLABEL: case NET_PINLABEL:
case NET_SHEETLABEL: case NET_SHEETLABEL:
case NET_NOCONNECT: case NET_NOCONNECT:
if( g_TabObjNet[i].GetNet() != 0 ) if( g_NetObjectslist[i]->GetNet() != 0 )
break; /* Deja connecte */ break; /* Deja connecte */
case NET_SEGMENT: case NET_SEGMENT:
/* Controle des connexions type point a point ( Sans BUS ) */ /* Controle des connexions type point a point ( Sans BUS ) */
if( g_TabObjNet[i].GetNet() == 0 ) if( g_NetObjectslist[i]->GetNet() == 0 )
{ {
g_TabObjNet[i].SetNet( LastNetCode ); g_NetObjectslist[i]->SetNet( LastNetCode );
LastNetCode++; LastNetCode++;
} }
PointToPointConnect( g_TabObjNet + i, 0, istart ); PointToPointConnect( g_NetObjectslist[i], 0, istart );
break; break;
case NET_JONCTION: case NET_JONCTION:
/* Controle des jonction , hors BUS */ /* Controle des jonction , hors BUS */
if( g_TabObjNet[i].GetNet() == 0 ) if( g_NetObjectslist[i]->GetNet() == 0 )
{ {
g_TabObjNet[i].SetNet( LastNetCode ); g_NetObjectslist[i]->SetNet( LastNetCode );
LastNetCode++; LastNetCode++;
} }
SegmentToPointConnect( g_TabObjNet + i, 0, istart ); SegmentToPointConnect( g_NetObjectslist[i], 0, istart );
/* Controle des jonction , sur BUS */ /* Controle des jonction , sur BUS */
if( g_TabObjNet[i].m_BusNetCode == 0 ) if( g_NetObjectslist[i]->m_BusNetCode == 0 )
{ {
g_TabObjNet[i].m_BusNetCode = LastBusNetCode; g_NetObjectslist[i]->m_BusNetCode = LastBusNetCode;
LastBusNetCode++; LastBusNetCode++;
} }
SegmentToPointConnect( g_TabObjNet + i, ISBUS, istart ); SegmentToPointConnect( g_NetObjectslist[i], ISBUS, istart );
break; break;
case NET_LABEL: case NET_LABEL:
case NET_HIERLABEL: case NET_HIERLABEL:
case NET_GLOBLABEL: case NET_GLOBLABEL:
/* Controle des connexions type jonction ( Sans BUS ) */ /* Controle des connexions type jonction ( Sans BUS ) */
if( g_TabObjNet[i].GetNet() == 0 ) if( g_NetObjectslist[i]->GetNet() == 0 )
{ {
g_TabObjNet[i].SetNet( LastNetCode ); g_NetObjectslist[i]->SetNet( LastNetCode );
LastNetCode++; LastNetCode++;
} }
SegmentToPointConnect( g_TabObjNet + i, 0, istart ); SegmentToPointConnect( g_NetObjectslist[i], 0, istart );
break; break;
case NET_SHEETBUSLABELMEMBER: case NET_SHEETBUSLABELMEMBER:
if( g_TabObjNet[i].m_BusNetCode != 0 ) if( g_NetObjectslist[i]->m_BusNetCode != 0 )
break; /* Deja connecte */ break; /* Deja connecte */
case NET_BUS: case NET_BUS:
/* Controle des connexions type point a point mode BUS */ /* Controle des connexions type point a point mode BUS */
if( g_TabObjNet[i].m_BusNetCode == 0 ) if( g_NetObjectslist[i]->m_BusNetCode == 0 )
{ {
g_TabObjNet[i].m_BusNetCode = LastBusNetCode; g_NetObjectslist[i]->m_BusNetCode = LastBusNetCode;
LastBusNetCode++; LastBusNetCode++;
} }
PointToPointConnect( g_TabObjNet + i, ISBUS, istart ); PointToPointConnect( g_NetObjectslist[i], ISBUS, istart );
break; break;
case NET_BUSLABELMEMBER: case NET_BUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER: case NET_HIERBUSLABELMEMBER:
case NET_GLOBBUSLABELMEMBER: case NET_GLOBBUSLABELMEMBER:
/* Controle des connexions semblables a des sur BUS */ /* Controle des connexions semblables a des sur BUS */
if( g_TabObjNet[i].GetNet() == 0 ) if( g_NetObjectslist[i]->GetNet() == 0 )
{ {
g_TabObjNet[i].m_BusNetCode = LastBusNetCode; g_NetObjectslist[i]->m_BusNetCode = LastBusNetCode;
LastBusNetCode++; LastBusNetCode++;
} }
SegmentToPointConnect( g_TabObjNet + i, ISBUS, istart ); SegmentToPointConnect( g_NetObjectslist[i], ISBUS, istart );
break; break;
} }
} }
#if defined (NETLIST_DEBUG) && defined (DEBUG) #if defined(NETLIST_DEBUG) && defined(DEBUG)
std::cout << "\n\nafter sheet local\n\n"; std::cout << "\n\nafter sheet local\n\n";
dumpNetTable(); dumpNetTable();
#endif #endif
...@@ -346,15 +219,15 @@ void* WinEDA_SchematicFrame::BuildNetListBase() ...@@ -346,15 +219,15 @@ void* WinEDA_SchematicFrame::BuildNetListBase()
SetStatusText( activity ); SetStatusText( activity );
/* Mise a jour des NetCodes des Bus Labels connectes par les Bus */ /* Mise a jour des NetCodes des Bus Labels connectes par les Bus */
ConnectBusLabels( g_TabObjNet, g_NbrObjNet ); ConnectBusLabels( g_NetObjectslist );
activity << wxT( "; " ) << _( "Labels" ); activity << wxT( "; " ) << _( "Labels" );
SetStatusText( activity ); SetStatusText( activity );
/* Connections des groupes d'objets par labels identiques */ /* Connections des groupes d'objets par labels identiques */
for( i = 0; i<g_NbrObjNet; i++ ) for( unsigned i = 0; i<g_NetObjectslist.size(); i++ )
{ {
switch( g_TabObjNet[i].m_Type ) switch( g_NetObjectslist[i]->m_Type )
{ {
case NET_PIN: case NET_PIN:
case NET_SHEETLABEL: case NET_SHEETLABEL:
...@@ -369,17 +242,19 @@ void* WinEDA_SchematicFrame::BuildNetListBase() ...@@ -369,17 +242,19 @@ void* WinEDA_SchematicFrame::BuildNetListBase()
case NET_PINLABEL: case NET_PINLABEL:
case NET_BUSLABELMEMBER: case NET_BUSLABELMEMBER:
case NET_GLOBBUSLABELMEMBER: case NET_GLOBBUSLABELMEMBER:
LabelConnect( g_TabObjNet + i ); LabelConnect( g_NetObjectslist[i] );
break; break;
case NET_SHEETBUSLABELMEMBER: case NET_SHEETBUSLABELMEMBER:
case NET_HIERLABEL: case NET_HIERLABEL:
case NET_HIERBUSLABELMEMBER: case NET_HIERBUSLABELMEMBER:
break; break;
case NET_ITEM_UNSPECIFIED:
break;
} }
} }
#if defined (NETLIST_DEBUG) && defined (DEBUG) #if defined(NETLIST_DEBUG) && defined(DEBUG)
std::cout << "\n\nafter sheet global\n\n"; std::cout << "\n\nafter sheet global\n\n";
dumpNetTable(); dumpNetTable();
#endif #endif
...@@ -391,18 +266,18 @@ void* WinEDA_SchematicFrame::BuildNetListBase() ...@@ -391,18 +266,18 @@ void* WinEDA_SchematicFrame::BuildNetListBase()
activity << wxT( "; " ) << _( "Hierar." ); activity << wxT( "; " ) << _( "Hierar." );
SetStatusText( activity ); SetStatusText( activity );
for( i = 0; i<g_NbrObjNet; i++ ) for( unsigned i = 0; i< g_NetObjectslist.size(); i++ )
{ {
if( g_TabObjNet[i].m_Type == NET_SHEETLABEL if( g_NetObjectslist[i]->m_Type == NET_SHEETLABEL
|| g_TabObjNet[i].m_Type == NET_SHEETBUSLABELMEMBER ) || g_NetObjectslist[i]->m_Type == NET_SHEETBUSLABELMEMBER )
SheetLabelConnect( g_TabObjNet + i ); SheetLabelConnect( g_NetObjectslist[i] );
} }
/* Sort objects by NetCode */ /* Sort objects by NetCode */
qsort( g_TabObjNet, g_NbrObjNet, sizeof(ObjetNetListStruct), TriNetCode ); sort( g_NetObjectslist.begin(), g_NetObjectslist.end(), SortItemsbyNetcode );
#if defined (NETLIST_DEBUG) && defined (DEBUG) #if defined(NETLIST_DEBUG) && defined(DEBUG)
std::cout << "after qsort()\n"; std::cout << "after qsort()\n";
dumpNetTable(); dumpNetTable();
#endif #endif
...@@ -414,34 +289,29 @@ void* WinEDA_SchematicFrame::BuildNetListBase() ...@@ -414,34 +289,29 @@ void* WinEDA_SchematicFrame::BuildNetListBase()
activity << wxT( "; " ) << _( "Sorting Nets" ); activity << wxT( "; " ) << _( "Sorting Nets" );
SetStatusText( activity ); SetStatusText( activity );
LastNetCode = NetCode = 0; LastNetCode = NetCode = 0;
for( i = 0; i < g_NbrObjNet; i++ ) for( unsigned i = 0; i < g_NetObjectslist.size(); i++ )
{ {
if( g_TabObjNet[i].GetNet() != LastNetCode ) if( g_NetObjectslist[i]->GetNet() != LastNetCode )
{ {
NetCode++; NetCode++;
LastNetCode = g_TabObjNet[i].GetNet(); LastNetCode = g_NetObjectslist[i]->GetNet();
} }
g_TabObjNet[i].SetNet( NetCode ); g_NetObjectslist[i]->SetNet( NetCode );
} }
activity << wxT( " " ) << _( "Done" ); activity << wxT( " " ) << _( "Done" );
SetStatusText( activity ); SetStatusText( activity );
/* Affectation du m_FlagOfConnection en fonction de connection ou non */ /* Affectation du m_FlagOfConnection en fonction de connection ou non */
SetUnconnectedFlag( g_TabObjNet, g_NbrObjNet ); SetUnconnectedFlag( g_NetObjectslist );
return (void*) g_TabObjNet;
} }
/************************************************************* /*************************************************************
* Routine qui connecte les sous feuilles par les sheetLabels * * Routine qui connecte les sous feuilles par les sheetLabels *
**************************************************************/ **************************************************************/
static void SheetLabelConnect( ObjetNetListStruct* SheetLabel ) static void SheetLabelConnect( NETLIST_OBJECT* SheetLabel )
{ {
int i;
ObjetNetListStruct* ObjetNet;
if( SheetLabel->GetNet() == 0 ) if( SheetLabel->GetNet() == 0 )
return; return;
...@@ -449,43 +319,46 @@ static void SheetLabelConnect( ObjetNetListStruct* SheetLabel ) ...@@ -449,43 +319,46 @@ static void SheetLabelConnect( ObjetNetListStruct* SheetLabel )
/* Comparaison du SheetLabel avec les GLABELS de la sous feuille /* Comparaison du SheetLabel avec les GLABELS de la sous feuille
* pour regroupement des NetCodes */ * pour regroupement des NetCodes */
for( i = 0, ObjetNet = g_TabObjNet; i < g_NbrObjNet; i++ ) for( unsigned i = 0; i < g_NetObjectslist.size(); i++ )
{ {
if( ObjetNet[i].m_SheetList != SheetLabel->m_SheetListInclude ) NETLIST_OBJECT* ObjetNet = g_NetObjectslist[i];
if( ObjetNet->m_SheetList != SheetLabel->m_SheetListInclude )
continue; //use SheetInclude, not the sheet!! continue; //use SheetInclude, not the sheet!!
if( (ObjetNet[i].m_Type != NET_HIERLABEL ) if( (ObjetNet->m_Type != NET_HIERLABEL )
&& (ObjetNet[i].m_Type != NET_HIERBUSLABELMEMBER ) ) && (ObjetNet->m_Type != NET_HIERBUSLABELMEMBER ) )
continue; continue;
if( ObjetNet[i].GetNet() == SheetLabel->GetNet() ) if( ObjetNet->GetNet() == SheetLabel->GetNet() )
continue; //already connected. continue; //already connected.
if( ObjetNet[i].m_Label->CmpNoCase( *SheetLabel->m_Label ) != 0 ) if( ObjetNet->m_Label->CmpNoCase( *SheetLabel->m_Label ) != 0 )
continue; //different names. continue; //different names.
/* Propagation du Netcode a tous les Objets de meme NetCode */ /* Propagation du Netcode a tous les Objets de meme NetCode */
if( ObjetNet[i].GetNet() ) if( ObjetNet->GetNet() )
PropageNetCode( ObjetNet[i].GetNet(), SheetLabel->GetNet(), 0 ); PropageNetCode( ObjetNet[i].GetNet(), SheetLabel->GetNet(), 0 );
else else
ObjetNet[i].SetNet( SheetLabel->GetNet() ); ObjetNet->SetNet( SheetLabel->GetNet() );
} }
} }
/**************************************************************************************/ /**************************************************************************************/
static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* ObjNet ) static void ListeObjetConnection( DrawSheetPath* sheetlist,
std::vector<NETLIST_OBJECT*>& aNetItemBuffer )
/**************************************************************************************/ /**************************************************************************************/
/** Function ListeObjetConnection /** Function ListeObjetConnection
* Creates the list of objects related to connections (pins of components, wires, labels, junctions ...) * Creates the list of objects related to connections (pins of components, wires, labels, junctions ...)
* @param sheetlist: pointer to a sheetlist. * @param sheetlist: pointer to a sheetlist.
* @param ObjNet: if NULL, objects count else list to fill * @param aNetItemBuffer: a std::vector to store pointer on NETLIST_OBJECT created
*/ */
{ {
int ii, NbrItem = 0; int ii;
EDA_BaseStruct* DrawList; SCH_ITEM* DrawList;
SCH_COMPONENT* DrawLibItem; NETLIST_OBJECT* new_item;
SCH_COMPONENT* DrawLibItem;
EDA_LibComponentStruct* Entry; EDA_LibComponentStruct* Entry;
LibEDA_BaseStruct* DEntry; LibEDA_BaseStruct* DEntry;
Hierarchical_PIN_Sheet_Struct* SheetLabel; Hierarchical_PIN_Sheet_Struct* SheetLabel;
...@@ -499,81 +372,80 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O ...@@ -499,81 +372,80 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O
case DRAW_SEGMENT_STRUCT_TYPE: case DRAW_SEGMENT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ( (EDA_DrawLineStruct*) DrawList ) #define STRUCT ( (EDA_DrawLineStruct*) DrawList )
if( ObjNet ) if( (STRUCT->GetLayer() != LAYER_BUS) && (STRUCT->GetLayer() != LAYER_WIRE) )
{ break;
if( (STRUCT->GetLayer() != LAYER_BUS) && (STRUCT->GetLayer() != LAYER_WIRE) )
break;
ObjNet[NbrItem].m_SheetList = *sheetlist; new_item = new NETLIST_OBJECT();
ObjNet[NbrItem].m_SheetListInclude = *sheetlist; new_item->m_SheetList = *sheetlist;
ObjNet[NbrItem].m_Comp = STRUCT; new_item->m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_Start = STRUCT->m_Start; new_item->m_Comp = STRUCT;
ObjNet[NbrItem].m_End = STRUCT->m_End; new_item->m_Start = STRUCT->m_Start;
new_item->m_End = STRUCT->m_End;
if( STRUCT->GetLayer() == LAYER_BUS ) if( STRUCT->GetLayer() == LAYER_BUS )
{ {
ObjNet[NbrItem].m_Type = NET_BUS; new_item->m_Type = NET_BUS;
}
else /* Cas des WIRE */
{
ObjNet[NbrItem].m_Type = NET_SEGMENT;
}
} }
NbrItem++; else /* Cas des WIRE */
{
new_item->m_Type = NET_SEGMENT;
}
aNetItemBuffer.push_back( new_item );
break; break;
case DRAW_JUNCTION_STRUCT_TYPE: case DRAW_JUNCTION_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ( (DrawJunctionStruct*) DrawList ) #define STRUCT ( (DrawJunctionStruct*) DrawList )
if( ObjNet ) new_item = new NETLIST_OBJECT();
{
ObjNet[NbrItem].m_SheetList = *sheetlist; new_item->m_SheetList = *sheetlist;
ObjNet[NbrItem].m_SheetListInclude = *sheetlist; new_item->m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_Comp = STRUCT; new_item->m_Comp = STRUCT;
ObjNet[NbrItem].m_Type = NET_JONCTION; new_item->m_Type = NET_JONCTION;
ObjNet[NbrItem].m_Start = ObjNet[NbrItem].m_End = STRUCT->m_Pos; new_item->m_Start = new_item->m_End = STRUCT->m_Pos;
}
NbrItem++; aNetItemBuffer.push_back( new_item );
break; break;
case DRAW_NOCONNECT_STRUCT_TYPE: case DRAW_NOCONNECT_STRUCT_TYPE:
#undef STRUCT #undef STRUCT
#define STRUCT ( (DrawNoConnectStruct*) DrawList ) #define STRUCT ( (DrawNoConnectStruct*) DrawList )
if( ObjNet ) new_item = new NETLIST_OBJECT();
{
ObjNet[NbrItem].m_SheetList = *sheetlist; new_item->m_SheetList = *sheetlist;
ObjNet[NbrItem].m_SheetListInclude = *sheetlist; new_item->m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_Comp = STRUCT; new_item->m_Comp = STRUCT;
ObjNet[NbrItem].m_Type = NET_NOCONNECT; new_item->m_Type = NET_NOCONNECT;
ObjNet[NbrItem].m_Start = ObjNet[NbrItem].m_End = STRUCT->m_Pos; new_item->m_Start = new_item->m_End = STRUCT->m_Pos;
}
NbrItem++; aNetItemBuffer.push_back( new_item );
break; break;
case TYPE_SCH_LABEL: case TYPE_SCH_LABEL:
#undef STRUCT #undef STRUCT
#define STRUCT ( (SCH_LABEL*) DrawList ) #define STRUCT ( (SCH_LABEL*) DrawList )
ii = IsBusLabel( STRUCT->m_Text ); ii = IsBusLabel( STRUCT->m_Text );
if( ObjNet )
{
ObjNet[NbrItem].m_SheetList = *sheetlist;
ObjNet[NbrItem].m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_Comp = STRUCT;
ObjNet[NbrItem].m_Type = NET_LABEL;
if( STRUCT->m_Layer == LAYER_GLOBLABEL ) new_item = new NETLIST_OBJECT();
ObjNet[NbrItem].m_Type = NET_GLOBLABEL; new_item->m_SheetList = *sheetlist;
if( STRUCT->m_Layer == LAYER_HIERLABEL ) new_item->m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_Type = NET_HIERLABEL; new_item->m_Comp = STRUCT;
new_item->m_Type = NET_LABEL;
if( STRUCT->m_Layer == LAYER_GLOBLABEL )
new_item->m_Type = NET_GLOBLABEL;
if( STRUCT->m_Layer == LAYER_HIERLABEL )
new_item->m_Type = NET_HIERLABEL;
new_item->m_Label = &STRUCT->m_Text;
new_item->m_Start = new_item->m_End = STRUCT->m_Pos;
aNetItemBuffer.push_back( new_item );
/* Si c'est un Bus, eclatement en Label */
if( ii )
ConvertBusToMembers( aNetItemBuffer, *new_item );
ObjNet[NbrItem].m_Label = &STRUCT->m_Text;
ObjNet[NbrItem].m_Start = ObjNet[NbrItem].m_End = STRUCT->m_Pos;
/* Si c'est un Bus, eclatement en Label */
if( ii )
ConvertBusToMembers( ObjNet + NbrItem );
}
NbrItem += ii + 1;
break; break;
case TYPE_SCH_GLOBALLABEL: case TYPE_SCH_GLOBALLABEL:
...@@ -581,26 +453,26 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O ...@@ -581,26 +453,26 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O
#undef STRUCT #undef STRUCT
#define STRUCT ( (SCH_LABEL*) DrawList ) #define STRUCT ( (SCH_LABEL*) DrawList )
ii = IsBusLabel( STRUCT->m_Text ); ii = IsBusLabel( STRUCT->m_Text );
if( ObjNet ) new_item = new NETLIST_OBJECT();
{ new_item->m_SheetList = *sheetlist;
ObjNet[NbrItem].m_SheetList = *sheetlist; new_item->m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_SheetListInclude = *sheetlist; new_item->m_Comp = STRUCT;
ObjNet[NbrItem].m_Comp = STRUCT; new_item->m_Type = NET_LABEL;
ObjNet[NbrItem].m_Type = NET_LABEL;
if( STRUCT->m_Layer == LAYER_GLOBLABEL ) //this is not the simplest way of doing it if( STRUCT->m_Layer == LAYER_GLOBLABEL ) //this is not the simplest way of doing it
ObjNet[NbrItem].m_Type = NET_GLOBLABEL; // (look at the case statement above). new_item->m_Type = NET_GLOBLABEL; // (look at the case statement above).
if( STRUCT->m_Layer == LAYER_HIERLABEL ) if( STRUCT->m_Layer == LAYER_HIERLABEL )
ObjNet[NbrItem].m_Type = NET_HIERLABEL; new_item->m_Type = NET_HIERLABEL;
new_item->m_Label = &STRUCT->m_Text;
new_item->m_Start = new_item->m_End = STRUCT->m_Pos;
aNetItemBuffer.push_back( new_item );
/* Si c'est un Bus, eclatement en Label */
if( ii )
ConvertBusToMembers( aNetItemBuffer, *new_item );
ObjNet[NbrItem].m_Label = &STRUCT->m_Text;
ObjNet[NbrItem].m_Start = ObjNet[NbrItem].m_End = STRUCT->m_Pos;
/* Si c'est un Bus, eclatement en Label */
if( ii )
ConvertBusToMembers( ObjNet + NbrItem );
}
NbrItem += ii + 1;
break; break;
case TYPE_SCH_COMPONENT: case TYPE_SCH_COMPONENT:
...@@ -631,37 +503,35 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O ...@@ -631,37 +503,35 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O
wxPoint pos2 = wxPoint pos2 =
TransformCoordinate( DrawLibItem->m_Transform, TransformCoordinate( DrawLibItem->m_Transform,
Pin->m_Pos ) + DrawLibItem->m_Pos; Pin->m_Pos ) + DrawLibItem->m_Pos;
if( ObjNet ) new_item = new NETLIST_OBJECT();
{ new_item->m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_SheetListInclude = *sheetlist; new_item->m_Comp = DEntry;
ObjNet[NbrItem].m_Comp = DEntry; new_item->m_SheetList = *sheetlist;
ObjNet[NbrItem].m_SheetList = *sheetlist; new_item->m_Type = NET_PIN;
ObjNet[NbrItem].m_Type = NET_PIN; new_item->m_Link = DrawLibItem;
ObjNet[NbrItem].m_Link = DrawLibItem; new_item->m_ElectricalType = Pin->m_PinType;
ObjNet[NbrItem].m_ElectricalType = Pin->m_PinType; new_item->m_PinNum = Pin->m_PinNum;
ObjNet[NbrItem].m_PinNum = Pin->m_PinNum; new_item->m_Label = &Pin->m_PinName;
ObjNet[NbrItem].m_Label = &Pin->m_PinName; new_item->m_Start = new_item->m_End = pos2;
ObjNet[NbrItem].m_Start = ObjNet[NbrItem].m_End = pos2;
} aNetItemBuffer.push_back( new_item );
NbrItem++;
if( ( (int) Pin->m_PinType == (int) PIN_POWER_IN ) if( ( (int) Pin->m_PinType == (int) PIN_POWER_IN )
&& ( Pin->m_Attributs & PINNOTDRAW ) ) && ( Pin->m_Attributs & PINNOTDRAW ) )
{ {
/* Il y a un PIN_LABEL Associe */ /* Il y a un PIN_LABEL Associe */
if( ObjNet ) new_item = new NETLIST_OBJECT();
{ new_item->m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_SheetListInclude = *sheetlist; new_item->m_Comp = NULL;
ObjNet[NbrItem].m_Comp = NULL; new_item->m_SheetList = *sheetlist;
ObjNet[NbrItem].m_SheetList = *sheetlist; new_item->m_Type = NET_PINLABEL;
ObjNet[NbrItem].m_Type = NET_PINLABEL; new_item->m_Label = &Pin->m_PinName;
ObjNet[NbrItem].m_Label = &Pin->m_PinName; new_item->m_Start = pos2;
ObjNet[NbrItem].m_Start = pos2; new_item->m_End = new_item->m_Start;
ObjNet[NbrItem].m_End = ObjNet[NbrItem].m_Start;
} aNetItemBuffer.push_back( new_item );
NbrItem++;
} }
} }
...@@ -681,26 +551,24 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O ...@@ -681,26 +551,24 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O
list.Push( STRUCT ); list.Push( STRUCT );
SheetLabel = STRUCT->m_Label; SheetLabel = STRUCT->m_Label;
for( ; SheetLabel != NULL; for( ; SheetLabel != NULL;
SheetLabel = SheetLabel->Next() ) SheetLabel = SheetLabel->Next() )
{ {
ii = IsBusLabel( SheetLabel->m_Text ); ii = IsBusLabel( SheetLabel->m_Text );
if( ObjNet ) new_item = new NETLIST_OBJECT();
{ new_item->m_SheetListInclude = *sheetlist;
ObjNet[NbrItem].m_SheetListInclude = *sheetlist; new_item->m_Comp = SheetLabel;
ObjNet[NbrItem].m_Comp = SheetLabel; new_item->m_SheetList = *sheetlist;
ObjNet[NbrItem].m_SheetList = *sheetlist; new_item->m_Link = DrawList;
ObjNet[NbrItem].m_Link = DrawList; new_item->m_Type = NET_SHEETLABEL;
ObjNet[NbrItem].m_Type = NET_SHEETLABEL; new_item->m_ElectricalType = SheetLabel->m_Shape;
ObjNet[NbrItem].m_ElectricalType = SheetLabel->m_Shape; new_item->m_Label = &SheetLabel->m_Text;
ObjNet[NbrItem].m_Label = &SheetLabel->m_Text; new_item->m_SheetListInclude = list;
ObjNet[NbrItem].m_SheetListInclude = list; new_item->m_Start = new_item->m_End = SheetLabel->m_Pos;
ObjNet[NbrItem].m_Start = ObjNet[NbrItem].m_End = SheetLabel->m_Pos; aNetItemBuffer.push_back( new_item );
/* Si c'est un Bus, eclatement en Label */ /* Si c'est un Bus, eclatement en Label */
if( ii ) if( ii )
ConvertBusToMembers( ObjNet + NbrItem ); ConvertBusToMembers( aNetItemBuffer, *new_item );
}
NbrItem += ii + 1;
} }
break; break;
...@@ -713,19 +581,17 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O ...@@ -713,19 +581,17 @@ static int ListeObjetConnection( DrawSheetPath* sheetlist, ObjetNetListStruct* O
{ {
wxString msg; wxString msg;
msg.Printf( wxT( "Netlist: unexpected type struct %d" ), msg.Printf( wxT( "Netlist: unexpected type struct %d" ),
DrawList->Type() ); DrawList->Type() );
DisplayError( NULL, msg ); DisplayError( NULL, msg );
break; break;
} }
} }
} }
return NbrItem;
} }
/************************************************************************/ /************************************************************************/
static void ConnectBusLabels( ObjetNetListStruct* Label, int NbItems ) static void ConnectBusLabels( NETLIST_OBJECT_LIST& aNetItemBuffer )
/************************************************************************/ /************************************************************************/
/* Routine qui analyse les labels type xxBUSLABELMEMBER /* Routine qui analyse les labels type xxBUSLABELMEMBER
...@@ -735,12 +601,9 @@ static void ConnectBusLabels( ObjetNetListStruct* Label, int NbItems ) ...@@ -735,12 +601,9 @@ static void ConnectBusLabels( ObjetNetListStruct* Label, int NbItems )
* Utilise et met a jour la variable LastNetCode * Utilise et met a jour la variable LastNetCode
*/ */
{ {
ObjetNetListStruct* LabelInTst, * Lim; for( unsigned ii = 0; ii < aNetItemBuffer.size(); ii++ )
Lim = Label + NbItems;
for( ; Label < Lim; Label++ )
{ {
NETLIST_OBJECT* Label = aNetItemBuffer[ii];
if( (Label->m_Type == NET_SHEETBUSLABELMEMBER) if( (Label->m_Type == NET_SHEETBUSLABELMEMBER)
|| (Label->m_Type == NET_BUSLABELMEMBER) || (Label->m_Type == NET_BUSLABELMEMBER)
|| (Label->m_Type == NET_HIERBUSLABELMEMBER) ) || (Label->m_Type == NET_HIERBUSLABELMEMBER) )
...@@ -751,8 +614,9 @@ static void ConnectBusLabels( ObjetNetListStruct* Label, int NbItems ) ...@@ -751,8 +614,9 @@ static void ConnectBusLabels( ObjetNetListStruct* Label, int NbItems )
LastNetCode++; LastNetCode++;
} }
for( LabelInTst = Label + 1; LabelInTst < Lim; LabelInTst++ ) for( unsigned jj = ii + 1; jj < aNetItemBuffer.size(); jj++ )
{ {
NETLIST_OBJECT* LabelInTst = aNetItemBuffer[jj];
if( (LabelInTst->m_Type == NET_SHEETBUSLABELMEMBER) if( (LabelInTst->m_Type == NET_SHEETBUSLABELMEMBER)
|| (LabelInTst->m_Type == NET_BUSLABELMEMBER) || (LabelInTst->m_Type == NET_BUSLABELMEMBER)
|| (LabelInTst->m_Type == NET_HIERBUSLABELMEMBER) ) || (LabelInTst->m_Type == NET_HIERBUSLABELMEMBER) )
...@@ -834,25 +698,21 @@ int IsBusLabel( const wxString& LabelDrawList ) ...@@ -834,25 +698,21 @@ int IsBusLabel( const wxString& LabelDrawList )
EXCHG( FirstNumWireBus, LastNumWireBus ); EXCHG( FirstNumWireBus, LastNumWireBus );
} }
if( error && (s_PassNumber == 0) )
{
wxString msg = _( "Bad Bus Label: " ) + LabelDrawList;
DisplayError( NULL, msg );
}
return LastNumWireBus - FirstNumWireBus + 1; return LastNumWireBus - FirstNumWireBus + 1;
} }
/***************************************************************/ /***************************************************************/
static int ConvertBusToMembers( ObjetNetListStruct* BusLabel ) static int ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer,
NETLIST_OBJECT& BusLabel )
/***************************************************************/ /***************************************************************/
/* Routine qui eclate un label type Bus en autant de Label qu'il contient de membres, /* Routine qui eclate un label type Bus en autant de Label qu'il contient de membres,
* et qui cree les structures avec le type NET_GLOBBUSLABELMEMBER, NET_BUSLABELMEMBER * et qui cree les structures avec le type NET_GLOBBUSLABELMEMBER, NET_BUSLABELMEMBER
* ou NET_SHEETBUSLABELMEMBER * ou NET_SHEETBUSLABELMEMBER
* entree = pointeur sur l'ObjetNetListStruct initialise corresp au buslabel * entree = pointeur sur l'NETLIST_OBJECT initialise corresp au buslabel
* suppose que FirstNumWireBus, LastNumWireBus et RootBusNameLength sont a jour * suppose que FirstNumWireBus, LastNumWireBus et RootBusNameLength sont a jour
* modifie l'ObjetNetListStruct de base et remplit les suivants * modifie l'NETLIST_OBJECT de base et remplit les suivants
* m_Label is a pointer to a new wxString * m_Label is a pointer to a new wxString
* m_Label must be deallocated by the user (only for a NET_GLOBBUSLABELMEMBER, * m_Label must be deallocated by the user (only for a NET_GLOBBUSLABELMEMBER,
* NET_BUSLABELMEMBER or a NET_SHEETBUSLABELMEMBER object type) * NET_BUSLABELMEMBER or a NET_SHEETBUSLABELMEMBER object type)
...@@ -861,37 +721,37 @@ static int ConvertBusToMembers( ObjetNetListStruct* BusLabel ) ...@@ -861,37 +721,37 @@ static int ConvertBusToMembers( ObjetNetListStruct* BusLabel )
int NumItem, BusMember; int NumItem, BusMember;
wxString BufLine; wxString BufLine;
if( BusLabel->m_Type == NET_HIERLABEL ) if( BusLabel.m_Type == NET_HIERLABEL )
BusLabel->m_Type = NET_HIERBUSLABELMEMBER; BusLabel.m_Type = NET_HIERBUSLABELMEMBER;
else if( BusLabel->m_Type == NET_GLOBLABEL ) else if( BusLabel.m_Type == NET_GLOBLABEL )
BusLabel->m_Type = NET_GLOBBUSLABELMEMBER; BusLabel.m_Type = NET_GLOBBUSLABELMEMBER;
else if( BusLabel->m_Type == NET_SHEETLABEL ) else if( BusLabel.m_Type == NET_SHEETLABEL )
BusLabel->m_Type = NET_SHEETBUSLABELMEMBER; BusLabel.m_Type = NET_SHEETBUSLABELMEMBER;
else else
BusLabel->m_Type = NET_BUSLABELMEMBER; BusLabel.m_Type = NET_BUSLABELMEMBER;
/* Convertion du BusLabel en la racine du Label + le numero du fil */ /* Convertion du BusLabel en la racine du Label + le numero du fil */
BufLine = BusLabel->m_Label->Left( RootBusNameLength ); BufLine = BusLabel.m_Label->Left( RootBusNameLength );
BusMember = FirstNumWireBus; BusMember = FirstNumWireBus;
BufLine << BusMember; BufLine << BusMember;
BusLabel->m_Label = new wxString( BufLine ); BusLabel.m_Label = new wxString( BufLine );
BusLabel->m_Member = BusMember; BusLabel.m_Member = BusMember;
NumItem = 1; NumItem = 1;
for( BusMember++; BusMember <= LastNumWireBus; BusMember++ ) for( BusMember++; BusMember <= LastNumWireBus; BusMember++ )
{ {
*(BusLabel + 1) = *BusLabel; //copy constructor. NETLIST_OBJECT* new_label = new NETLIST_OBJECT( BusLabel );
BusLabel++;
NumItem++; NumItem++;
/* Convertion du BusLabel en la racine du Label + le numero du fil */ /* Convertion du BusLabel en la racine du Label + le numero du fil */
BufLine = BusLabel->m_Label->Left( RootBusNameLength ); BufLine = BusLabel.m_Label->Left( RootBusNameLength );
BufLine << BusMember; BufLine << BusMember;
BusLabel->m_Label = new wxString( BufLine ); new_label->m_Label = new wxString( BufLine );
BusLabel->m_Member = BusMember; new_label->m_Member = BusMember;
aNetItemBuffer.push_back( new_label );
} }
return NumItem; return NumItem;
...@@ -909,19 +769,14 @@ static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus ) ...@@ -909,19 +769,14 @@ static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus )
*/ */
{ {
int jj;
ObjetNetListStruct* Objet = g_TabObjNet;
if( OldNetCode == NewNetCode ) if( OldNetCode == NewNetCode )
return; return;
#if defined (NETLIST_DEBUG) && defined (DEBUG)
printf( "replacing net %d with %d\n", OldNetCode, NewNetCode );
#endif
if( IsBus == 0 ) /* Propagation du NetCode */ if( IsBus == 0 ) /* Propagation du NetCode */
{ {
for( jj = 0; jj < g_NbrObjNet; jj++, Objet++ ) for( unsigned jj = 0; jj < g_NetObjectslist.size(); jj++ )
{ {
NETLIST_OBJECT* Objet = g_NetObjectslist[jj];
if( Objet->GetNet() == OldNetCode ) if( Objet->GetNet() == OldNetCode )
{ {
Objet->SetNet( NewNetCode ); Objet->SetNet( NewNetCode );
...@@ -930,8 +785,9 @@ static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus ) ...@@ -930,8 +785,9 @@ static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus )
} }
else /* Propagation du BusNetCode */ else /* Propagation du BusNetCode */
{ {
for( jj = 0; jj < g_NbrObjNet; jj++, Objet++ ) for( unsigned jj = 0; jj < g_NetObjectslist.size(); jj++ )
{ {
NETLIST_OBJECT* Objet = g_NetObjectslist[jj];
if( Objet->m_BusNetCode == OldNetCode ) if( Objet->m_BusNetCode == OldNetCode )
{ {
Objet->m_BusNetCode = NewNetCode; Objet->m_BusNetCode = NewNetCode;
...@@ -942,7 +798,7 @@ static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus ) ...@@ -942,7 +798,7 @@ static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus )
/***************************************************************************/ /***************************************************************************/
static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start ) static void PointToPointConnect( NETLIST_OBJECT* Ref, int IsBus, int start )
/***************************************************************************/ /***************************************************************************/
/* Routine qui verifie si l'element *Ref est connecte a /* Routine qui verifie si l'element *Ref est connecte a
...@@ -964,18 +820,18 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start ) ...@@ -964,18 +820,18 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start )
* ( il ne peut y avoir connexion physique entre elements de differentes sheets) * ( il ne peut y avoir connexion physique entre elements de differentes sheets)
*/ */
{ {
int i, netCode; int netCode;
ObjetNetListStruct* netTable = g_TabObjNet;
if( IsBus == 0 ) /* Objets autres que BUS et BUSLABELS */ if( IsBus == 0 ) /* Objets autres que BUS et BUSLABELS */
{ {
netCode = Ref->GetNet(); netCode = Ref->GetNet();
for( i = start; i < g_NbrObjNet; i++ ) for( unsigned i = start; i < g_NetObjectslist.size(); i++ )
{ {
if( netTable[i].m_SheetList != Ref->m_SheetList ) //used to be > (why?) NETLIST_OBJECT* item = g_NetObjectslist[i];
if( item->m_SheetList != Ref->m_SheetList ) //used to be > (why?)
continue; continue;
switch( netTable[i].m_Type ) switch( item->m_Type )
{ {
case NET_SEGMENT: case NET_SEGMENT:
case NET_PIN: case NET_PIN:
...@@ -986,15 +842,15 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start ) ...@@ -986,15 +842,15 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start )
case NET_PINLABEL: case NET_PINLABEL:
case NET_JONCTION: case NET_JONCTION:
case NET_NOCONNECT: case NET_NOCONNECT:
if( Ref->m_Start == netTable[i].m_Start if( Ref->m_Start == item->m_Start
|| Ref->m_Start == netTable[i].m_End || Ref->m_Start == item->m_End
|| Ref->m_End == netTable[i].m_Start || Ref->m_End == item->m_Start
|| Ref->m_End == netTable[i].m_End ) || Ref->m_End == item->m_End )
{ {
if( netTable[i].GetNet() == 0 ) if( item->GetNet() == 0 )
netTable[i].SetNet( netCode ); item->SetNet( netCode );
else else
PropageNetCode( netTable[i].GetNet(), netCode, 0 ); PropageNetCode( item->GetNet(), netCode, 0 );
} }
break; break;
...@@ -1003,6 +859,7 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start ) ...@@ -1003,6 +859,7 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start )
case NET_SHEETBUSLABELMEMBER: case NET_SHEETBUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER: case NET_HIERBUSLABELMEMBER:
case NET_GLOBBUSLABELMEMBER: case NET_GLOBBUSLABELMEMBER:
case NET_ITEM_UNSPECIFIED:
break; break;
} }
} }
...@@ -1010,13 +867,15 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start ) ...@@ -1010,13 +867,15 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start )
else /* Objets type BUS et BUSLABELS ( et JONCTIONS )*/ else /* Objets type BUS et BUSLABELS ( et JONCTIONS )*/
{ {
netCode = Ref->m_BusNetCode; netCode = Ref->m_BusNetCode;
for( i = start; i<g_NbrObjNet; i++ ) for( unsigned i = start; i<g_NetObjectslist.size(); i++ )
{ {
if( netTable[i].m_SheetList != Ref->m_SheetList ) NETLIST_OBJECT* item = g_NetObjectslist[i];
if( item->m_SheetList != Ref->m_SheetList )
continue; continue;
switch( netTable[i].m_Type ) switch( item->m_Type )
{ {
case NET_ITEM_UNSPECIFIED:
case NET_SEGMENT: case NET_SEGMENT:
case NET_PIN: case NET_PIN:
case NET_LABEL: case NET_LABEL:
...@@ -1033,15 +892,15 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start ) ...@@ -1033,15 +892,15 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start )
case NET_HIERBUSLABELMEMBER: case NET_HIERBUSLABELMEMBER:
case NET_GLOBBUSLABELMEMBER: case NET_GLOBBUSLABELMEMBER:
case NET_JONCTION: case NET_JONCTION:
if( Ref->m_Start == netTable[i].m_Start if( Ref->m_Start == item->m_Start
|| Ref->m_Start == netTable[i].m_End || Ref->m_Start == item->m_End
|| Ref->m_End == netTable[i].m_Start || Ref->m_End == item->m_Start
|| Ref->m_End == netTable[i].m_End ) || Ref->m_End == item->m_End )
{ {
if( netTable[i].m_BusNetCode == 0 ) if( item->m_BusNetCode == 0 )
netTable[i].m_BusNetCode = netCode; item->m_BusNetCode = netCode;
else else
PropageNetCode( netTable[i].m_BusNetCode, netCode, 1 ); PropageNetCode( item->m_BusNetCode, netCode, 1 );
} }
break; break;
} }
...@@ -1051,7 +910,7 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start ) ...@@ -1051,7 +910,7 @@ static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start )
/**************************************************************/ /**************************************************************/
static void SegmentToPointConnect( ObjetNetListStruct* Jonction, static void SegmentToPointConnect( NETLIST_OBJECT* Jonction,
int IsBus, int start ) int IsBus, int start )
/***************************************************************/ /***************************************************************/
...@@ -1065,45 +924,44 @@ static void SegmentToPointConnect( ObjetNetListStruct* Jonction, ...@@ -1065,45 +924,44 @@ static void SegmentToPointConnect( ObjetNetListStruct* Jonction,
* ( il ne peut y avoir connexion physique entre elements de differentes sheets) * ( il ne peut y avoir connexion physique entre elements de differentes sheets)
*/ */
{ {
int i; for( unsigned i = start; i < g_NetObjectslist.size(); i++ )
ObjetNetListStruct* Segment = g_TabObjNet;
for( i = start; i < g_NbrObjNet; i++ )
{ {
if( Segment[i].m_SheetList != Jonction->m_SheetList ) NETLIST_OBJECT* Segment = g_NetObjectslist[i];
if( Segment->m_SheetList != Jonction->m_SheetList )
continue; continue;
if( IsBus == 0 ) if( IsBus == 0 )
{ {
if( Segment[i].m_Type != NET_SEGMENT ) if( Segment->m_Type != NET_SEGMENT )
continue; continue;
} }
else else
{ {
if( Segment[i].m_Type != NET_BUS ) if( Segment->m_Type != NET_BUS )
continue; continue;
} }
if( SegmentIntersect( Segment[i].m_Start.x, Segment[i].m_Start.y, if( SegmentIntersect( Segment->m_Start.x, Segment->m_Start.y,
Segment[i].m_End.x, Segment[i].m_End.y, Segment->m_End.x, Segment->m_End.y,
Jonction->m_Start.x, Jonction->m_Start.y ) ) Jonction->m_Start.x, Jonction->m_Start.y ) )
{ {
/* Propagation du Netcode a tous les Objets de meme NetCode */ /* Propagation du Netcode a tous les Objets de meme NetCode */
if( IsBus == 0 ) if( IsBus == 0 )
{ {
if( Segment[i].GetNet() ) if( Segment->GetNet() )
PropageNetCode( Segment[i].GetNet(), PropageNetCode( Segment->GetNet(),
Jonction->GetNet(), IsBus ); Jonction->GetNet(), IsBus );
else else
Segment[i].SetNet( Jonction->GetNet() ); Segment->SetNet( Jonction->GetNet() );
} }
else else
{ {
if( Segment[i].m_BusNetCode ) if( Segment->m_BusNetCode )
PropageNetCode( Segment[i].m_BusNetCode, PropageNetCode( Segment->m_BusNetCode,
Jonction->m_BusNetCode, IsBus ); Jonction->m_BusNetCode, IsBus );
else else
Segment[i].m_BusNetCode = Jonction->m_BusNetCode; Segment->m_BusNetCode = Jonction->m_BusNetCode;
} }
} }
} }
...@@ -1113,26 +971,24 @@ static void SegmentToPointConnect( ObjetNetListStruct* Jonction, ...@@ -1113,26 +971,24 @@ static void SegmentToPointConnect( ObjetNetListStruct* Jonction,
/***************************************************************** /*****************************************************************
* Function which connects the groups of object which have the same label * Function which connects the groups of object which have the same label
*******************************************************************/ *******************************************************************/
static void LabelConnect( ObjetNetListStruct* LabelRef ) void LabelConnect( NETLIST_OBJECT* LabelRef )
{ {
if( LabelRef->GetNet() == 0 ) if( LabelRef->GetNet() == 0 )
return; return;
ObjetNetListStruct* netTable = g_TabObjNet; for( unsigned i = 0; i < g_NetObjectslist.size(); i++ )
for( int i = 0; i<g_NbrObjNet; i++ )
{ {
if( netTable[i].GetNet() == LabelRef->GetNet() ) if( g_NetObjectslist[i]->GetNet() == LabelRef->GetNet() )
continue; continue;
if( netTable[i].m_SheetList != LabelRef->m_SheetList ) if( g_NetObjectslist[i]->m_SheetList != LabelRef->m_SheetList )
{ {
if( (netTable[i].m_Type != NET_PINLABEL if( (g_NetObjectslist[i]->m_Type != NET_PINLABEL
&& netTable[i].m_Type != NET_GLOBLABEL && g_NetObjectslist[i]->m_Type != NET_GLOBLABEL
&& netTable[i].m_Type != NET_GLOBBUSLABELMEMBER) ) && g_NetObjectslist[i]->m_Type != NET_GLOBBUSLABELMEMBER) )
continue; continue;
if( (netTable[i].m_Type == NET_GLOBLABEL if( (g_NetObjectslist[i]->m_Type == NET_GLOBLABEL
|| netTable[i].m_Type == NET_GLOBBUSLABELMEMBER) || g_NetObjectslist[i]->m_Type == NET_GLOBBUSLABELMEMBER)
&& netTable[i].m_Type != LabelRef->m_Type ) && g_NetObjectslist[i]->m_Type != LabelRef->m_Type )
//global labels only connect other global labels. //global labels only connect other global labels.
continue; continue;
} }
...@@ -1141,114 +997,111 @@ static void LabelConnect( ObjetNetListStruct* LabelRef ) ...@@ -1141,114 +997,111 @@ static void LabelConnect( ObjetNetListStruct* LabelRef )
//NET_HIERLABEL are used to connect sheets. //NET_HIERLABEL are used to connect sheets.
//NET_LABEL is sheet-local (***) //NET_LABEL is sheet-local (***)
//NET_GLOBLABEL is global. //NET_GLOBLABEL is global.
if( netTable[i].m_Type == NET_LABEL NetObjetType ntype = g_NetObjectslist[i]->m_Type;
|| netTable[i].m_Type == NET_GLOBLABEL if( ntype == NET_LABEL
|| netTable[i].m_Type == NET_HIERLABEL || ntype == NET_GLOBLABEL
|| netTable[i].m_Type == NET_BUSLABELMEMBER || ntype == NET_HIERLABEL
|| netTable[i].m_Type == NET_GLOBBUSLABELMEMBER || ntype == NET_BUSLABELMEMBER
|| netTable[i].m_Type == NET_HIERBUSLABELMEMBER || ntype == NET_GLOBBUSLABELMEMBER
|| netTable[i].m_Type == NET_PINLABEL ) || ntype == NET_HIERBUSLABELMEMBER
|| ntype == NET_PINLABEL )
{ {
if( netTable[i].m_Label->CmpNoCase( *LabelRef->m_Label ) != 0 ) if( g_NetObjectslist[i]->m_Label->CmpNoCase( *LabelRef->m_Label ) != 0 )
continue; continue;
// Propagation du Netcode a tous les Objets de meme NetCode // Propagation du Netcode a tous les Objets de meme NetCode
if( netTable[i].GetNet() ) if( g_NetObjectslist[i]->GetNet() )
PropageNetCode( netTable[i].GetNet(), LabelRef->GetNet(), 0 ); PropageNetCode( g_NetObjectslist[i]->GetNet(), LabelRef->GetNet(), 0 );
else else
netTable[i].SetNet( LabelRef->GetNet() ); g_NetObjectslist[i]->SetNet( LabelRef->GetNet() );
} }
} }
} }
/****************************************************************************/ /****************************************************************************/
static int TriNetCode( const void* o1, const void* o2 ) bool SortItemsbyNetcode( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
/****************************************************************************/ /****************************************************************************/
/* Routine de comparaison pour le tri par NetCode croissant /* Routine de comparaison pour le tri par NetCode croissant
* du tableau des elements connectes ( TabPinSort ) par qsort() * du tableau des elements connectes ( TabPinSort ) par qsort()
*/ */
{ {
ObjetNetListStruct* Objet1 = (ObjetNetListStruct*) o1; return Objet1->GetNet() < Objet2->GetNet();
ObjetNetListStruct* Objet2 = (ObjetNetListStruct*) o2;
return Objet1->GetNet() - Objet2->GetNet();
} }
/*****************************************************************************/ /*****************************************************************************************/
static int TriBySheet( const void* o1, const void* o2 ) bool SortItemsBySheet( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
/*****************************************************************************/ /*****************************************************************************************/
/* Routine de comparaison pour le tri par NumSheet /* Routine de comparaison pour le tri par NumSheet
* du tableau des elements connectes ( TabPinSort ) par qsort() */ * du tableau des elements connectes ( TabPinSort ) par qsort() */
{ {
ObjetNetListStruct* Objet1 = (ObjetNetListStruct*) o1; return Objet1->m_SheetList.Cmp( Objet2->m_SheetList ) < 0;
ObjetNetListStruct* Objet2 = (ObjetNetListStruct*) o2;
return Objet1->m_SheetList.Cmp( Objet2->m_SheetList );
} }
/**********************************************************************/ /**********************************************************************/
static void SetUnconnectedFlag( ObjetNetListStruct* ListObj, int NbItems ) static void SetUnconnectedFlag( NETLIST_OBJECT_LIST& aNetItemBuffer )
/**********************************************************************/ /**********************************************************************/
/* Routine positionnant le membre .FlagNoConnect des elements de /* Routine positionnant le membre .FlagNoConnect des elements de
* la liste des objets netliste, tries par ordre de NetCode * la liste des objets netliste, tries par ordre de NetCode
*/ */
{ {
ObjetNetListStruct* NetItemRef, * NetItemTst, * ItemPtr; NETLIST_OBJECT* NetItemRef;
ObjetNetListStruct* NetStart, * NetEnd, * Lim; unsigned NetStart, NetEnd;
int Nb;
ConnectType StateFlag; ConnectType StateFlag;
NetStart = NetEnd = 0;
NetStart = NetEnd = ListObj;
NetItemRef = NetStart;
Nb = 0;
StateFlag = UNCONNECTED; StateFlag = UNCONNECTED;
for( unsigned ii = 0; ii < aNetItemBuffer.size(); ii++ )
Lim = ListObj + NbItems;
for( ; NetItemRef < Lim; NetItemRef++ )
{ {
if( NetItemRef->m_Type == NET_NOCONNECT ) NetItemRef = aNetItemBuffer[ii];
if( StateFlag != PAD_CONNECT ) if( NetItemRef->m_Type == NET_NOCONNECT && StateFlag != PAD_CONNECT )
StateFlag = NOCONNECT; StateFlag = NOCONNECT_SYMBOL_PRESENT;
/* Analyse du net en cours */ /* Analyse du net en cours */
NetItemTst = NetItemRef + 1; unsigned idxtoTest = ii + 1;
if( (NetItemTst >= Lim) if( ( idxtoTest >= aNetItemBuffer.size() )
|| ( NetItemRef->GetNet() != NetItemTst->GetNet() ) ) || ( NetItemRef->GetNet() != aNetItemBuffer[idxtoTest]->GetNet() ) )
{ {
/* Net analyse: mise a jour de m_FlagOfConnection */ /* Net analyse: mise a jour de m_FlagOfConnection */
NetEnd = NetItemTst; NetEnd = idxtoTest;
for( ItemPtr = NetStart; ItemPtr < NetEnd; ItemPtr++ ) /* set m_FlagOfConnection member to StateFlag for all items of this net: */
{ for( unsigned kk = NetStart; kk < NetEnd; kk++ )
ItemPtr->m_FlagOfConnection = StateFlag; aNetItemBuffer[kk]->m_FlagOfConnection = StateFlag;
}
if( NetItemTst >= Lim ) if( idxtoTest >= aNetItemBuffer.size() )
return; return;
/* Start Analyse Nouveau Net */ /* Start Analysis next Net */
StateFlag = UNCONNECTED; StateFlag = UNCONNECTED;
NetStart = NetItemTst; NetStart = idxtoTest;
continue; continue;
} }
for( ; ; NetItemTst++ ) /* test the current item: if this is a pin and if the reference item is also a pin,
* then 2 pins are connected, so set StateFlag to PAD_CONNECT (can be already done)
* Of course, if the current item is a no connect symbol, set StateFlag to NOCONNECT_SYMBOL_PRESENT
* to inhibit error diags. However if StateFlag is already set to PAD_CONNECT
* this state is kept (the no connect symbol was surely an error and an ERC will report this)
*/
for( ; ; idxtoTest++ )
{ {
if( (NetItemTst >= Lim) if( ( idxtoTest >= aNetItemBuffer.size() )
|| ( NetItemRef->GetNet() != NetItemTst->GetNet() ) ) || ( NetItemRef->GetNet() != aNetItemBuffer[idxtoTest]->GetNet() ) )
break; break;
switch( NetItemTst->m_Type ) switch( aNetItemBuffer[idxtoTest]->m_Type )
{ {
case NET_ITEM_UNSPECIFIED:
wxMessageBox(wxT("BuildNetListBase() error"));
break;
case NET_SEGMENT: case NET_SEGMENT:
case NET_LABEL: case NET_LABEL:
case NET_HIERLABEL: case NET_HIERLABEL:
...@@ -1270,7 +1123,7 @@ static void SetUnconnectedFlag( ObjetNetListStruct* ListObj, int NbItems ) ...@@ -1270,7 +1123,7 @@ static void SetUnconnectedFlag( ObjetNetListStruct* ListObj, int NbItems )
case NET_NOCONNECT: case NET_NOCONNECT:
if( StateFlag != PAD_CONNECT ) if( StateFlag != PAD_CONNECT )
StateFlag = NOCONNECT; StateFlag = NOCONNECT_SYMBOL_PRESENT;
break; break;
} }
} }
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins #define CUSTOMPANEL_COUNTMAX 8 // Max number of netlist plugins
#include "class_netlist_object.h"
/* Id to select netlist type */ /* Id to select netlist type */
enum TypeNetForm { enum TypeNetForm {
NET_TYPE_UNINIT = 0, NET_TYPE_UNINIT = 0,
...@@ -30,69 +32,6 @@ enum TypeNetForm { ...@@ -30,69 +32,6 @@ enum TypeNetForm {
/* Max pin number per component and footprint */ /* Max pin number per component and footprint */
#define MAXPIN 5000 #define MAXPIN 5000
enum NetObjetType {
/* Type des objets de Net */
NET_SEGMENT,
NET_BUS,
NET_JONCTION,
NET_LABEL,
NET_GLOBLABEL,
NET_HIERLABEL, //on a screen to indicate connection to a higher-level sheet
NET_SHEETLABEL, //on a drawscreen element to indicate connection to a lower-level sheet.
NET_BUSLABELMEMBER,
NET_GLOBBUSLABELMEMBER,
NET_HIERBUSLABELMEMBER,
NET_SHEETBUSLABELMEMBER,
NET_PINLABEL,
NET_PIN,
NET_NOCONNECT
};
enum ConnectType {
/* Valeur du Flag de connection */
UNCONNECTED = 0, /* Pin ou Label non connecte */
NOCONNECT, /* Pin volontairement non connectee (Symb. NoConnect utilise) */
PAD_CONNECT /* connexion normale */
};
/* Structure decrivant 1 element de connexion (pour netlist ) */
class ObjetNetListStruct
{
public:
NetObjetType m_Type; // Type of this item (see NetObjetType enum)
EDA_BaseStruct* m_Comp; /* Pointer on the schematic item that created this net object (the parent)*/
void* m_Link; /* For Hierarchical_PIN_Sheet_Struct:
* Pointer to the hierarchy sheet that contains this Hierarchical_PIN_Sheet_Struct
* For Pins: pointer to the component that contains this pin
*/
int m_Flag; /* flag used in calculations */
DrawSheetPath m_SheetList;
int m_ElectricalType; /* Has meaning only for Pins and hierachical pins: electrical type */
private:
int m_NetCode; /* net code for all items except BUS labels because a BUS label has
* as many net codes as bus members
*/
public:
int m_BusNetCode; /* Used for BUS connections */
int m_Member; /* for labels type NET_BUSLABELMEMBER ( bus member created from the BUS label )
* member number
*/
ConnectType m_FlagOfConnection;
DrawSheetPath m_SheetListInclude; /* sheet that the hierarchal label connects to.*/
long m_PinNum; /* numero de pin( 4 octets -> 4 codes ascii) */
const wxString* m_Label; /* For all labels:pointer on the text label */
wxPoint m_Start, m_End;
#if defined(DEBUG)
void Show( std::ostream& out, int ndx );
#endif
void SetNet( int aNetCode ) { m_NetCode = aNetCode; }
int GetNet() const { return m_NetCode; }
};
/* object used in annotation to handle a list of components in schematic /* object used in annotation to handle a list of components in schematic
...@@ -150,15 +89,17 @@ public: ...@@ -150,15 +89,17 @@ public:
/* Global Variables */ /* Global Variables */
extern int g_NbrObjNet;
extern ObjetNetListStruct* g_TabObjNet; // Buffer to build the list of items used in netlist and erc calculations
typedef std::vector <NETLIST_OBJECT*> NETLIST_OBJECT_LIST;
extern NETLIST_OBJECT_LIST g_NetObjectslist;
/* Prototypes: */ /* Prototypes: */
void WriteNetList( WinEDA_SchematicFrame* frame, void WriteNetList( WinEDA_SchematicFrame* frame,
const wxString& FileNameNL, const wxString& FileNameNL,
bool use_netnames ); bool use_netnames );
void FreeTabNetList( ObjetNetListStruct* TabNetItems, int NbrNetItems ); void FreeNetObjectsList( std::vector <NETLIST_OBJECT*>& aNetObjectslist );
/** Function ReturnUserNetlistTypeName /** Function ReturnUserNetlistTypeName
* to retrieve user netlist type names * to retrieve user netlist type names
......
...@@ -28,8 +28,6 @@ ...@@ -28,8 +28,6 @@
#define CUSTOM_NETLIST_TITLE wxT( "CustomNetlistTitle" ) #define CUSTOM_NETLIST_TITLE wxT( "CustomNetlistTitle" )
#define CUSTOM_NETLIST_COMMAND wxT( "CustomNetlistCommand" ) #define CUSTOM_NETLIST_COMMAND wxT( "CustomNetlistCommand" )
/* Loacl variable */
/****************************************************/ /****************************************************/
wxString ReturnUserNetlistTypeName( bool first_item ) wxString ReturnUserNetlistTypeName( bool first_item )
/****************************************************/ /****************************************************/
...@@ -531,7 +529,6 @@ void WinEDA_NetlistFrame::GenNetlist( wxCommandEvent& event ) ...@@ -531,7 +529,6 @@ void WinEDA_NetlistFrame::GenNetlist( wxCommandEvent& event )
break; break;
} }
FreeTabNetList( g_TabObjNet, g_NbrObjNet );
m_Parent->m_NetlistFormat = netformat_tmp; m_Parent->m_NetlistFormat = netformat_tmp;
WriteCurrentNetlistSetup(); WriteCurrentNetlistSetup();
......
...@@ -166,7 +166,7 @@ public: ...@@ -166,7 +166,7 @@ public:
SCH_COMPONENT* LibItem ); SCH_COMPONENT* LibItem );
/* netlist generation */ /* netlist generation */
void* BuildNetListBase(); void BuildNetListBase();
/** /**
* Function DeleteAnnotation * Function DeleteAnnotation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment