25#include <netlist_lexer.h>
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 )
128 if(
token == T_group )
135 while( (
token = NextTok() ) != T_EOF )
137 if(
token == T_RIGHT )
139 else if(
token == T_LEFT )
149 while( (
token = NextTok() ) != T_EOF )
151 if(
token == T_RIGHT )
153 else if(
token == T_LEFT )
156 if(
token == T_libpart )
188 wxFAIL_MSG( wxString::Format( wxT(
"KICAD_NETLIST_PARSER::Parse(): bad parenthesis "
189 "count (count = %d" ),
208 wxString pin_function;
212 while( (
token = NextTok() ) != T_EOF )
214 if(
token == T_RIGHT )
216 else if(
token == T_LEFT )
222 NeedSYMBOLorNUMBER();
228 NeedSYMBOLorNUMBER();
235 pin_function.Clear();
238 while( (
token = NextTok() ) != T_EOF )
240 if(
token == T_RIGHT )
242 else if(
token == T_LEFT )
248 NeedSYMBOLorNUMBER();
254 NeedSYMBOLorNUMBER();
260 NeedSYMBOLorNUMBER();
266 NeedSYMBOLorNUMBER();
280 if( strtol( code.c_str(),
nullptr, 10 ) >= 1 )
283 name = wxT(
"N-00000") + code;
285 component->AddNet( pin_number,
name, pin_function, pin_type );
321 wxString humanSheetPath;
324 std::vector<KIID> uuids;
325 std::map<wxString, wxString> properties;
326 nlohmann::ordered_map<wxString, wxString> fields;
327 std::unordered_set<wxString> componentClasses;
329 bool duplicatePinsAreJumpers =
false;
330 std::vector<std::set<wxString>> jumperPinGroups;
333 while( (
token = NextTok() ) != T_RIGHT )
335 if(
token == T_LEFT )
341 NeedSYMBOLorNUMBER();
347 NeedSYMBOLorNUMBER();
353 NeedSYMBOLorNUMBER();
354 footprint = FromUTF8();
360 while( (
token = NextTok() ) != T_RIGHT )
362 if(
token == T_LEFT )
367 NeedSYMBOLorNUMBER();
371 else if(
token == T_part )
373 NeedSYMBOLorNUMBER();
377 else if(
token == T_description )
379 NeedSYMBOLorNUMBER();
384 Expecting(
"part, lib or description" );
394 while( (
token = NextTok() ) != T_RIGHT )
396 if(
token == T_LEFT )
399 if(
token == T_name )
401 NeedSYMBOLorNUMBER();
405 else if(
token == T_value )
407 NeedSYMBOLorNUMBER();
413 Expecting(
"name or value" );
417 if( !propName.IsEmpty() )
418 properties[propName] = std::move( propValue );
423 while( (
token = NextTok() ) != T_RIGHT )
425 if(
token == T_LEFT )
428 if(
token == T_field )
433 while( (
token = NextTok() ) != T_RIGHT )
435 if(
token == T_LEFT )
438 if(
token == T_name )
440 NeedSYMBOLorNUMBER();
444 else if(
token == T_STRING )
450 if( !fieldName.IsEmpty() )
451 fields[fieldName] = std::move( fieldValue );
455 Expecting(
"field" );
461 while( (
token = NextTok() ) != T_EOF )
463 if(
token == T_names )
465 NeedSYMBOLorNUMBER();
470 if(
token == T_tstamps )
472 NeedSYMBOLorNUMBER();
484 while( (
token = NextTok() ) != T_EOF )
486 if(
token == T_RIGHT )
489 uuids.emplace_back(
From_UTF8( CurText() ) );
494 case T_component_classes:
495 while( (
token = NextTok() ) != T_RIGHT )
497 if(
token != T_LEFT )
500 if( (
token = NextTok() ) != T_class )
501 Expecting( T_class );
503 NeedSYMBOLorNUMBER();
504 componentClasses.insert(
From_UTF8( CurText() ) );
510 case T_duplicate_pin_numbers_are_jumpers:
512 NeedSYMBOLorNUMBER();
513 duplicatePinsAreJumpers =
From_UTF8( CurText() ) == wxT(
"1" );
518 case T_jumper_pin_groups:
520 std::set<wxString>* currentGroup =
nullptr;
522 for(
token = NextTok(); currentGroup ||
token != T_RIGHT;
token = NextTok() )
524 if(
token == T_LEFT )
530 currentGroup = &jumperPinGroups.emplace_back();
535 NeedSYMBOLorNUMBER();
536 wxString padName =
From_UTF8( CurText() );
538 wxCHECK2( currentGroup,
continue );
539 currentGroup->insert( padName );
544 currentGroup =
nullptr;
548 Expecting(
"group or pin" );
562 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
565 error.Printf(
_(
"Invalid footprint ID in\nfile: '%s'\nline: %d\nofff: %d" ),
566 CurSource(), CurLineNumber(), CurOffset() );
579 std::ranges::copy( jumperPinGroups, std::inserter( component->
JumperPadGroups(),
597 std::vector<KIID> members;
600 while( (
token = NextTok() ) != T_EOF )
602 if(
token == T_RIGHT )
604 else if(
token == T_LEFT )
610 NeedSYMBOLorNUMBER();
616 NeedSYMBOLorNUMBER();
622 NeedSYMBOLorNUMBER();
628 while( (
token = NextTok() ) != T_RIGHT )
630 if(
token == T_LEFT )
633 if(
token == T_member )
637 while( (
token = NextTok() ) != T_RIGHT )
639 if(
token == T_LEFT )
642 if(
token == T_uuid )
644 NeedSYMBOLorNUMBER();
654 members.emplace_back( memberUuid );
658 Expecting(
"member" );
672 if( !libId.IsEmpty() && groupLibId.
Parse( libId,
true ) >= 0 )
675 error.Printf(
_(
"Invalid lib_id ID in\nfile: '%s'\nline: %d\nofff: %d" ), CurSource(), CurLineNumber(),
682 std::move( members ) };
711 wxString libPartName;
712 wxArrayString footprintFilters;
713 wxArrayString aliases;
717 while( (
token = NextTok() ) != T_RIGHT )
719 if(
token == T_LEFT )
725 NeedSYMBOLorNUMBER();
731 NeedSYMBOLorNUMBER();
738 while( (
token = NextTok() ) != T_RIGHT )
740 if(
token == T_LEFT )
749 if(
token == T_RIGHT )
753 Expecting(
"footprint ID" );
755 footprintFilters.Add(
From_UTF8( CurText() ) );
761 while( (
token = NextTok() ) != T_RIGHT )
763 if(
token == T_LEFT )
766 if(
token != T_alias )
767 Expecting( T_alias );
769 NeedSYMBOLorNUMBER();
776 while( (
token = NextTok() ) != T_RIGHT )
778 if(
token == T_LEFT )
802 if( component->
IsLibSource( libName, libPartName ) )
808 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
810 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 SetDuplicatePadNumbersAreJumpers(bool aEnabled)
void SetComponentClassNames(const std::unordered_set< wxString > &aClassNames)
std::vector< std::set< wxString > > & JumperPadGroups()
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...
void parseGroup()
Parse a group section (group (name "GroupName") (member (uuid "..."))))
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 AddGroup(NETLIST_GROUP *aGroup)
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.
void ApplyGroupMembership()
After groups and components are parsed, apply the group memberships to the internal components based ...
#define THROW_IO_ERROR(msg)
static bool IsNumber(char x)
wxString From_UTF8(const char *cstring)