LTspice import: don't try loading .asc files for non-subsheets.

Subsheets don't have "Prefix" attribute, components do.
This commit is contained in:
Alex Shvartzkop 2023-07-11 15:59:50 +05:00
parent ab4535f01b
commit a5ba9ccce2
2 changed files with 42 additions and 5 deletions

View File

@ -75,6 +75,16 @@ void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
} ); } );
for( LTSPICE_FILE& newSubSchematicElement : newSubSchematicElements ) for( LTSPICE_FILE& newSubSchematicElement : newSubSchematicElements )
{
wxString asyName = newSubSchematicElement.ElementName;
auto it = mapOfAsyFiles.find( asyName );
if( it == mapOfAsyFiles.end() )
continue;
wxString asyBuffer = SafeReadFile( it->second, "r" );
if( IsAsySubsheet( asyBuffer ) )
{ {
newSubSchematicElement.ParentIndex = parentSheetIndex; newSubSchematicElement.ParentIndex = parentSheetIndex;
newSubSchematicElement.Screen = screen; newSubSchematicElement.Screen = screen;
@ -83,6 +93,7 @@ void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
ascFileQueue.push( newSubSchematicElement.ElementName ); ascFileQueue.push( newSubSchematicElement.ElementName );
ascFiles.push_back( newSubSchematicElement ); ascFiles.push_back( newSubSchematicElement );
} }
}
ascFileQueue.pop(); ascFileQueue.pop();
@ -264,6 +275,25 @@ std::vector<LTSPICE_FILE> LTSPICE_SCHEMATIC::GetSchematicElements( const wxStrin
} }
bool LTSPICE_SCHEMATIC::IsAsySubsheet( const wxString& aAsyFile )
{
wxStringTokenizer lines( aAsyFile, "\n" );
while( lines.HasMoreTokens() )
{
wxStringTokenizer parts( lines.GetNextToken(), " " );
if( parts.GetNextToken().IsSameAs( wxS( "SYMATTR" ), false )
&& parts.GetNextToken().IsSameAs( wxS( "Prefix" ), false ) )
{
return false;
}
}
return true;
}
int LTSPICE_SCHEMATIC::integerCheck( const wxString& aToken, int aLineNumber, int LTSPICE_SCHEMATIC::integerCheck( const wxString& aToken, int aLineNumber,
const wxString& aFileName ) const wxString& aFileName )
{ {

View File

@ -314,6 +314,13 @@ public:
*/ */
std::vector<LTSPICE_FILE> GetSchematicElements( const wxString& aAscFile ); std::vector<LTSPICE_FILE> GetSchematicElements( const wxString& aAscFile );
/**
* Check if the asy file content indicates that we need to load subsheet.
*
* @param aAsyFile contents of .asy file.
*/
bool IsAsySubsheet( const wxString& aAsyFile );
/** /**
* The function returns a map. This map has all the asy files in form of string. For asy files * The function returns a map. This map has all the asy files in form of string. For asy files
* the key will be symbol name. * the key will be symbol name.