29 #include <netlist_lexer.h> 42 if( m_footprintReader )
44 m_footprintReader->Load( m_netlist );
48 for(
unsigned i = 0; i < m_netlist->GetCount(); i++ )
49 m_netlist->GetComponent( i )->SortPins();
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(
"KICAD_NETLIST_PARSER::Parse(): bad parenthesis " 172 "count (count = %d", plevel ) );
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;
316 while( (
token = NextTok() ) != T_RIGHT )
318 if(
token == T_LEFT )
324 NeedSYMBOLorNUMBER();
330 NeedSYMBOLorNUMBER();
336 NeedSYMBOLorNUMBER();
337 footprint = FromUTF8();
343 while( (
token = NextTok() ) != T_RIGHT )
345 if(
token == T_LEFT )
350 NeedSYMBOLorNUMBER();
354 else if(
token == T_part )
356 NeedSYMBOLorNUMBER();
360 else if(
token == T_description )
362 NeedSYMBOLorNUMBER();
367 Expecting(
"part, lib or description" );
377 while( (
token = NextTok() ) != T_RIGHT )
379 if(
token == T_LEFT )
382 if(
token == T_name )
384 NeedSYMBOLorNUMBER();
388 else if(
token == T_value )
390 NeedSYMBOLorNUMBER();
396 Expecting(
"name or value" );
400 if( !propName.IsEmpty() )
401 properties[ propName ] = propValue;
406 while( (
token = NextTok() ) != T_EOF )
408 if(
token == T_tstamps )
412 NeedSYMBOLorNUMBER();
419 while( (
token = NextTok() ) != T_EOF )
421 if(
token == T_RIGHT )
424 uuids.emplace_back(
FROM_UTF8( CurText() ) );
436 if( !footprint.IsEmpty() && fpid.
Parse( footprint,
true ) >= 0 )
439 error.Printf(
_(
"Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),
440 CurSource(), CurLineNumber(), CurOffset() );
477 wxString libPartName;
478 wxArrayString footprintFilters;
479 wxArrayString aliases;
483 while( (
token = NextTok() ) != T_RIGHT )
485 if(
token == T_LEFT )
491 NeedSYMBOLorNUMBER();
497 NeedSYMBOLorNUMBER();
504 while( (
token = NextTok() ) != T_RIGHT )
506 if(
token == T_LEFT )
512 NeedSYMBOLorNUMBER();
513 footprintFilters.Add(
FROM_UTF8( CurText() ) );
519 while( (
token = NextTok() ) != T_RIGHT )
521 if(
token == T_LEFT )
524 if(
token != T_alias )
525 Expecting( T_alias );
527 NeedSYMBOLorNUMBER();
534 while( (
token = NextTok() ) != T_RIGHT )
536 if(
token == T_LEFT )
560 if( component->
IsLibSource( libName, libPartName ) )
566 for(
unsigned jj = 0; jj < aliases.GetCount(); jj++ )
568 if( component->
IsLibSource( libName, aliases[jj] ) )
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
char * Line() const
Return a pointer to the last line that was read in.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
void SetLibrary(const wxString &aLibrary)
NETLIST * m_netlist
The netlist to parse into. Not owned.
void parseComponent()
Function parseComponent parse a component description: (comp (ref P1) (value DB25FEMELLE) (footprint ...
void skipCurrent()
Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes ...
unsigned GetCount() const
Function GetCount.
void SetProperties(std::map< wxString, wxString > &aProps)
A logical library item identifier and consists of various portions much like a URI.
This file contains miscellaneous commonly used macros and functions.
void AddComponent(COMPONENT *aComponent)
Function AddComponent adds aComponent to the NETLIST.
virtual void LoadNetlist() override
Function LoadNetlist loads the contents of the netlist file into aNetlist.
KICAD_NETLIST_PARSER(LINE_READER *aReader, NETLIST *aNetlist)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
void parseLibPartList()
Function parseLibPartList reads the section "libparts" in the netlist: (libparts (libpart (lib device...
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
LINE_READER * m_lineReader
The line reader used to parse the netlist. Not owned.
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
void SetPinCount(int aPinCount)
COMPONENT is used to store components and all of their related information found in a netlist.
unsigned Length() const
Return the number of bytes in the last line read from this LINE_READER.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
void SetFootprintFilters(const wxArrayString &aFilters)
void Parse()
Function Parse parse the full netlist.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
void SetName(const wxString &aName)
void parseNet()
Function parseNet Parses a section like (net (code 20) (name /PC-A0) (node (ref BUS1) (pin 62)) (node...
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
COMPONENT * GetComponentByReference(const wxString &aReference)
Function GetComponentByReference returns a COMPONENT by aReference.
#define THROW_IO_ERROR(msg)