KiCad PCB EDA Suite
NETLIST_EXPORTER_BASE Class Reference

An abstract class used for the netlist exporters that Eeschema supports. More...

#include <netlist_exporter_base.h>

Inheritance diagram for NETLIST_EXPORTER_BASE:
NETLIST_EXPORTER_CADSTAR NETLIST_EXPORTER_ORCADPCB2 NETLIST_EXPORTER_PSPICE NETLIST_EXPORTER_XML NETLIST_EXPORTER_PSPICE_SIM NETLIST_EXPORTER_KICAD

Public Member Functions

 NETLIST_EXPORTER_BASE (SCHEMATIC_IFACE *aSchematic)
 
virtual ~NETLIST_EXPORTER_BASE ()
 
virtual bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions)
 Write to specified output file. More...
 

Static Public Member Functions

static wxString MakeCommandLine (const wxString &aFormatString, const wxString &aNetlistFile, const wxString &aFinalFile, const wxString &aProjectDirectory)
 Build up a string that describes a command line for executing a child process. More...
 

Protected Member Functions

void CreatePinList (SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
 Find a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList. More...
 
SCH_SYMBOLfindNextSymbol (EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
 Check if the given symbol should be processed for netlisting. More...
 
void eraseDuplicatePins ()
 Erase duplicate pins from m_sortedSymbolPinList (i.e. More...
 
void findAllUnitsOfSymbol (SCH_SYMBOL *aSchSymbol, LIB_SYMBOL *aLibSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
 Find all units for symbols with multiple symbols per package. More...
 

Protected Attributes

std::vector< PIN_INFOm_sortedSymbolPinList
 Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic symbol data in netlist (comp section). More...
 
UNIQUE_STRINGS m_referencesAlreadyFound
 Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once. More...
 
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THANm_libParts
 unique library symbols used. LIB_SYMBOL items are sorted by names More...
 
SCHEMATIC_IFACEm_schematic
 The schematic we're generating a netlist for. More...
 
SCH_SHEET_PATH m_savedCurrentSheet
 The schematic's CurrentSheet when we entered. Restore on exiting. More...
 

Detailed Description

An abstract class used for the netlist exporters that Eeschema supports.

Definition at line 91 of file netlist_exporter_base.h.

Constructor & Destructor Documentation

◆ NETLIST_EXPORTER_BASE()

NETLIST_EXPORTER_BASE::NETLIST_EXPORTER_BASE ( SCHEMATIC_IFACE aSchematic)
inline
Parameters
aMasterListwe take ownership of this here.
aLibTableis the symbol library table of the project.

Definition at line 98 of file netlist_exporter_base.h.

98  :
99  m_schematic( aSchematic )
100  {
101  wxASSERT( aSchematic );
103  }
virtual SCH_SHEET_PATH & CurrentSheet() const =0
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
SCH_SHEET_PATH m_savedCurrentSheet
The schematic's CurrentSheet when we entered. Restore on exiting.

References SCHEMATIC_IFACE::CurrentSheet(), m_savedCurrentSheet, and m_schematic.

◆ ~NETLIST_EXPORTER_BASE()

virtual NETLIST_EXPORTER_BASE::~NETLIST_EXPORTER_BASE ( )
inlinevirtual

Definition at line 105 of file netlist_exporter_base.h.

106  {
108  }
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
virtual void SetCurrentSheet(const SCH_SHEET_PATH &aPath)=0
SCH_SHEET_PATH m_savedCurrentSheet
The schematic's CurrentSheet when we entered. Restore on exiting.

References m_savedCurrentSheet, m_schematic, and SCHEMATIC_IFACE::SetCurrentSheet().

Member Function Documentation

◆ CreatePinList()

void NETLIST_EXPORTER_BASE::CreatePinList ( SCH_SYMBOL aSymbol,
SCH_SHEET_PATH aSheetPath,
bool  aKeepUnconnectedPins 
)
protected

Find a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList.

This list is sorted by pin number. The symbol is the next actual symbol after aSymbol. Power symbols and virtual symbols that have their reference designators starting with '#' are skipped. if aKeepUnconnectedPins = false, unconnected pins will be removed from list but usually we need all pins in netlists.

Definition at line 124 of file netlist_exporter_base.cpp.

127 {
128  wxString ref( aSymbol->GetRef( aSheetPath ) );
129 
130  // Power symbols and other symbols which have the reference starting with "#" are not
131  // included in netlist (pseudo or virtual symbols)
132 
133  if( ref[0] == wxChar( '#' ) )
134  return;
135 
136  // if( aSymbol->m_FlagControlMulti == 1 )
137  // continue; /* yes */
138  // removed because with multiple instances of one schematic (several sheets pointing to
139  // 1 screen), this will be erroneously be toggled.
140 
141  if( !aSymbol->GetLibSymbolRef() )
142  return;
143 
144  m_sortedSymbolPinList.clear();
145 
146  // If symbol is a "multi parts per package" type
147  if( aSymbol->GetLibSymbolRef()->GetUnitCount() > 1 )
148  {
149  // Collect all pins for this reference designator by searching the entire design for
150  // other parts with the same reference designator.
151  // This is only done once, it would be too expensive otherwise.
152  findAllUnitsOfSymbol( aSymbol, aSymbol->GetLibSymbolRef().get(),
153  aSheetPath, aKeepUnconnectedPins );
154  }
155 
156  else // GetUnitCount() <= 1 means one part per package
157  {
159 
160  for( const SCH_PIN* pin : aSymbol->GetPins( aSheetPath ) )
161  {
162  if( SCH_CONNECTION* conn = pin->Connection( aSheetPath ) )
163  {
164  const wxString& netName = conn->Name();
165 
166  if( !aKeepUnconnectedPins ) // Skip unconnected pins if requested
167  {
168  CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath );
169 
170  if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
171  continue;
172  }
173 
174  m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
175  }
176  }
177  }
178 
179  // Sort pins in m_SortedSymbolPinList by pin number
181 
182  // Remove duplicate Pins in m_SortedSymbolPinList
184 
185  // record the usage of this library symbol
186  m_libParts.insert( aSymbol->GetLibSymbolRef().get() ); // rejects non-unique pointers
187 }
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Returns the subgraph for a given net name on a given sheet.
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...
Calculates the connectivity of a schematic and generates netlists.
void eraseDuplicatePins()
Erase duplicate pins from m_sortedSymbolPinList (i.e.
virtual CONNECTION_GRAPH * ConnectionGraph() const =0
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:441
static bool sortPinsByNum(PIN_INFO &aPin1, PIN_INFO &aPin2)
Comparison routine for sorting by pin numbers.
A subgraph is a set of items that are electrically connected on a single sheet.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:164
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
std::vector< SCH_ITEM * > m_items
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void findAllUnitsOfSymbol(SCH_SYMBOL *aSchSymbol, LIB_SYMBOL *aLibSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
Find all units for symbols with multiple symbols per package.
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THAN > m_libParts
unique library symbols used. LIB_SYMBOL items are sorted by names
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
Definition: sch_symbol.cpp:866

References SCHEMATIC_IFACE::ConnectionGraph(), eraseDuplicatePins(), findAllUnitsOfSymbol(), CONNECTION_GRAPH::FindSubgraphByName(), SCH_SYMBOL::GetLibSymbolRef(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), CONNECTION_SUBGRAPH::m_items, m_libParts, CONNECTION_SUBGRAPH::m_no_connect, m_schematic, m_sortedSymbolPinList, pin, and sortPinsByNum().

Referenced by NETLIST_EXPORTER_PSPICE::ProcessNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ eraseDuplicatePins()

void NETLIST_EXPORTER_BASE::eraseDuplicatePins ( )
protected

Erase duplicate pins from m_sortedSymbolPinList (i.e.

set pointer in this list to NULL).

(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 once when in "multiple symbols per package" symbols. For instance, a 74ls00 has 4 symbols, and therefore the VCC pin and GND pin appears 4 times in the list. 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

Definition at line 190 of file netlist_exporter_base.cpp.

191 {
192  for( unsigned ii = 0; ii < m_sortedSymbolPinList.size(); ii++ )
193  {
194  if( m_sortedSymbolPinList[ii].num.empty() ) /* already deleted */
195  continue;
196 
197  /* Search for duplicated pins
198  * If found, remove duplicates. The priority is to keep connected pins
199  * and remove unconnected
200  * - So this allows (for instance when using multi op amps per package
201  * - to connect only one op amp to power
202  * Because the pin list is sorted by m_PinNum value, duplicated pins
203  * are necessary successive in list
204  */
205  int idxref = ii;
206 
207  for( unsigned jj = ii + 1; jj < m_sortedSymbolPinList.size(); jj++ )
208  {
209  if( m_sortedSymbolPinList[jj].num.empty() ) // Already removed
210  continue;
211 
212  // if other pin num, stop search,
213  // because all pins having the same number are consecutive in list.
214  if( m_sortedSymbolPinList[idxref].num != m_sortedSymbolPinList[jj].num )
215  break;
216 
217  m_sortedSymbolPinList[jj].num.clear();
218  }
219  }
220 }
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...

References m_sortedSymbolPinList.

Referenced by CreatePinList().

◆ findAllUnitsOfSymbol()

void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol ( SCH_SYMBOL aSchSymbol,
LIB_SYMBOL aLibSymbol,
SCH_SHEET_PATH aSheetPath,
bool  aKeepUnconnectedPins 
)
protected

Find all units for symbols with multiple symbols per package.

Search the entire design for all units of aSymbol based on matching reference designator, and for each unit, add all its pins to the temporary sorted pin list, m_sortedSymbolPinList. if aKeepUnconnectedPins = false, unconnected pins will be removed from list but usually we need all pins in netlists.

Definition at line 223 of file netlist_exporter_base.cpp.

226 {
227  wxString ref = aSchSymbol->GetRef( aSheetPath );
228  wxString ref2;
229 
230  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
232 
233  for( unsigned i = 0; i < sheetList.size(); i++ )
234  {
235  SCH_SHEET_PATH& sheet = sheetList[i];
236 
237  for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
238  {
239  SCH_SYMBOL* comp2 = static_cast<SCH_SYMBOL*>( item );
240 
241  ref2 = comp2->GetRef( &sheet );
242 
243  if( ref2.CmpNoCase( ref ) != 0 )
244  continue;
245 
246  for( const SCH_PIN* pin : comp2->GetPins( &sheet ) )
247  {
248  if( SCH_CONNECTION* conn = pin->Connection( &sheet ) )
249  {
250  const wxString& netName = conn->Name();
251 
252  if( !aKeepUnconnectedPins ) // Skip unconnected pins if requested
253  {
254  CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, sheet );
255 
256  if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
257  continue;
258  }
259 
260  m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
261  }
262  }
263  }
264  }
265 }
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Returns the subgraph for a given net name on a given sheet.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...
Calculates the connectivity of a schematic and generates netlists.
virtual CONNECTION_GRAPH * ConnectionGraph() const =0
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:441
A subgraph is a set of items that are electrically connected on a single sheet.
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
std::vector< SCH_ITEM * > m_items
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition: sch_symbol.h:78
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
virtual SCH_SHEET_LIST GetSheets() const =0
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:193
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
Definition: sch_symbol.cpp:866

References SCHEMATIC_IFACE::ConnectionGraph(), CONNECTION_GRAPH::FindSubgraphByName(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), SCHEMATIC_IFACE::GetSheets(), CONNECTION_SUBGRAPH::m_items, CONNECTION_SUBGRAPH::m_no_connect, m_schematic, m_sortedSymbolPinList, pin, and SCH_SYMBOL_T.

Referenced by CreatePinList().

◆ findNextSymbol()

SCH_SYMBOL * NETLIST_EXPORTER_BASE::findNextSymbol ( EDA_ITEM aItem,
SCH_SHEET_PATH aSheetPath 
)
protected

Check if the given symbol should be processed for netlisting.

Prevent processing multi-unit symbols more than once, etc.

Parameters
aItemis a symbol to check
aSheetPathis the sheet to check the symbol for
Returns
the symbol if it should be processed, or nullptr

Definition at line 73 of file netlist_exporter_base.cpp.

74 {
75  wxCHECK( aItem, nullptr );
76  wxCHECK( aSheetPath, nullptr );
77 
78  wxString ref;
79 
80  if( aItem->Type() != SCH_SYMBOL_T )
81  return nullptr;
82 
83  // found next symbol
84  SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem;
85 
86  // Power symbols and other symbols which have the reference starting with "#" are not
87  // included in netlist (pseudo or virtual symbols)
88  ref = symbol->GetRef( aSheetPath );
89 
90  if( ref[0] == wxChar( '#' ) )
91  return nullptr;
92 
93  SCH_SCREEN* screen = aSheetPath->LastScreen();
94 
95  wxCHECK( screen, nullptr );
96 
97  LIB_SYMBOL* libSymbol = screen->GetLibSymbols()[ symbol->GetSchSymbolLibraryName() ];
98 
99  wxCHECK( libSymbol, nullptr );
100 
101  // If symbol is a "multi parts per package" type
102  if( libSymbol->GetUnitCount() > 1 )
103  {
104  // test if this reference has already been processed, and if so skip
105  if( m_referencesAlreadyFound.Lookup( ref ) )
106  return nullptr;
107  }
108 
109  // record the usage of this library symbol entry.
110  m_libParts.insert( libSymbol ); // rejects non-unique pointers
111 
112  return symbol;
113 }
bool Lookup(const wxString &aString)
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:441
Define a library symbol object.
Definition: lib_symbol.h:96
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:248
int GetUnitCount() const override
For items with units, return the number of units.
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:424
Schematic symbol object.
Definition: sch_symbol.h:78
SCH_SCREEN * LastScreen()
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THAN > m_libParts
unique library symbols used. LIB_SYMBOL items are sorted by names
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References SCH_SCREEN::GetLibSymbols(), SCH_SYMBOL::GetRef(), SCH_SYMBOL::GetSchSymbolLibraryName(), LIB_SYMBOL::GetUnitCount(), SCH_SHEET_PATH::LastScreen(), UNIQUE_STRINGS::Lookup(), m_libParts, m_referencesAlreadyFound, SCH_SYMBOL_T, and EDA_ITEM::Type().

Referenced by NETLIST_EXPORTER_XML::makeSymbols(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().

◆ MakeCommandLine()

wxString NETLIST_EXPORTER_BASE::MakeCommandLine ( const wxString &  aFormatString,
const wxString &  aNetlistFile,
const wxString &  aFinalFile,
const wxString &  aProjectDirectory 
)
static

Build up a string that describes a command line for executing a child process.

The input and output file names along with any options to the executable are all possibly in the returned string.

Parameters
aFormatStringholds:
  • the name of the external program
  • any options needed by that program
  • formatting sequences, see below.
aNetlistFileis the name of the input file for the external program, that is a intermediate netlist file in xml format.
aFinalFileis the name of the output file that the user expects.
aProjectDirectoryis used for P replacement, it should omit the trailing '/'.

Supported formatting sequences and their meaning:

  • B => base filename of selected output file, minus path and extension.
  • I => complete filename and path of the temporary input file.
  • O => complete filename and path of the user chosen output file.
  • P => project directory, without name and without trailing '/'

Definition at line 37 of file netlist_exporter_base.cpp.

41 {
42  // Expand format symbols in the command line:
43  // %B => base filename of selected output file, minus path and extension.
44  // %P => project directory name, without trailing '/' or '\'.
45  // %I => full filename of the input file (the intermediate net file).
46  // %O => complete filename and path (but without extension) of the user chosen output file.
47 
48  wxString ret = aFormatString;
49  wxFileName in = aNetlistFile;
50  wxFileName out = aFinalFile;
51  wxString str_out = out.GetFullPath();
52 
53  ret.Replace( "%P", aProjectPath, true );
54  ret.Replace( "%B", out.GetName(), true );
55  ret.Replace( "%I", in.GetFullPath(), true );
56 
57 #ifdef __WINDOWS__
58  // A ugly hack to run xsltproc that has a serious bug on Window since a long time:
59  // the filename given after -o option (output filename) cannot use '\' in filename
60  // so replace if by '/' if possible (I mean if the filename does not start by "\\"
61  // that is a filename on a Windows server)
62 
63  if( !str_out.StartsWith( "\\\\" ) )
64  str_out.Replace( "\\", "/" );
65 #endif
66 
67  ret.Replace( "%O", str_out, true );
68 
69  return ret;
70 }

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

◆ WriteNetlist()

virtual bool NETLIST_EXPORTER_BASE::WriteNetlist ( const wxString &  aOutFileName,
unsigned  aNetlistOptions 
)
inlinevirtual

Write to specified output file.

Reimplemented in NETLIST_EXPORTER_PSPICE, NETLIST_EXPORTER_XML, NETLIST_EXPORTER_KICAD, NETLIST_EXPORTER_CADSTAR, and NETLIST_EXPORTER_ORCADPCB2.

Definition at line 113 of file netlist_exporter_base.h.

114  {
115  return false;
116  }

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

Member Data Documentation

◆ m_libParts

std::set<LIB_SYMBOL*, LIB_SYMBOL_LESS_THAN> NETLIST_EXPORTER_BASE::m_libParts
protected

◆ m_referencesAlreadyFound

UNIQUE_STRINGS NETLIST_EXPORTER_BASE::m_referencesAlreadyFound
protected

Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.

Definition at line 206 of file netlist_exporter_base.h.

Referenced by findNextSymbol(), NETLIST_EXPORTER_XML::makeSymbols(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().

◆ m_savedCurrentSheet

SCH_SHEET_PATH NETLIST_EXPORTER_BASE::m_savedCurrentSheet
protected

The schematic's CurrentSheet when we entered. Restore on exiting.

Definition at line 215 of file netlist_exporter_base.h.

Referenced by NETLIST_EXPORTER_BASE(), and ~NETLIST_EXPORTER_BASE().

◆ m_schematic

◆ m_sortedSymbolPinList

std::vector<PIN_INFO> NETLIST_EXPORTER_BASE::m_sortedSymbolPinList
protected

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

Definition at line 202 of file netlist_exporter_base.h.

Referenced by CreatePinList(), eraseDuplicatePins(), findAllUnitsOfSymbol(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().


The documentation for this class was generated from the following files: