void KICAD_NETLIST_PARSER::parseComponent() throw( IO_ERROR, PARSE_ERROR, boost::bad_pointer ) { /* Parses a section like * (comp (ref P1) * (value DB25FEMELLE) * (footprint DB25FC) * (libsource (lib conn) (part DB25)) * (sheetpath (names /) (tstamps /)) * (tstamp 3256759C)) * * other fields (unused) are skipped * A component need a reference, value, footprint name and a full time stamp * The full time stamp is the sheetpath time stamp + the component time stamp */ FPID fpid; wxString footprint; wxString tmp; wxString ref; wxString value; wxString library; wxString name; wxString pathtimestamp, timestamp; // The token comp was read, so the next data is (ref P1) while( (token = NextTok()) != T_RIGHT ) { if( token == T_LEFT ) token = NextTok(); switch( token ) { case T_ref: NeedSYMBOLorNUMBER(); ref = FROM_UTF8( CurText() ); NeedRIGHT(); break; case T_value: NeedSYMBOLorNUMBER(); value = FROM_UTF8( CurText() ); NeedRIGHT(); break; case T_footprint: NeedSYMBOLorNUMBER(); footprint = FromUTF8(); NeedRIGHT(); break; case T_libsource: // Read libsource while( (token = NextTok()) != T_RIGHT ) { if( token == T_LEFT ) token = NextTok(); if( token == T_lib ) { NeedSYMBOLorNUMBER(); library = FROM_UTF8( CurText() ); NeedRIGHT(); } else if( token == T_part ) { NeedSYMBOLorNUMBER(); name = FROM_UTF8( CurText() ); NeedRIGHT(); } else { Expecting( "part or lib" ); } } break; case T_sheetpath: while( ( token = NextTok() ) != T_tstamps ); NeedSYMBOLorNUMBER(); pathtimestamp = FROM_UTF8( CurText() ); NeedRIGHT(); NeedRIGHT(); break; case T_tstamp: NeedSYMBOLorNUMBER(); timestamp = FROM_UTF8( CurText() ); NeedRIGHT(); break; default: // Skip not used data (i.e all other tokens) skipCurrent(); break; } } if( !footprint.IsEmpty() && fpid.Parse( footprint ) >= 0 ) { wxString error; error.Printf( _( "invalid PFID in\nfile: <%s>\nline: %d\noffset: %d" ), GetChars( CurSource() ), CurLineNumber(), CurOffset() ); THROW_IO_ERROR( error ); } pathtimestamp += timestamp; COMPONENT* component = new COMPONENT( fpid, ref, value, pathtimestamp ); component->SetName( name ); component->SetLibrary( library ); m_netlist->AddComponent( component ); }
COMPONENT* LEGACY_NETLIST_READER::loadComponent( char* aText ) throw( PARSE_ERROR, boost::bad_pointer ) { char* text; wxString msg; wxString timeStamp; // the full time stamp read from netlist wxString footprintName; // the footprint name read from netlist wxString value; // the component value read from netlist wxString reference; // the component schematic reference designator read from netlist wxString name; // the name of component that was placed in the schematic char line[1024]; strcpy( line, aText ); value = wxT( "~" ); // Sample component line: /40C08647 $noname R20 4.7K {Lib=R} // Read time stamp (first word) if( ( text = strtok( line, " ()\t\n" ) ) == NULL ) { msg = _( "Cannot parse time stamp in component section of netlist." ); THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), line, m_lineReader->LineNumber(), m_lineReader->Length() ); } timeStamp = FROM_UTF8( text ); // Read footprint name (second word) if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL ) { msg = _( "Cannot parse footprint name in component section of netlist." ); THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(), m_lineReader->Length() ); } footprintName = FROM_UTF8( text ); // The footprint name will have to be looked up in the *.cmp file. if( footprintName == wxT( "$noname" ) ) footprintName = wxEmptyString; // Read schematic reference designator (third word) if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL ) { msg = _( "Cannot parse reference designator in component section of netlist." ); THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(), m_lineReader->Length() ); } reference = FROM_UTF8( text ); // Read schematic value (forth word) if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL ) { msg = _( "Cannot parse value in component section of netlist." ); THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), aText, m_lineReader->LineNumber(), m_lineReader->Length() ); } value = FROM_UTF8( text ); // Read component name (fifth word) {Lib=C} // This is an optional field (a comment), which does not always exists if( ( text = strtok( NULL, " ()\t\n" ) ) != NULL ) { name = FROM_UTF8( text ).AfterFirst( wxChar( '=' ) ).BeforeLast( wxChar( '}' ) ); } FPID fpid; if( !footprintName.IsEmpty() ) fpid.SetFootprintName( footprintName ); COMPONENT* component = new COMPONENT( fpid, reference, value, timeStamp ); component->SetName( name ); m_netlist->AddComponent( component ); return component; }