KiCad PCB EDA Suite
NETLIST_READER Class Referenceabstract

Class NETLIST_READER is 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=NULL)
 Constructor. More...
 
virtual ~NETLIST_READER ()
 
virtual void LoadNetlist ()=0 throw ( IO_ERROR, PARSE_ERROR, boost::bad_pointer )
 Function LoadNetlist loads the contents of the netlist file into aNetlist. More...
 
LINE_READERGetLineReader ()
 Function GetLineReader() More...
 

Static Public Member Functions

static NETLIST_FILE_T GuessNetlistFileType (LINE_READER *aLineReader)
 Function GuessNetlistFileType looks 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) throw ( IO_ERROR )
 Function GetNetlistReader attempts 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

Class NETLIST_READER is a pure virtual class to derive a specific type of netlist reader from.

Definition at line 111 of file netlist_reader.h.

Member Enumeration Documentation

Enumerator
UNKNOWN 
ORCAD 
LEGACY 
KICAD 

Definition at line 115 of file netlist_reader.h.

116  {
117  UNKNOWN = -1,
118  ORCAD,
119  LEGACY,
120  KICAD,
121 
122  // Add new types here. Don't forget to create the appropriate class derived from
123  // NETCLASS_READER and add the entry to the NETLIST_READER::GetNetlistReader()
124  // function.
125  };

Constructor & Destructor Documentation

NETLIST_READER::NETLIST_READER ( LINE_READER aLineReader,
NETLIST aNetlist,
CMP_READER aFootprintLinkReader = NULL 
)
inline

Constructor.

Parameters
aLineReaderownership is taken of this LINE_READER.
aFootprintLinkReaderownership is taken of this CMP_READER.

Definition at line 133 of file netlist_reader.h.

References m_footprintReader, m_loadFootprintFilters, m_loadNets, and m_netlist.

136  {
137  wxASSERT( aLineReader != NULL );
138 
139  m_lineReader = aLineReader;
140  m_footprintReader = aFootprintLinkReader;
141  m_netlist = aNetlist;
142  m_loadFootprintFilters = true;
143  m_loadNets = true;
144  }
NETLIST * m_netlist
The net list to read the file(s) into.
bool m_loadFootprintFilters
Load the component footprint filters section if true.
bool m_loadNets
Load the nets section of the netlist file if true.
LINE_READER * m_lineReader
The line reader of the netlist.
CMP_READER * m_footprintReader
The reader used to load the footprint links. If NULL, footprint links are not read.
NETLIST_READER::~NETLIST_READER ( )
virtual

Definition at line 41 of file netlist_reader.cpp.

References m_footprintReader, and m_lineReader.

42 {
43  delete m_lineReader;
44  delete m_footprintReader;
45 }
LINE_READER * m_lineReader
The line reader of the netlist.
CMP_READER * m_footprintReader
The reader used to load the footprint links. If NULL, footprint links are not read.

Member Function Documentation

LINE_READER* NETLIST_READER::GetLineReader ( )

Function GetLineReader()

Returns
the LINE_READER associated with the NETLIST_READER.
NETLIST_READER * NETLIST_READER::GetNetlistReader ( NETLIST aNetlist,
const wxString &  aNetlistFileName,
const wxString &  aCompFootprintFileName = wxEmptyString 
)
throw (IO_ERROR
)
static

Function GetNetlistReader attempts 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 79 of file netlist_reader.cpp.

Referenced by PCB_EDIT_FRAME::ReadPcbNetlist(), and DIALOG_NETLIST::verifyFootprints().

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

Function GuessNetlistFileType looks 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.

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

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  // Our legacy netlist format starts by "# EESchema Netlist "
55  wxRegEx reLegacy( wxT( "(?i)#[ \t]+EESchema[ \t]+Netlist[ \t]+" ), wxRE_ADVANCED );
56  wxASSERT( reLegacy.IsValid() );
57  // Our new netlist format starts by "(export (version "
58  wxRegEx reKicad( wxT( "[ ]*\\(export[ ]+" ), wxRE_ADVANCED );
59  wxASSERT( reKicad.IsValid() );
60 
61  wxString line;
62 
63  while( aLineReader->ReadLine() )
64  {
65  line = FROM_UTF8( aLineReader->Line() );
66 
67  if( reLegacy.Matches( line ) )
68  return LEGACY;
69  else if( reKicad.Matches( line ) )
70  return KICAD;
71  else if( reOrcad.Matches( line ) )
72  return ORCAD;
73  }
74 
75  return UNKNOWN;
76 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter...
virtual void NETLIST_READER::LoadNetlist ( )
throw ( IO_ERROR,
PARSE_ERROR,
boost::bad_pointer
)
pure virtual

Function LoadNetlist loads 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 KICAD_NETLIST_READER, and LEGACY_NETLIST_READER.

Referenced by DIALOG_NETLIST::verifyFootprints().

Member Data Documentation

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 198 of file netlist_reader.h.

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

LINE_READER* NETLIST_READER::m_lineReader
protected

The line reader of the netlist.

Definition at line 195 of file netlist_reader.h.

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

bool NETLIST_READER::m_loadFootprintFilters
protected

Load the component footprint filters section if true.

Definition at line 193 of file netlist_reader.h.

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

bool NETLIST_READER::m_loadNets
protected

Load the nets section of the netlist file if true.

Definition at line 194 of file netlist_reader.h.

Referenced by NETLIST_READER().

NETLIST* NETLIST_READER::m_netlist
protected

The net list to read the file(s) into.

Definition at line 192 of file netlist_reader.h.

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


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