KiCad PCB EDA Suite
NETLIST_READER Class Referenceabstract

A pure virtual class to derive a specific type of netlist reader from. More...

#include <netlist_reader.h>

Inheritance diagram for NETLIST_READER:
KICAD_NETLIST_READER LEGACY_NETLIST_READER

Public Types

enum  NETLIST_FILE_T { UNKNOWN = -1 , ORCAD , LEGACY , KICAD }
 

Public Member Functions

 NETLIST_READER (LINE_READER *aLineReader, NETLIST *aNetlist, CMP_READER *aFootprintLinkReader=nullptr)
 
virtual ~NETLIST_READER ()
 
virtual void LoadNetlist ()=0
 Load the contents of the netlist file into aNetlist. More...
 

Static Public Member Functions

static NETLIST_FILE_T GuessNetlistFileType (LINE_READER *aLineReader)
 Look at aFileHeaderLine to see if it matches any of the netlist file types it knows about. More...
 
static NETLIST_READERGetNetlistReader (NETLIST *aNetlist, const wxString &aNetlistFileName, const wxString &aCompFootprintFileName=wxEmptyString)
 Attempt to determine the net list file type of aNetlistFileName and return the appropriate NETLIST_READER type. More...
 

Protected Attributes

NETLISTm_netlist
 The net list to read the file(s) into. More...
 
bool m_loadFootprintFilters
 Load the component footprint filters section if true. More...
 
bool m_loadNets
 Load the nets section of the netlist file if true. More...
 
LINE_READERm_lineReader
 The line reader of the netlist. More...
 
CMP_READERm_footprintReader
 The reader used to load the footprint links. If NULL, footprint links are not read. More...
 

Detailed Description

A pure virtual class to derive a specific type of netlist reader from.

Definition at line 102 of file netlist_reader.h.

Member Enumeration Documentation

◆ NETLIST_FILE_T

Enumerator
UNKNOWN 
ORCAD 
LEGACY 
KICAD 

Definition at line 106 of file netlist_reader.h.

107 {
108 UNKNOWN = -1,
109 ORCAD,
110 LEGACY,
111 KICAD,
112
113 // Add new types here. Don't forget to create the appropriate class derived from
114 // NETCLASS_READER and add the entry to the NETLIST_READER::GetNetlistReader()
115 // function.
116 };

Constructor & Destructor Documentation

◆ NETLIST_READER()

NETLIST_READER::NETLIST_READER ( LINE_READER aLineReader,
NETLIST aNetlist,
CMP_READER aFootprintLinkReader = nullptr 
)
inline
Parameters
aLineReaderownership is taken of this LINE_READER.
aNetlistthe NETLIST object to read into.
aFootprintLinkReaderownership is taken of this CMP_READER.

Definition at line 123 of file netlist_reader.h.

126 {
127 wxASSERT( aLineReader != nullptr );
128
129 m_lineReader = aLineReader;
130 m_footprintReader = aFootprintLinkReader;
131 m_netlist = aNetlist;
133 m_loadNets = true;
134 }
NETLIST * m_netlist
The net list to read the file(s) into.
LINE_READER * m_lineReader
The line reader of the netlist.
bool m_loadFootprintFilters
Load the component footprint filters section if true.
CMP_READER * m_footprintReader
The reader used to load the footprint links. If NULL, footprint links are not read.
bool m_loadNets
Load the nets section of the netlist file if true.

References m_footprintReader, m_lineReader, m_loadFootprintFilters, m_loadNets, and m_netlist.

◆ ~NETLIST_READER()

NETLIST_READER::~NETLIST_READER ( )
virtual

Definition at line 41 of file netlist_reader.cpp.

42{
43 delete m_lineReader;
44 delete m_footprintReader;
45}

References m_footprintReader, and m_lineReader.

Member Function Documentation

◆ GetNetlistReader()

NETLIST_READER * NETLIST_READER::GetNetlistReader ( NETLIST aNetlist,
const wxString &  aNetlistFileName,
const wxString &  aCompFootprintFileName = wxEmptyString 
)
static

Attempt to determine the net list file type of aNetlistFileName and return the appropriate NETLIST_READER type.

Parameters
aNetlistis the netlist to load aNetlistFileName into.
aNetlistFileNameis the full path and file name of the net list to read.
aCompFootprintFileNameis the full path and file name of the component footprint associations to read. Set to wxEmptyString if loading the footprint association file is not required.
Returns
the appropriate NETLIST_READER if aNetlistFileName is a valid netlist or NULL if aNetlistFileName is not a valid netlist files.

Definition at line 81 of file netlist_reader.cpp.

84{
85 wxASSERT( aNetlist != nullptr );
86
87 std::unique_ptr<FILE_LINE_READER> file_rdr =
88 std::make_unique<FILE_LINE_READER>( aNetlistFileName );
89
90 NETLIST_FILE_T type = GuessNetlistFileType( file_rdr.get() );
91 file_rdr->Rewind();
92
93 // The component footprint link reader is NULL if no file name was specified.
94 std::unique_ptr<CMP_READER> cmp_rdr( aCompFootprintFileName.IsEmpty() ?
95 nullptr :
96 new CMP_READER( new FILE_LINE_READER( aCompFootprintFileName ) ) );
97
98 switch( type )
99 {
100 case LEGACY:
101 case ORCAD:
102 return new LEGACY_NETLIST_READER( file_rdr.release(), aNetlist, cmp_rdr.release() );
103
104 case KICAD:
105 return new KICAD_NETLIST_READER( file_rdr.release(), aNetlist, cmp_rdr.release() );
106
107 default: // Unrecognized format:
108 break;
109 }
110
111 return nullptr;
112}
Read a component footprint link file (*.cmp) format.
A LINE_READER that reads from an open file.
Definition: richio.h:173
Read the new s-expression based KiCad netlist format.
Read the KiCad legacy and the old Orcad netlist formats.
static NETLIST_FILE_T GuessNetlistFileType(LINE_READER *aLineReader)
Look at aFileHeaderLine to see if it matches any of the netlist file types it knows about.

References GuessNetlistFileType(), KICAD, LEGACY, and ORCAD.

Referenced by TEST_NETLIST_EXPORTER_KICAD_FIXTURE::CompareNetlists(), and PCB_EDIT_FRAME::ReadNetlistFromFile().

◆ GuessNetlistFileType()

NETLIST_READER::NETLIST_FILE_T NETLIST_READER::GuessNetlistFileType ( LINE_READER aLineReader)
static

Look at aFileHeaderLine to see if it matches any of the netlist file types it knows about.

Parameters
aLineReaderis the LINE_READER object containing lines from the netlist to test.
Returns
the NETLIST_FILE_T of aLineReader.

Definition at line 48 of file netlist_reader.cpp.

49{
50 // Orcad Pcb2 netlist format starts by "( {", followed by an unknown comment,
51 // depending on the tool which created the file
52 wxRegEx reOrcad( wxT( "(?i)[ ]*\\([ \t]+{+" ), wxRE_ADVANCED );
53 wxASSERT( reOrcad.IsValid() );
54
55 // Our legacy netlist format starts by "# EESchema Netlist "
56 wxRegEx reLegacy( wxT( "(?i)#[ \t]+EESchema[ \t]+Netlist[ \t]+" ), wxRE_ADVANCED );
57 wxASSERT( reLegacy.IsValid() );
58
59 // Our new netlist format starts by "(export (version "
60 wxRegEx reKicad( wxT( "[ ]*\\(export[ ]+" ), wxRE_ADVANCED );
61 wxASSERT( reKicad.IsValid() );
62
63 wxString line;
64
65 while( aLineReader->ReadLine() )
66 {
67 line = FROM_UTF8( aLineReader->Line() );
68
69 if( reLegacy.Matches( line ) )
70 return LEGACY;
71 else if( reKicad.Matches( line ) )
72 return KICAD;
73 else if( reOrcad.Matches( line ) )
74 return ORCAD;
75 }
76
77 return UNKNOWN;
78}
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110

References FROM_UTF8(), KICAD, LEGACY, LINE_READER::Line(), ORCAD, LINE_READER::ReadLine(), and UNKNOWN.

Referenced by GetNetlistReader().

◆ LoadNetlist()

virtual void NETLIST_READER::LoadNetlist ( )
pure virtual

Load the contents of the netlist file into aNetlist.

Exceptions
IO_ERRORif a file IO error occurs.
PARSE_ERRORif an error occurs while parsing the file.

Implemented in LEGACY_NETLIST_READER, and KICAD_NETLIST_READER.

Member Data Documentation

◆ m_footprintReader

CMP_READER* NETLIST_READER::m_footprintReader
protected

The reader used to load the footprint links. If NULL, footprint links are not read.

Definition at line 178 of file netlist_reader.h.

Referenced by LEGACY_NETLIST_READER::LoadNetlist(), KICAD_NETLIST_READER::LoadNetlist(), NETLIST_READER(), and ~NETLIST_READER().

◆ m_lineReader

◆ m_loadFootprintFilters

bool NETLIST_READER::m_loadFootprintFilters
protected

Load the component footprint filters section if true.

Definition at line 173 of file netlist_reader.h.

Referenced by LEGACY_NETLIST_READER::LoadNetlist(), and NETLIST_READER().

◆ m_loadNets

bool NETLIST_READER::m_loadNets
protected

Load the nets section of the netlist file if true.

Definition at line 174 of file netlist_reader.h.

Referenced by NETLIST_READER().

◆ m_netlist

NETLIST* NETLIST_READER::m_netlist
protected

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