25#include <netlist_lexer.h>
27#include <nlohmann/json.hpp>
56 NETLIST_LEXER( aReader )
68 while( (
token = NextTok() ) != T_EOF )
73 if(
token == T_RIGHT )
88 while( (
token = NextTok() ) != T_EOF )
107 while( (
token = NextTok() ) != T_EOF )
109 if(
token == T_RIGHT )
111 else if(
token == T_LEFT )
114 if(
token == T_comp )
121 while( (
token = NextTok() ) != T_EOF )
123 if(
token == T_RIGHT )
125 else if(
token == T_LEFT )
135 while( (
token = NextTok() ) != T_EOF )
137 if(
token == T_RIGHT )
139 else if(
token == T_LEFT )
142 if(
token == T_libpart )
171 wxFAIL_MSG( wxString::Format( wxT(
"KICAD_NETLIST_PARSER::Parse(): bad parenthesis "
172 "count (count = %d" ),
191 wxString pin_function;
195 while( (
token = NextTok() ) != T_EOF )
197 if(
token == T_RIGHT )
199 else if(
token == T_LEFT )
205 NeedSYMBOLorNUMBER();
211 NeedSYMBOLorNUMBER();
218 pin_function.Clear();
221 while( (
token = NextTok() ) != T_EOF )
223 if(
token == T_RIGHT )
225 else if(
token == T_LEFT )
231 NeedSYMBOLorNUMBER();
237 NeedSYMBOLorNUMBER();
243 NeedSYMBOLorNUMBER();
249 NeedSYMBOLorNUMBER();
263 if( strtol( code.c_str(),
nullptr, 10 ) >= 1 )
266 name = wxT(
"N-00000") + code;
268 component->AddNet( pin_number,
name, pin_function, pin_type );
304 wxString humanSheetPath;
307 std::vector<KIID> uuids;
308 std::map<wxString, wxString> properties;
309 nlohmann::ordered_map<wxString, wxString> fields;
310 std::unordered_set<wxString> componentClasses;
313 while( (
token = NextTok() ) != T_RIGHT )
315 if(
token == T_LEFT )
321 NeedSYMBOLorNUMBER();
327 NeedSYMBOLorNUMBER();
333 NeedSYMBOLorNUMBER();
334 footprint = FromUTF8();
340 while( (
token = NextTok() ) != T_RIGHT )
342 if(
token == T_LEFT )
347 NeedSYMBOLorNUMBER();
351 else if(
token == T_part )
353 NeedSYMBOLorNUMBER();
357 else if(
token == T_description )
359 NeedSYMBOLorNUMBER();
364 Expecting(
"part, lib or description" );
374 while( (
token = NextTok() ) != T_RIGHT )
376 if(
token == T_LEFT )
379 if(
token == T_name )
381 NeedSYMBOLorNUMBER();
385 else if(
token == T_value )
387 NeedSYMBOLorNUMBER();
393 Expecting(
"name or value" );
397 if( !propName.IsEmpty() )
398 properties[ propName ] = propValue;
403 while( (
token = NextTok() ) != T_RIGHT )
405 if(
token == T_LEFT )
408 if(
token == T_field )
413 while( (
token = NextTok() ) != T_RIGHT )
415 if(
token == T_LEFT )
418 if(
token == T_name )
420 NeedSYMBOLorNUMBER();
424 else if(
token == T_STRING )
430 if( !fieldName.IsEmpty() )
431 fields[fieldName] = fieldValue;
435 Expecting(
"field" );
441 while( (
token = NextTok() ) != T_EOF )
443 if(
token == T_names )
445 NeedSYMBOLorNUMBER();
450 if(
token == T_tstamps )
452 NeedSYMBOLorNUMBER();
464 while( (
token = NextTok() ) != T_EOF )
466 if(
token == T_RIGHT )
469 uuids.emplace_back(
From_UTF8( CurText() ) );
474 case T_component_classes:
475 while( (
token = NextTok() ) != T_RIGHT )
477 if(
token != T_LEFT )
480 if( (
token = NextTok() ) != T_class )
481 Expecting( T_class );
483 NeedSYMBOLorNUMBER();
484 componentClasses.insert(
From_UTF8( CurText() ) );
497 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
500 error.Printf(
_(
"Invalid footprint ID in\nfile: '%s'\nline: %d\nofff: %d" ),
501 CurSource(), CurLineNumber(), CurOffset() );
541 wxString libPartName;
542 wxArrayString footprintFilters;
543 wxArrayString aliases;
547 while( (
token = NextTok() ) != T_RIGHT )
549 if(
token == T_LEFT )
555 NeedSYMBOLorNUMBER();
561 NeedSYMBOLorNUMBER();
568 while( (
token = NextTok() ) != T_RIGHT )
570 if(
token == T_LEFT )
576 NeedSYMBOLorNUMBER();
577 footprintFilters.Add(
From_UTF8( CurText() ) );
583 while( (
token = NextTok() ) != T_RIGHT )
585 if(
token == T_LEFT )
588 if(
token != T_alias )
589 Expecting( T_alias );
591 NeedSYMBOLorNUMBER();
598 while( (
token = NextTok() ) != T_RIGHT )
600 if(
token == T_LEFT )
624 if( component->
IsLibSource( libName, libPartName ) )
630 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
632 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 SetHumanReadablePath(const wxString &aPath)
void SetComponentClassNames(const std::unordered_set< wxString > &aClassNames)
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)