KiCad PCB EDA Suite
KICAD_NETLIST_READER Class Reference

Class KICAD_NETLIST_READER read the new s-expression based KiCad netlist format. More...

#include <netlist_reader.h>

Inheritance diagram for KICAD_NETLIST_READER:
NETLIST_READER

Public Types

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

Public Member Functions

 KICAD_NETLIST_READER (LINE_READER *aLineReader, NETLIST *aNetlist, CMP_READER *aFootprintLinkReader=NULL)
 
virtual ~KICAD_NETLIST_READER ()
 
virtual void LoadNetlist () override 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...
 

Private Attributes

KICAD_NETLIST_PARSERm_parser
 The s-expression format parser. More...
 

Detailed Description

Class KICAD_NETLIST_READER read the new s-expression based KiCad netlist format.

Definition at line 382 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

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

Definition at line 387 of file netlist_reader.h.

389  :
390  NETLIST_READER( aLineReader, aNetlist, aFootprintLinkReader ),
391  m_parser( new KICAD_NETLIST_PARSER( aLineReader, aNetlist ) )
392  {
393  }
Class KICAD_NETLIST_PARSER is the parser for reading the KiCad s-expression netlist format...
KICAD_NETLIST_PARSER * m_parser
The s-expression format parser.
NETLIST_READER(LINE_READER *aLineReader, NETLIST *aNetlist, CMP_READER *aFootprintLinkReader=NULL)
Constructor.
virtual KICAD_NETLIST_READER::~KICAD_NETLIST_READER ( )
inlinevirtual

Definition at line 395 of file netlist_reader.h.

396  {
397  delete m_parser;
398  }
KICAD_NETLIST_PARSER * m_parser
The s-expression format parser.

Member Function Documentation

LINE_READER* NETLIST_READER::GetLineReader ( )
inherited

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
)
staticinherited

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)
staticinherited

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(), NETLIST_READER::KICAD, NETLIST_READER::LEGACY, LINE_READER::Line(), NETLIST_READER::ORCAD, LINE_READER::ReadLine(), and NETLIST_READER::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...
void KICAD_NETLIST_READER::LoadNetlist ( )
throw ( IO_ERROR,
PARSE_ERROR,
boost::bad_pointer
)
overridevirtual

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.

Implements NETLIST_READER.

Definition at line 38 of file kicad_netlist_reader.cpp.

Referenced by PCB_EDIT_FRAME::KiwayMailIn(), and CVPCB_MAINFRAME::ReadSchematicNetlist().

39 {
40  m_parser->Parse();
41 
42  if( m_footprintReader )
43  {
45 
46  // Sort the component pins so they are in the same order as the legacy format. This
47  // is useful for comparing legacy and s-expression netlist dumps.
48  for( unsigned i = 0; i < m_netlist->GetCount(); i++ )
50  }
51 }
NETLIST * m_netlist
The net list to read the file(s) into.
bool Load(NETLIST *aNetlist)
Function Load read the *.cmp file format contains the component footprint assignments created by CvPc...
KICAD_NETLIST_PARSER * m_parser
The s-expression format parser.
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:256
void Parse()
Function Parse parse the full netlist.
void SortPins()
Definition: pcb_netlist.h:141
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:247
CMP_READER * m_footprintReader
The reader used to load the footprint links. If NULL, footprint links are not read.

Member Data Documentation

CMP_READER* NETLIST_READER::m_footprintReader
protectedinherited

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::NETLIST_READER(), and NETLIST_READER::~NETLIST_READER().

LINE_READER* NETLIST_READER::m_lineReader
protectedinherited
bool NETLIST_READER::m_loadFootprintFilters
protectedinherited

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::NETLIST_READER().

bool NETLIST_READER::m_loadNets
protectedinherited

Load the nets section of the netlist file if true.

Definition at line 194 of file netlist_reader.h.

Referenced by NETLIST_READER::NETLIST_READER().

NETLIST* NETLIST_READER::m_netlist
protectedinherited

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::NETLIST_READER().

KICAD_NETLIST_PARSER* KICAD_NETLIST_READER::m_parser
private

The s-expression format parser.

Definition at line 384 of file netlist_reader.h.


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