Get rid of m_sortedSymbolPinList in favour of a properly scoped variable.

Fixes https://gitlab.com/kicad/code/kicad/issues/14083

(cherry picked from commit 2a79a453ec)
This commit is contained in:
Jeff Young 2023-02-25 20:34:30 +00:00
parent 33f835a437
commit e82c21e944
5 changed files with 45 additions and 46 deletions

View File

@ -113,16 +113,18 @@ SCH_SYMBOL* NETLIST_EXPORTER_BASE::findNextSymbol( EDA_ITEM* aItem, SCH_SHEET_PA
}
void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPath,
bool aKeepUnconnectedPins )
std::vector<PIN_INFO> NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol,
SCH_SHEET_PATH* aSheetPath,
bool aKeepUnconnectedPins )
{
wxString ref( aSymbol->GetRef( aSheetPath ) );
wxString ref( aSymbol->GetRef( aSheetPath ) );
std::vector<PIN_INFO> pins;
// Power symbols and other symbols which have the reference starting with "#" are not
// included in netlist (pseudo or virtual symbols)
if( ref[0] == wxChar( '#' ) )
return;
return pins;
// if( aSymbol->m_FlagControlMulti == 1 )
// continue; /* yes */
@ -130,9 +132,7 @@ void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH*
// 1 screen), this will be erroneously be toggled.
if( !aSymbol->GetLibSymbolRef() )
return;
m_sortedSymbolPinList.clear();
return pins;
// If symbol is a "multi parts per package" type
if( aSymbol->GetLibSymbolRef()->GetUnitCount() > 1 )
@ -140,7 +140,7 @@ void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH*
// Collect all pins for this reference designator by searching the entire design for
// other parts with the same reference designator.
// This is only done once, it would be too expensive otherwise.
findAllUnitsOfSymbol( aSymbol, aSheetPath, aKeepUnconnectedPins );
findAllUnitsOfSymbol( aSymbol, aSheetPath, pins, aKeepUnconnectedPins );
}
else // GetUnitCount() <= 1 means one part per package
@ -161,31 +161,33 @@ void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH*
continue;
}
m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
pins.emplace_back( pin->GetShownNumber(), netName );
}
}
}
// Sort pins in m_SortedSymbolPinList by pin number
std::sort( m_sortedSymbolPinList.begin(), m_sortedSymbolPinList.end(),
std::sort( pins.begin(), pins.end(),
[]( const PIN_INFO& lhs, const PIN_INFO& rhs )
{
return StrNumCmp( lhs.num, rhs.num, true ) < 0;
} );
// Remove duplicate Pins in m_SortedSymbolPinList
eraseDuplicatePins();
eraseDuplicatePins( pins );
// record the usage of this library symbol
m_libParts.insert( aSymbol->GetLibSymbolRef().get() ); // rejects non-unique pointers
return pins;
}
void NETLIST_EXPORTER_BASE::eraseDuplicatePins()
void NETLIST_EXPORTER_BASE::eraseDuplicatePins( std::vector<PIN_INFO>& aPins )
{
for( unsigned ii = 0; ii < m_sortedSymbolPinList.size(); ii++ )
for( unsigned ii = 0; ii < aPins.size(); ii++ )
{
if( m_sortedSymbolPinList[ii].num.empty() ) /* already deleted */
if( aPins[ii].num.empty() ) /* already deleted */
continue;
/* Search for duplicated pins
@ -198,17 +200,17 @@ void NETLIST_EXPORTER_BASE::eraseDuplicatePins()
*/
int idxref = ii;
for( unsigned jj = ii + 1; jj < m_sortedSymbolPinList.size(); jj++ )
for( unsigned jj = ii + 1; jj < aPins.size(); jj++ )
{
if( m_sortedSymbolPinList[jj].num.empty() ) // Already removed
if( aPins[jj].num.empty() ) // Already removed
continue;
// if other pin num, stop search,
// because all pins having the same number are consecutive in list.
if( m_sortedSymbolPinList[idxref].num != m_sortedSymbolPinList[jj].num )
if( aPins[idxref].num != aPins[jj].num )
break;
m_sortedSymbolPinList[jj].num.clear();
aPins[jj].num.clear();
}
}
}
@ -216,6 +218,7 @@ void NETLIST_EXPORTER_BASE::eraseDuplicatePins()
void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol,
SCH_SHEET_PATH* aSheetPath,
std::vector<PIN_INFO>& aPins,
bool aKeepUnconnectedPins )
{
wxString ref = aSchSymbol->GetRef( aSheetPath );
@ -251,7 +254,7 @@ void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol,
continue;
}
m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
aPins.emplace_back( pin->GetShownNumber(), netName );
}
}
}

View File

@ -147,7 +147,7 @@ public:
protected:
/**
* Find a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList.
* Find a symbol from the DrawList and builds its pin list.
*
* This list is sorted by pin number. The symbol is the next actual symbol after \a aSymbol.
* Power symbols and virtual symbols that have their reference designators starting with
@ -155,8 +155,8 @@ protected:
* if aKeepUnconnectedPins = false, unconnected pins will be removed from list
* but usually we need all pins in netlists.
*/
void CreatePinList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPath,
bool aKeepUnconnectedPins );
std::vector<PIN_INFO> CreatePinList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPath,
bool aKeepUnconnectedPins );
/**
* Check if the given symbol should be processed for netlisting.
@ -170,7 +170,7 @@ protected:
SCH_SYMBOL* findNextSymbol( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
/**
* Erase duplicate pins from m_sortedSymbolPinList (i.e. set pointer in this list to NULL).
* Erase duplicate pins.
*
* (This is a list of pins found in the whole schematic, for a single symbol.) These
* duplicate pins were put in list because some pins (power pins...) are found more than
@ -179,24 +179,18 @@ protected:
* Note: this list *MUST* be sorted by pin number (.m_PinNum member value)
* Also set the m_Flag member of "removed" NETLIST_OBJECT pin item to 1
*/
void eraseDuplicatePins();
void eraseDuplicatePins( std::vector<PIN_INFO>& pins );
/**
* Find all units for symbols with multiple symbols per package.
*
* Search the entire design for all units of \a aSymbol based on matching reference
* designator, and for each unit, add all its pins to the temporary sorted pin list,
* m_sortedSymbolPinList.
* designator, and for each unit, add all its pins to the sorted pin list.
* if aKeepUnconnectedPins = false, unconnected pins will be removed from list
* but usually we need all pins in netlists.
*/
void findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, SCH_SHEET_PATH* aSheetPath,
bool aKeepUnconnectedPins );
/// Used to temporarily store and filter the list of pins of a schematic symbol when
/// generating schematic symbol data in netlist (comp section). No ownership of members.
/// TODO(snh): Descope this object
std::vector<PIN_INFO> m_sortedSymbolPinList;
std::vector<PIN_INFO>& aPins, bool aKeepUnconnectedPins );
/// Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than
/// once

View File

@ -79,7 +79,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
if( !symbol->GetIncludeOnBoard() )
continue;
CreatePinList( symbol, &sheet, true );
std::vector<PIN_INFO> pins = CreatePinList( symbol, &sheet, true );
if( symbol->GetLibSymbolRef()
&& symbol->GetLibSymbolRef()->GetFPFilters().GetCount() != 0 )
@ -110,7 +110,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
ret |= fprintf( f, "\n" );
// Write pin list:
for( const PIN_INFO& pin : m_sortedSymbolPinList )
for( const PIN_INFO& pin : pins )
{
if( pin.num.IsEmpty() ) // Erased pin in list
continue;

View File

@ -220,7 +220,7 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
if( !symbol || symbol->GetFieldText( SIM_ENABLE_FIELD ) == wxT( "0" ) )
continue;
CreatePinList( symbol, &sheet, true );
std::vector<PIN_INFO> pins = CreatePinList( symbol, &sheet, true );
SPICE_ITEM spiceItem;
@ -267,8 +267,8 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
{
readRefName( sheet, *symbol, spiceItem, refNames );
readModel( sheet, *symbol, spiceItem );
readPinNumbers( *symbol, spiceItem );
readPinNetNames( *symbol, spiceItem, ncCounter );
readPinNumbers( *symbol, spiceItem, pins );
readPinNetNames( *symbol, spiceItem, pins, ncCounter );
// TODO: transmission line handling?
@ -533,20 +533,20 @@ void NETLIST_EXPORTER_SPICE::readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSym
}
void NETLIST_EXPORTER_SPICE::readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem )
void NETLIST_EXPORTER_SPICE::readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
const std::vector<PIN_INFO>& aPins )
{
for( const PIN_INFO& pin : m_sortedSymbolPinList )
aItem.pinNumbers.emplace_back( std::string( pin.num.ToUTF8() ) );
for( const PIN_INFO& pin : aPins )
aItem.pinNumbers.emplace_back( pin.num.ToStdString() );
}
void NETLIST_EXPORTER_SPICE::readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
int& aNcCounter )
const std::vector<PIN_INFO>& aPins, int& aNcCounter )
{
for( const PIN_INFO& pinInfo : m_sortedSymbolPinList )
for( const PIN_INFO& pinInfo : aPins )
{
std::string netName = GenerateItemPinNetName( std::string( pinInfo.netName.ToUTF8() ),
aNcCounter );
std::string netName = GenerateItemPinNetName( pinInfo.netName.ToStdString(), aNcCounter );
aItem.pinNetNames.push_back( netName );
m_nets.insert( netName );

View File

@ -144,8 +144,10 @@ private:
void readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
std::set<std::string>& aRefNames );
void readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem );
void readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem );
void readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem, int& aNcCounter );
void readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
const std::vector<PIN_INFO>& aPins );
void readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
const std::vector<PIN_INFO>& aPins, int& aNcCounter );
void writeInclude( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
const wxString& aPath );