Allow unnamed embedded step files in altium boards.

Fixes https://gitlab.com/kicad/code/kicad/issues/7898
This commit is contained in:
Jeff Young 2021-07-10 16:37:19 +01:00
parent e02bb80bf3
commit 01d3a88faa
3 changed files with 14 additions and 11 deletions

View File

@ -113,9 +113,8 @@ std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties()
if( !hasNullByte ) if( !hasNullByte )
{ {
wxLogError( _( "For Altium import, we assumes a null byte at the end of a list of " wxLogError( _( "Missing null byte at end of property list. Imported data might be "
"properties. Because this is missing, imported data might be malformed or " "malformed or missing." ) );
"missing." ) );
} }
// we use std::string because std::string can handle NULL-bytes // we use std::string because std::string can handle NULL-bytes

View File

@ -251,7 +251,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
// implement the pseudo code from KIWAY_PLAYER.h: // implement the pseudo code from KIWAY_PLAYER.h:
wxString msg; wxString msg;
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ); EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
// This is for python: // This is for python:
if( aFileSet.size() != 1 ) if( aFileSet.size() != 1 )

View File

@ -1258,9 +1258,7 @@ void ALTIUM_PCB::ParseModelsData( const CFB::CompoundFileReader& aReader,
ALTIUM_PARSER reader( aReader, aEntry ); ALTIUM_PARSER reader( aReader, aEntry );
if( reader.GetRemainingBytes() == 0 ) if( reader.GetRemainingBytes() == 0 )
{ return;
return; // fast path: no 3d-models present which need to be imported -> no directory needs to be created
}
wxString projectPath = wxPathOnly( m_board->GetFileName() ); wxString projectPath = wxPathOnly( m_board->GetFileName() );
// TODO: set KIPRJMOD always after import (not only when loading project)? // TODO: set KIPRJMOD always after import (not only when loading project)?
@ -1271,6 +1269,7 @@ void ALTIUM_PCB::ParseModelsData( const CFB::CompoundFileReader& aReader,
wxFileName altiumModelsPath = wxFileName::DirName( projectPath ); wxFileName altiumModelsPath = wxFileName::DirName( projectPath );
wxString kicadModelPrefix = "${KIPRJMOD}/" + altiumModelDir + "/"; wxString kicadModelPrefix = "${KIPRJMOD}/" + altiumModelDir + "/";
if( !altiumModelsPath.AppendDir( altiumModelDir ) ) if( !altiumModelsPath.AppendDir( altiumModelDir ) )
{ {
THROW_IO_ERROR( "Cannot construct directory path for step models" ); THROW_IO_ERROR( "Cannot construct directory path for step models" );
@ -1281,21 +1280,28 @@ void ALTIUM_PCB::ParseModelsData( const CFB::CompoundFileReader& aReader,
{ {
if( !altiumModelsPath.Mkdir() ) if( !altiumModelsPath.Mkdir() )
{ {
wxLogError( _( "Failed to create folder '%s'." ) + _( "No 3D-models will be imported." ), wxLogError( _( "Failed to create folder '%s'." ) + wxS( " " )
+ _( "No 3D-models will be imported." ),
altiumModelsPath.GetFullPath() ); altiumModelsPath.GetFullPath() );
return; return;
} }
} }
int idx = 0; int idx = 0;
while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ ) while( reader.GetRemainingBytes() >= 4 /* TODO: use Header section of file */ )
{ {
checkpoint(); checkpoint();
AMODEL elem( reader ); AMODEL elem( reader );
wxString stepPath = aRootDir + std::to_string( idx++ ); wxString stepPath = wxString::Format( aRootDir + "%d", idx );
wxString storageName = elem.name.IsEmpty() ? wxString::Format( "%d", idx ) : elem.name;
wxFileName storagePath( altiumModelsPath.GetPath(), storageName );
idx++;
const CFB::COMPOUND_FILE_ENTRY* stepEntry = FindStream( aReader, stepPath.c_str() ); const CFB::COMPOUND_FILE_ENTRY* stepEntry = FindStream( aReader, stepPath.c_str() );
if( stepEntry == nullptr ) if( stepEntry == nullptr )
{ {
wxLogError( _( "File not found: '%s'. 3D-model not imported." ), stepPath ); wxLogError( _( "File not found: '%s'. 3D-model not imported." ), stepPath );
@ -1308,8 +1314,6 @@ void ALTIUM_PCB::ParseModelsData( const CFB::CompoundFileReader& aReader,
// read file into buffer // read file into buffer
aReader.ReadFile( stepEntry, 0, stepContent.get(), stepSize ); aReader.ReadFile( stepEntry, 0, stepContent.get(), stepSize );
wxFileName storagePath( altiumModelsPath.GetPath(), elem.name );
if( !storagePath.IsDirWritable() ) if( !storagePath.IsDirWritable() )
{ {
wxLogError( _( "Insufficient permissions to save file '%s'." ), wxLogError( _( "Insufficient permissions to save file '%s'." ),