25#include <netlist_lexer.h>
27#include <nlohmann/json.hpp>
55 NETLIST_LEXER( aReader )
67 while( (
token = NextTok() ) != T_EOF )
72 if(
token == T_RIGHT )
87 while( (
token = NextTok() ) != T_EOF )
106 while( (
token = NextTok() ) != T_EOF )
108 if(
token == T_RIGHT )
110 else if(
token == T_LEFT )
113 if(
token == T_comp )
120 while( (
token = NextTok() ) != T_EOF )
122 if(
token == T_RIGHT )
124 else if(
token == T_LEFT )
134 while( (
token = NextTok() ) != T_EOF )
136 if(
token == T_RIGHT )
138 else if(
token == T_LEFT )
141 if(
token == T_libpart )
170 wxFAIL_MSG( wxString::Format( wxT(
"KICAD_NETLIST_PARSER::Parse(): bad parenthesis "
171 "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();
262 if( strtol( code.c_str(),
nullptr, 10 ) >= 1 )
265 name = wxT(
"N-00000") + code;
267 component->AddNet( pin_number,
name, pin_function, pin_type );
304 std::vector<KIID> uuids;
305 std::map<wxString, wxString> properties;
306 nlohmann::ordered_map<wxString, wxString> fields;
309 while( (
token = NextTok() ) != T_RIGHT )
311 if(
token == T_LEFT )
317 NeedSYMBOLorNUMBER();
323 NeedSYMBOLorNUMBER();
329 NeedSYMBOLorNUMBER();
330 footprint = FromUTF8();
336 while( (
token = NextTok() ) != T_RIGHT )
338 if(
token == T_LEFT )
343 NeedSYMBOLorNUMBER();
347 else if(
token == T_part )
349 NeedSYMBOLorNUMBER();
353 else if(
token == T_description )
355 NeedSYMBOLorNUMBER();
360 Expecting(
"part, lib or description" );
370 while( (
token = NextTok() ) != T_RIGHT )
372 if(
token == T_LEFT )
375 if(
token == T_name )
377 NeedSYMBOLorNUMBER();
381 else if(
token == T_value )
383 NeedSYMBOLorNUMBER();
389 Expecting(
"name or value" );
393 if( !propName.IsEmpty() )
394 properties[ propName ] = propValue;
401 while( (
token = NextTok() ) != T_RIGHT )
403 if(
token == T_LEFT )
406 if(
token == T_field )
411 while( (
token = NextTok() ) != T_RIGHT )
413 if(
token == T_LEFT )
416 if(
token == T_name )
418 NeedSYMBOLorNUMBER();
422 else if(
token == T_STRING )
424 fieldValue = CurText();
428 if( !fieldName.IsEmpty() )
429 fields[fieldName] = fieldValue;
433 Expecting(
"field" );
439 while( (
token = NextTok() ) != T_EOF )
441 if(
token == T_tstamps )
445 NeedSYMBOLorNUMBER();
452 while( (
token = NextTok() ) != T_EOF )
454 if(
token == T_RIGHT )
457 uuids.emplace_back(
From_UTF8( CurText() ) );
469 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
472 error.Printf(
_(
"Invalid footprint ID in\nfile: '%s'\nline: %d\noffset: %d" ),
473 CurSource(), CurLineNumber(), CurOffset() );
511 wxString libPartName;
512 wxArrayString footprintFilters;
513 wxArrayString aliases;
517 while( (
token = NextTok() ) != T_RIGHT )
519 if(
token == T_LEFT )
525 NeedSYMBOLorNUMBER();
531 NeedSYMBOLorNUMBER();
538 while( (
token = NextTok() ) != T_RIGHT )
540 if(
token == T_LEFT )
546 NeedSYMBOLorNUMBER();
547 footprintFilters.Add(
From_UTF8( CurText() ) );
553 while( (
token = NextTok() ) != T_RIGHT )
555 if(
token == T_LEFT )
558 if(
token != T_alias )
559 Expecting( T_alias );
561 NeedSYMBOLorNUMBER();
568 while( (
token = NextTok() ) != T_RIGHT )
570 if(
token == T_LEFT )
594 if( component->
IsLibSource( libName, libPartName ) )
600 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
602 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 SetFields(nlohmann::ordered_map< wxString, wxString > &aFields)
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 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...
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)
wxString From_UTF8(const char *cstring)