2012-01-26 09:37:36 +00:00
|
|
|
/**
|
2013-05-28 16:54:59 +00:00
|
|
|
* @file kicad_netlist_reader.cpp
|
2012-01-26 09:37:36 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2011 Jean-Pierre Charras.
|
2020-02-20 12:11:04 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see change_log.txt for contributors.
|
2012-01-26 09:37:36 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <netlist_lexer.h> // netlist_lexer is common to Eeschema and Pcbnew
|
2013-04-25 16:29:35 +00:00
|
|
|
#include <macros.h>
|
2013-09-14 20:33:22 +00:00
|
|
|
|
2019-11-17 12:58:38 +00:00
|
|
|
#include "pcb_netlist.h"
|
|
|
|
#include "netlist_reader.h"
|
2012-01-26 09:37:36 +00:00
|
|
|
|
|
|
|
using namespace NL_T;
|
|
|
|
|
2012-01-29 19:29:19 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void KICAD_NETLIST_READER::LoadNetlist()
|
2012-01-26 09:37:36 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
m_parser->Parse();
|
2012-01-26 09:37:36 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( m_footprintReader )
|
2012-01-28 19:25:59 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
m_footprintReader->Load( m_netlist );
|
2012-01-28 19:25:59 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// Sort the component pins so they are in the same order as the legacy format. This
|
|
|
|
// is useful for comparing legacy and s-expression netlist dumps.
|
|
|
|
for( unsigned i = 0; i < m_netlist->GetCount(); i++ )
|
|
|
|
m_netlist->GetComponent( i )->SortPins();
|
2012-01-28 19:25:59 +00:00
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// KICAD_NETLIST_PARSER
|
|
|
|
KICAD_NETLIST_PARSER::KICAD_NETLIST_PARSER( LINE_READER* aReader, NETLIST* aNetlist ) :
|
2012-01-26 09:37:36 +00:00
|
|
|
NETLIST_LEXER( aReader )
|
|
|
|
{
|
2015-02-22 21:25:29 +00:00
|
|
|
m_lineReader = aReader;
|
|
|
|
m_netlist = aNetlist;
|
|
|
|
token = T_NONE;
|
2012-01-26 09:37:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void KICAD_NETLIST_PARSER::skipCurrent()
|
2012-01-26 09:37:36 +00:00
|
|
|
{
|
|
|
|
int curr_level = 0;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
while( ( token = NextTok() ) != T_EOF )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
curr_level--;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
if( token == T_RIGHT )
|
|
|
|
{
|
|
|
|
curr_level++;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
if( curr_level > 0 )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void KICAD_NETLIST_PARSER::Parse()
|
2012-01-26 09:37:36 +00:00
|
|
|
{
|
2019-10-07 11:50:02 +00:00
|
|
|
int plevel = 0; // the count of ')' to read at end of file after parsing all sections
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
while( ( token = NextTok() ) != T_EOF )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2013-04-03 16:16:26 +00:00
|
|
|
|
|
|
|
switch( token )
|
2012-01-26 09:37:36 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
case T_export: // The netlist starts here.
|
2019-10-07 11:50:02 +00:00
|
|
|
// nothing to do here, just increment the count of ')' to read at end of file
|
2013-04-25 16:29:35 +00:00
|
|
|
plevel++;
|
|
|
|
break;
|
2013-04-03 16:16:26 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
case T_version: // The netlist starts here.
|
|
|
|
// version id not yet used: read it but does not use it
|
|
|
|
NextTok();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_components: // The section comp starts here.
|
2019-10-07 11:50:02 +00:00
|
|
|
while( ( token = NextTok() ) != T_EOF )
|
2013-04-25 16:29:35 +00:00
|
|
|
{
|
2019-10-07 11:50:02 +00:00
|
|
|
if( token == T_RIGHT )
|
|
|
|
break;
|
|
|
|
else if( token == T_LEFT )
|
2013-04-25 16:29:35 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
2019-10-07 11:50:02 +00:00
|
|
|
if( token == T_comp ) // A component section found. Read it
|
2013-04-25 16:29:35 +00:00
|
|
|
parseComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_nets: // The section nets starts here.
|
2019-10-07 11:50:02 +00:00
|
|
|
while( ( token = NextTok() ) != T_EOF )
|
2013-04-25 16:29:35 +00:00
|
|
|
{
|
2019-10-07 11:50:02 +00:00
|
|
|
if( token == T_RIGHT )
|
|
|
|
break;
|
|
|
|
else if( token == T_LEFT )
|
2013-04-25 16:29:35 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
2019-10-07 11:50:02 +00:00
|
|
|
if( token == T_net ) // A net section if found. Read it
|
2013-04-25 16:29:35 +00:00
|
|
|
parseNet();
|
|
|
|
}
|
2012-02-01 19:49:37 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_libparts: // The section libparts starts here.
|
2019-10-07 11:50:02 +00:00
|
|
|
while( ( token = NextTok() ) != T_EOF )
|
2013-04-25 16:29:35 +00:00
|
|
|
{
|
2019-10-07 11:50:02 +00:00
|
|
|
if( token == T_RIGHT )
|
|
|
|
break;
|
|
|
|
else if( token == T_LEFT )
|
2013-04-25 16:29:35 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
2019-10-07 11:50:02 +00:00
|
|
|
if( token == T_libpart ) // A libpart section if found. Read it
|
2013-04-25 16:29:35 +00:00
|
|
|
parseLibPartList();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_libraries: // The section libraries starts here.
|
|
|
|
// List of libraries in use.
|
|
|
|
// Not used here, just skip it
|
|
|
|
skipCurrent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_design: // The section design starts here.
|
|
|
|
// Not used (mainly they are comments), just skip it
|
|
|
|
skipCurrent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_RIGHT: // The closing parenthesis of the file.
|
|
|
|
plevel--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
skipCurrent();
|
|
|
|
break;
|
2012-02-01 19:49:37 +00:00
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
}
|
2013-04-03 16:16:26 +00:00
|
|
|
|
|
|
|
if( plevel != 0 )
|
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
wxLogDebug( wxT( "KICAD_NETLIST_PARSER::Parse(): bad parenthesis count (count = %d"),
|
2013-04-03 16:16:26 +00:00
|
|
|
plevel );
|
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void KICAD_NETLIST_PARSER::parseNet()
|
2012-01-26 09:37:36 +00:00
|
|
|
{
|
|
|
|
/* Parses a section like
|
|
|
|
* (net (code 20) (name /PC-A0)
|
2019-11-17 09:11:29 +00:00
|
|
|
* (node (ref "BUS1") (pin "62)")
|
|
|
|
* (node (ref "U3") ("pin 3") (pin_function "clock"))
|
|
|
|
* (node (ref "U9") (pin "M6") (pin_function "reset")))
|
2012-01-26 09:37:36 +00:00
|
|
|
*/
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
COMPONENT* component = NULL;
|
|
|
|
wxString code;
|
|
|
|
wxString name;
|
|
|
|
wxString reference;
|
2019-11-17 09:11:29 +00:00
|
|
|
wxString pin_number;
|
|
|
|
wxString pin_function;
|
2013-04-25 16:29:35 +00:00
|
|
|
int nodecount = 0;
|
2012-03-10 07:58:21 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
// The token net was read, so the next data is (code <number>)
|
2019-10-07 11:50:02 +00:00
|
|
|
while( (token = NextTok()) != T_EOF )
|
2012-01-26 09:37:36 +00:00
|
|
|
{
|
2019-10-07 11:50:02 +00:00
|
|
|
if( token == T_RIGHT )
|
|
|
|
break;
|
|
|
|
else if( token == T_LEFT )
|
2012-01-26 09:37:36 +00:00
|
|
|
token = NextTok();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_code:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
code = FROM_UTF8( CurText() );
|
|
|
|
NeedRIGHT();
|
2013-04-25 16:29:35 +00:00
|
|
|
break;
|
2012-01-26 09:37:36 +00:00
|
|
|
|
|
|
|
case T_name:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
name = FROM_UTF8( CurText() );
|
|
|
|
NeedRIGHT();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
if( name.IsEmpty() ) // Give a dummy net name like N-000109
|
|
|
|
name = wxT("N-00000") + code;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_node:
|
2019-11-17 09:11:29 +00:00
|
|
|
pin_function.Clear(); // By default: no pin function.
|
|
|
|
|
2019-10-07 11:50:02 +00:00
|
|
|
while( (token = NextTok()) != T_EOF )
|
2012-01-26 09:37:36 +00:00
|
|
|
{
|
2019-10-07 11:50:02 +00:00
|
|
|
if( token == T_RIGHT )
|
|
|
|
break;
|
|
|
|
else if( token == T_LEFT )
|
2012-01-26 09:37:36 +00:00
|
|
|
token = NextTok();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_ref:
|
|
|
|
NeedSYMBOLorNUMBER();
|
2013-04-25 16:29:35 +00:00
|
|
|
reference = FROM_UTF8( CurText() );
|
2012-01-26 09:37:36 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pin:
|
|
|
|
NeedSYMBOLorNUMBER();
|
2019-11-17 09:11:29 +00:00
|
|
|
pin_number = FROM_UTF8( CurText() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_pinfunction:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
pin_function = FROM_UTF8( CurText() );
|
2012-01-26 09:37:36 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-04-25 16:29:35 +00:00
|
|
|
skipCurrent();
|
2012-01-26 09:37:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
component = m_netlist->GetComponentByReference( reference );
|
|
|
|
|
|
|
|
// Cannot happen if the netlist is valid.
|
|
|
|
if( component == NULL )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2020-03-17 16:08:29 +00:00
|
|
|
msg.Printf( _( "Cannot find component with reference designator \"%s\" in netlist." ),
|
|
|
|
reference );
|
2013-04-25 16:29:35 +00:00
|
|
|
THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), m_lineReader->Line(),
|
|
|
|
m_lineReader->LineNumber(), m_lineReader->Length() );
|
|
|
|
}
|
|
|
|
|
2019-11-17 09:11:29 +00:00
|
|
|
component->AddNet( pin_number, name, pin_function );
|
2012-01-26 09:37:36 +00:00
|
|
|
nodecount++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-04-25 16:29:35 +00:00
|
|
|
skipCurrent();
|
2012-01-26 09:37:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void KICAD_NETLIST_PARSER::parseComponent()
|
2012-01-26 09:37:36 +00:00
|
|
|
{
|
|
|
|
/* Parses a section like
|
|
|
|
* (comp (ref P1)
|
2020-02-20 12:11:04 +00:00
|
|
|
* (value DB25FEMALE)
|
2012-01-26 09:37:36 +00:00
|
|
|
* (footprint DB25FC)
|
|
|
|
* (libsource (lib conn) (part DB25))
|
|
|
|
* (sheetpath (names /) (tstamps /))
|
2020-02-20 12:11:04 +00:00
|
|
|
* (tstamp 68183921-93a5-49ac-91b0-49d05a0e1647))
|
2012-01-26 09:37:36 +00:00
|
|
|
*
|
|
|
|
* other fields (unused) are skipped
|
2013-04-25 16:29:35 +00:00
|
|
|
* A component need a reference, value, footprint name and a full time stamp
|
2012-01-26 09:37:36 +00:00
|
|
|
* The full time stamp is the sheetpath time stamp + the component time stamp
|
|
|
|
*/
|
2020-02-21 22:20:42 +00:00
|
|
|
LIB_ID fpid;
|
|
|
|
wxString footprint;
|
|
|
|
wxString ref;
|
|
|
|
wxString value;
|
|
|
|
wxString library;
|
|
|
|
wxString name;
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path;
|
|
|
|
KIID uuid;
|
2012-01-26 09:37:36 +00:00
|
|
|
|
2013-04-28 20:20:40 +00:00
|
|
|
// The token comp was read, so the next data is (ref P1)
|
2012-01-26 09:37:36 +00:00
|
|
|
while( (token = NextTok()) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
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();
|
2013-09-17 00:52:08 +00:00
|
|
|
footprint = FromUTF8();
|
2013-09-08 18:31:21 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
case T_libsource:
|
2012-02-01 19:49:37 +00:00
|
|
|
// Read libsource
|
|
|
|
while( (token = NextTok()) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
if( token == T_lib )
|
|
|
|
{
|
|
|
|
NeedSYMBOLorNUMBER();
|
2013-04-28 20:20:40 +00:00
|
|
|
library = FROM_UTF8( CurText() );
|
2013-04-25 16:29:35 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
else if( token == T_part )
|
2012-02-01 19:49:37 +00:00
|
|
|
{
|
|
|
|
NeedSYMBOLorNUMBER();
|
2013-04-28 20:20:40 +00:00
|
|
|
name = FROM_UTF8( CurText() );
|
2012-02-01 19:49:37 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2018-06-06 00:59:56 +00:00
|
|
|
else if( token == T_description )
|
|
|
|
{
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
2012-02-01 19:49:37 +00:00
|
|
|
else
|
2013-04-25 16:29:35 +00:00
|
|
|
{
|
2018-06-06 00:59:56 +00:00
|
|
|
Expecting( "part, lib or description" );
|
2013-04-25 16:29:35 +00:00
|
|
|
}
|
2012-02-01 19:49:37 +00:00
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_sheetpath:
|
2019-10-07 11:50:02 +00:00
|
|
|
while( ( token = NextTok() ) != T_EOF )
|
|
|
|
{
|
|
|
|
if( token == T_tstamps )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
2020-02-21 22:20:42 +00:00
|
|
|
path = KIID_PATH( FROM_UTF8( CurText() ) );
|
2012-01-26 09:37:36 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_tstamp:
|
|
|
|
NeedSYMBOLorNUMBER();
|
2020-02-21 22:20:42 +00:00
|
|
|
uuid = KIID( FROM_UTF8( CurText() ) );
|
2012-01-26 09:37:36 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Skip not used data (i.e all other tokens)
|
2013-04-25 16:29:35 +00:00
|
|
|
skipCurrent();
|
2012-01-26 09:37:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
if( !footprint.IsEmpty() && fpid.Parse( footprint, LIB_ID::ID_PCB, true ) >= 0 )
|
2013-09-17 00:52:08 +00:00
|
|
|
{
|
|
|
|
wxString error;
|
2019-08-04 08:33:54 +00:00
|
|
|
error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),
|
|
|
|
CurSource(), CurLineNumber(), CurOffset() );
|
2013-09-17 00:52:08 +00:00
|
|
|
|
|
|
|
THROW_IO_ERROR( error );
|
|
|
|
}
|
2013-09-08 18:31:21 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
path.push_back( uuid );
|
|
|
|
COMPONENT* component = new COMPONENT( fpid, ref, value, path );
|
2013-04-28 20:20:40 +00:00
|
|
|
component->SetName( name );
|
|
|
|
component->SetLibrary( library );
|
2013-04-25 16:29:35 +00:00
|
|
|
m_netlist->AddComponent( component );
|
2012-01-26 09:37:36 +00:00
|
|
|
}
|
2012-01-29 19:29:19 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void KICAD_NETLIST_PARSER::parseLibPartList()
|
2012-01-29 19:29:19 +00:00
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
/* Parses a section like
|
2013-04-25 16:29:35 +00:00
|
|
|
* (libpart (lib device) (part C)
|
2015-01-02 07:52:29 +00:00
|
|
|
* (aliases
|
|
|
|
* (alias Cxx)
|
|
|
|
* (alias Cyy))
|
2013-04-25 16:29:35 +00:00
|
|
|
* (description "Condensateur non polarise")
|
|
|
|
* (footprints
|
|
|
|
* (fp SM*)
|
|
|
|
* (fp C?)
|
|
|
|
* (fp C1-1))
|
|
|
|
* (fields
|
|
|
|
* (field (name Reference) C)
|
|
|
|
* (field (name Value) C))
|
|
|
|
* (pins
|
|
|
|
* (pin (num 1) (name ~) (type passive))
|
|
|
|
* (pin (num 2) (name ~) (type passive))))
|
|
|
|
*
|
|
|
|
* Currently footprints section/fp are read and data stored
|
|
|
|
* other fields (unused) are skipped
|
|
|
|
*/
|
|
|
|
COMPONENT* component = NULL;
|
|
|
|
wxString libName;
|
|
|
|
wxString libPartName;
|
|
|
|
wxArrayString footprintFilters;
|
2015-01-02 07:52:29 +00:00
|
|
|
wxArrayString aliases;
|
2018-03-26 18:55:59 +00:00
|
|
|
int pinCount = 0;
|
2012-02-01 19:49:37 +00:00
|
|
|
|
|
|
|
// The last token read was libpart, so read the next token
|
|
|
|
while( (token = NextTok()) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
switch( token )
|
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
case T_lib:
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
libName = FROM_UTF8( CurText() );
|
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
case T_part:
|
|
|
|
NeedSYMBOLorNUMBER();
|
2013-04-25 16:29:35 +00:00
|
|
|
libPartName = FROM_UTF8( CurText() );
|
2012-02-01 19:49:37 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_footprints:
|
|
|
|
// Read all fp elements (footprint filter item)
|
|
|
|
while( (token = NextTok()) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
if( token != T_fp )
|
|
|
|
Expecting( T_fp );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
2013-04-25 16:29:35 +00:00
|
|
|
footprintFilters.Add( FROM_UTF8( CurText() ) );
|
2012-02-01 19:49:37 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-01-02 07:52:29 +00:00
|
|
|
case T_aliases:
|
|
|
|
while( (token = NextTok()) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_alias )
|
|
|
|
Expecting( T_alias );
|
|
|
|
|
|
|
|
NeedSYMBOLorNUMBER();
|
|
|
|
aliases.Add( FROM_UTF8( CurText() ) );
|
|
|
|
NeedRIGHT();
|
|
|
|
}
|
|
|
|
break;
|
2018-03-26 18:55:59 +00:00
|
|
|
|
|
|
|
case T_pins:
|
|
|
|
while( (token = NextTok()) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token != T_pin )
|
|
|
|
Expecting( T_pin );
|
|
|
|
|
|
|
|
pinCount++;
|
|
|
|
|
|
|
|
skipCurrent();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
default:
|
|
|
|
// Skip not used data (i.e all other tokens)
|
2013-04-25 16:29:35 +00:00
|
|
|
skipCurrent();
|
2012-02-01 19:49:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
// Find all of the components that reference this component library part definition.
|
|
|
|
for( unsigned i = 0; i < m_netlist->GetCount(); i++ )
|
|
|
|
{
|
|
|
|
component = m_netlist->GetComponent( i );
|
|
|
|
|
|
|
|
if( component->IsLibSource( libName, libPartName ) )
|
2018-03-26 18:55:59 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
component->SetFootprintFilters( footprintFilters );
|
2018-03-26 18:55:59 +00:00
|
|
|
component->SetPinCount( pinCount );
|
|
|
|
}
|
2015-01-02 07:52:29 +00:00
|
|
|
|
|
|
|
for( unsigned jj = 0; jj < aliases.GetCount(); jj++ )
|
|
|
|
{
|
|
|
|
if( component->IsLibSource( libName, aliases[jj] ) )
|
2018-03-26 18:55:59 +00:00
|
|
|
{
|
2015-01-02 07:52:29 +00:00
|
|
|
component->SetFootprintFilters( footprintFilters );
|
2018-03-26 18:55:59 +00:00
|
|
|
component->SetPinCount( pinCount );
|
|
|
|
}
|
2015-01-02 07:52:29 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
}
|
2012-01-29 19:29:19 +00:00
|
|
|
}
|