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

@ -76,12 +76,23 @@ void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
for( LTSPICE_FILE& newSubSchematicElement : newSubSchematicElements )
{
newSubSchematicElement.ParentIndex = parentSheetIndex;
newSubSchematicElement.Screen = screen;
newSubSchematicElement.Sheet = new SCH_SHEET();
wxString asyName = newSubSchematicElement.ElementName;
auto it = mapOfAsyFiles.find( asyName );
ascFileQueue.push( newSubSchematicElement.ElementName );
ascFiles.push_back( newSubSchematicElement );
if( it == mapOfAsyFiles.end() )
continue;
wxString asyBuffer = SafeReadFile( it->second, "r" );
if( IsAsySubsheet( asyBuffer ) )
{
newSubSchematicElement.ParentIndex = parentSheetIndex;
newSubSchematicElement.Screen = screen;
newSubSchematicElement.Sheet = new SCH_SHEET();
ascFileQueue.push( newSubSchematicElement.ElementName );
ascFiles.push_back( newSubSchematicElement );
}
}
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,
const wxString& aFileName )
{

View File

@ -314,6 +314,13 @@ public:
*/
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 key will be symbol name.