Eeschema: ERC dialog code improvements.

* Rename the "net", "lastNet" and "nextNet" variables to "item", "lastItem"
  and "nextItem", respectively, because these refer to netlist items, not
  nets.
* This adds a suffix "Idx" to the indexes into the list, and introduces local
  copies of the pointers to the objects we are looking at, in order to have a
  shorter way of addressing them.
* The ERC code depends on netlist items to be sorted by net code, so verify
  that in debug builds. While this condition is stricter than necessary, it
  should still hold with the current code, and provide a good canary if a
  change to the sorting code might break ERC.
This commit is contained in:
Simon Richter 2016-06-28 08:52:22 -04:00 committed by Wayne Stambaugh
parent 10c8dae794
commit 527c0eff8e
1 changed files with 26 additions and 16 deletions

View File

@ -49,11 +49,11 @@
#include <erc.h>
#include <id.h>
extern int DiagErc[PINTYPE_COUNT][PINTYPE_COUNT];
extern int DefaultDiagErc[PINTYPE_COUNT][PINTYPE_COUNT];
bool DIALOG_ERC::m_writeErcFile = false; // saved only for the current session
bool DIALOG_ERC::m_TestSimilarLabels = true; // Save in project config
bool DIALOG_ERC::m_diagErcTableInit = false; // saved only for the current session
@ -62,6 +62,7 @@ bool DIALOG_ERC::m_tstUniqueGlobalLabels = true; // saved only for the curren
// Control identifiers for events
#define ID_MATRIX_0 1800
BEGIN_EVENT_TABLE( DIALOG_ERC, DIALOG_ERC_BASE )
EVT_COMMAND_RANGE( ID_MATRIX_0, ID_MATRIX_0 + ( PINTYPE_COUNT * PINTYPE_COUNT ) - 1,
wxEVT_COMMAND_BUTTON_CLICKED, DIALOG_ERC::ChangeErrorLevel )
@ -80,6 +81,7 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) :
Centre();
}
DIALOG_ERC::~DIALOG_ERC()
{
m_TestSimilarLabels = m_cbTestSimilarLabels->GetValue();
@ -157,6 +159,7 @@ void DIALOG_ERC::OnButtonCloseClick( wxCommandEvent& event )
Close();
}
void DIALOG_ERC::OnCloseErcDialog( wxCloseEvent& event )
{
Destroy();
@ -438,7 +441,7 @@ void DIALOG_ERC::ChangeErrorLevel( wxCommandEvent& event )
break;
}
setDRCMatrixButtonState( butt, level);
setDRCMatrixButtonState( butt, level );
DiagErc[y][x] = DiagErc[x][y] = level;
}
@ -492,8 +495,8 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
// Reset the connection type indicator
objectsConnectedList->ResetConnectionsType();
unsigned lastNet;
unsigned nextNet = lastNet = 0;
unsigned lastItemIdx;
unsigned nextItemIdx = lastItemIdx = 0;
int MinConn = NOC;
/* The netlist generated by SCH_EDIT_FRAME::BuildNetListBase is sorted
@ -505,17 +508,24 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
* pass.
*/
for( unsigned net = 0; net < objectsConnectedList->size(); net++ )
for( unsigned itemIdx = 0; itemIdx < objectsConnectedList->size(); itemIdx++ )
{
if( objectsConnectedList->GetItemNet( lastNet ) !=
objectsConnectedList->GetItemNet( net ) )
auto item = objectsConnectedList->GetItem( itemIdx );
auto lastItem = objectsConnectedList->GetItem( lastItemIdx );
auto lastNet = lastItem->GetNet();
auto net = item->GetNet();
wxASSERT_MSG( lastNet <= net, wxT( "Netlist not correctly ordered" ) );
if( lastNet != net )
{
// New net found:
MinConn = NOC;
nextNet = net;
nextItemIdx = itemIdx;
}
switch( objectsConnectedList->GetItemType( net ) )
switch( item->m_Type )
{
// These items do not create erc problems
case NET_ITEM_UNSPECIFIED:
@ -535,11 +545,11 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
// ERC problems when pin sheets do not match hierarchical labels.
// Each pin sheet must match a hierarchical label
// Each hierarchical label must match a pin sheet
objectsConnectedList->TestforNonOrphanLabel( net, nextNet );
objectsConnectedList->TestforNonOrphanLabel( itemIdx, nextItemIdx );
break;
case NET_GLOBLABEL:
if( m_tstUniqueGlobalLabels )
objectsConnectedList->TestforNonOrphanLabel( net, nextNet );
objectsConnectedList->TestforNonOrphanLabel( itemIdx, nextItemIdx );
break;
case NET_NOCONNECT:
@ -547,19 +557,19 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
// ERC problems when a noconnect symbol is connected to more than one pin.
MinConn = NET_NC;
if( objectsConnectedList->CountPinsInNet( nextNet ) > 1 )
Diagnose( objectsConnectedList->GetItem( net ), NULL, MinConn, UNC );
if( objectsConnectedList->CountPinsInNet( nextItemIdx ) > 1 )
Diagnose( item, NULL, MinConn, UNC );
break;
case NET_PIN:
// Look for ERC problems between pins:
TestOthersItems( objectsConnectedList.get(), net, nextNet, &MinConn );
TestOthersItems( objectsConnectedList.get(), itemIdx, nextItemIdx, &MinConn );
break;
}
lastNet = net;
lastItemIdx = itemIdx;
}
// Test similar labels (i;e. labels which are identical when