KiCad PCB EDA Suite
Loading...
Searching...
No Matches
NETLIST_EXPORTER_KICAD Class Reference

Generate the KiCad netlist format supported by Pcbnew. More...

#include <netlist_exporter_kicad.h>

Inheritance diagram for NETLIST_EXPORTER_KICAD:
NETLIST_EXPORTER_XML NETLIST_EXPORTER_BASE

Public Member Functions

 NETLIST_EXPORTER_KICAD (SCHEMATIC *aSchematic)
 
bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter) override
 Write netlist to aOutFileName.
 
void Format (OUTPUTFORMATTER *aOutputFormatter, int aCtl)
 Output this s-expression netlist into aOutputFormatter.
 

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.
 

Protected Member Functions

XNODEnode (const wxString &aName, const wxString &aTextualContent=wxEmptyString)
 A convenience function that creates a new XNODE with an optional textual child.
 
XNODEmakeRoot (unsigned aCtl=GNL_ALL)
 Build the entire document tree for the generic export.
 
XNODEmakeSymbols (unsigned aCtl)
 
XNODEmakeGroups ()
 
XNODEmakeDesignHeader ()
 Fill out a project "design" header into an XML node.
 
XNODEmakeLibParts ()
 Fill out an XML node with the unique library parts and returns it.
 
XNODEmakeListOfNets (unsigned aCtl)
 Fill out an XML node with a list of nets and returns it.
 
XNODEmakeLibraries ()
 Fill out an XML node with a list of used libraries and returns it.
 
void addSymbolFields (XNODE *aNode, SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSheet, const SCH_SHEET_LIST &aSheetList)
 Holder for multi-unit symbol fields.
 
std::vector< wxString > getComponentClassNamesForAllSymbolUnits (SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSymbolSheet, const SCH_SHEET_LIST &aSheetList)
 Finds all component class names attached to any sub-unit of a given symbol.
 
std::vector< PIN_INFOCreatePinList (SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSheetPath, bool aKeepUnconnectedPins)
 Find a symbol from the DrawList and builds its pin list.
 
SCH_SYMBOLfindNextSymbol (EDA_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath)
 Check if the given symbol should be processed for netlisting.
 
void eraseDuplicatePins (std::vector< PIN_INFO > &pins)
 Erase duplicate pins.
 
void findAllUnitsOfSymbol (SCH_SYMBOL *aSchSymbol, const SCH_SHEET_PATH &aSheetPath, std::vector< PIN_INFO > &aPins, bool aKeepUnconnectedPins)
 Find all units for symbols with multiple symbols per package.
 

Protected Attributes

bool m_resolveTextVars
 
UNIQUE_STRINGS m_referencesAlreadyFound
 Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
 
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THANm_libParts
 unique library symbols used. LIB_SYMBOL items are sorted by names
 
SCHEMATICm_schematic
 The schematic we're generating a netlist for.
 

Private Attributes

std::set< wxString > m_libraries
 

Detailed Description

Generate the KiCad netlist format supported by Pcbnew.

It is basically the XML netlist just formatted slightly different.

Definition at line 37 of file netlist_exporter_kicad.h.

Constructor & Destructor Documentation

◆ NETLIST_EXPORTER_KICAD()

NETLIST_EXPORTER_KICAD::NETLIST_EXPORTER_KICAD ( SCHEMATIC * aSchematic)
inline

Member Function Documentation

◆ addSymbolFields()

◆ CreatePinList()

std::vector< PIN_INFO > NETLIST_EXPORTER_BASE::CreatePinList ( SCH_SYMBOL * aSymbol,
const SCH_SHEET_PATH & aSheetPath,
bool aKeepUnconnectedPins )
protectedinherited

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 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 128 of file netlist_exporter_base.cpp.

References eraseDuplicatePins(), findAllUnitsOfSymbol(), CONNECTION_GRAPH::FindSubgraphByName(), CONNECTION_SUBGRAPH::GetItems(), SCH_SYMBOL::GetLibSymbolRef(), CONNECTION_SUBGRAPH::GetNoConnect(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), LIB_SYMBOL::GetUnitCount(), SCH_SYMBOL::IsPower(), m_libParts, m_schematic, and pin.

Referenced by NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ eraseDuplicatePins()

void NETLIST_EXPORTER_BASE::eraseDuplicatePins ( std::vector< PIN_INFO > & pins)
protectedinherited

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 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 215 of file netlist_exporter_base.cpp.

Referenced by CreatePinList().

◆ findAllUnitsOfSymbol()

void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol ( SCH_SYMBOL * aSchSymbol,
const SCH_SHEET_PATH & aSheetPath,
std::vector< PIN_INFO > & aPins,
bool aKeepUnconnectedPins )
protectedinherited

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 sorted pin list. if aKeepUnconnectedPins = false, unconnected pins will be removed from list but usually we need all pins in netlists.

Definition at line 248 of file netlist_exporter_base.cpp.

References CONNECTION_GRAPH::FindSubgraphByName(), CONNECTION_SUBGRAPH::GetItems(), CONNECTION_SUBGRAPH::GetNoConnect(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), m_schematic, pin, and SCH_SYMBOL_T.

Referenced by CreatePinList().

◆ findNextSymbol()

SCH_SYMBOL * NETLIST_EXPORTER_BASE::findNextSymbol ( EDA_ITEM * aItem,
const SCH_SHEET_PATH & aSheetPath )
protectedinherited

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 82 of file netlist_exporter_base.cpp.

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

Referenced by NETLIST_EXPORTER_ALLEGRO::extractComponentsInfo(), NETLIST_EXPORTER_XML::makeSymbols(), NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries(), NETLIST_EXPORTER_CADSTAR::WriteNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_PADS::WriteNetlist().

◆ Format()

void NETLIST_EXPORTER_KICAD::Format ( OUTPUTFORMATTER * aOutputFormatter,
int aCtl )

Output this s-expression netlist into aOutputFormatter.

Parameters
aOutputFormatteris the destination of the serialization to text.
aCtlis bit set composed by OR-ing together enum GNL bits, it allows outputting a subset of the full document model.
Exceptions
IO_ERRORif any problems.

Definition at line 55 of file netlist_exporter_kicad.cpp.

References NETLIST_EXPORTER_XML::makeRoot().

Referenced by SCH::generateSchematicNetlist(), SCH_EDIT_FRAME::KiwayMailIn(), SCH_EDIT_FRAME::sendNetlistToCvpcb(), and WriteNetlist().

◆ getComponentClassNamesForAllSymbolUnits()

std::vector< wxString > NETLIST_EXPORTER_XML::getComponentClassNamesForAllSymbolUnits ( SCH_SYMBOL * aSymbol,
const SCH_SHEET_PATH & aSymbolSheet,
const SCH_SHEET_LIST & aSheetList )
protectedinherited

Finds all component class names attached to any sub-unit of a given symbol.

Definition at line 542 of file netlist_exporter_xml.cpp.

References SCH_SYMBOL::GetComponentClassNames(), SCH_SYMBOL::GetRef(), SCH_SYMBOL::GetUnitCount(), SCH_SYMBOL::GetUnitSelection(), and SCH_SYMBOL_T.

Referenced by makeSymbols().

◆ MakeCommandLine()

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

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 46 of file netlist_exporter_base.cpp.

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

◆ makeDesignHeader()

XNODE * NETLIST_EXPORTER_XML::makeDesignHeader ( )
protectedinherited

◆ makeGroups()

XNODE * NETLIST_EXPORTER_XML::makeGroups ( )
protectedinherited
Returns
a sub-tree holding all the schematic groups.

Definition at line 493 of file netlist_exporter_xml.cpp.

References group, NETLIST_EXPORTER_BASE::m_referencesAlreadyFound, NETLIST_EXPORTER_BASE::m_schematic, node(), SCH_GROUP_T, and SCH_SYMBOL_T.

Referenced by makeRoot().

◆ makeLibParts()

XNODE * NETLIST_EXPORTER_XML::makeLibParts ( )
protectedinherited

Fill out an XML node with the unique library parts and returns it.

Returns
the library parts nodes

Definition at line 708 of file netlist_exporter_xml.cpp.

References SCH_PIN::GetCanonicalElectricalTypeName(), SCH_PIN::GetShownName(), SCH_PIN::GetShownNumber(), SCH_PIN::GetStackedPinNumbers(), NETLIST_EXPORTER_BASE::m_libParts, m_libraries, node(), pin, and sortPinsByNumber().

Referenced by makeRoot().

◆ makeLibraries()

XNODE * NETLIST_EXPORTER_XML::makeLibraries ( )
protectedinherited

Fill out an XML node with a list of used libraries and returns it.

Must have called makeGenericLibParts() before this function.

Returns
the library nodes

Definition at line 684 of file netlist_exporter_xml.cpp.

References LIB_TABLE::GetFullURI(), LIB_TABLE::HasLibrary(), m_libraries, NETLIST_EXPORTER_BASE::m_schematic, node(), and PROJECT_SCH::SchSymbolLibTable().

Referenced by makeRoot().

◆ makeListOfNets()

XNODE * NETLIST_EXPORTER_XML::makeListOfNets ( unsigned aCtl)
protectedinherited

◆ makeRoot()

XNODE * NETLIST_EXPORTER_XML::makeRoot ( unsigned aCtl = GNL_ALL)
protectedinherited

Build the entire document tree for the generic export.

This is factored out here so we can write the tree in either S-expression file format or in XML if we put the tree built here into a wxXmlDocument.

Parameters
aCtla bitset or-ed together from GNL_ENUM values
Returns
the root nodes

Definition at line 66 of file netlist_exporter_xml.cpp.

References GNL_HEADER, GNL_LIBRARIES, GNL_NETS, GNL_OPT_KICAD, GNL_PARTS, GNL_SYMBOLS, makeDesignHeader(), makeGroups(), makeLibParts(), makeLibraries(), makeListOfNets(), makeSymbols(), and node().

Referenced by NETLIST_EXPORTER_KICAD::Format(), and WriteNetlist().

◆ makeSymbols()

◆ node()

XNODE * NETLIST_EXPORTER_XML::node ( const wxString & aName,
const wxString & aTextualContent = wxEmptyString )
protectedinherited

A convenience function that creates a new XNODE with an optional textual child.

It also provides some insulation from a possible change in XML library.

Parameters
aNameis the name to associate with a new node of type wxXML_ELEMENT_NODE.
aTextualContentis optional, and if given is the text to include in a child of the returned node, and has type wxXML_TEXT_NODE.

Definition at line 1054 of file netlist_exporter_xml.cpp.

Referenced by addSymbolFields(), makeDesignHeader(), makeGroups(), makeLibParts(), makeLibraries(), makeListOfNets(), makeRoot(), and makeSymbols().

◆ WriteNetlist()

bool NETLIST_EXPORTER_KICAD::WriteNetlist ( const wxString & aOutFileName,
unsigned aNetlistOptions,
REPORTER & aReporter )
overridevirtual

Write netlist to aOutFileName.

Generate the KiCad netlist format supported by Pcbnew. It is basically the XML netlist just formatted slightly different.

Reimplemented from NETLIST_EXPORTER_BASE.

Definition at line 36 of file netlist_exporter_kicad.cpp.

References Format(), GNL_ALL, GNL_OPT_KICAD, REPORTER::Report(), RPT_SEVERITY_ERROR, and IO_ERROR::What().

Member Data Documentation

◆ m_libParts

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

◆ m_libraries

std::set<wxString> NETLIST_EXPORTER_XML::m_libraries
privateinherited

Definition at line 152 of file netlist_exporter_xml.h.

Referenced by makeLibParts(), and makeLibraries().

◆ m_referencesAlreadyFound

UNIQUE_STRINGS NETLIST_EXPORTER_BASE::m_referencesAlreadyFound
protectedinherited

◆ m_resolveTextVars

bool NETLIST_EXPORTER_XML::m_resolveTextVars
protectedinherited

Definition at line 149 of file netlist_exporter_xml.h.

Referenced by addSymbolFields(), makeSymbols(), and NETLIST_EXPORTER_XML().

◆ m_schematic


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