More debug output for models that are not found.
Fixes https://gitlab.com/kicad/code/kicad/issues/7670
This commit is contained in:
parent
2ec1c215cd
commit
9d35c551ba
|
@ -256,7 +256,8 @@ bool S3D_RESOLVER::createPathList( void )
|
|||
}
|
||||
|
||||
|
||||
wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName )
|
||||
wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName,
|
||||
std::vector<wxString>& aSearchedPaths )
|
||||
{
|
||||
std::lock_guard<std::mutex> lock( mutex3D_resolver );
|
||||
|
||||
|
@ -291,18 +292,25 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName )
|
|||
wxFileName tmpFN( tname );
|
||||
|
||||
// in the case of absolute filenames we don't store a map item
|
||||
if( !aFileName.StartsWith( "${" ) && !aFileName.StartsWith( "$(" )
|
||||
&& tmpFN.IsAbsolute() && tmpFN.FileExists() )
|
||||
if( !aFileName.StartsWith( "${" ) && !aFileName.StartsWith( "$(" ) && tmpFN.IsAbsolute() )
|
||||
{
|
||||
tmpFN.Normalize();
|
||||
return tmpFN.GetFullPath();
|
||||
if( tmpFN.FileExists() )
|
||||
{
|
||||
tmpFN.Normalize();
|
||||
return tmpFN.GetFullPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
aSearchedPaths.push_back( tmpFN.GetFullPath() );
|
||||
}
|
||||
}
|
||||
|
||||
// this case covers full paths, leading expanded vars, and paths relative to the current
|
||||
// working directory (which is not necessarily the current project directory)
|
||||
tmpFN.Normalize();
|
||||
|
||||
if( tmpFN.FileExists() )
|
||||
{
|
||||
tmpFN.Normalize();
|
||||
tname = tmpFN.GetFullPath();
|
||||
m_NameMap[ aFileName ] = tname;
|
||||
|
||||
|
@ -313,6 +321,10 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName )
|
|||
|
||||
return tname;
|
||||
}
|
||||
else if( tmpFN.GetFullPath() != aFileName )
|
||||
{
|
||||
aSearchedPaths.push_back( tmpFN.GetFullPath() );
|
||||
}
|
||||
|
||||
// if a path begins with ${ENV_VAR}/$(ENV_VAR) and is not resolved then the file either does
|
||||
// not exist or the ENV_VAR is not defined
|
||||
|
@ -339,14 +351,19 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName )
|
|||
if( fullPath.StartsWith( "${" ) || fullPath.StartsWith( "$(" ) )
|
||||
fullPath = expandVars( fullPath );
|
||||
|
||||
if( wxFileName::FileExists( fullPath ) )
|
||||
tmpFN.Assign( fullPath );
|
||||
tmpFN.Normalize();
|
||||
|
||||
if( tmpFN.FileExists() )
|
||||
{
|
||||
tmpFN.Assign( fullPath );
|
||||
tmpFN.Normalize();
|
||||
tname = tmpFN.GetFullPath();
|
||||
m_NameMap[ aFileName ] = tname;
|
||||
return tname;
|
||||
}
|
||||
else if( tmpFN.GetFullPath() != aFileName )
|
||||
{
|
||||
aSearchedPaths.push_back( tmpFN.GetFullPath() );
|
||||
}
|
||||
}
|
||||
|
||||
// check the partial path relative to ${KICAD6_3DMODEL_DIR} (legacy behavior)
|
||||
|
@ -358,13 +375,18 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName )
|
|||
fullPath.Append( tname );
|
||||
fullPath = expandVars( fullPath );
|
||||
fpath.Assign( fullPath );
|
||||
fpath.Normalize();
|
||||
|
||||
if( fpath.Normalize() && fpath.FileExists() )
|
||||
if( fpath.FileExists() )
|
||||
{
|
||||
tname = fpath.GetFullPath();
|
||||
m_NameMap[ aFileName ] = tname;
|
||||
return tname;
|
||||
}
|
||||
else
|
||||
{
|
||||
aSearchedPaths.push_back( fpath.GetFullPath() );
|
||||
}
|
||||
}
|
||||
|
||||
// at this point the filename must contain an alias or else it is invalid
|
||||
|
@ -393,18 +415,19 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName )
|
|||
if( fullPath.StartsWith( "${") || fullPath.StartsWith( "$(" ) )
|
||||
fullPath = expandVars( fullPath );
|
||||
|
||||
if( wxFileName::FileExists( fullPath ) )
|
||||
wxFileName tmp( fullPath );
|
||||
tmp.Normalize();
|
||||
|
||||
if( tmp.FileExists() )
|
||||
{
|
||||
tname = fullPath;
|
||||
|
||||
wxFileName tmp( tname );
|
||||
|
||||
if( tmp.Normalize() )
|
||||
tname = tmp.GetFullPath();
|
||||
|
||||
tname = tmp.GetFullPath();
|
||||
m_NameMap[ aFileName ] = tname;
|
||||
return tname;
|
||||
}
|
||||
else
|
||||
{
|
||||
aSearchedPaths.push_back( tmp.GetFullPath() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,8 +129,10 @@ public:
|
|||
* In the future remote files may be supported, in which case it is best to require a full
|
||||
* URI in which case #ResolvePath should check that the URI conforms to RFC-2396 and related
|
||||
* documents and copies \a aFileName into the resolved name if the URI is valid.
|
||||
*
|
||||
* If the file is not found, \a aSearchedPaths will contain the paths that were searched.
|
||||
*/
|
||||
wxString ResolvePath( const wxString& aFileName );
|
||||
wxString ResolvePath( const wxString& aFileName, std::vector<wxString>& aSearchedPaths );
|
||||
|
||||
/**
|
||||
* Produce a relative path based on the existing search directories or returns the same path
|
||||
|
|
|
@ -432,14 +432,23 @@ bool KICADFOOTPRINT::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver,
|
|||
if( mname.empty() )
|
||||
continue;
|
||||
|
||||
mname = resolver->ResolvePath( mname );
|
||||
std::vector<wxString> searchedPaths;
|
||||
mname = resolver->ResolvePath( mname, searchedPaths );
|
||||
|
||||
if( !wxFileName::FileExists( mname ) )
|
||||
{
|
||||
wxString paths;
|
||||
|
||||
for( const wxString& path : searchedPaths )
|
||||
paths += " " + path + "\n";
|
||||
|
||||
ReportMessage( wxString::Format( "Could not add 3D model to %s.\n"
|
||||
"File not found: %s\n",
|
||||
"File not found: %s\n"
|
||||
"Searched paths:\n"
|
||||
"%s",
|
||||
m_refdes,
|
||||
mname ) );
|
||||
mname,
|
||||
paths) );
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue