Factor bus label parsing function into net list object.

This commit is contained in:
Wayne Stambaugh 2011-10-12 11:34:52 -04:00
parent 4e55b6be65
commit 31ed2c288c
6 changed files with 178 additions and 138 deletions

View File

@ -1,3 +1,28 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 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 class_netlist_object.cpp * @file class_netlist_object.cpp
* @brief Class NETLIST_OBJECT to handle 1 item connected (in netlist and erc calculations) * @brief Class NETLIST_OBJECT to handle 1 item connected (in netlist and erc calculations)
@ -13,7 +38,7 @@
#if defined(DEBUG) #if defined(DEBUG)
#include <iostream> #include <iostream>
const char* ShowType( NetObjetType aType ) const char* ShowType( NETLIST_ITEM_T aType )
{ {
const char* ret; const char* ret;
@ -117,7 +142,7 @@ void NETLIST_OBJECT::Show( std::ostream& out, int ndx )
NETLIST_OBJECT::NETLIST_OBJECT() NETLIST_OBJECT::NETLIST_OBJECT()
{ {
m_Type = NET_ITEM_UNSPECIFIED; /* Type of this item (see NetObjetType enum) */ m_Type = NET_ITEM_UNSPECIFIED; /* Type of this item (see NETLIST_ITEM_T enum) */
m_Comp = NULL; /* Pointer on the library item that created this net object m_Comp = NULL; /* Pointer on the library item that created this net object
* (the parent)*/ * (the parent)*/
m_Link = NULL; /* For SCH_SHEET_PIN: m_Link = NULL; /* For SCH_SHEET_PIN:
@ -126,7 +151,7 @@ NETLIST_OBJECT::NETLIST_OBJECT()
* contains this pin * contains this pin
*/ */
m_Flag = 0; /* flag used in calculations */ m_Flag = 0; /* flag used in calculations */
m_ElectricalType = 0; /* Has meaning only for Pins and hierachical pins: electrical m_ElectricalType = 0; /* Has meaning only for Pins and hierarchical pins: electrical
* type */ * type */
m_NetCode = 0; /* net code for all items except BUS labels because a BUS m_NetCode = 0; /* net code for all items except BUS labels because a BUS
* label has as many net codes as bus members * label has as many net codes as bus members
@ -174,3 +199,80 @@ bool NETLIST_OBJECT::IsLabelConnected( NETLIST_OBJECT* aNetItem )
return false; //these two are unconnected return false; //these two are unconnected
} }
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;
wxString tmp, busName;
long begin, end, member;
/* Search for '[' because a bus label is like "busname[nn..mm]" */
i = m_Label.Find( '[' );
busName = m_Label.Left( i );
i++;
while( m_Label[i] != '.' && i < m_Label.Len() )
{
tmp.Append( m_Label[i] );
i++;
}
tmp.ToLong( &begin );
while( m_Label[i] == '.' && i < m_Label.Len() )
i++;
tmp.Empty();
while( m_Label[i] != ']' && i < m_Label.Len() )
{
tmp.Append( m_Label[i] );
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 );
}
}

View File

@ -1,3 +1,28 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 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 class_netlist_object.h * @file class_netlist_object.h
* @brief Definition of the NETLIST_OBJECT class. * @brief Definition of the NETLIST_OBJECT class.
@ -12,8 +37,15 @@
#include "lib_pin.h" // LIB_PIN::ReturnPinStringNum( m_PinNum ) #include "lib_pin.h" // LIB_PIN::ReturnPinStringNum( m_PinNum )
class NETLIST_OBJECT;
// Buffer to build the list of items used in netlist and erc calculations
typedef std::vector <NETLIST_OBJECT*> NETLIST_OBJECT_LIST;
/* Type of Net objects (wires, labels, pins...) */ /* Type of Net objects (wires, labels, pins...) */
enum NetObjetType { enum NETLIST_ITEM_T {
NET_ITEM_UNSPECIFIED, // only for not yet initialized instances NET_ITEM_UNSPECIFIED, // only for not yet initialized instances
NET_SEGMENT, // connection by wire NET_SEGMENT, // connection by wire
NET_BUS, // connection by bus NET_BUS, // connection by bus
@ -47,8 +79,9 @@ enum NetObjetType {
NET_NOCONNECT // this is a no connect symbol NET_NOCONNECT // this is a no connect symbol
}; };
/* Values for .m_FlagOfConnection member */ /* Values for .m_FlagOfConnection member */
enum ConnectType { enum NET_CONNECTION_T {
UNCONNECTED = 0, /* Pin or Label not connected (error) */ UNCONNECTED = 0, /* Pin or Label not connected (error) */
NOCONNECT_SYMBOL_PRESENT, /* Pin not connected but have a NoConnect NOCONNECT_SYMBOL_PRESENT, /* Pin not connected but have a NoConnect
* symbol on it (no error) */ * symbol on it (no error) */
@ -56,11 +89,24 @@ enum ConnectType {
}; };
/**
* Function IsBusLabel
* test if \a aLabel has a bus notation.
*
* @param aLabel A wxString object containing the label to test.
* @return true if text is a bus notation format otherwise false is returned.
*/
inline bool IsBusLabel( const wxString& aLabel )
{
/* Search for '[' because a bus label is like "busname[nn..mm]" */
return aLabel.Find( '[' ) != wxNOT_FOUND;
}
class NETLIST_OBJECT class NETLIST_OBJECT
{ {
public: public:
NetObjetType m_Type; /* Type of item (see NetObjetType NETLIST_ITEM_T m_Type; /* Type of item (see NETLIST_ITEM_T enum) */
* enum) */
EDA_ITEM* m_Comp; /* Pointer on the library item that EDA_ITEM* m_Comp; /* Pointer on the library item that
* created this net object (the parent) * created this net object (the parent)
*/ */
@ -81,20 +127,15 @@ private:
*/ */
public: public:
int m_BusNetCode; /* Used for BUS connections */ int m_BusNetCode; /* Used for BUS connections */
int m_Member; /* for labels type NET_BUSLABELMEMBER int m_Member; /* for labels type NET_BUSLABELMEMBER ( bus member
* ( bus member created from the BUS * created from the BUS label ) member number.
* label ) member number
*/ */
ConnectType m_FlagOfConnection; NET_CONNECTION_T m_FlagOfConnection;
SCH_SHEET_PATH m_SheetListInclude; /* sheet that the hierarchical label SCH_SHEET_PATH m_SheetListInclude; /* sheet that the hierarchical label connects to.*/
* connects to.*/ long m_PinNum; /* pin number ( 1 long = 4 bytes -> 4 ascii codes) */
long m_PinNum; /* pin number ( 1 long = 4 bytes ->
* 4 ascii codes) */
wxString m_Label; /* Label text. */ wxString m_Label; /* Label text. */
wxPoint m_Start; // Position of object or for segments: wxPoint m_Start; // Position of object or for segments: starting point
// starting point wxPoint m_End; // For segments (wire and buses): ending point
wxPoint m_End; // For segments (wire and buses):
// ending point
NETLIST_OBJECT* m_NetNameCandidate; /* a pointer to a label connected to the net, NETLIST_OBJECT* m_NetNameCandidate; /* a pointer to a label connected to the net,
* that can be used to give a name to the net * that can be used to give a name to the net
* NULL if no usable label * NULL if no usable label
@ -120,7 +161,7 @@ public:
wxString GetPinNumText() wxString GetPinNumText()
{ {
// hide the ugliness in here, but do it inline. // hide the ugliness in here, but do it inline.
return LIB_PIN::ReturnPinStringNum( m_PinNum ); return LIB_PIN::ReturnPinStringNum( m_PinNum );
} }
/** /**
@ -133,11 +174,18 @@ public:
* if no connection to \a aNetItem. * if no connection to \a aNetItem.
*/ */
bool IsLabelConnected( NETLIST_OBJECT* aNetItem ); bool IsLabelConnected( NETLIST_OBJECT* aNetItem );
/**
* Function ConvertBusToNetListItems
* breaks the text of a bus label type net list object into as many members as
* it contains and creates a #NETLIST_OBJECT for each label and adds it to \a
* aNetListItems.
*
* @param aNetListItems A reference to vector of #NETLIST_OBJECT pointers to add
* the bus label NETLIST_OBJECTs.
*/
void ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItems );
}; };
// Buffer to build the list of items used in netlist and erc calculations
typedef std::vector <NETLIST_OBJECT*> NETLIST_OBJECT_LIST;
#endif // _CLASS_NETLIST_OBJECT_H_ #endif // _CLASS_NETLIST_OBJECT_H_

View File

@ -539,92 +539,6 @@ static void SheetLabelConnect( NETLIST_OBJECT* SheetLabel )
} }
/**
* Function ConvertBusToMembers
* breaks the text of a bus label type in as many members as it contains and
* creates a #NETLIST_OBJECT for each label.
*
* @param aNetListItems A reference to vector of #NETLIST_OBJECT pointers to add
* the bus label NETLIST_OBJECTs.
* @param aBusLabel A reference to the base bus label #NETLIST_OBJECT.
*/
void ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetListItems, NETLIST_OBJECT& aBusLabel )
{
wxCHECK_RET( IsBusLabel( aBusLabel.m_Label ),
wxT( "<" ) + aBusLabel.m_Label + wxT( "> is not a valid bus label." ) );
if( aBusLabel.m_Type == NET_HIERLABEL )
aBusLabel.m_Type = NET_HIERBUSLABELMEMBER;
else if( aBusLabel.m_Type == NET_GLOBLABEL )
aBusLabel.m_Type = NET_GLOBBUSLABELMEMBER;
else if( aBusLabel.m_Type == NET_SHEETLABEL )
aBusLabel.m_Type = NET_SHEETBUSLABELMEMBER;
else if( aBusLabel.m_Type == NET_LABEL )
aBusLabel.m_Type = NET_BUSLABELMEMBER;
else
wxCHECK_RET( false, wxT( "Net object type is not valid." ) );
unsigned i;
wxString tmp, busName;
long begin, end, member;
/* Search for '[' because a bus label is like "busname[nn..mm]" */
i = aBusLabel.m_Label.Find( '[' );
busName = aBusLabel.m_Label.Left( i );
i++;
while( aBusLabel.m_Label[i] != '.' && i < aBusLabel.m_Label.Len() )
{
tmp.Append( aBusLabel.m_Label[i] );
i++;
}
tmp.ToLong( &begin );
while( aBusLabel.m_Label[i] == '.' && i < aBusLabel.m_Label.Len() )
i++;
tmp.Empty();
while( aBusLabel.m_Label[i] != ']' && i < aBusLabel.m_Label.Len() )
{
tmp.Append( aBusLabel.m_Label[i] );
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;
aBusLabel.m_Label = tmp;
aBusLabel.m_Member = member;
for( member++; member <= end; member++ )
{
NETLIST_OBJECT* item = new NETLIST_OBJECT( aBusLabel );
/* Conversion of BusLabel to the root name + the current member id.*/
tmp = busName;
tmp << member;
item->m_Label = tmp;
item->m_Member = member;
aNetListItems.push_back( item );
}
}
/* /*
* Routine that analyzes the type labels xxBUSLABELMEMBER * Routine that analyzes the type labels xxBUSLABELMEMBER
* Propagate Netcode between the corresponding labels (ie when * Propagate Netcode between the corresponding labels (ie when
@ -672,13 +586,6 @@ static void ConnectBusLabels( NETLIST_OBJECT_LIST& aNetItemBuffer )
} }
bool IsBusLabel( const wxString& aLabel )
{
/* Search for '[' because a bus label is like "busname[nn..mm]" */
return aLabel.Find( '[' ) != wxNOT_FOUND;
}
/* /*
* PropageNetCode propagates Netcode NewNetCode on all elements * PropageNetCode propagates Netcode NewNetCode on all elements
* belonging to the former Netcode OldNetCode * belonging to the former Netcode OldNetCode
@ -913,7 +820,7 @@ void LabelConnect( NETLIST_OBJECT* LabelRef )
// NET_LABEL is sheet-local (***) // NET_LABEL is sheet-local (***)
// NET_GLOBLABEL is global. // NET_GLOBLABEL is global.
// NET_PINLABEL is a kind of global label (generated by a power pin invisible) // NET_PINLABEL is a kind of global label (generated by a power pin invisible)
NetObjetType ntype = g_NetObjectslist[i]->m_Type; NETLIST_ITEM_T ntype = g_NetObjectslist[i]->m_Type;
if( ntype == NET_LABEL if( ntype == NET_LABEL
|| ntype == NET_GLOBLABEL || ntype == NET_GLOBLABEL
@ -960,7 +867,7 @@ static void SetUnconnectedFlag( NETLIST_OBJECT_LIST& aNetItemBuffer )
{ {
NETLIST_OBJECT* NetItemRef; NETLIST_OBJECT* NetItemRef;
unsigned NetStart, NetEnd; unsigned NetStart, NetEnd;
ConnectType StateFlag; NET_CONNECTION_T StateFlag;
NetStart = NetEnd = 0; NetStart = NetEnd = 0;
StateFlag = UNCONNECTED; StateFlag = UNCONNECTED;

View File

@ -58,19 +58,6 @@ void DrawDanglingSymbol( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& pos, in
EDA_Colors ReturnLayerColor( int Layer ); EDA_Colors ReturnLayerColor( int Layer );
/***************/
/* NETLIST.CPP */
/***************/
/**
* Function IsBusLabel
* test if the \a aLabel has a bus notation.
*
* @param aLabel A wxString object containing the label to test.
* @return false if text is not a bus notattion otherwise true is returned.
*/
bool IsBusLabel( const wxString& aLabel );
/***************/ /***************/
/* PINEDIT.CPP */ /* PINEDIT.CPP */
/***************/ /***************/

View File

@ -47,9 +47,6 @@
#include "class_netlist_object.h" #include "class_netlist_object.h"
extern void ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer, NETLIST_OBJECT& aBusLabel );
SCH_SHEET::SCH_SHEET( const wxPoint& pos ) : SCH_SHEET::SCH_SHEET( const wxPoint& pos ) :
SCH_ITEM( NULL, SCH_SHEET_T ) SCH_ITEM( NULL, SCH_SHEET_T )
{ {
@ -1118,7 +1115,7 @@ void SCH_SHEET::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
aNetListItems.push_back( item ); aNetListItems.push_back( item );
if( IsBusLabel( m_pins[i].m_Text ) ) if( IsBusLabel( m_pins[i].m_Text ) )
ConvertBusToMembers( aNetListItems, *item ); item->ConvertBusToNetListItems( aNetListItems );
} }
} }

View File

@ -45,7 +45,6 @@
extern void IncrementLabelMember( wxString& name ); extern void IncrementLabelMember( wxString& name );
extern void ConvertBusToMembers( NETLIST_OBJECT_LIST& aNetItemBuffer, NETLIST_OBJECT& aBusLabel );
/* Names of sheet label types. */ /* Names of sheet label types. */
@ -696,7 +695,7 @@ void SCH_TEXT::GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
/* If a bus connects to label */ /* If a bus connects to label */
if( IsBusLabel( m_Text ) ) if( IsBusLabel( m_Text ) )
ConvertBusToMembers( aNetListItems, *item ); item->ConvertBusToNetListItems( aNetListItems );
} }