Fix kicad2step sexpr parser to include new footprint token.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/6406
This commit is contained in:
Wayne Stambaugh 2020-11-17 08:49:24 -05:00
parent 993a684959
commit 723b9e6a77
3 changed files with 31 additions and 18 deletions

View File

@ -395,8 +395,8 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName )
if( !( m_errflags & ERRFLG_ENVPATH ) ) if( !( m_errflags & ERRFLG_ENVPATH ) )
{ {
m_errflags |= ERRFLG_ENVPATH; m_errflags |= ERRFLG_ENVPATH;
wxString errmsg = "[3D File Resolver] file not found:\n"; wxString errmsg = "[3D File Resolver] File \"";
errmsg << tname << "\n"; errmsg << aFileName << "\" not found\n";
ReportMessage( errmsg ); ReportMessage( errmsg );
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com> * Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright 2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -40,6 +40,7 @@
#include <Standard_Failure.hxx> #include <Standard_Failure.hxx>
KICADFOOTPRINT::KICADFOOTPRINT( KICADPCB* aParent ) KICADFOOTPRINT::KICADFOOTPRINT( KICADPCB* aParent )
{ {
m_parent = aParent; m_parent = aParent;
@ -77,7 +78,7 @@ bool KICADFOOTPRINT::Read( SEXPR::SEXPR* aEntry )
SEXPR::SEXPR* child = aEntry->GetChild( 0 ); SEXPR::SEXPR* child = aEntry->GetChild( 0 );
std::string name = child->GetSymbol(); std::string name = child->GetSymbol();
if( name != "module" ) if( name != "module" && name != "footprint" )
{ {
std::ostringstream ostr; std::ostringstream ostr;
ostr << "* BUG: module parser invoked for type '" << name << "'\n"; ostr << "* BUG: module parser invoked for type '" << name << "'\n";
@ -93,7 +94,7 @@ bool KICADFOOTPRINT::Read( SEXPR::SEXPR* aEntry )
std::string symname; std::string symname;
// skip the optional locked and/or placed attributes; due to the vagaries of the // skip the optional locked and/or placed attributes; due to the vagaries of the
// kicad version of sexpr, the attribute may be a Symbol or a String // KiCad version of sexpr, the attribute may be a Symbol or a String
if( child->IsSymbol() || child->IsString() ) if( child->IsSymbol() || child->IsString() )
{ {
if( child->IsSymbol() ) if( child->IsSymbol() )
@ -391,7 +392,8 @@ bool KICADFOOTPRINT::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver,
} }
catch( const Standard_Failure& e) catch( const Standard_Failure& e)
{ {
ReportMessage( wxString::Format( "could not add component %s\n>>Opencascade error: %s\n ", ReportMessage( wxString::Format( "could not add component %s\n>>Opencascade "
"error: %s\n ",
m_refdes, e.GetMessageString() ) ); m_refdes, e.GetMessageString() ) );
} }
} }

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com> * Copyright (C) 2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -47,7 +48,7 @@
/* /*
* GetKicadConfigPath() is taken from KiCad's common.cpp source: * GetKicadConfigPath() is taken from KiCad's common.cpp source:
* Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2014-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2015 KiCad Developers * Copyright (C) 1992-2015 KiCad Developers
*/ */
static wxString GetKicadConfigPath() static wxString GetKicadConfigPath()
@ -121,7 +122,8 @@ bool KICADPCB::ReadFile( const wxString& aFileName )
if( fname.GetExt() != "kicad_pcb" ) if( fname.GetExt() != "kicad_pcb" )
{ {
ReportMessage( wxString::Format( "expecting extension kicad_pcb, got %s\n", fname.GetExt() ) ); ReportMessage( wxString::Format( "expecting extension kicad_pcb, got %s\n",
fname.GetExt() ) );
return false; return false;
} }
@ -157,7 +159,8 @@ bool KICADPCB::ReadFile( const wxString& aFileName )
} }
catch( ... ) catch( ... )
{ {
ReportMessage( wxString::Format( "unexpected exception while reading file: %s\n", aFileName ) ); ReportMessage( wxString::Format( "unexpected exception while reading file: %s\n",
aFileName ) );
return false; return false;
} }
@ -208,7 +211,8 @@ bool KICADPCB::parsePCB( SEXPR::SEXPR* data )
if( !child->IsList() ) if( !child->IsList() )
{ {
ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n", child->GetLineNumber() ) ); ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n",
child->GetLineNumber() ) );
return false; return false;
} }
@ -222,6 +226,8 @@ bool KICADPCB::parsePCB( SEXPR::SEXPR* data )
result = result && parseLayers( child ); result = result && parseLayers( child );
else if( symname == "module" ) else if( symname == "module" )
result = result && parseModule( child ); result = result && parseModule( child );
else if( symname == "footprint" )
result = result && parseModule( child );
else if( symname == "gr_arc" ) else if( symname == "gr_arc" )
result = result && parseCurve( child, CURVE_ARC ); result = result && parseCurve( child, CURVE_ARC );
else if( symname == "gr_line" ) else if( symname == "gr_line" )
@ -253,7 +259,8 @@ bool KICADPCB::parseGeneral( SEXPR::SEXPR* data )
if( !child->IsList() ) if( !child->IsList() )
{ {
ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n", child->GetLineNumber() ) ); ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n",
child->GetLineNumber() ) );
return false; return false;
} }
@ -278,14 +285,15 @@ bool KICADPCB::parseLayers( SEXPR::SEXPR* data )
size_t nc = data->GetNumberOfChildren(); size_t nc = data->GetNumberOfChildren();
SEXPR::SEXPR* child = NULL; SEXPR::SEXPR* child = NULL;
// Read the layername and the correstponding layer id list: // Read the layername and the corresponding layer id list:
for( size_t i = 1; i < nc; ++i ) for( size_t i = 1; i < nc; ++i )
{ {
child = data->GetChild( i ); child = data->GetChild( i );
if( !child->IsList() ) if( !child->IsList() )
{ {
ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n", child->GetLineNumber() ) ); ReportMessage( wxString::Format( "corrupt PCB file (line %d)\n",
child->GetLineNumber() ) );
return false; return false;
} }
std::string ref; std::string ref;
@ -301,6 +309,7 @@ bool KICADPCB::parseLayers( SEXPR::SEXPR* data )
return true; return true;
} }
int KICADPCB::GetLayerId( std::string& aLayerName ) int KICADPCB::GetLayerId( std::string& aLayerName )
{ {
int lid = -1; int lid = -1;
@ -336,7 +345,8 @@ bool KICADPCB::parseSetup( SEXPR::SEXPR* data )
if( child->GetNumberOfChildren() != 3 ) if( child->GetNumberOfChildren() != 3 )
{ {
ReportMessage( wxString::Format( ReportMessage( wxString::Format(
"corrupt PCB file (line %d): grid_origin has %d children (expected: 3)\n", "corrupt PCB file (line %d): grid_origin has %d children "
"(expected: 3)\n",
child->GetLineNumber(), child->GetNumberOfChildren() ) ); child->GetLineNumber(), child->GetNumberOfChildren() ) );
return false; return false;
} }
@ -350,7 +360,8 @@ bool KICADPCB::parseSetup( SEXPR::SEXPR* data )
if( child->GetNumberOfChildren() != 3 ) if( child->GetNumberOfChildren() != 3 )
{ {
ReportMessage( wxString::Format( ReportMessage( wxString::Format(
"corrupt PCB file (line %d)m: aux_axis_origin has %d children (expected: 3)\n", "corrupt PCB file (line %d)m: aux_axis_origin has %d children "
"(expected: 3)\n",
child->GetLineNumber(), child->GetNumberOfChildren() ) ); child->GetLineNumber(), child->GetNumberOfChildren() ) );
return false; return false;
} }