27#include <netlist_lexer.h>
50 for(
unsigned i = 0; i <
m_netlist->GetCount(); i++ )
58 NETLIST_LEXER( aReader )
60 m_lineReader = aReader;
70 while( (
token = NextTok() ) != T_EOF )
75 if(
token == T_RIGHT )
90 while( (
token = NextTok() ) != T_EOF )
109 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Parse: entering components section" ) );
111 while( (
token = NextTok() ) != T_EOF )
113 if(
token == T_RIGHT )
115 else if(
token == T_LEFT )
118 if(
token == T_comp )
125 while( (
token = NextTok() ) != T_EOF )
127 if(
token == T_RIGHT )
129 else if(
token == T_LEFT )
132 if(
token == T_group )
139 while( (
token = NextTok() ) != T_EOF )
141 if(
token == T_RIGHT )
143 else if(
token == T_LEFT )
146 if(
token == T_variant )
153 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Parse: entering nets section" ) );
155 while( (
token = NextTok() ) != T_EOF )
157 if(
token == T_RIGHT )
159 else if(
token == T_LEFT )
169 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Parse: entering libparts section" ) );
171 while( (
token = NextTok() ) != T_EOF )
173 if(
token == T_RIGHT )
175 else if(
token == T_LEFT )
178 if(
token == T_libpart )
210 wxFAIL_MSG( wxString::Format( wxT(
"KICAD_NETLIST_PARSER::Parse(): bad parenthesis "
211 "count (count = %d" ),
230 wxString pin_function;
234 while( (
token = NextTok() ) != T_EOF )
236 if(
token == T_RIGHT )
238 else if(
token == T_LEFT )
244 NeedSYMBOLorNUMBER();
250 NeedSYMBOLorNUMBER();
257 pin_function.Clear();
260 while( (
token = NextTok() ) != T_EOF )
262 if(
token == T_RIGHT )
264 else if(
token == T_LEFT )
270 NeedSYMBOLorNUMBER();
276 NeedSYMBOLorNUMBER();
282 NeedSYMBOLorNUMBER();
288 NeedSYMBOLorNUMBER();
302 if( strtol( code.c_str(),
nullptr, 10 ) >= 1 )
305 name = wxT(
"N-00000") + code;
307 component->AddNet( pin_number,
name, pin_function, pin_type );
343 wxString humanSheetPath;
346 std::vector<KIID> uuids;
347 std::map<wxString, wxString> properties;
348 nlohmann::ordered_map<wxString, wxString> fields;
349 std::unordered_set<wxString> componentClasses;
351 bool duplicatePinsAreJumpers =
false;
352 std::vector<std::set<wxString>> jumperPinGroups;
354 std::vector<COMPONENT::UNIT_INFO> parsedUnits;
355 std::vector<COMPONENT_VARIANT> parsedVariants;
358 while( (
token = NextTok() ) != T_RIGHT )
360 if(
token == T_LEFT )
366 NeedSYMBOLorNUMBER();
372 NeedSYMBOLorNUMBER();
378 NeedSYMBOLorNUMBER();
379 footprint = FromUTF8();
385 while( (
token = NextTok() ) != T_RIGHT )
387 if(
token == T_LEFT )
392 NeedSYMBOLorNUMBER();
396 else if(
token == T_part )
398 NeedSYMBOLorNUMBER();
402 else if(
token == T_description )
404 NeedSYMBOLorNUMBER();
409 Expecting(
"part, lib or description" );
412 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseComponent: ref='%s' libsource='%s:%s'" ),
421 while( (
token = NextTok() ) != T_RIGHT )
423 if(
token == T_LEFT )
426 if(
token == T_name )
428 NeedSYMBOLorNUMBER();
432 else if(
token == T_value )
434 NeedSYMBOLorNUMBER();
440 Expecting(
"name or value" );
444 if( !propName.IsEmpty() )
445 properties[propName] = std::move( propValue );
450 while( (
token = NextTok() ) != T_RIGHT )
452 if(
token == T_LEFT )
455 if(
token == T_field )
460 while( (
token = NextTok() ) != T_RIGHT )
462 if(
token == T_LEFT )
465 if(
token == T_name )
467 NeedSYMBOLorNUMBER();
471 else if(
token == T_STRING )
477 if( !fieldName.IsEmpty() )
478 fields[fieldName] = std::move( fieldValue );
482 Expecting(
"field" );
488 while( (
token = NextTok() ) != T_EOF )
490 if(
token == T_names )
492 NeedSYMBOLorNUMBER();
497 if(
token == T_tstamps )
499 NeedSYMBOLorNUMBER();
511 while( (
token = NextTok() ) != T_EOF )
513 if(
token == T_RIGHT )
516 uuids.emplace_back(
From_UTF8( CurText() ) );
525 while( (
token = NextTok() ) != T_RIGHT )
527 if(
token == T_LEFT )
530 if(
token == T_unit )
532 COMPONENT::UNIT_INFO
info;
534 while( (
token = NextTok() ) != T_RIGHT )
536 if(
token == T_LEFT )
542 NeedSYMBOLorNUMBER();
548 while( (
token = NextTok() ) != T_RIGHT )
550 if(
token == T_LEFT )
560 if(
token == T_LEFT )
565 NeedSYMBOLorNUMBER();
576 if( !pinNum.IsEmpty() )
577 info.m_pins.emplace_back( pinNum );
592 parsedUnits.push_back(
info );
603 case T_component_classes:
604 while( (
token = NextTok() ) != T_RIGHT )
606 if(
token != T_LEFT )
609 if( (
token = NextTok() ) != T_class )
610 Expecting( T_class );
612 NeedSYMBOLorNUMBER();
613 componentClasses.insert(
From_UTF8( CurText() ) );
619 case T_duplicate_pin_numbers_are_jumpers:
621 NeedSYMBOLorNUMBER();
622 duplicatePinsAreJumpers =
From_UTF8( CurText() ) == wxT(
"1" );
627 case T_jumper_pin_groups:
629 std::set<wxString>* currentGroup =
nullptr;
631 for(
token = NextTok(); currentGroup ||
token != T_RIGHT;
token = NextTok() )
633 if(
token == T_LEFT )
639 currentGroup = &jumperPinGroups.emplace_back();
644 NeedSYMBOLorNUMBER();
645 wxString padName =
From_UTF8( CurText() );
647 wxCHECK2( currentGroup,
continue );
648 currentGroup->insert( padName );
653 currentGroup =
nullptr;
657 Expecting(
"group or pin" );
666 while( (
token = NextTok() ) != T_RIGHT )
668 if(
token == T_LEFT )
671 if(
token != T_variant )
677 COMPONENT_VARIANT variant;
681 if(
token == T_LEFT )
687 NeedSYMBOLorNUMBER();
696 bool hasValue =
false;
698 while( (
token = NextTok() ) != T_RIGHT )
700 if(
token == T_LEFT )
703 if(
token == T_name )
705 NeedSYMBOLorNUMBER();
709 else if(
token == T_value )
711 NeedSYMBOLorNUMBER();
718 Expecting(
"name or value" );
722 if( propName.IsEmpty() )
725 bool propBool =
true;
729 wxString normalized = propValue;
730 normalized.MakeLower();
732 if( normalized == wxT(
"0" ) || normalized == wxT(
"false" ) )
734 else if( normalized == wxT(
"1" ) || normalized == wxT(
"true" ) )
737 propBool = !propValue.IsEmpty();
740 if( propName.CmpNoCase( wxT(
"dnp" ) ) == 0 )
742 variant.
m_dnp = propBool;
745 else if( propName.CmpNoCase( wxT(
"exclude_from_bom" ) ) == 0 )
750 else if( propName.CmpNoCase( wxT(
"exclude_from_sim" ) ) == 0 )
755 else if( propName.CmpNoCase( wxT(
"exclude_from_pos_files" ) ) == 0 )
765 while( (
token = NextTok() ) != T_RIGHT )
767 if(
token == T_LEFT )
770 if(
token == T_field )
775 while( (
token = NextTok() ) != T_RIGHT )
777 if(
token == T_LEFT )
780 if(
token == T_name )
782 NeedSYMBOLorNUMBER();
786 else if(
token == T_value )
788 NeedSYMBOLorNUMBER();
792 else if(
token == T_STRING )
798 if( !fieldName.IsEmpty() )
799 variant.
m_fields[fieldName] = std::move( fieldValue );
803 Expecting(
"field" );
814 if( !variant.
m_name.IsEmpty() )
815 parsedVariants.push_back( std::move( variant ) );
828 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
831 error.Printf(
_(
"Invalid footprint ID in\nfile: '%s'\nline: %d\noffset: %d" ),
832 CurSource(), CurLineNumber(), CurOffset() );
845 std::ranges::copy( jumperPinGroups, std::inserter( component->
JumperPadGroups(),
849 for(
const COMPONENT_VARIANT& variant : parsedVariants )
868 std::vector<KIID> members;
871 while( (
token = NextTok() ) != T_EOF )
873 if(
token == T_RIGHT )
875 else if(
token == T_LEFT )
881 NeedSYMBOLorNUMBER();
887 NeedSYMBOLorNUMBER();
893 NeedSYMBOLorNUMBER();
899 while( (
token = NextTok() ) != T_RIGHT )
901 if(
token == T_LEFT )
904 if(
token == T_member )
908 while( (
token = NextTok() ) != T_RIGHT )
910 if(
token == T_LEFT )
913 if(
token == T_uuid )
915 NeedSYMBOLorNUMBER();
925 members.emplace_back( memberUuid );
929 Expecting(
"member" );
943 if( !libId.IsEmpty() && groupLibId.
Parse( libId,
true ) >= 0 )
946 error.Printf(
_(
"Invalid lib_id ID in\nfile: '%s'\nline: %d\noffset: %d" ), CurSource(), CurLineNumber(),
952 NETLIST_GROUP*
group =
new NETLIST_GROUP{ std::move(
name ), std::move( uuid ), std::move( groupLibId ),
953 std::move( members ) };
964 wxString description;
968 if(
token == T_LEFT )
974 NeedSYMBOLorNUMBER();
980 NeedSYMBOLorNUMBER();
991 if( !
name.IsEmpty() )
1020 wxString libPartName;
1021 wxArrayString footprintFilters;
1022 wxArrayString aliases;
1026 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseLibPartList: begin libpart" ) );
1027 while( (
token = NextTok() ) != T_RIGHT )
1029 if(
token == T_LEFT )
1035 NeedSYMBOLorNUMBER();
1041 NeedSYMBOLorNUMBER();
1048 while( (
token = NextTok() ) != T_RIGHT )
1050 if(
token == T_LEFT )
1059 if(
token == T_RIGHT )
1063 Expecting(
"footprint ID" );
1065 footprintFilters.Add(
From_UTF8( CurText() ) );
1071 while( (
token = NextTok() ) != T_RIGHT )
1073 if(
token == T_LEFT )
1076 if(
token != T_alias )
1077 Expecting( T_alias );
1079 NeedSYMBOLorNUMBER();
1086 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseLibPartList: entering pins for '%s:%s'" ),
1087 libName, libPartName );
1088 while( (
token = NextTok() ) != T_RIGHT )
1090 if(
token == T_LEFT )
1093 if(
token != T_pin )
1097 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseLibPartList: pin #%d for '%s:%s'" ),
1098 pinCount, libName, libPartName );
1102 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Parsed libpart '%s:%s' pins => pinCount=%d" ),
1103 libName, libPartName, pinCount );
1114 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"parseLibPartList: assigning pinCount=%d for libpart '%s:%s'" ),
1115 pinCount, libName, libPartName );
1116 for(
unsigned i = 0; i <
m_netlist->GetCount(); i++ )
1118 component =
m_netlist->GetComponent( i );
1120 if( component->
IsLibSource( libName, libPartName ) )
1124 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"Assign pinCount=%d to component ref='%s' part='%s:%s'" ),
1125 pinCount, component->
GetReference(), libName, libPartName );
1128 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
1130 if( component->
IsLibSource( libName, aliases[jj] ) )
1134 wxLogTrace(
"CVPCB_PINCOUNT",
1135 wxT(
"Assign pinCount=%d to component ref='%s' via alias='%s:%s'" ),
1136 pinCount, component->
GetReference(), libName, aliases[jj] );
Store all of the related component information found in a netlist.
void SetLibrary(const wxString &aLibrary)
const wxString & GetReference() const
void AddVariant(const COMPONENT_VARIANT &aVariant)
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 parseVariant()
Parse a variant section (variant (name "VariantName") (description "Description"))
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)
bool m_excludedFromPosFiles
bool m_hasExcludedFromBOM
bool m_hasExcludedFromSim
bool m_hasExcludedFromPosFiles
nlohmann::ordered_map< wxString, wxString > m_fields