kicad/eeschema/netlist.cpp

963 lines
29 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file eeschema/netlist.cpp
*/
2007-05-06 16:03:28 +00:00
#include <fctsys.h>
#include <wxEeschemaStruct.h>
#include <netlist.h>
#include <class_netlist_object.h>
#include <class_library.h>
#include <lib_pin.h>
#include <sch_junction.h>
#include <sch_component.h>
#include <sch_line.h>
#include <sch_no_connect.h>
#include <sch_text.h>
#include <sch_sheet.h>
#include <algorithm>
#include <boost/foreach.hpp>
#define IS_WIRE false
#define IS_BUS true
// Buffer to build the list of items used in netlist and erc calculations
NETLIST_OBJECT_LIST s_NetObjectslist( true );
//#define NETLIST_DEBUG
2007-05-06 16:03:28 +00:00
NETLIST_OBJECT_LIST::~NETLIST_OBJECT_LIST()
{
if( m_isOwner )
FreeList();
else
Clear();
}
2007-09-21 04:40:12 +00:00
/*
* Delete all objects in list and clear list
* (free memory used to store info about NETLIST_OBJECT items)
*/
void NETLIST_OBJECT_LIST::FreeList()
2007-09-21 04:40:12 +00:00
{
std::vector<NETLIST_OBJECT*>::iterator iter;
for( iter = begin(); iter != end(); iter++ )
2007-09-21 04:40:12 +00:00
{
NETLIST_OBJECT* item = *iter;
delete item;
2007-09-21 04:40:12 +00:00
}
clear();
}
2007-09-20 21:06:49 +00:00
void NETLIST_OBJECT_LIST::SortListbyNetcode()
{
sort( this->begin(), this->end(), NETLIST_OBJECT_LIST::sortItemsbyNetcode );
}
void NETLIST_OBJECT_LIST::SortListbySheet()
2007-05-06 16:03:28 +00:00
{
sort( this->begin(), this->end(), NETLIST_OBJECT_LIST::sortItemsBySheet );
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
/*
* Build net list connection table.
* Initializes s_NetObjectslist
2007-09-20 21:06:49 +00:00
*/
NETLIST_OBJECT_LIST * SCH_EDIT_FRAME::BuildNetListBase()
2007-05-06 16:03:28 +00:00
{
wxBusyCursor Busy;
2007-09-20 21:06:49 +00:00
// Creates the flattened sheet list:
SCH_SHEET_LIST aSheets;
// Build netlist info
bool success = s_NetObjectslist.BuildNetListInfo( aSheets );
2007-09-20 21:06:49 +00:00
if( !success )
{
SetStatusText( _("No Objects" ) );
return &s_NetObjectslist;
}
/* The new %zu specification is needed to properly format a size_t
* value (returned by size(), here) */
wxString msg;
2007-09-20 21:06:49 +00:00
msg.Printf( _( "Net count = %zu" ), s_NetObjectslist.size() );
SetStatusText( msg );
return &s_NetObjectslist;
}
2007-09-20 21:06:49 +00:00
/* the master function of NETLIST_OBJECT_LIST class.
* Build the list of connected objects (pins, labels ...) and
* all info needed to generate netlists or run ERC diags
*/
bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets )
{
s_NetObjectslist.SetOwner( true );
s_NetObjectslist.FreeList();
2007-09-20 21:06:49 +00:00
SCH_SHEET_PATH* sheet;
// Fill list with connected items from the flattened sheet list
for( sheet = aSheets.GetFirst(); sheet != NULL;
sheet = aSheets.GetNext() )
{
for( SCH_ITEM* item = sheet->LastScreen()->GetDrawItems(); item; item = item->Next() )
{
item->GetNetListItem( *this, sheet );
}
}
if( size() == 0 )
return false;
2007-09-20 21:06:49 +00:00
// Sort objects by Sheet
SortListbySheet();
sheet = &(GetItem( 0 )->m_SheetPath);
m_lastNetCode = m_lastBusNetCode = 1;
2008-03-20 01:50:21 +00:00
for( unsigned ii = 0, istart = 0; ii < size(); ii++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* net_item = GetItem( ii );
if( net_item->m_SheetPath != *sheet ) // Sheet change
2007-09-20 21:06:49 +00:00
{
sheet = &(net_item->m_SheetPath);
istart = ii;
2007-09-20 21:06:49 +00:00
}
switch( net_item->m_Type )
2007-09-20 21:06:49 +00:00
{
case NET_ITEM_UNSPECIFIED:
wxMessageBox( wxT( "BuildNetListBase() error" ) );
break;
2007-09-20 21:06:49 +00:00
case NET_PIN:
case NET_PINLABEL:
case NET_SHEETLABEL:
case NET_NOCONNECT:
if( net_item->GetNet() != 0 )
break;
2007-09-20 21:06:49 +00:00
case NET_SEGMENT:
// Test connections point to point type without bus.
if( net_item->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
net_item->SetNet( m_lastNetCode );
m_lastNetCode++;
2007-09-20 21:06:49 +00:00
}
pointToPointConnect( net_item, IS_WIRE, istart );
2007-09-20 21:06:49 +00:00
break;
case NET_JUNCTION:
// Control of the junction outside BUS.
if( net_item->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
net_item->SetNet( m_lastNetCode );
m_lastNetCode++;
2007-09-20 21:06:49 +00:00
}
segmentToPointConnect( net_item, IS_WIRE, istart );
2007-09-20 21:06:49 +00:00
/* Control of the junction, on BUS. */
if( net_item->m_BusNetCode == 0 )
2007-09-20 21:06:49 +00:00
{
net_item->m_BusNetCode = m_lastBusNetCode;
m_lastBusNetCode++;
2007-09-20 21:06:49 +00:00
}
segmentToPointConnect( net_item, IS_BUS, istart );
2007-09-20 21:06:49 +00:00
break;
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
// Test connections type junction without bus.
if( net_item->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
net_item->SetNet( m_lastNetCode );
m_lastNetCode++;
2007-09-20 21:06:49 +00:00
}
segmentToPointConnect( net_item, IS_WIRE, istart );
2007-09-20 21:06:49 +00:00
break;
case NET_SHEETBUSLABELMEMBER:
if( net_item->m_BusNetCode != 0 )
break;
2007-09-20 21:06:49 +00:00
case NET_BUS:
/* Control type connections point to point mode bus */
if( net_item->m_BusNetCode == 0 )
2007-09-20 21:06:49 +00:00
{
net_item->m_BusNetCode = m_lastBusNetCode;
m_lastBusNetCode++;
2007-09-20 21:06:49 +00:00
}
pointToPointConnect( net_item, IS_BUS, istart );
2007-09-20 21:06:49 +00:00
break;
case NET_BUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
/* Control connections similar has on BUS */
if( net_item->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
net_item->m_BusNetCode = m_lastBusNetCode;
m_lastBusNetCode++;
2007-09-20 21:06:49 +00:00
}
segmentToPointConnect( net_item, IS_BUS, istart );
2007-09-20 21:06:49 +00:00
break;
}
}
#if defined(NETLIST_DEBUG) && defined(DEBUG)
std::cout << "\n\nafter sheet local\n\n";
DumpNetTable();
2008-03-20 01:50:21 +00:00
#endif
2007-09-21 04:40:12 +00:00
/* Updating the Bus Labels Netcode connected by Bus */
connectBusLabels();
2007-09-20 21:06:49 +00:00
/* Group objects by label. */
for( unsigned ii = 0; ii < size(); ii++ )
2007-09-20 21:06:49 +00:00
{
switch( GetItem( ii )->m_Type )
2007-09-20 21:06:49 +00:00
{
case NET_PIN:
case NET_SHEETLABEL:
case NET_SEGMENT:
case NET_JUNCTION:
2007-09-20 21:06:49 +00:00
case NET_BUS:
case NET_NOCONNECT:
break;
case NET_LABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_PINLABEL:
case NET_BUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
labelConnect( GetItem( ii ) );
2007-09-20 21:06:49 +00:00
break;
case NET_SHEETBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_HIERLABEL:
case NET_HIERBUSLABELMEMBER:
2007-09-20 21:06:49 +00:00
break;
case NET_ITEM_UNSPECIFIED:
break;
2007-09-20 21:06:49 +00:00
}
}
#if defined(NETLIST_DEBUG) && defined(DEBUG)
std::cout << "\n\nafter sheet global\n\n";
DumpNetTable();
2008-03-20 01:50:21 +00:00
#endif
// Connection between hierarchy sheets
for( unsigned ii = 0; ii < size(); ii++ )
2007-09-20 21:06:49 +00:00
{
if( GetItem( ii )->m_Type == NET_SHEETLABEL
|| GetItem( ii )->m_Type == NET_SHEETBUSLABELMEMBER )
sheetLabelConnect( GetItem( ii ) );
2007-09-20 21:06:49 +00:00
}
2008-03-20 01:50:21 +00:00
// Sort objects by NetCode
SortListbyNetcode();
2007-09-20 21:06:49 +00:00
#if defined(NETLIST_DEBUG) && defined(DEBUG)
std::cout << "\n\nafter qsort()\n";
DumpNetTable();
2008-03-20 01:50:21 +00:00
#endif
/* Compress numbers of Netcode having consecutive values. */
int NetCode = 0;
m_lastNetCode = 0;
for( unsigned ii = 0; ii < size(); ii++ )
2007-09-20 21:06:49 +00:00
{
if( GetItem( ii )->GetNet() != m_lastNetCode )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
NetCode++;
m_lastNetCode = GetItem( ii )->GetNet();
2007-09-20 21:06:49 +00:00
}
GetItem( ii )->SetNet( NetCode );
2007-09-20 21:06:49 +00:00
}
// Set the minimal connection info:
setUnconnectedFlag();
// find the best label object to give the best net name to each net
findBestNetNameForEachNet();
return true;
}
// Helper function to give a priority to sort labels:
// NET_PINLABEL and NET_GLOBLABEL are global labels
// and the priority is hight
static int getPriority( const NETLIST_OBJECT* Objet )
{
switch( Objet->m_Type )
{
case NET_PIN: return 1;
case NET_LABEL: return 2;
case NET_HIERLABEL: return 3;
case NET_PINLABEL: return 4;
case NET_GLOBLABEL: return 5;
default: break;
}
return 0;
}
/* function evalLabelsPriority used by findBestNetNameForEachNet()
* evalLabelsPriority calculates the priority of alabel1 and aLabel2
* return true if alabel1 has a highter priority than aLabel2
*/
static bool evalLabelsPriority( const NETLIST_OBJECT* aLabel1,
const NETLIST_OBJECT* aLabel2 )
{
int priority1 = getPriority( aLabel1 );
int priority2 = getPriority( aLabel2 );
if( priority1 != priority2 )
return priority1 > priority2;
// Objects have here the same priority, therefore they have the same type.
// for global labels, we select the best candidate by alphabetic order
// because they have no sheetpath as prefix name
// for other labels, we select them before by sheet deep order
// because the actual name is /sheetpath/label
// and for a given path length, by alphabetic order
if( aLabel1->m_Type == NET_PINLABEL || aLabel1->m_Type == NET_GLOBLABEL )
return aLabel1->m_Label.Cmp( aLabel2->m_Label );
// not global: names are prefixed by their sheetpath
// use name defined in higher hierarchical sheet
// (i.e. shorter path because paths are /<timestamp1>/<timestamp2>/...
// and timestamp = 8 letters.
if( aLabel1->m_SheetPath.Path().Length() != aLabel2->m_SheetPath.Path().Length() )
return aLabel1->m_SheetPath.Path().Length() < aLabel2->m_SheetPath.Path().Length();
// Sheet paths have the same length: use alphabetic label name order
// For labels on sheets having an equivalent deep in hierarchy, use
// alphabetic label name order:
if( aLabel1->m_Label.Cmp( aLabel2->m_Label ) != 0 )
return aLabel1->m_Label.Cmp( aLabel2->m_Label ) < 0;
return aLabel1->m_SheetPath.PathHumanReadable().Cmp(
aLabel2->m_SheetPath.PathHumanReadable() ) < 0;
}
/**
* Function findBestNetNameForEachNet
* fill the .m_NetNameCandidate member of each item of aNetItemBuffer
* with a reference to the "best" NETLIST_OBJECT usable to give a name to the net
* If no suitable object found, .m_NetNameCandidate is filled with 0.
* The "best" NETLIST_OBJECT is a NETLIST_OBJECT that have the type label
* and by priority order:
* the label is global or local
* the label is in the first sheet in a hierarchy (the root sheet has the most priority)
* alphabetic order.
*/
void NETLIST_OBJECT_LIST::findBestNetNameForEachNet()
{
int netcode = 0; // current netcode for tested items
unsigned idxstart = 0; // index of the first item of this net
NETLIST_OBJECT* item;
NETLIST_OBJECT* candidate;
// Pass 1: find the best name for labelled nets:
item = NULL;
candidate = NULL;
for( unsigned ii = 0; ii <= size(); ii++ )
{
if( ii == size() ) // last item already found
netcode = -2;
else
item = GetItem( ii );
if( netcode != item->GetNet() ) // End of net found
{
if( candidate ) // One or more labels exists, find the best
{
for (unsigned jj = idxstart; jj < ii; jj++ )
GetItem( jj )->SetNetNameCandidate( candidate );
}
if( netcode == -2 )
break;
netcode = item->GetNet();
candidate = NULL;
idxstart = ii;
}
switch( item->m_Type )
{
case NET_HIERLABEL:
case NET_LABEL:
case NET_PINLABEL:
case NET_GLOBLABEL:
// A candidate is found: select the better between the previous
// and this one
if( candidate == NULL )
candidate = item;
else
{
if( evalLabelsPriority( item, candidate ) )
// item has a highter priority than candidate
// so update the best candidate
candidate = item;
}
break;
default:
break;
}
}
// Pass 2: find the best name for not labelled nets:
// The "default" net name is Net-<<Ref cmp>_Pad<num pad>>
// (see NETLIST_OBJECT::GetShortNetName())
// therefore the "best" is the short net name alphabetically classed first
// (to avoid net names changes when the net is not modified,
// even if components are moved or deleted and undelete or replaced, as long
// the reference is kept)
// Build the list of items with no net names
NETLIST_OBJECT_LIST list;
for( unsigned ii = 0; ii < size(); ii++ )
{
item = GetItem( ii );
if( !item->HasNetNameCandidate() )
list.push_back( item );
}
if( list.size() == 0 )
return;
idxstart = 0;
candidate = NULL;
netcode = list.GetItemNet( 0 );
for( unsigned ii = 0; ii <= list.size(); ii++ )
{
if( ii < list.size() )
item = list.GetItem( ii );
if( netcode != item->GetNet() || ii >= list.size() ) // End of net found
{
if( candidate )
{
for (unsigned jj = idxstart; jj < ii; jj++ )
{
NETLIST_OBJECT* obj = list.GetItem( jj );
obj->SetNetNameCandidate( candidate );
}
}
if( ii >= list.size() )
break;
netcode = item->GetNet();
candidate = NULL;
idxstart = ii;
}
// Examine all pins of the net to find the best candidate,
// i.e. the first net name candidate, by alphabetic order
// the net names are names bu_ilt by GetShortNetName
// (Net-<{reference}-Pad{pad number}> like Net-<U3-Pad5>
// Not named nets do not have usually a lot of members.
// Many have only 2 members(a pad and a non connection symbol)
if( item->m_Type == NET_PIN )
{
// A candidate is found, however components which are not in
// netlist are not candidate because some have their reference
// changed each time the netlist is built (power components)
// and anyway obviously they are not a good candidate
SCH_COMPONENT* link = item->GetComponentParent();
if( link && link->IsInNetlist() )
{
// select the better between the previous and this one
item->SetNetNameCandidate( item ); // Needed to calculate GetShortNetName
if( candidate == NULL )
candidate = item;
else
{
if( item->GetShortNetName().Cmp( candidate->GetShortNetName() ) < 0 )
candidate = item;
}
}
}
}
}
2007-09-20 21:06:49 +00:00
/*
* Propagate net codes from a parent sheet to an include sheet,
* from a pin sheet connection
*/
void NETLIST_OBJECT_LIST::sheetLabelConnect( NETLIST_OBJECT* SheetLabel )
2007-05-06 16:03:28 +00:00
{
2007-10-13 06:18:44 +00:00
if( SheetLabel->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
return;
for( unsigned ii = 0; ii < size(); ii++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* ObjetNet = GetItem( ii );
if( ObjetNet->m_SheetPath != SheetLabel->m_SheetPathInclude )
continue; //use SheetInclude, not the sheet!!
2008-03-20 01:50:21 +00:00
if( (ObjetNet->m_Type != NET_HIERLABEL ) && (ObjetNet->m_Type != NET_HIERBUSLABELMEMBER ) )
2007-09-20 21:06:49 +00:00
continue;
2008-03-20 01:50:21 +00:00
if( ObjetNet->GetNet() == SheetLabel->GetNet() )
continue; //already connected.
2008-03-20 01:50:21 +00:00
if( ObjetNet->m_Label.CmpNoCase( SheetLabel->m_Label ) != 0 )
continue; //different names.
2007-09-20 21:06:49 +00:00
// Propagate Netcode having all the objects of the same Netcode.
if( ObjetNet->GetNet() )
propageNetCode( ObjetNet->GetNet(), SheetLabel->GetNet(), IS_WIRE );
2007-09-20 21:06:49 +00:00
else
ObjetNet->SetNet( SheetLabel->GetNet() );
2007-09-20 21:06:49 +00:00
}
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
/*
* Analyzes the labels type bus member (<BUS_NAME><member_number>
* Propagate net codes between the corresponding labels (ie when
* the <member_number> is the same) when they are connected
* uqsually by their BusNetCode
* Uses and updates the variable m_lastNetCode
2007-09-20 21:06:49 +00:00
*/
void NETLIST_OBJECT_LIST::connectBusLabels()
2007-05-06 16:03:28 +00:00
{
for( unsigned ii = 0; ii < size(); ii++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* Label = GetItem( ii );
if( (Label->m_Type == NET_SHEETBUSLABELMEMBER)
|| (Label->m_Type == NET_BUSLABELMEMBER)
|| (Label->m_Type == NET_HIERBUSLABELMEMBER) )
2007-09-20 21:06:49 +00:00
{
2007-10-13 06:18:44 +00:00
if( Label->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
Label->SetNet( m_lastNetCode );
m_lastNetCode++;
2007-09-20 21:06:49 +00:00
}
2008-03-20 01:50:21 +00:00
for( unsigned jj = ii + 1; jj < size(); jj++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* LabelInTst = GetItem( jj );
2007-09-20 21:06:49 +00:00
if( (LabelInTst->m_Type == NET_SHEETBUSLABELMEMBER)
|| (LabelInTst->m_Type == NET_BUSLABELMEMBER)
|| (LabelInTst->m_Type == NET_HIERBUSLABELMEMBER) )
2007-09-20 21:06:49 +00:00
{
if( LabelInTst->m_BusNetCode != Label->m_BusNetCode )
continue;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
if( LabelInTst->m_Member != Label->m_Member )
continue;
2008-03-20 01:50:21 +00:00
2007-10-13 06:18:44 +00:00
if( LabelInTst->GetNet() == 0 )
LabelInTst->SetNet( Label->GetNet() );
2007-09-20 21:06:49 +00:00
else
propageNetCode( LabelInTst->GetNet(), Label->GetNet(), IS_WIRE );
2007-09-20 21:06:49 +00:00
}
}
}
}
2007-05-06 16:03:28 +00:00
}
/*
* propageNetCode propagates the net code NewNetCode to all elements
* having previously the net code OldNetCode
* If IsBus == false, m_Netcode is used to propagate the new net code
* If IsBus == true, m_BusNetCode is used to propagate the new net code
2007-09-20 21:06:49 +00:00
*/
void NETLIST_OBJECT_LIST::propageNetCode( int aOldNetCode, int aNewNetCode, bool aIsBus )
2007-05-06 16:03:28 +00:00
{
if( aOldNetCode == aNewNetCode )
2007-09-20 21:06:49 +00:00
return;
if( aIsBus == false ) // Propagate NetCode
2007-09-20 21:06:49 +00:00
{
for( unsigned jj = 0; jj < size(); jj++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* objet = GetItem( jj );
if( objet->GetNet() == aOldNetCode )
objet->SetNet( aNewNetCode );
2007-09-20 21:06:49 +00:00
}
}
else // Propagate BusNetCode
2007-09-20 21:06:49 +00:00
{
for( unsigned jj = 0; jj < size(); jj++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* objet = GetItem( jj );
if( objet->m_BusNetCode == aOldNetCode )
objet->m_BusNetCode = aNewNetCode;
2007-09-20 21:06:49 +00:00
}
}
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
/*
* Check if Ref element is connected to other elements of the list of objects
* in the schematic, by mode point
* A point (end superimposed)
2008-03-20 01:50:21 +00:00
*
* If IsBus:
* The connection involves elements such as bus
* (Or BUS or BUSLABEL JUNCTION)
* Otherwise
* The connection involves elements such as non-bus
* (Other than BUS or BUSLABEL)
2008-03-20 01:50:21 +00:00
*
* The Ref object must have a valid Netcode.
2008-03-20 01:50:21 +00:00
*
* The list of objects is SUPPOSED class by SheetPath Croissants,
* And research is done from the start element, 1st element
* Leaf schema
* (There can be no physical connection between elements of different sheets)
2007-09-20 21:06:49 +00:00
*/
void NETLIST_OBJECT_LIST::pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus,
int start )
2007-05-06 16:03:28 +00:00
{
int netCode;
2007-09-20 21:06:49 +00:00
if( aIsBus == false ) // Objects other than BUS and BUSLABELS
2007-09-20 21:06:49 +00:00
{
netCode = aRef->GetNet();
for( unsigned i = start; i < size(); i++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* item = GetItem( i );
if( item->m_SheetPath != aRef->m_SheetPath ) //used to be > (why?)
continue;
2008-03-20 01:50:21 +00:00
switch( item->m_Type )
2007-09-20 21:06:49 +00:00
{
case NET_SEGMENT:
case NET_PIN:
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_SHEETLABEL:
case NET_PINLABEL:
case NET_JUNCTION:
2007-09-20 21:06:49 +00:00
case NET_NOCONNECT:
if( aRef->m_Start == item->m_Start
|| aRef->m_Start == item->m_End
|| aRef->m_End == item->m_Start
|| aRef->m_End == item->m_End )
2007-09-20 21:06:49 +00:00
{
if( item->GetNet() == 0 )
item->SetNet( netCode );
2007-09-20 21:06:49 +00:00
else
propageNetCode( item->GetNet(), netCode, IS_WIRE );
2007-09-20 21:06:49 +00:00
}
break;
case NET_BUS:
case NET_BUSLABELMEMBER:
case NET_SHEETBUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
case NET_ITEM_UNSPECIFIED:
2007-09-20 21:06:49 +00:00
break;
}
}
}
else /* Object type BUS, BUSLABELS, and junctions. */
2007-09-20 21:06:49 +00:00
{
netCode = aRef->m_BusNetCode;
for( unsigned i = start; i < size(); i++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* item = GetItem( i );
if( item->m_SheetPath != aRef->m_SheetPath )
continue;
2007-09-20 21:06:49 +00:00
switch( item->m_Type )
2007-09-20 21:06:49 +00:00
{
case NET_ITEM_UNSPECIFIED:
2007-09-20 21:06:49 +00:00
case NET_SEGMENT:
case NET_PIN:
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_SHEETLABEL:
case NET_PINLABEL:
case NET_NOCONNECT:
break;
case NET_BUS:
case NET_BUSLABELMEMBER:
case NET_SHEETBUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
case NET_JUNCTION:
if( aRef->m_Start == item->m_Start
|| aRef->m_Start == item->m_End
|| aRef->m_End == item->m_Start
|| aRef->m_End == item->m_End )
2007-09-20 21:06:49 +00:00
{
if( item->m_BusNetCode == 0 )
item->m_BusNetCode = netCode;
2007-09-20 21:06:49 +00:00
else
propageNetCode( item->m_BusNetCode, netCode, IS_BUS );
2007-09-20 21:06:49 +00:00
}
break;
}
}
}
2007-05-06 16:03:28 +00:00
}
/*
* Search connections betweena junction and segments
* Propagate the junction net code to objects connected by this junction.
* The junction must have a valid net code
* The list of objects is expected sorted by sheets.
* Search is done from index aIdxStart to the last element of list
2007-09-20 21:06:49 +00:00
*/
void NETLIST_OBJECT_LIST::segmentToPointConnect( NETLIST_OBJECT* aJonction,
bool aIsBus, int aIdxStart )
2007-05-06 16:03:28 +00:00
{
for( unsigned i = aIdxStart; i < size(); i++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* segment = GetItem( i );
// if different sheets, obviously no physical connection between elements.
if( segment->m_SheetPath != aJonction->m_SheetPath )
continue;
2007-09-20 21:06:49 +00:00
if( aIsBus == IS_WIRE )
2007-09-20 21:06:49 +00:00
{
if( segment->m_Type != NET_SEGMENT )
2007-09-20 21:06:49 +00:00
continue;
}
else
{
if( segment->m_Type != NET_BUS )
2007-09-20 21:06:49 +00:00
continue;
}
if( IsPointOnSegment( segment->m_Start, segment->m_End, aJonction->m_Start ) )
2007-09-20 21:06:49 +00:00
{
// Propagation Netcode has all the objects of the same Netcode.
if( aIsBus == IS_WIRE )
2007-09-20 21:06:49 +00:00
{
if( segment->GetNet() )
propageNetCode( segment->GetNet(), aJonction->GetNet(), aIsBus );
2007-09-20 21:06:49 +00:00
else
segment->SetNet( aJonction->GetNet() );
2007-09-20 21:06:49 +00:00
}
else
{
if( segment->m_BusNetCode )
propageNetCode( segment->m_BusNetCode, aJonction->m_BusNetCode, aIsBus );
2007-09-20 21:06:49 +00:00
else
segment->m_BusNetCode = aJonction->m_BusNetCode;
2007-09-20 21:06:49 +00:00
}
}
}
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
/*
* This function merges the net codes of groups of objects already connected
* to labels (wires, bus, pins ... ) when 2 labels are equivalents
* (i.e. group objects connected by labels)
*/
void NETLIST_OBJECT_LIST::labelConnect( NETLIST_OBJECT* aLabelRef )
2007-05-06 16:03:28 +00:00
{
if( aLabelRef->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
return;
for( unsigned i = 0; i < size(); i++ )
2007-09-20 21:06:49 +00:00
{
NETLIST_OBJECT* item = GetItem( i );
if( item->GetNet() == aLabelRef->GetNet() )
2007-09-20 21:06:49 +00:00
continue;
if( item->m_SheetPath != aLabelRef->m_SheetPath )
2007-09-20 21:06:49 +00:00
{
if( item->m_Type != NET_PINLABEL && item->m_Type != NET_GLOBLABEL
&& item->m_Type != NET_GLOBBUSLABELMEMBER )
2008-03-20 01:50:21 +00:00
continue;
if( (item->m_Type == NET_GLOBLABEL
|| item->m_Type == NET_GLOBBUSLABELMEMBER)
&& item->m_Type != aLabelRef->m_Type )
2008-03-20 01:50:21 +00:00
//global labels only connect other global labels.
2007-09-20 21:06:49 +00:00
continue;
}
// NET_HIERLABEL are used to connect sheets.
// NET_LABEL are local to a sheet
// NET_GLOBLABEL are global.
// NET_PINLABEL is a kind of global label (generated by a power pin invisible)
if( item->IsLabelType() )
2007-09-20 21:06:49 +00:00
{
if( item->m_Label.CmpNoCase( aLabelRef->m_Label ) != 0 )
2007-09-20 21:06:49 +00:00
continue;
if( item->GetNet() )
propageNetCode( item->GetNet(), aLabelRef->GetNet(), IS_WIRE );
2007-09-20 21:06:49 +00:00
else
item->SetNet( aLabelRef->GetNet() );
2007-09-20 21:06:49 +00:00
}
}
2007-05-06 16:03:28 +00:00
}
/* Set the m_ConnectionType member of items in list
* depending on the connection type:
* UNCONNECTED, PAD_CONNECT or NOCONNECT_SYMBOL_PRESENT
* The list is expected sorted by order of net code,
* i.e. items having the same net code are grouped
2007-09-20 21:06:49 +00:00
*/
void NETLIST_OBJECT_LIST::setUnconnectedFlag()
2007-05-06 16:03:28 +00:00
{
NETLIST_OBJECT* NetItemRef;
unsigned NetStart, NetEnd;
NET_CONNECTION_T StateFlag;
2007-09-20 21:06:49 +00:00
NetStart = NetEnd = 0;
StateFlag = UNCONNECTED;
for( unsigned ii = 0; ii < size(); ii++ )
2007-09-20 21:06:49 +00:00
{
NetItemRef = GetItem( ii );
if( NetItemRef->m_Type == NET_NOCONNECT && StateFlag != PAD_CONNECT )
StateFlag = NOCONNECT_SYMBOL_PRESENT;
2007-09-20 21:06:49 +00:00
/* Analysis of current net. */
unsigned idxtoTest = ii + 1;
2007-09-20 21:06:49 +00:00
if( ( idxtoTest >= size() )
|| ( NetItemRef->GetNet() != GetItem( idxtoTest )->GetNet() ) )
2008-03-20 01:50:21 +00:00
{
/* Net analysis to update m_ConnectionType */
NetEnd = idxtoTest;
2007-09-20 21:06:49 +00:00
/* set m_ConnectionType member to StateFlag for all items of
* this net: */
for( unsigned kk = NetStart; kk < NetEnd; kk++ )
GetItem( kk )->m_ConnectionType = StateFlag;
2007-09-20 21:06:49 +00:00
if( idxtoTest >= size() )
2007-09-20 21:06:49 +00:00
return;
/* Start Analysis next Net */
StateFlag = UNCONNECTED;
NetStart = idxtoTest;
2007-09-20 21:06:49 +00:00
continue;
}
/* 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++ )
2007-09-20 21:06:49 +00:00
{
if( ( idxtoTest >= size() )
|| ( NetItemRef->GetNet() != GetItem( idxtoTest )->GetNet() ) )
2007-09-20 21:06:49 +00:00
break;
switch( GetItem( idxtoTest )->m_Type )
2007-09-20 21:06:49 +00:00
{
case NET_ITEM_UNSPECIFIED:
wxMessageBox( wxT( "BuildNetListBase() error" ) );
break;
2007-09-20 21:06:49 +00:00
case NET_SEGMENT:
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_SHEETLABEL:
case NET_PINLABEL:
case NET_BUS:
case NET_BUSLABELMEMBER:
case NET_SHEETBUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
case NET_JUNCTION:
2007-09-20 21:06:49 +00:00
break;
case NET_PIN:
if( NetItemRef->m_Type == NET_PIN )
2008-01-05 17:30:56 +00:00
StateFlag = PAD_CONNECT;
2007-09-20 21:06:49 +00:00
break;
case NET_NOCONNECT:
2008-01-05 17:30:56 +00:00
if( StateFlag != PAD_CONNECT )
StateFlag = NOCONNECT_SYMBOL_PRESENT;
2007-09-20 21:06:49 +00:00
break;
}
}
}
2007-05-06 16:03:28 +00:00
}