25#include <netlist_lexer.h>
27#include <nlohmann/json.hpp>
55 NETLIST_LEXER( aReader )
67 while( (
token = NextTok() ) != T_EOF )
72 if(
token == T_RIGHT )
87 while( (
token = NextTok() ) != T_EOF )
106 while( (
token = NextTok() ) != T_EOF )
108 if(
token == T_RIGHT )
110 else if(
token == T_LEFT )
113 if(
token == T_comp )
120 while( (
token = NextTok() ) != T_EOF )
122 if(
token == T_RIGHT )
124 else if(
token == T_LEFT )
134 while( (
token = NextTok() ) != T_EOF )
136 if(
token == T_RIGHT )
138 else if(
token == T_LEFT )
141 if(
token == T_libpart )
170 wxFAIL_MSG( wxString::Format( wxT(
"KICAD_NETLIST_PARSER::Parse(): bad parenthesis "
171 "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();
260 if( strtol( code.c_str(), NULL, 10 ) >= 1 )
263 name = wxT(
"N-00000") + code;
268 if( component == NULL )
271 msg.Printf(
_(
"Cannot find component with ref '%s' in netlist." ),
277 component->
AddNet( pin_number,
name, pin_function, pin_type );
312 std::vector<KIID> uuids;
313 std::map<wxString, wxString> properties;
314 nlohmann::ordered_map<wxString, wxString> fields;
317 while( (
token = NextTok() ) != T_RIGHT )
319 if(
token == T_LEFT )
325 NeedSYMBOLorNUMBER();
331 NeedSYMBOLorNUMBER();
337 NeedSYMBOLorNUMBER();
338 footprint = FromUTF8();
344 while( (
token = NextTok() ) != T_RIGHT )
346 if(
token == T_LEFT )
351 NeedSYMBOLorNUMBER();
355 else if(
token == T_part )
357 NeedSYMBOLorNUMBER();
361 else if(
token == T_description )
363 NeedSYMBOLorNUMBER();
368 Expecting(
"part, lib or description" );
378 while( (
token = NextTok() ) != T_RIGHT )
380 if(
token == T_LEFT )
383 if(
token == T_name )
385 NeedSYMBOLorNUMBER();
389 else if(
token == T_value )
391 NeedSYMBOLorNUMBER();
397 Expecting(
"name or value" );
401 if( !propName.IsEmpty() )
402 properties[ propName ] = propValue;
409 while( (
token = NextTok() ) != T_RIGHT )
411 if(
token == T_LEFT )
414 if(
token == T_field )
419 while( (
token = NextTok() ) != T_RIGHT )
421 if(
token == T_LEFT )
424 if(
token == T_name )
426 NeedSYMBOLorNUMBER();
430 else if(
token == T_STRING )
432 fieldValue = CurText();
436 if( !fieldName.IsEmpty() )
437 fields[fieldName] = fieldValue;
441 Expecting(
"field" );
447 while( (
token = NextTok() ) != T_EOF )
449 if(
token == T_tstamps )
453 NeedSYMBOLorNUMBER();
460 while( (
token = NextTok() ) != T_EOF )
462 if(
token == T_RIGHT )
465 uuids.emplace_back(
From_UTF8( CurText() ) );
477 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
480 error.Printf(
_(
"Invalid footprint ID in\nfile: '%s'\nline: %d\noffset: %d" ),
481 CurSource(), CurLineNumber(), CurOffset() );
519 wxString libPartName;
520 wxArrayString footprintFilters;
521 wxArrayString aliases;
525 while( (
token = NextTok() ) != T_RIGHT )
527 if(
token == T_LEFT )
533 NeedSYMBOLorNUMBER();
539 NeedSYMBOLorNUMBER();
546 while( (
token = NextTok() ) != T_RIGHT )
548 if(
token == T_LEFT )
554 NeedSYMBOLorNUMBER();
555 footprintFilters.Add(
From_UTF8( CurText() ) );
561 while( (
token = NextTok() ) != T_RIGHT )
563 if(
token == T_LEFT )
566 if(
token != T_alias )
567 Expecting( T_alias );
569 NeedSYMBOLorNUMBER();
576 while( (
token = NextTok() ) != T_RIGHT )
578 if(
token == T_LEFT )
602 if( component->
IsLibSource( libName, libPartName ) )
608 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
610 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 AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
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...
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
unsigned Length() const
Return the number of bytes in the last line read from this LINE_READER.
char * Line() const
Return a pointer to the last line that was read in.
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)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
wxString From_UTF8(const char *cstring)