From 48082e3234f6906e735590c1cb5307c3425f50ad Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 14 Sep 2021 12:20:35 +0100 Subject: [PATCH] Improve debugability of 3D file resolver failures. Fixes https://gitlab.com/kicad/code/kicad/issues/7670 --- utils/kicad2step/pcb/3d_resolver.cpp | 17 ++++++++--------- utils/kicad2step/pcb/kicadfootprint.cpp | 11 ++++------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/utils/kicad2step/pcb/3d_resolver.cpp b/utils/kicad2step/pcb/3d_resolver.cpp index 3223c8c184..d6a14b079a 100644 --- a/utils/kicad2step/pcb/3d_resolver.cpp +++ b/utils/kicad2step/pcb/3d_resolver.cpp @@ -268,7 +268,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) createPathList(); // look up the filename in the internal filename map - std::map< wxString, wxString, S3D::rsort_wxString >::iterator mi; + std::map::iterator mi; mi = m_NameMap.find( aFileName ); if( mi != m_NameMap.end() ) @@ -305,7 +305,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) { tmpFN.Normalize(); tname = tmpFN.GetFullPath(); - m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); + m_NameMap[ aFileName ] = tname; // special case: if a path begins with ${ENV_VAR} but is not in the resolver's path list // then add it @@ -320,7 +320,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) if( aFileName.StartsWith( "${" ) || aFileName.StartsWith( "$(" ) ) { m_errflags |= ERRFLG_ENVPATH; - return wxEmptyString; + return aFileName; } // at this point aFileName is: @@ -345,8 +345,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) tmpFN.Assign( fullPath ); tmpFN.Normalize(); tname = tmpFN.GetFullPath(); - m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); - + m_NameMap[ aFileName ] = tname; return tname; } } @@ -364,7 +363,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) if( fpath.Normalize() && fpath.FileExists() ) { tname = fpath.GetFullPath(); - m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); + m_NameMap[ aFileName ] = tname; return tname; } } @@ -378,7 +377,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) // this can happen if the file was intended to be relative to ${KICAD6_3DMODEL_DIR} // but ${KICAD6_3DMODEL_DIR} is not set or is incorrect. m_errflags |= ERRFLG_RELPATH; - return wxEmptyString; + return aFileName; } for( const SEARCH_PATH& path : m_Paths ) @@ -402,14 +401,14 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) if( tmp.Normalize() ) tname = tmp.GetFullPath(); - m_NameMap.insert( std::pair< wxString, wxString > ( aFileName, tname ) ); + m_NameMap[ aFileName ] = tname; return tname; } } } m_errflags |= ERRFLG_ALIAS; - return wxEmptyString; + return aFileName; } diff --git a/utils/kicad2step/pcb/kicadfootprint.cpp b/utils/kicad2step/pcb/kicadfootprint.cpp index f37c84c661..b2e00188eb 100644 --- a/utils/kicad2step/pcb/kicadfootprint.cpp +++ b/utils/kicad2step/pcb/kicadfootprint.cpp @@ -431,8 +431,7 @@ bool KICADFOOTPRINT::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver, if( mname.empty() ) { - ReportMessage( wxString::Format( "No model defined for component %s.\n", - m_refdes ) ); + ReportMessage( wxString::Format( "No model defined for component %s.\n", m_refdes ) ); return false; } @@ -440,14 +439,13 @@ bool KICADFOOTPRINT::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver, if( !wxFileName::FileExists( mname ) ) { - ReportMessage( wxString::Format( "Could not add component %s\n" - "File not found: %s\n ", + ReportMessage( wxString::Format( "Could not add component %s.\nFile not found: %s\n", m_refdes, mname ) ); return false; } - std::string fname( resolver->ResolvePath( mname ).ToUTF8() ); + std::string fname( mname.ToUTF8() ); try { @@ -460,8 +458,7 @@ bool KICADFOOTPRINT::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver, } catch( const Standard_Failure& e) { - ReportMessage( wxString::Format( "Could not add component %s\n" - "Open CASCADE error: %s\n ", + ReportMessage( wxString::Format( "Could not add component %s.\nOpenCASCADE error: %s\n", m_refdes, e.GetMessageString() ) ); }