2009-05-24 18:28:36 +00:00
|
|
|
/***********************/
|
|
|
|
/**** class_netinfolist.cpp ****/
|
|
|
|
/***********************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "pcbnew.h"
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor and destructor
|
|
|
|
NETINFO_LIST::NETINFO_LIST( BOARD* aParent )
|
|
|
|
{
|
|
|
|
m_Parent = aParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NETINFO_LIST::~NETINFO_LIST()
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
DeleteData();
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function GetItem
|
2009-05-24 18:28:36 +00:00
|
|
|
* @param aNetcode = netcode to identify a given NETINFO_ITEM
|
|
|
|
* @return a NETINFO_ITEM pointer to the selected NETINFO_ITEM by its netcode, or NULL if not found
|
|
|
|
*/
|
2009-06-06 18:08:49 +00:00
|
|
|
NETINFO_ITEM* NETINFO_LIST::GetNetItem( int aNetcode )
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
2009-08-17 02:59:38 +00:00
|
|
|
if( aNetcode < 0 || ( aNetcode > (int) ( GetCount() - 1 ) ) )
|
2009-05-24 18:28:36 +00:00
|
|
|
return NULL;
|
|
|
|
return m_NetBuffer[aNetcode];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function DeleteData
|
2009-05-24 18:28:36 +00:00
|
|
|
* delete the list of nets (and free memory)
|
|
|
|
*/
|
2009-05-28 08:42:24 +00:00
|
|
|
void NETINFO_LIST::DeleteData()
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
2009-08-17 02:59:38 +00:00
|
|
|
for( unsigned ii = 0; ii < GetCount(); 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
|
|
|
*/
|
|
|
|
|
|
|
|
static bool PadlistSortByNetnames( const D_PAD* a, const D_PAD* b )
|
|
|
|
{
|
|
|
|
return ( a->GetNetname().Cmp( b->GetNetname() ) ) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************/
|
|
|
|
void NETINFO_LIST::BuildListOfNets()
|
|
|
|
/*****************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
{
|
|
|
|
D_PAD* pad;
|
|
|
|
int nodes_count = 0;
|
|
|
|
NETINFO_ITEM* net_item;
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
DeleteData(); // 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
|
2009-05-24 18:28:36 +00:00
|
|
|
net_item = new NETINFO_ITEM( m_Parent );
|
2009-06-06 18:08:49 +00:00
|
|
|
AppendNet( net_item );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
|
|
|
/* Build the PAD list, sorted by net */
|
2009-06-11 14:26:17 +00:00
|
|
|
Build_Pads_Full_List();
|
2009-05-24 18:28:36 +00:00
|
|
|
|
|
|
|
/* Build netnames list, and create a netcode for each netname */
|
|
|
|
D_PAD* last_pad = NULL;
|
2009-06-05 15:57:41 +00:00
|
|
|
int netcode = 0;
|
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];
|
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
|
|
|
|
*/
|
|
|
|
if( last_pad == NULL || ( pad->GetNetname() != last_pad->GetNetname() ) ) // create a new net_code
|
|
|
|
{
|
|
|
|
netcode++;
|
|
|
|
net_item = new NETINFO_ITEM( m_Parent );
|
|
|
|
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 );
|
|
|
|
net_item->m_ListPad.push_back( pad );
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
wxLogWarning(wxT("icnt %d, netcode %d, netname <%s>\n"),
|
|
|
|
icnt, m_NetBuffer[icnt]->GetNet(),
|
|
|
|
GetChars( m_NetBuffer[icnt]->GetNetname() ) );
|
|
|
|
}
|
|
|
|
#endif
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
/*****************************************/
|
|
|
|
void NETINFO_LIST::Build_Pads_Full_List()
|
|
|
|
/*****************************************/
|
2009-05-24 18:28:36 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Build_Pads_Full_List
|
2009-09-17 17:48:40 +00:00
|
|
|
* Create the pad list, sorted by net names (sorted by an alphabetic case sensitive sort)
|
2009-05-24 18:28:36 +00:00
|
|
|
* initialise:
|
|
|
|
* m_Pads (list of pads)
|
|
|
|
* set m_Status_Pcb = LISTE_PAD_OK;
|
2009-05-28 08:42:24 +00:00
|
|
|
* also clear m_Pcb->m_FullRatsnest that could have bad data
|
|
|
|
* (m_Pcb->m_FullRatsnest uses pointer to pads)
|
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 the sort function used here
|
2009-05-24 18:28:36 +00:00
|
|
|
*/
|
|
|
|
{
|
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
|
|
|
|
|
|
|
/* Clear variables used in rastnest 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
|
2009-09-17 17:48:40 +00:00
|
|
|
//
|
2009-06-11 14:26:17 +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
|
|
|
}
|