2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file class_netinfolist.cpp
|
|
|
|
*/
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_netinfo.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
|
|
|
// Constructor and destructor
|
|
|
|
NETINFO_LIST::NETINFO_LIST( BOARD* aParent )
|
|
|
|
{
|
|
|
|
m_Parent = aParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NETINFO_LIST::~NETINFO_LIST()
|
|
|
|
{
|
2011-12-10 05:33:24 +00:00
|
|
|
clear();
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
void NETINFO_LIST::clear()
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
2011-12-10 05:33:24 +00:00
|
|
|
for( unsigned ii = 0; ii < GetNetCount(); ii++ )
|
2009-05-24 18:28:36 +00:00
|
|
|
delete m_NetBuffer[ii];
|
|
|
|
|
|
|
|
m_NetBuffer.clear();
|
2009-06-11 14:26:17 +00:00
|
|
|
m_PadsFullList.clear();
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Append
|
|
|
|
* adds \a aNewElement to the end of the list.
|
|
|
|
*/
|
2009-06-06 18:08:49 +00:00
|
|
|
void NETINFO_LIST::AppendNet( NETINFO_ITEM* aNewElement )
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
|
|
|
m_NetBuffer.push_back( aNewElement );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* sort function, to sort pad list by netnames
|
2009-09-17 17:48:40 +00:00
|
|
|
* this is a case sensitive sort.
|
|
|
|
* DO NOT change it because NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname )
|
|
|
|
* when search a net by its net name does a binary search
|
|
|
|
* and expects to have a nets list sorted by an alphabetic case sensitive sort
|
2009-05-24 18:28:36 +00:00
|
|
|
*/
|
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
static bool padlistSortByNetnames( const D_PAD* a, const D_PAD* b )
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
|
|
|
return ( a->GetNetname().Cmp( b->GetNetname() ) ) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute and update the net_codes for PADS et and equipots (.m_NetCode member)
|
|
|
|
* net_codes are >= 1 (net_code = 0 means not connected)
|
2009-09-17 17:48:40 +00:00
|
|
|
* Update the net buffer
|
2009-05-24 18:28:36 +00:00
|
|
|
* Must be called after editing pads (netname, or deleting) or after read a netlist
|
|
|
|
* set to 1 flag NET_CODE_OK of m_Pcb->m_Status_Pcb;
|
|
|
|
* m_Pcb->m_NbNodes and m_Pcb->m_NbNets are updated
|
2009-09-17 17:48:40 +00:00
|
|
|
* Be aware NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname )
|
|
|
|
* when search a net by its net name does a binary search
|
|
|
|
* and expects to have a nets list sorted by an alphabetic case sensitive sort
|
|
|
|
* So do not change Build_Pads_Full_List() taht build a sorted list of pads
|
2009-05-24 18:28:36 +00:00
|
|
|
*/
|
2011-12-10 05:33:24 +00:00
|
|
|
void NETINFO_LIST::buildListOfNets()
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
2011-12-10 05:33:24 +00:00
|
|
|
D_PAD* pad;
|
|
|
|
int nodes_count = 0;
|
|
|
|
NETINFO_ITEM* net_item;
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
clear(); // Remove all nets info and free memory
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
// Create and add the "unconnected net", always existing,
|
|
|
|
// used to handle pads and tracks that are not member of a "real" net
|
2011-09-23 13:57:12 +00:00
|
|
|
net_item = new NETINFO_ITEM( (BOARD_ITEM*) m_Parent );
|
2009-06-06 18:08:49 +00:00
|
|
|
AppendNet( net_item );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
// Build the PAD list, sorted by net
|
|
|
|
buildPadsFullList();
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
// Build netnames list, and create a netcode for each netname
|
2009-05-24 18:28:36 +00:00
|
|
|
D_PAD* last_pad = NULL;
|
2009-06-05 15:57:41 +00:00
|
|
|
int netcode = 0;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
for( unsigned ii = 0; ii < m_PadsFullList.size(); ii++ )
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
pad = m_PadsFullList[ii];
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
if( pad->GetNetname().IsEmpty() ) // pad not connected
|
|
|
|
{
|
|
|
|
pad->SetNet( 0 );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the current netname was already found: add pad to the current net_item ,
|
|
|
|
* else create a new net_code and a new net_item
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
if( last_pad == NULL || ( pad->GetNetname() != last_pad->GetNetname() ) )
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
|
|
|
netcode++;
|
2011-09-23 13:57:12 +00:00
|
|
|
net_item = new NETINFO_ITEM( (BOARD_ITEM*)m_Parent );
|
2009-05-24 18:28:36 +00:00
|
|
|
net_item->SetNet( netcode );
|
|
|
|
net_item->SetNetname( pad->GetNetname() );
|
2009-06-06 18:08:49 +00:00
|
|
|
AppendNet( net_item );
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pad->SetNet( netcode );
|
2011-12-17 21:21:03 +00:00
|
|
|
net_item->m_PadInNetList.push_back( pad );
|
2009-05-24 18:28:36 +00:00
|
|
|
nodes_count ++;
|
|
|
|
last_pad = pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Parent->m_NbNodes = nodes_count;
|
2009-08-17 02:59:38 +00:00
|
|
|
|
|
|
|
m_Parent->SynchronizeNetsAndNetClasses( );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
|
|
|
m_Parent->m_Status_Pcb |= NET_CODES_OK;
|
|
|
|
|
|
|
|
m_Parent->SetAreasNetCodesFromNetNames();
|
2009-10-13 16:29:02 +00:00
|
|
|
|
|
|
|
// For test and debug purposes only
|
|
|
|
#if 0
|
|
|
|
for( unsigned icnt = 0; icnt < GetCount(); icnt++)
|
|
|
|
{
|
2011-09-23 13:57:12 +00:00
|
|
|
wxLogWarning( wxT( "icnt %d, netcode %d, netname <%s>\n" ),
|
|
|
|
icnt, m_NetBuffer[icnt]->GetNet(),
|
|
|
|
GetChars( m_NetBuffer[icnt]->GetNetname() ) );
|
2009-10-13 16:29:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
void NETINFO_LIST::buildPadsFullList()
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
2011-12-10 05:33:24 +00:00
|
|
|
/*
|
|
|
|
* initialize:
|
|
|
|
* m_Pads (list of pads)
|
|
|
|
* set m_Status_Pcb = LISTE_PAD_OK;
|
|
|
|
* also clear m_Pcb->m_FullRatsnest that could have bad data
|
|
|
|
* (m_Pcb->m_FullRatsnest uses pointer to pads)
|
|
|
|
* Be aware NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname )
|
|
|
|
* when search a net by its net name does a binary search
|
|
|
|
* and expects to have a nets list sorted by an alphabetic case sensitive sort
|
|
|
|
* So do not change the sort function used here
|
|
|
|
*/
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
if( m_Parent->m_Status_Pcb & LISTE_PAD_OK )
|
2009-05-24 18:28:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// empty the old list
|
2009-06-11 14:26:17 +00:00
|
|
|
m_PadsFullList.clear();
|
|
|
|
m_Parent->m_FullRatsnest.clear();
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
// Clear variables used in ratsnest computation
|
2009-06-11 14:26:17 +00:00
|
|
|
for( MODULE* module = m_Parent->m_Modules; module; module = module->Next() )
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
|
|
|
for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() )
|
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
m_PadsFullList.push_back( pad );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
|
|
|
pad->SetSubRatsnest( 0 );
|
|
|
|
pad->SetParent( module );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort pad list per net
|
2011-12-10 05:33:24 +00:00
|
|
|
sort( m_PadsFullList.begin(), m_PadsFullList.end(), padlistSortByNetnames );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
m_Parent->m_Status_Pcb = LISTE_PAD_OK;
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|