25#include <netlist_lexer.h>
54 NETLIST_LEXER( aReader )
66 while( (
token = NextTok() ) != T_EOF )
71 if(
token == T_RIGHT )
86 while( (
token = NextTok() ) != T_EOF )
105 while( (
token = NextTok() ) != T_EOF )
107 if(
token == T_RIGHT )
109 else if(
token == T_LEFT )
112 if(
token == T_comp )
119 while( (
token = NextTok() ) != T_EOF )
121 if(
token == T_RIGHT )
123 else if(
token == T_LEFT )
133 while( (
token = NextTok() ) != T_EOF )
135 if(
token == T_RIGHT )
137 else if(
token == T_LEFT )
140 if(
token == T_libpart )
169 wxFAIL_MSG( wxString::Format( wxT(
"KICAD_NETLIST_PARSER::Parse(): bad parenthesis "
170 "count (count = %d" ),
190 wxString pin_function;
194 while( (
token = NextTok() ) != T_EOF )
196 if(
token == T_RIGHT )
198 else if(
token == T_LEFT )
204 NeedSYMBOLorNUMBER();
210 NeedSYMBOLorNUMBER();
217 pin_function.Clear();
220 while( (
token = NextTok() ) != T_EOF )
222 if(
token == T_RIGHT )
224 else if(
token == T_LEFT )
230 NeedSYMBOLorNUMBER();
236 NeedSYMBOLorNUMBER();
242 NeedSYMBOLorNUMBER();
248 NeedSYMBOLorNUMBER();
259 if( strtol( code.c_str(), NULL, 10 ) >= 1 )
262 name = wxT(
"N-00000") + code;
267 if( component == NULL )
270 msg.Printf(
_(
"Cannot find component with ref '%s' in netlist." ),
276 component->
AddNet( pin_number,
name, pin_function, pin_type );
311 std::vector<KIID> uuids;
312 std::map<wxString, wxString> properties;
315 while( (
token = NextTok() ) != T_RIGHT )
317 if(
token == T_LEFT )
323 NeedSYMBOLorNUMBER();
329 NeedSYMBOLorNUMBER();
335 NeedSYMBOLorNUMBER();
336 footprint = FromUTF8();
342 while( (
token = NextTok() ) != T_RIGHT )
344 if(
token == T_LEFT )
349 NeedSYMBOLorNUMBER();
353 else if(
token == T_part )
355 NeedSYMBOLorNUMBER();
359 else if(
token == T_description )
361 NeedSYMBOLorNUMBER();
366 Expecting(
"part, lib or description" );
376 while( (
token = NextTok() ) != T_RIGHT )
378 if(
token == T_LEFT )
381 if(
token == T_name )
383 NeedSYMBOLorNUMBER();
387 else if(
token == T_value )
389 NeedSYMBOLorNUMBER();
395 Expecting(
"name or value" );
399 if( !propName.IsEmpty() )
400 properties[ propName ] = propValue;
405 while( (
token = NextTok() ) != T_EOF )
407 if(
token == T_tstamps )
411 NeedSYMBOLorNUMBER();
418 while( (
token = NextTok() ) != T_EOF )
420 if(
token == T_RIGHT )
423 uuids.emplace_back(
FROM_UTF8( CurText() ) );
435 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
438 error.Printf(
_(
"Invalid footprint ID in\nfile: '%s'\nline: %d\noffset: %d" ),
439 CurSource(), CurLineNumber(), CurOffset() );
476 wxString libPartName;
477 wxArrayString footprintFilters;
478 wxArrayString aliases;
482 while( (
token = NextTok() ) != T_RIGHT )
484 if(
token == T_LEFT )
490 NeedSYMBOLorNUMBER();
496 NeedSYMBOLorNUMBER();
503 while( (
token = NextTok() ) != T_RIGHT )
505 if(
token == T_LEFT )
511 NeedSYMBOLorNUMBER();
512 footprintFilters.Add(
FROM_UTF8( CurText() ) );
518 while( (
token = NextTok() ) != T_RIGHT )
520 if(
token == T_LEFT )
523 if(
token != T_alias )
524 Expecting( T_alias );
526 NeedSYMBOLorNUMBER();
533 while( (
token = NextTok() ) != T_RIGHT )
535 if(
token == T_LEFT )
559 if( component->
IsLibSource( libName, libPartName ) )
565 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
567 if( component->
IsLibSource( libName, aliases[jj] ) )
bool Load(NETLIST *aNetlist)
Read the *.cmp file format contains the component footprint assignments created by CvPcb into aNetlis...
Store all of the related footprint information found in a netlist.
void SetLibrary(const wxString &aLibrary)
void SetProperties(std::map< wxString, wxString > &aProps)
void SetPinCount(int aPinCount)
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
void SetFootprintFilters(const wxArrayString &aFilters)
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
void SetName(const wxString &aName)
The parser for reading the KiCad s-expression netlist format.
KICAD_NETLIST_PARSER(LINE_READER *aReader, NETLIST *aNetlist)
void parseComponent()
Parse a component description: (comp (ref P1) (value DB25FEMELLE) (footprint DB25FC) (libsource (lib ...
void Parse()
Function Parse parse the full netlist.
void parseNet()
Parse a net section (net (code 20) (name /PC-A0) (node (ref BUS1) (pin 62)) (node (ref U3) (pin 3)) (...
NETLIST * m_netlist
The netlist to parse into. Not owned.
void parseLibPartList()
Read the section "libparts" in the netlist: (libparts (libpart (lib device) (part C) (description "Co...
LINE_READER * m_lineReader
The line reader used to parse the netlist. Not owned.
void skipCurrent()
Skip the current token level, i.e search for the RIGHT parenthesis which closes the current descripti...
virtual void LoadNetlist() override
Load the contents of the netlist file into aNetlist.
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
unsigned Length() const
Return the number of bytes in the last line read from this LINE_READER.
char * Line() const
Return a pointer to the last line that was read in.
NETLIST * m_netlist
The net list to read the file(s) into.
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.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
unsigned GetCount() const
void AddComponent(COMPONENT *aComponent)
Add aComponent to the NETLIST.
COMPONENT * GetComponentByReference(const wxString &aReference)
Return a COMPONENT by aReference.
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
#define THROW_IO_ERROR(msg)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
This file contains miscellaneous commonly used macros and functions.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.