KiCad PCB EDA Suite
netlist_reader.h
Go to the documentation of this file.
1 #ifndef NETLIST_READER_H
2 #define NETLIST_READER_H
3 
8 /*
9  * This program source code file is part of KiCad, a free EDA CAD application.
10  *
11  * Copyright (C) 2012 Jean-Pierre Charras.
12  * Copyright (C) 2013-2017 Wayne Stambaugh <stambaughw@gmail.com>.
13  * Copyright (C) 2012-2017 KiCad Developers, see AUTHORS.txt for contributors.
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, you may find one here:
27  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
28  * or you may search the http://www.gnu.org website for the version 2 license,
29  * or you may write to the Free Software Foundation, Inc.,
30  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
31  */
32 
33 #include <boost/ptr_container/ptr_vector.hpp>
34 
35 #include <fctsys.h>
36 #include <macros.h>
37 #include <lib_id.h>
38 
39 #include <netlist_lexer.h> // netlist_lexer is common to Eeschema and Pcbnew
40 
41 
42 class NETLIST;
43 class COMPONENT;
44 
45 
51 {
53 
54 public:
61  CMP_READER( LINE_READER* aLineReader )
62  {
63  m_lineReader = aLineReader;
64  }
65 
67  {
68  if( m_lineReader )
69  {
70  delete m_lineReader;
71  m_lineReader = NULL;
72  }
73  }
74 
103  bool Load( NETLIST* aNetlist );
104 };
105 
106 
112 {
113 public:
114 
116  {
117  UNKNOWN = -1,
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  };
126 
127 
135  NETLIST* aNetlist,
136  CMP_READER* aFootprintLinkReader = NULL )
137  {
138  wxASSERT( aLineReader != NULL );
139 
140  m_lineReader = aLineReader;
141  m_footprintReader = aFootprintLinkReader;
142  m_netlist = aNetlist;
143  m_loadFootprintFilters = true;
144  m_loadNets = true;
145  }
146 
147  virtual ~NETLIST_READER();
148 
157  static NETLIST_FILE_T GuessNetlistFileType( LINE_READER* aLineReader );
158 
172  static NETLIST_READER* GetNetlistReader( NETLIST* aNetlist,
173  const wxString& aNetlistFileName,
174  const wxString& aCompFootprintFileName = wxEmptyString );
175 
183  virtual void LoadNetlist() = 0;
184 
190 
191 protected:
194  bool m_loadNets;
196 
199 };
200 
201 
210 {
223  COMPONENT* loadComponent( char* aText );
224 
244  void loadFootprintFilters();
245 
254  void loadNet( char* aText, COMPONENT* aComponent );
255 
256 public:
257 
259  NETLIST* aNetlist,
260  CMP_READER* aFootprintLinkReader = NULL ) :
261  NETLIST_READER( aLineReader, aNetlist, aFootprintLinkReader )
262  {
263  }
264 
286  virtual void LoadNetlist() override;
287 };
288 
289 
295 {
296 private:
300 
306  void skipCurrent();
307 
318  void parseComponent();
319 
330  void parseNet();
331 
354  void parseLibPartList();
355 
356 
357 public:
358  KICAD_NETLIST_PARSER( LINE_READER* aReader, NETLIST* aNetlist );
359 
360  void SetLineReader( LINE_READER* aLineReader );
361 
362  void SetNetlist( NETLIST* aNetlist ) { m_netlist = aNetlist; }
363 
368  void Parse();
369 
370  // Useful for debug only:
371  const char* getTokenName( NL_T::T aTok )
372  {
373  return NETLIST_LEXER::TokenName( aTok );
374  }
375 };
376 
377 
383 {
385 
386 public:
388  NETLIST* aNetlist,
389  CMP_READER* aFootprintLinkReader = NULL ) :
390  NETLIST_READER( aLineReader, aNetlist, aFootprintLinkReader ),
391  m_parser( new KICAD_NETLIST_PARSER( aLineReader, aNetlist ) )
392  {
393  }
394 
396  {
397  delete m_parser;
398  }
399 
400  virtual void LoadNetlist() override;
401 };
402 
403 
404 #endif // NETLIST_READER_H
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
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.
static const char * TokenName(NL_T::T aTok)
Function TokenName returns the name of the token in ASCII form.
void SetNetlist(NETLIST *aNetlist)
LINE_READER * m_lineReader
The line reader to read.
Class NETLIST_LEXER is an automatically generated class using the TokenList2DnsLexer.cmake technology, based on keywords provided by file: /home/kicad/workspace/kicad-doxygen/common/netlist.keywords.
Definition: netlist_lexer.h:92
NETLIST * m_netlist
The netlist to parse into. Not owned.
static NETLIST_READER * GetNetlistReader(NETLIST *aNetlist, const wxString &aNetlistFileName, const wxString &aCompFootprintFileName=wxEmptyString)
Function GetNetlistReader attempts to determine the net list file type of aNetlistFileName and return...
NETLIST * m_netlist
The net list to read the file(s) into.
void parseComponent()
Function parseComponent parse a component description: (comp (ref P1) (value DB25FEMELLE) (footprint ...
CMP_READER(LINE_READER *aLineReader)
CMP_READER constructor.
void skipCurrent()
Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes ...
This file contains miscellaneous commonly used macros and functions.
Class KICAD_NETLIST_PARSER is the parser for reading the KiCad s-expression netlist format...
virtual ~KICAD_NETLIST_READER()
bool Load(NETLIST *aNetlist)
Function Load read the *.cmp file format contains the component footprint assignments created by CvPc...
virtual void LoadNetlist() override
Function LoadNetlist loads the contents of the netlist file into aNetlist.
KICAD_NETLIST_PARSER(LINE_READER *aReader, NETLIST *aNetlist)
virtual void LoadNetlist()=0
Function LoadNetlist loads the contents of the netlist file into aNetlist.
KICAD_NETLIST_READER(LINE_READER *aLineReader, NETLIST *aNetlist, CMP_READER *aFootprintLinkReader=NULL)
void parseLibPartList()
Function parseLibPartList reads the section "libparts" in the netlist: (libparts (libpart (lib device...
Class NETLIST stores all of information read from a netlist along with the flags used to update the N...
Definition: pcb_netlist.h:205
LINE_READER * m_lineReader
The line reader used to parse the netlist. Not owned.
T
enum T contains all this lexer's tokens.
Definition: netlist_lexer.h:26
virtual ~NETLIST_READER()
Class NETLIST_READER is a pure virtual class to derive a specific type of netlist reader from...
KICAD_NETLIST_PARSER * m_parser
The s-expression format parser.
void loadNet(char *aText, COMPONENT *aComponent)
Function loadNet read a component net description from aText.
Class LEGACY_NETLIST_READER reads the KiCad legacy and the old Orcad netlist formats.
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
LEGACY_NETLIST_READER(LINE_READER *aLineReader, NETLIST *aNetlist, CMP_READER *aFootprintLinkReader=NULL)
void Parse()
Function Parse parse the full netlist.
bool m_loadFootprintFilters
Load the component footprint filters section if true.
virtual void LoadNetlist() override
Function LoadNetlist read the netlist file in the legacy format into aNetlist.
const char * getTokenName(NL_T::T aTok)
Class CMP_READER reads a component footprint link file (*.cmp) format.
bool m_loadNets
Load the nets section of the netlist file if true.
void parseNet()
Function parseNet Parses a section like (net (code 20) (name /PC-A0) (node (ref BUS1) (pin 62)) (node...
void loadFootprintFilters()
Function loadFootprintFilters loads the footprint filter section of netlist file. ...
LINE_READER * m_lineReader
The line reader of the netlist.
NETLIST_READER(LINE_READER *aLineReader, NETLIST *aNetlist, CMP_READER *aFootprintLinkReader=NULL)
Constructor.
void SetLineReader(LINE_READER *aLineReader)
LINE_READER * GetLineReader()
Function GetLineReader()
COMPONENT * loadComponent(char *aText)
Function loadComponent read the aLine containing the description of a component from a legacy format ...
CMP_READER * m_footprintReader
The reader used to load the footprint links. If NULL, footprint links are not read.