25#include <netlist_lexer.h>
48 for(
unsigned i = 0; i <
m_netlist->GetCount(); i++ )
56 NETLIST_LEXER( aReader )
58 m_lineReader = aReader;
68 while( (
token = NextTok() ) != T_EOF )
73 if(
token == T_RIGHT )
88 while( (
token = NextTok() ) != T_EOF )
107 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Parse: entering components section" ) );
109 while( (
token = NextTok() ) != T_EOF )
111 if(
token == T_RIGHT )
113 else if(
token == T_LEFT )
116 if(
token == T_comp )
123 while( (
token = NextTok() ) != T_EOF )
125 if(
token == T_RIGHT )
127 else if(
token == T_LEFT )
130 if(
token == T_group )
137 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Parse: entering nets section" ) );
139 while( (
token = NextTok() ) != T_EOF )
141 if(
token == T_RIGHT )
143 else if(
token == T_LEFT )
153 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Parse: entering libparts section" ) );
155 while( (
token = NextTok() ) != T_EOF )
157 if(
token == T_RIGHT )
159 else if(
token == T_LEFT )
162 if(
token == T_libpart )
194 wxFAIL_MSG( wxString::Format( wxT(
"KICAD_NETLIST_PARSER::Parse(): bad parenthesis "
195 "count (count = %d" ),
214 wxString pin_function;
218 while( (
token = NextTok() ) != T_EOF )
220 if(
token == T_RIGHT )
222 else if(
token == T_LEFT )
228 NeedSYMBOLorNUMBER();
234 NeedSYMBOLorNUMBER();
241 pin_function.Clear();
244 while( (
token = NextTok() ) != T_EOF )
246 if(
token == T_RIGHT )
248 else if(
token == T_LEFT )
254 NeedSYMBOLorNUMBER();
260 NeedSYMBOLorNUMBER();
266 NeedSYMBOLorNUMBER();
272 NeedSYMBOLorNUMBER();
286 if( strtol( code.c_str(),
nullptr, 10 ) >= 1 )
289 name = wxT(
"N-00000") + code;
291 component->AddNet( pin_number,
name, pin_function, pin_type );
327 wxString humanSheetPath;
330 std::vector<KIID> uuids;
331 std::map<wxString, wxString> properties;
332 nlohmann::ordered_map<wxString, wxString> fields;
333 std::unordered_set<wxString> componentClasses;
335 bool duplicatePinsAreJumpers =
false;
336 std::vector<std::set<wxString>> jumperPinGroups;
338 std::vector<COMPONENT::UNIT_INFO> parsedUnits;
341 while( (
token = NextTok() ) != T_RIGHT )
343 if(
token == T_LEFT )
349 NeedSYMBOLorNUMBER();
355 NeedSYMBOLorNUMBER();
361 NeedSYMBOLorNUMBER();
362 footprint = FromUTF8();
368 while( (
token = NextTok() ) != T_RIGHT )
370 if(
token == T_LEFT )
375 NeedSYMBOLorNUMBER();
379 else if(
token == T_part )
381 NeedSYMBOLorNUMBER();
385 else if(
token == T_description )
387 NeedSYMBOLorNUMBER();
392 Expecting(
"part, lib or description" );
395 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseComponent: ref='%s' libsource='%s:%s'" ),
404 while( (
token = NextTok() ) != T_RIGHT )
406 if(
token == T_LEFT )
409 if(
token == T_name )
411 NeedSYMBOLorNUMBER();
415 else if(
token == T_value )
417 NeedSYMBOLorNUMBER();
423 Expecting(
"name or value" );
427 if( !propName.IsEmpty() )
428 properties[propName] = std::move( propValue );
433 while( (
token = NextTok() ) != T_RIGHT )
435 if(
token == T_LEFT )
438 if(
token == T_field )
443 while( (
token = NextTok() ) != T_RIGHT )
445 if(
token == T_LEFT )
448 if(
token == T_name )
450 NeedSYMBOLorNUMBER();
454 else if(
token == T_STRING )
460 if( !fieldName.IsEmpty() )
461 fields[fieldName] = std::move( fieldValue );
465 Expecting(
"field" );
471 while( (
token = NextTok() ) != T_EOF )
473 if(
token == T_names )
475 NeedSYMBOLorNUMBER();
480 if(
token == T_tstamps )
482 NeedSYMBOLorNUMBER();
494 while( (
token = NextTok() ) != T_EOF )
496 if(
token == T_RIGHT )
499 uuids.emplace_back(
From_UTF8( CurText() ) );
508 while( (
token = NextTok() ) != T_RIGHT )
510 if(
token == T_LEFT )
513 if(
token == T_unit )
515 COMPONENT::UNIT_INFO
info;
517 while( (
token = NextTok() ) != T_RIGHT )
519 if(
token == T_LEFT )
525 NeedSYMBOLorNUMBER();
531 while( (
token = NextTok() ) != T_RIGHT )
533 if(
token == T_LEFT )
543 if(
token == T_LEFT )
548 NeedSYMBOLorNUMBER();
559 if( !pinNum.IsEmpty() )
560 info.m_pins.emplace_back( pinNum );
575 parsedUnits.push_back(
info );
586 case T_component_classes:
587 while( (
token = NextTok() ) != T_RIGHT )
589 if(
token != T_LEFT )
592 if( (
token = NextTok() ) != T_class )
593 Expecting( T_class );
595 NeedSYMBOLorNUMBER();
596 componentClasses.insert(
From_UTF8( CurText() ) );
602 case T_duplicate_pin_numbers_are_jumpers:
604 NeedSYMBOLorNUMBER();
605 duplicatePinsAreJumpers =
From_UTF8( CurText() ) == wxT(
"1" );
610 case T_jumper_pin_groups:
612 std::set<wxString>* currentGroup =
nullptr;
614 for(
token = NextTok(); currentGroup ||
token != T_RIGHT;
token = NextTok() )
616 if(
token == T_LEFT )
622 currentGroup = &jumperPinGroups.emplace_back();
627 NeedSYMBOLorNUMBER();
628 wxString padName =
From_UTF8( CurText() );
630 wxCHECK2( currentGroup,
continue );
631 currentGroup->insert( padName );
636 currentGroup =
nullptr;
640 Expecting(
"group or pin" );
654 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
657 error.Printf(
_(
"Invalid footprint ID in\nfile: '%s'\nline: %d\nofff: %d" ),
658 CurSource(), CurLineNumber(), CurOffset() );
671 std::ranges::copy( jumperPinGroups, std::inserter( component->
JumperPadGroups(),
690 std::vector<KIID> members;
693 while( (
token = NextTok() ) != T_EOF )
695 if(
token == T_RIGHT )
697 else if(
token == T_LEFT )
703 NeedSYMBOLorNUMBER();
709 NeedSYMBOLorNUMBER();
715 NeedSYMBOLorNUMBER();
721 while( (
token = NextTok() ) != T_RIGHT )
723 if(
token == T_LEFT )
726 if(
token == T_member )
730 while( (
token = NextTok() ) != T_RIGHT )
732 if(
token == T_LEFT )
735 if(
token == T_uuid )
737 NeedSYMBOLorNUMBER();
747 members.emplace_back( memberUuid );
751 Expecting(
"member" );
765 if( !libId.IsEmpty() && groupLibId.
Parse( libId,
true ) >= 0 )
768 error.Printf(
_(
"Invalid lib_id ID in\nfile: '%s'\nline: %d\nofff: %d" ), CurSource(), CurLineNumber(),
774 NETLIST_GROUP*
group =
new NETLIST_GROUP{ std::move(
name ), std::move( uuid ), std::move( groupLibId ),
775 std::move( members ) };
804 wxString libPartName;
805 wxArrayString footprintFilters;
806 wxArrayString aliases;
810 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseLibPartList: begin libpart" ) );
811 while( (
token = NextTok() ) != T_RIGHT )
813 if(
token == T_LEFT )
819 NeedSYMBOLorNUMBER();
825 NeedSYMBOLorNUMBER();
832 while( (
token = NextTok() ) != T_RIGHT )
834 if(
token == T_LEFT )
843 if(
token == T_RIGHT )
847 Expecting(
"footprint ID" );
849 footprintFilters.Add(
From_UTF8( CurText() ) );
855 while( (
token = NextTok() ) != T_RIGHT )
857 if(
token == T_LEFT )
860 if(
token != T_alias )
861 Expecting( T_alias );
863 NeedSYMBOLorNUMBER();
870 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseLibPartList: entering pins for '%s:%s'" ),
871 libName, libPartName );
872 while( (
token = NextTok() ) != T_RIGHT )
874 if(
token == T_LEFT )
881 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseLibPartList: pin #%d for '%s:%s'" ),
882 pinCount, libName, libPartName );
886 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Parsed libpart '%s:%s' pins => pinCount=%d" ),
887 libName, libPartName, pinCount );
898 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseLibPartList: assigning pinCount=%d for libpart '%s:%s'" ),
899 pinCount, libName, libPartName );
900 for(
unsigned i = 0; i <
m_netlist->GetCount(); i++ )
902 component =
m_netlist->GetComponent( i );
904 if( component->
IsLibSource( libName, libPartName ) )
908 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Assign pinCount=%d to component ref='%s' part='%s:%s'" ),
909 pinCount, component->
GetReference(), libName, libPartName );
912 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
914 if( component->
IsLibSource( libName, aliases[jj] ) )
918 wxLogTrace(
"CVPCB_PINCOUNT",
919 wxT(
"Assign pinCount=%d to component ref='%s' via alias='%s:%s'" ),
920 pinCount, component->
GetReference(), libName, aliases[jj] );
void SetLibrary(const wxString &aLibrary)
const wxString & GetReference() const
void SetProperties(std::map< wxString, wxString > aProps)
void SetPinCount(int aPinCount)
void SetUnitInfo(const std::vector< UNIT_INFO > &aUnits)
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
void SetFootprintFilters(const wxArrayString &aFilters)
void SetFields(nlohmann::ordered_map< wxString, wxString > aFields)
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)
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)) (...
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 "..."))))
void skipCurrent()
Skip the current token level, i.e search for the RIGHT parenthesis which closes the current descripti...
NETLIST * m_netlist
The netlist to parse into. Not owned.
virtual void LoadNetlist() override
Load the contents of the netlist file into aNetlist.
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...
CMP_READER * m_footprintReader
The reader used to load the footprint links. If NULL, footprint links are not read.
LINE_READER * m_lineReader
The line reader of the netlist.
NETLIST * m_netlist
The net list to read the file(s) into.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
static bool IsNumber(char x)
wxString From_UTF8(const char *cstring)