fixed: eeschema crashes when creating netlist with hierarchies (due to netlist calculations rework)

This commit is contained in:
charras 2009-07-15 07:10:07 +00:00
parent b78444c226
commit ff58b0a819
2 changed files with 61 additions and 68 deletions

View File

@ -21,9 +21,9 @@
#include "dialog_load_error.h" #include "dialog_load_error.h"
/* MDC file strings */ /* MDC and MOD file strings */
wxString mdc_files_not_found; static wxString s_files_not_found;
wxString mdc_files_invalid; static wxString s_files_invalid;
/* routines locales : */ /* routines locales : */
static void ReadDocLib( const wxString& ModLibName, FOOTPRINT_LIST& list ); static void ReadDocLib( const wxString& ModLibName, FOOTPRINT_LIST& list );
@ -76,7 +76,7 @@ bool LoadFootprintFiles( const wxArrayString& libNames,
if( !tmp ) if( !tmp )
{ {
mdc_files_not_found << filename.GetFullName() << wxT("\n"); s_files_not_found << filename.GetFullName() << wxT("\n");
continue; continue;
} }
@ -85,7 +85,7 @@ bool LoadFootprintFiles( const wxArrayString& libNames,
if( file == NULL ) if( file == NULL )
{ {
mdc_files_invalid << tmp << _(" (file cannot be opened)") << wxT("\n"); s_files_invalid << tmp << _(" (file cannot be opened)") << wxT("\n");
continue; continue;
} }
@ -93,7 +93,7 @@ bool LoadFootprintFiles( const wxArrayString& libNames,
fgets( buffer, 32, file ); fgets( buffer, 32, file );
if( strncmp( buffer, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 ) if( strncmp( buffer, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
{ {
mdc_files_invalid << tmp << _(" (Not a Kicad file)") << wxT("\n"); s_files_invalid << tmp << _(" (Not a Kicad file)") << wxT("\n");
fclose( file ); fclose( file );
continue; continue;
} }
@ -123,7 +123,7 @@ bool LoadFootprintFiles( const wxArrayString& libNames,
if( !end ) if( !end )
{ {
mdc_files_invalid << tmp << _(" (Unexpected end of file)") << wxT("\n"); s_files_invalid << tmp << _(" (Unexpected end of file)") << wxT("\n");
} }
} }
} }
@ -132,27 +132,24 @@ bool LoadFootprintFiles( const wxArrayString& libNames,
ReadDocLib( tmp, list ); ReadDocLib( tmp, list );
} }
/* Display if there are mdc files not found */ /* Display if there are mdc files not found */
if( !mdc_files_not_found.IsEmpty() || !mdc_files_invalid.IsEmpty() ) if( !s_files_not_found.IsEmpty() || !s_files_invalid.IsEmpty() )
{ {
DIALOG_LOAD_ERROR dialog(NULL); DIALOG_LOAD_ERROR dialog(NULL);
if( !mdc_files_not_found.IsEmpty() ) if( !s_files_not_found.IsEmpty() )
{ {
wxString message = _("Some MDC files could not be found!"); wxString message = _("Some files could not be found!");
dialog.MessageSet(message); dialog.MessageSet(message);
dialog.ListSet(mdc_files_not_found); dialog.ListSet(s_files_not_found);
mdc_files_not_found.Empty(); s_files_not_found.Empty();
} }
/* Display if there are mdc files invalid */ /* Display if there are mdc files invalid */
if( !mdc_files_invalid.IsEmpty() ) if( !s_files_invalid.IsEmpty() )
{ {
dialog.MessageSet( _("Some MDC files are invalid!")); dialog.MessageSet( _("Some files are invalid!"));
dialog.ListSet(mdc_files_invalid); dialog.ListSet(s_files_invalid);
mdc_files_invalid.Empty(); s_files_invalid.Empty();
} }
dialog.ShowModal(); dialog.ShowModal();
} }
@ -184,7 +181,7 @@ ReadDocLib( const wxString& ModLibName,
/* Check if mdc file exists and can be opened */ /* Check if mdc file exists and can be opened */
if( ( mdc_file = wxFopen( mdc_filename.GetFullPath(), wxT( "rt" ) ) ) == NULL ) if( ( mdc_file = wxFopen( mdc_filename.GetFullPath(), wxT( "rt" ) ) ) == NULL )
{ {
mdc_files_not_found += mdc_filename.GetFullPath() + wxT("\n"); s_files_not_found += mdc_filename.GetFullPath() + wxT("\n");
return; return;
} }
@ -192,7 +189,7 @@ ReadDocLib( const wxString& ModLibName,
GetLine( mdc_file, Line, NULL, sizeof(Line) - 1 ); GetLine( mdc_file, Line, NULL, sizeof(Line) - 1 );
if( strnicmp( Line, ENTETE_LIBDOC, L_ENTETE_LIB ) != 0 ) if( strnicmp( Line, ENTETE_LIBDOC, L_ENTETE_LIB ) != 0 )
{ {
mdc_files_invalid += mdc_filename.GetFullPath() + wxT("\n"); s_files_invalid += mdc_filename.GetFullPath() + wxT("\n");
return; return;
} }

View File

@ -83,7 +83,7 @@ void WinEDA_SchematicFrame::BuildNetListBase()
*/ */
{ {
int NetNumber; int NetNumber;
int i, NetCode; int NetCode;
DrawSheetPath* sheet; DrawSheetPath* sheet;
wxString msg, activity; wxString msg, activity;
wxBusyCursor Busy; wxBusyCursor Busy;
@ -97,7 +97,6 @@ void WinEDA_SchematicFrame::BuildNetListBase()
/* Build the sheet (not screen) list (flattened)*/ /* Build the sheet (not screen) list (flattened)*/
EDA_SheetList SheetListList; EDA_SheetList SheetListList;
i = 0;
/* Fill g_NetObjectslist with items used in connectivity calculation */ /* Fill g_NetObjectslist with items used in connectivity calculation */
@ -122,14 +121,16 @@ void WinEDA_SchematicFrame::BuildNetListBase()
sheet = &(g_NetObjectslist[0]->m_SheetList); sheet = &(g_NetObjectslist[0]->m_SheetList);
LastNetCode = LastBusNetCode = 1; LastNetCode = LastBusNetCode = 1;
for( unsigned i = 0, istart = 0; i < g_NetObjectslist.size(); i++ ) for( unsigned ii = 0, istart = 0; ii < g_NetObjectslist.size(); ii++ )
{ {
if( g_NetObjectslist[i]->m_SheetList != *sheet ) NETLIST_OBJECT* net_item = g_NetObjectslist[ii];
if( net_item->m_SheetList != *sheet ) // Sheet change
{ {
sheet = &(g_NetObjectslist[i]->m_SheetList); sheet = &(net_item->m_SheetList);
istart = ii;
} }
switch( g_NetObjectslist[i]->m_Type ) switch( net_item->m_Type )
{ {
case NET_ITEM_UNSPECIFIED: case NET_ITEM_UNSPECIFIED:
wxMessageBox(wxT("BuildNetListBase() error")); wxMessageBox(wxT("BuildNetListBase() error"));
@ -138,73 +139,73 @@ void WinEDA_SchematicFrame::BuildNetListBase()
case NET_PINLABEL: case NET_PINLABEL:
case NET_SHEETLABEL: case NET_SHEETLABEL:
case NET_NOCONNECT: case NET_NOCONNECT:
if( g_NetObjectslist[i]->GetNet() != 0 ) if( net_item->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_NetObjectslist[i]->GetNet() == 0 ) if( net_item->GetNet() == 0 )
{ {
g_NetObjectslist[i]->SetNet( LastNetCode ); net_item->SetNet( LastNetCode );
LastNetCode++; LastNetCode++;
} }
PointToPointConnect( g_NetObjectslist[i], 0, istart ); PointToPointConnect( net_item, 0, istart );
break; break;
case NET_JONCTION: case NET_JONCTION:
/* Controle des jonction , hors BUS */ /* Controle des jonction , hors BUS */
if( g_NetObjectslist[i]->GetNet() == 0 ) if( net_item->GetNet() == 0 )
{ {
g_NetObjectslist[i]->SetNet( LastNetCode ); net_item->SetNet( LastNetCode );
LastNetCode++; LastNetCode++;
} }
SegmentToPointConnect( g_NetObjectslist[i], 0, istart ); SegmentToPointConnect( net_item, 0, istart );
/* Controle des jonction , sur BUS */ /* Controle des jonction , sur BUS */
if( g_NetObjectslist[i]->m_BusNetCode == 0 ) if( net_item->m_BusNetCode == 0 )
{ {
g_NetObjectslist[i]->m_BusNetCode = LastBusNetCode; net_item->m_BusNetCode = LastBusNetCode;
LastBusNetCode++; LastBusNetCode++;
} }
SegmentToPointConnect( g_NetObjectslist[i], ISBUS, istart ); SegmentToPointConnect( net_item, 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_NetObjectslist[i]->GetNet() == 0 ) if( net_item->GetNet() == 0 )
{ {
g_NetObjectslist[i]->SetNet( LastNetCode ); net_item->SetNet( LastNetCode );
LastNetCode++; LastNetCode++;
} }
SegmentToPointConnect( g_NetObjectslist[i], 0, istart ); SegmentToPointConnect( net_item, 0, istart );
break; break;
case NET_SHEETBUSLABELMEMBER: case NET_SHEETBUSLABELMEMBER:
if( g_NetObjectslist[i]->m_BusNetCode != 0 ) if( net_item->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_NetObjectslist[i]->m_BusNetCode == 0 ) if( net_item->m_BusNetCode == 0 )
{ {
g_NetObjectslist[i]->m_BusNetCode = LastBusNetCode; net_item->m_BusNetCode = LastBusNetCode;
LastBusNetCode++; LastBusNetCode++;
} }
PointToPointConnect( g_NetObjectslist[i], ISBUS, istart ); PointToPointConnect( net_item, 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_NetObjectslist[i]->GetNet() == 0 ) if( net_item->GetNet() == 0 )
{ {
g_NetObjectslist[i]->m_BusNetCode = LastBusNetCode; net_item->m_BusNetCode = LastBusNetCode;
LastBusNetCode++; LastBusNetCode++;
} }
SegmentToPointConnect( g_NetObjectslist[i], ISBUS, istart ); SegmentToPointConnect( net_item, ISBUS, istart );
break; break;
} }
} }
@ -225,9 +226,9 @@ void WinEDA_SchematicFrame::BuildNetListBase()
SetStatusText( activity ); SetStatusText( activity );
/* Connections des groupes d'objets par labels identiques */ /* Connections des groupes d'objets par labels identiques */
for( unsigned i = 0; i<g_NetObjectslist.size(); i++ ) for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
{ {
switch( g_NetObjectslist[i]->m_Type ) switch( g_NetObjectslist[ii]->m_Type )
{ {
case NET_PIN: case NET_PIN:
case NET_SHEETLABEL: case NET_SHEETLABEL:
@ -242,7 +243,7 @@ void WinEDA_SchematicFrame::BuildNetListBase()
case NET_PINLABEL: case NET_PINLABEL:
case NET_BUSLABELMEMBER: case NET_BUSLABELMEMBER:
case NET_GLOBBUSLABELMEMBER: case NET_GLOBBUSLABELMEMBER:
LabelConnect( g_NetObjectslist[i] ); LabelConnect( g_NetObjectslist[ii] );
break; break;
case NET_SHEETBUSLABELMEMBER: case NET_SHEETBUSLABELMEMBER:
@ -265,18 +266,16 @@ void WinEDA_SchematicFrame::BuildNetListBase()
/* Connexion des hierarchies */ /* Connexion des hierarchies */
activity << wxT( "; " ) << _( "Hierar." ); activity << wxT( "; " ) << _( "Hierar." );
SetStatusText( activity ); SetStatusText( activity );
for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
for( unsigned i = 0; i< g_NetObjectslist.size(); i++ )
{ {
if( g_NetObjectslist[i]->m_Type == NET_SHEETLABEL if( g_NetObjectslist[ii]->m_Type == NET_SHEETLABEL
|| g_NetObjectslist[i]->m_Type == NET_SHEETBUSLABELMEMBER ) || g_NetObjectslist[ii]->m_Type == NET_SHEETBUSLABELMEMBER )
SheetLabelConnect( g_NetObjectslist[i] ); SheetLabelConnect( g_NetObjectslist[ii] );
} }
/* Sort objects by NetCode */ /* Sort objects by NetCode */
sort( g_NetObjectslist.begin(), g_NetObjectslist.end(), SortItemsbyNetcode ); 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();
@ -286,22 +285,17 @@ void WinEDA_SchematicFrame::BuildNetListBase()
SetStatusText( activity ); SetStatusText( activity );
/* Compression des numeros de NetCode a des valeurs consecutives */ /* Compression des numeros de NetCode a des valeurs consecutives */
activity << wxT( "; " ) << _( "Sorting Nets" );
SetStatusText( activity );
LastNetCode = NetCode = 0; LastNetCode = NetCode = 0;
for( unsigned i = 0; i < g_NetObjectslist.size(); i++ ) for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
{ {
if( g_NetObjectslist[i]->GetNet() != LastNetCode ) if( g_NetObjectslist[ii]->GetNet() != LastNetCode )
{ {
NetCode++; NetCode++;
LastNetCode = g_NetObjectslist[i]->GetNet(); LastNetCode = g_NetObjectslist[ii]->GetNet();
} }
g_NetObjectslist[i]->SetNet( NetCode ); g_NetObjectslist[ii]->SetNet( NetCode );
} }
activity << wxT( " " ) << _( "Done" );
SetStatusText( activity );
/* Affectation du m_FlagOfConnection en fonction de connection ou non */ /* Affectation du m_FlagOfConnection en fonction de connection ou non */
SetUnconnectedFlag( g_NetObjectslist ); SetUnconnectedFlag( g_NetObjectslist );
} }
@ -319,9 +313,9 @@ static void SheetLabelConnect( NETLIST_OBJECT* 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( unsigned i = 0; i < g_NetObjectslist.size(); i++ ) for( unsigned ii = 0; ii < g_NetObjectslist.size(); ii++ )
{ {
NETLIST_OBJECT* ObjetNet = g_NetObjectslist[i]; NETLIST_OBJECT* ObjetNet = g_NetObjectslist[ii];
if( ObjetNet->m_SheetList != SheetLabel->m_SheetListInclude ) if( ObjetNet->m_SheetList != SheetLabel->m_SheetListInclude )
continue; //use SheetInclude, not the sheet!! continue; //use SheetInclude, not the sheet!!
@ -332,12 +326,14 @@ static void SheetLabelConnect( NETLIST_OBJECT* SheetLabel )
if( ObjetNet->GetNet() == SheetLabel->GetNet() ) if( ObjetNet->GetNet() == SheetLabel->GetNet() )
continue; //already connected. continue; //already connected.
wxASSERT(ObjetNet->m_Label);
wxASSERT(SheetLabel->m_Label);
if( ObjetNet->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->GetNet() ) if( ObjetNet->GetNet() )
PropageNetCode( ObjetNet[i].GetNet(), SheetLabel->GetNet(), 0 ); PropageNetCode( ObjetNet->GetNet(), SheetLabel->GetNet(), 0 );
else else
ObjetNet->SetNet( SheetLabel->GetNet() ); ObjetNet->SetNet( SheetLabel->GetNet() );
} }