2011-10-12 15:34:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-09-25 19:09:57 +00:00
|
|
|
* 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.
|
2011-10-12 15:34:52 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file class_netlist_object.cpp
|
|
|
|
* @brief Class NETLIST_OBJECT to handle 1 item connected (in netlist and erc calculations)
|
|
|
|
*/
|
2009-07-12 15:29:42 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
2009-07-12 15:29:42 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_component.h>
|
2013-09-25 19:09:57 +00:00
|
|
|
#include <class_netlist_object.h>
|
2009-07-12 15:29:42 +00:00
|
|
|
|
2013-08-13 23:04:41 +00:00
|
|
|
#include <wx/regex.h>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The regular expression string for label bus notation. Valid bus labels are defined as
|
|
|
|
* one or more non-whitespace characters from the beginning of the string followed by the
|
|
|
|
* bus notation [nn...mm] with no characters after the closing bracket.
|
|
|
|
*/
|
|
|
|
static wxRegEx busLabelRe( wxT( "^([^[:space:]]+)(\\[[\\d]+\\.+[\\d]+\\])$" ), wxRE_ADVANCED );
|
|
|
|
|
|
|
|
|
|
|
|
bool IsBusLabel( const wxString& aLabel )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( busLabelRe.IsValid(), false,
|
|
|
|
wxT( "Invalid regular expression in IsBusLabel()." ) );
|
|
|
|
|
|
|
|
return busLabelRe.Matches( aLabel );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
#if defined(DEBUG)
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
#include <iostream>
|
2011-10-12 15:34:52 +00:00
|
|
|
const char* ShowType( NETLIST_ITEM_T aType )
|
2009-07-12 15:29:42 +00:00
|
|
|
{
|
|
|
|
const char* ret;
|
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
case NET_SEGMENT:
|
|
|
|
ret = "segment"; break;
|
|
|
|
|
|
|
|
case NET_BUS:
|
|
|
|
ret = "bus"; break;
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
case NET_JUNCTION:
|
2009-07-12 15:29:42 +00:00
|
|
|
ret = "junction"; break;
|
|
|
|
|
|
|
|
case NET_LABEL:
|
|
|
|
ret = "label"; break;
|
|
|
|
|
|
|
|
case NET_HIERLABEL:
|
|
|
|
ret = "hierlabel"; break;
|
|
|
|
|
|
|
|
case NET_GLOBLABEL:
|
|
|
|
ret = "glabel"; break;
|
|
|
|
|
|
|
|
case NET_BUSLABELMEMBER:
|
|
|
|
ret = "buslblmember"; break;
|
|
|
|
|
|
|
|
case NET_HIERBUSLABELMEMBER:
|
|
|
|
ret = "hierbuslblmember"; break;
|
|
|
|
|
|
|
|
case NET_GLOBBUSLABELMEMBER:
|
|
|
|
ret = "gbuslblmember"; break;
|
|
|
|
|
|
|
|
case NET_SHEETBUSLABELMEMBER:
|
|
|
|
ret = "sbuslblmember"; break;
|
|
|
|
|
|
|
|
case NET_SHEETLABEL:
|
|
|
|
ret = "sheetlabel"; break;
|
|
|
|
|
|
|
|
case NET_PINLABEL:
|
|
|
|
ret = "pinlabel"; break;
|
|
|
|
|
|
|
|
case NET_PIN:
|
|
|
|
ret = "pin"; break;
|
|
|
|
|
|
|
|
case NET_NOCONNECT:
|
|
|
|
ret = "noconnect"; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = "??"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void NETLIST_OBJECT::Show( std::ostream& out, int ndx ) const
|
2009-07-12 15:29:42 +00:00
|
|
|
{
|
2013-09-29 18:24:38 +00:00
|
|
|
wxString path = m_SheetPath.PathHumanReadable();
|
2009-07-12 15:29:42 +00:00
|
|
|
|
|
|
|
out << "<netItem ndx=\"" << ndx << '"' <<
|
|
|
|
" type=\"" << ShowType( m_Type ) << '"' <<
|
|
|
|
" netCode=\"" << GetNet() << '"' <<
|
2011-02-28 18:36:19 +00:00
|
|
|
" sheet=\"" << TO_UTF8( path ) << '"' <<
|
2009-07-12 15:29:42 +00:00
|
|
|
">\n";
|
|
|
|
|
|
|
|
out << " <start " << m_Start << "/> <end " << m_End << "/>\n";
|
|
|
|
|
2010-06-28 13:11:14 +00:00
|
|
|
if( !m_Label.IsEmpty() )
|
2010-06-24 18:31:43 +00:00
|
|
|
out << " <label>" << m_Label.mb_str() << "</label>\n";
|
2009-07-12 15:29:42 +00:00
|
|
|
|
2013-09-29 18:24:38 +00:00
|
|
|
out << " <sheetpath>" << m_SheetPath.PathHumanReadable().mb_str() << "</sheetpath>\n";
|
2010-08-03 05:11:05 +00:00
|
|
|
|
|
|
|
switch( m_Type )
|
|
|
|
{
|
|
|
|
case NET_PIN:
|
2011-12-14 17:25:42 +00:00
|
|
|
/* GetRef() needs to be const
|
2013-09-30 06:36:40 +00:00
|
|
|
out << " <refOfComp>" << GetComponentParent()->GetRef(&m_SheetPath).mb_str()
|
2011-10-07 14:41:30 +00:00
|
|
|
<< "</refOfComp>\n";
|
2011-12-14 17:25:42 +00:00
|
|
|
*/
|
2010-08-03 05:11:05 +00:00
|
|
|
|
|
|
|
if( m_Comp )
|
|
|
|
m_Comp->Show( 1, out );
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2010-08-03 05:11:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// not all the m_Comp classes have working Show functions.
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* was segfault-ing
|
2009-07-12 15:29:42 +00:00
|
|
|
if( m_Comp )
|
2010-08-03 05:11:05 +00:00
|
|
|
m_Comp->Show( 1, out ); // labels may not have good Show() funcs?
|
2009-07-12 15:29:42 +00:00
|
|
|
else
|
|
|
|
out << " m_Comp==NULL\n";
|
2010-08-03 05:11:05 +00:00
|
|
|
*/
|
2009-07-12 15:29:42 +00:00
|
|
|
|
|
|
|
out << "</netItem>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
NETLIST_OBJECT::NETLIST_OBJECT()
|
|
|
|
{
|
2011-10-12 15:34:52 +00:00
|
|
|
m_Type = NET_ITEM_UNSPECIFIED; /* Type of this item (see NETLIST_ITEM_T enum) */
|
2010-06-24 18:31:43 +00:00
|
|
|
m_Comp = NULL; /* Pointer on the library item that created this net object
|
|
|
|
* (the parent)*/
|
|
|
|
m_Link = NULL; /* For SCH_SHEET_PIN:
|
|
|
|
* Pointer to the hierarchy sheet that contains this
|
|
|
|
* SCH_SHEET_PIN For Pins: pointer to the component that
|
|
|
|
* contains this pin
|
|
|
|
*/
|
|
|
|
m_Flag = 0; /* flag used in calculations */
|
2011-10-12 15:34:52 +00:00
|
|
|
m_ElectricalType = 0; /* Has meaning only for Pins and hierarchical pins: electrical
|
2010-06-24 18:31:43 +00:00
|
|
|
* type */
|
2013-09-25 19:09:57 +00:00
|
|
|
m_netCode = 0; /* net code for all items except BUS labels because a BUS
|
2010-06-24 18:31:43 +00:00
|
|
|
* label has as many net codes as bus members
|
|
|
|
*/
|
|
|
|
m_BusNetCode = 0; /* Used for BUS connections */
|
|
|
|
m_Member = 0; /* for labels type NET_BUSLABELMEMBER ( bus member created
|
|
|
|
* from the BUS label ) member number
|
|
|
|
*/
|
2013-09-27 12:30:35 +00:00
|
|
|
m_ConnectionType = UNCONNECTED;
|
2009-07-12 15:29:42 +00:00
|
|
|
m_PinNum = 0; /* pin number ( 1 long = 4 bytes -> 4 ascii codes) */
|
2013-09-25 19:09:57 +00:00
|
|
|
m_netNameCandidate = NULL; /* a pointer to a NETLIST_OBJECT type label connected to this
|
2010-06-24 18:31:43 +00:00
|
|
|
* object used to give a name to the net
|
2010-06-23 17:00:12 +00:00
|
|
|
*/
|
2009-07-12 15:29:42 +00:00
|
|
|
}
|
|
|
|
|
2010-06-23 17:00:12 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
// Copy constructor
|
|
|
|
NETLIST_OBJECT::NETLIST_OBJECT( NETLIST_OBJECT& aSource )
|
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
*this = aSource;
|
2009-07-12 15:29:42 +00:00
|
|
|
}
|
|
|
|
|
2010-06-23 17:00:12 +00:00
|
|
|
|
2009-07-12 15:29:42 +00:00
|
|
|
NETLIST_OBJECT::~NETLIST_OBJECT()
|
|
|
|
{
|
|
|
|
}
|
2010-08-03 02:13:33 +00:00
|
|
|
|
2013-09-25 19:09:57 +00:00
|
|
|
// return true if the object is a label of any type
|
|
|
|
bool NETLIST_OBJECT::IsLabelType() const
|
|
|
|
{
|
|
|
|
return m_Type == NET_LABEL
|
|
|
|
|| m_Type == NET_GLOBLABEL || m_Type == NET_HIERLABEL
|
|
|
|
|| m_Type == NET_BUSLABELMEMBER || m_Type == NET_GLOBBUSLABELMEMBER
|
|
|
|
|| m_Type == NET_HIERBUSLABELMEMBER
|
|
|
|
|| m_Type == NET_PINLABEL;
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
|
|
|
bool NETLIST_OBJECT::IsLabelConnected( NETLIST_OBJECT* aNetItem )
|
|
|
|
{
|
|
|
|
if( aNetItem == this ) // Don't compare the same net list object.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int at = m_Type;
|
|
|
|
int bt = aNetItem->m_Type;
|
|
|
|
|
|
|
|
if( ( at == NET_HIERLABEL || at == NET_HIERBUSLABELMEMBER )
|
|
|
|
&& ( bt == NET_SHEETLABEL || bt == NET_SHEETBUSLABELMEMBER ) )
|
|
|
|
{
|
2013-09-29 18:24:38 +00:00
|
|
|
if( m_SheetPath == aNetItem->m_SheetPathInclude )
|
2011-10-07 14:41:30 +00:00
|
|
|
{
|
|
|
|
return true; //connected!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; //these two are unconnected
|
|
|
|
}
|
2011-10-12 15:34:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
void NETLIST_OBJECT::ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItems )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( IsBusLabel( m_Label ),
|
|
|
|
wxT( "<" ) + m_Label + wxT( "> is not a valid bus label." ) );
|
|
|
|
|
|
|
|
if( m_Type == NET_HIERLABEL )
|
|
|
|
m_Type = NET_HIERBUSLABELMEMBER;
|
|
|
|
else if( m_Type == NET_GLOBLABEL )
|
|
|
|
m_Type = NET_GLOBBUSLABELMEMBER;
|
|
|
|
else if( m_Type == NET_SHEETLABEL )
|
|
|
|
m_Type = NET_SHEETBUSLABELMEMBER;
|
|
|
|
else if( m_Type == NET_LABEL )
|
|
|
|
m_Type = NET_BUSLABELMEMBER;
|
|
|
|
else
|
|
|
|
wxCHECK_RET( false, wxT( "Net list object type is not valid." ) );
|
|
|
|
|
|
|
|
unsigned i;
|
2013-08-13 23:04:41 +00:00
|
|
|
wxString tmp, busName, busNumber;
|
2011-10-12 15:34:52 +00:00
|
|
|
long begin, end, member;
|
|
|
|
|
2013-08-13 23:04:41 +00:00
|
|
|
busName = busLabelRe.GetMatch( m_Label, 1 );
|
|
|
|
busNumber = busLabelRe.GetMatch( m_Label, 2 );
|
2011-10-12 15:34:52 +00:00
|
|
|
|
2013-08-13 23:04:41 +00:00
|
|
|
/* Search for '[' because a bus label is like "busname[nn..mm]" */
|
|
|
|
i = busNumber.Find( '[' );
|
2011-10-12 15:34:52 +00:00
|
|
|
i++;
|
|
|
|
|
2013-08-13 23:04:41 +00:00
|
|
|
while( busNumber[i] != '.' && i < busNumber.Len() )
|
2011-10-12 15:34:52 +00:00
|
|
|
{
|
2013-08-13 23:04:41 +00:00
|
|
|
tmp.Append( busNumber[i] );
|
2011-10-12 15:34:52 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp.ToLong( &begin );
|
|
|
|
|
2013-08-13 23:04:41 +00:00
|
|
|
while( busNumber[i] == '.' && i < busNumber.Len() )
|
2011-10-12 15:34:52 +00:00
|
|
|
i++;
|
|
|
|
|
|
|
|
tmp.Empty();
|
|
|
|
|
2013-08-13 23:04:41 +00:00
|
|
|
while( busNumber[i] != ']' && i < busNumber.Len() )
|
2011-10-12 15:34:52 +00:00
|
|
|
{
|
2013-08-13 23:04:41 +00:00
|
|
|
tmp.Append( busNumber[i] );
|
2011-10-12 15:34:52 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp.ToLong( &end );
|
|
|
|
|
|
|
|
if( begin < 0 )
|
|
|
|
begin = 0;
|
|
|
|
|
|
|
|
if( end < 0 )
|
|
|
|
end = 0;
|
|
|
|
|
|
|
|
if( begin > end )
|
|
|
|
EXCHG( begin, end );
|
|
|
|
|
|
|
|
member = begin;
|
|
|
|
tmp = busName;
|
|
|
|
tmp << member;
|
|
|
|
m_Label = tmp;
|
|
|
|
m_Member = member;
|
|
|
|
|
|
|
|
for( member++; member <= end; member++ )
|
|
|
|
{
|
|
|
|
NETLIST_OBJECT* item = new NETLIST_OBJECT( *this );
|
|
|
|
|
|
|
|
// Conversion of bus label to the root name + the current member id.
|
|
|
|
tmp = busName;
|
|
|
|
tmp << member;
|
|
|
|
item->m_Label = tmp;
|
|
|
|
item->m_Member = member;
|
|
|
|
|
|
|
|
aNetListItems.push_back( item );
|
|
|
|
}
|
|
|
|
}
|
2013-09-25 19:09:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* return the net name of the item
|
|
|
|
*/
|
|
|
|
wxString NETLIST_OBJECT::GetNetName() const
|
|
|
|
{
|
|
|
|
if( m_netNameCandidate == NULL )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
wxString netName;
|
|
|
|
|
|
|
|
if( m_netNameCandidate->m_Type == NET_PIN )
|
|
|
|
return GetShortNetName();
|
|
|
|
|
|
|
|
if( !m_netNameCandidate->IsLabelGlobal() )
|
|
|
|
{
|
|
|
|
// usual net name, prefix it by the sheet path
|
2013-09-29 18:24:38 +00:00
|
|
|
netName = m_netNameCandidate->m_SheetPath.PathHumanReadable();
|
2013-09-25 19:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
netName += m_netNameCandidate->m_Label;
|
|
|
|
|
|
|
|
return netName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return the short net name of the item i.e. the net name
|
|
|
|
* from the "best" label without any prefix.
|
|
|
|
* 2 different nets can have the same short name
|
|
|
|
*/
|
|
|
|
wxString NETLIST_OBJECT::GetShortNetName() const
|
|
|
|
{
|
|
|
|
if( m_netNameCandidate == NULL )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
wxString netName;
|
|
|
|
|
|
|
|
if( m_netNameCandidate->m_Type == NET_PIN )
|
|
|
|
{
|
2013-09-30 06:36:40 +00:00
|
|
|
SCH_COMPONENT* link = m_netNameCandidate->GetComponentParent();
|
2013-09-27 17:58:58 +00:00
|
|
|
if( link ) // Should be always true
|
2013-09-25 19:09:57 +00:00
|
|
|
{
|
2013-10-14 16:03:38 +00:00
|
|
|
netName = wxT("Net-(");
|
2013-09-29 18:24:38 +00:00
|
|
|
netName << link->GetRef( &m_netNameCandidate->m_SheetPath );
|
2013-09-27 17:58:58 +00:00
|
|
|
netName << wxT("-Pad")
|
|
|
|
<< LIB_PIN::ReturnPinStringNum( m_netNameCandidate->m_PinNum )
|
2013-10-14 16:03:38 +00:00
|
|
|
<< wxT(")");
|
2013-09-25 19:09:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
netName = m_netNameCandidate->m_Label;
|
|
|
|
|
|
|
|
return netName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set m_netNameCandidate to a connected item which will
|
|
|
|
* be used to calcule the net name of the item
|
|
|
|
* Obviously the candidate can be only a label
|
|
|
|
* when there is no label on the net a pad which will
|
|
|
|
* used to build a net name (something like Cmp<REF>_Pad<PAD_NAME>
|
|
|
|
* @param aCandidate = the connected item candidate
|
|
|
|
*/
|
|
|
|
void NETLIST_OBJECT::SetNetNameCandidate( NETLIST_OBJECT* aCandidate )
|
|
|
|
{
|
|
|
|
switch( aCandidate->m_Type )
|
|
|
|
{
|
|
|
|
case NET_HIERLABEL:
|
|
|
|
case NET_LABEL:
|
|
|
|
case NET_PINLABEL:
|
|
|
|
case NET_GLOBLABEL:
|
|
|
|
case NET_PIN:
|
|
|
|
m_netNameCandidate = aCandidate;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|