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;
405 while( (
token = NextTok() ) != T_RIGHT )
407 if(
token == T_LEFT )
410 if(
token == T_field )
415 while( (
token = NextTok() ) != T_RIGHT )
417 if(
token == T_LEFT )
420 if(
token == T_name )
422 NeedSYMBOLorNUMBER();
426 else if(
token == T_STRING )
432 if( !fieldName.IsEmpty() )
433 fields[fieldName] = fieldValue;
437 Expecting(
"field" );
443 while( (
token = NextTok() ) != T_EOF )
445 if(
token == T_names )
447 NeedSYMBOLorNUMBER();
451 if(
token == T_tstamps )
453 NeedSYMBOLorNUMBER();
465 while( (
token = NextTok() ) != T_EOF )
467 if(
token == T_RIGHT )
470 uuids.emplace_back(
From_UTF8( CurText() ) );
475 case T_component_classes:
477 while( (
token = NextTok() ) != T_RIGHT )
479 if(
token != T_LEFT )
482 if( (
token = NextTok() ) != T_class )
483 Expecting( T_class );
485 NeedSYMBOLorNUMBER();
486 componentClasses.insert(
From_UTF8( CurText() ) );
500 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
503 error.Printf(
_(
"Invalid footprint ID in\nfile: '%s'\nline: %d\nofff: %d" ),
504 CurSource(), CurLineNumber(), CurOffset() );
544 wxString libPartName;
545 wxArrayString footprintFilters;
546 wxArrayString aliases;
550 while( (
token = NextTok() ) != T_RIGHT )
552 if(
token == T_LEFT )
558 NeedSYMBOLorNUMBER();
564 NeedSYMBOLorNUMBER();
571 while( (
token = NextTok() ) != T_RIGHT )
573 if(
token == T_LEFT )
579 NeedSYMBOLorNUMBER();
580 footprintFilters.Add(
From_UTF8( CurText() ) );
586 while( (
token = NextTok() ) != T_RIGHT )
588 if(
token == T_LEFT )
591 if(
token != T_alias )
592 Expecting( T_alias );
594 NeedSYMBOLorNUMBER();
601 while( (
token = NextTok() ) != T_RIGHT )
603 if(
token == T_LEFT )
627 if( component->
IsLibSource( libName, libPartName ) )
633 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
635 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)