diff --git a/eeschema/sch_plugins/ltspice/ltspice_schematic.cpp b/eeschema/sch_plugins/ltspice/ltspice_schematic.cpp index 5ed0e4613b..09c315df76 100644 --- a/eeschema/sch_plugins/ltspice/ltspice_schematic.cpp +++ b/eeschema/sch_plugins/ltspice/ltspice_schematic.cpp @@ -36,64 +36,52 @@ void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, const wxFileName& aLibraryFileName ) { - std::vector sourceFiles; std::map mapOfAscFiles; std::map mapOfAsyFiles; + GetAscAndAsyFilePaths( mapOfAscFiles, mapOfAsyFiles, aLibraryFileName ); + m_schematic = aSchematic; - std::queue ascFileQueue; - LTSPICE_FILE ascFileObject( aLibraryFileName.GetName(), { 0, 0 } ); + std::queue ascFileQueue; + ascFileQueue.push( aLibraryFileName.GetName().Lower() ); - ascFileObject.Screen = aRootSheet->GetScreen(); + LTSPICE_FILE rootAscFile( ascFileQueue.front(), { 0, 0 } ); - ascFileQueue.push( ascFileObject ); - - GetAscAndAsyFilePaths( mapOfAscFiles, mapOfAsyFiles, aLibraryFileName ); + rootAscFile.Sheet = aRootSheet; + rootAscFile.Screen = new SCH_SCREEN(); int parentSheetIndex = 0; // Asc files who are subschematic in nature std::vector ascFiles; - ascFileObject.Sheet = aRootSheet; - - ascFileObject.Screen = new SCH_SCREEN(); - - ascFiles.push_back( ascFileObject ); - - // Map stores sheetName and sheet - std::map ascSheetMap; + ascFiles.push_back( rootAscFile ); while( !ascFileQueue.empty() ) { SCH_SCREEN* screen = new SCH_SCREEN( m_schematic ); // Reading the .asc file - wxString fileIndex = ascFileQueue.front().ElementName; - wxString ascFilePath = mapOfAscFiles[fileIndex]; + wxString ascFilePath = mapOfAscFiles[ ascFileQueue.front() ]; wxString buffer = SafeReadFile( ascFilePath, "r" ); - std::vector newSubSchematicElements; + std::vector newSubSchematicElements = GetSchematicElements( buffer ); - // Getting the keywords to read - sourceFiles = GetSchematicElements( buffer ); + alg::delete_if( newSubSchematicElements, + [&mapOfAscFiles]( const LTSPICE_FILE& ii ) + { + return mapOfAscFiles[ii.ElementName].IsEmpty(); + } ); - SubSchematicCheck( sourceFiles, mapOfAscFiles, newSubSchematicElements ); - - for( unsigned int i = 0; i < newSubSchematicElements.size(); i++ ) + for( LTSPICE_FILE& newSubSchematicElement : newSubSchematicElements ) { - newSubSchematicElements[i].ParentIndex = parentSheetIndex; + newSubSchematicElement.ParentIndex = parentSheetIndex; + newSubSchematicElement.Screen = screen; + newSubSchematicElement.Sheet = new SCH_SHEET(); - newSubSchematicElements[i].Screen = screen; - - SCH_SHEET* sheet = new SCH_SHEET(); - - newSubSchematicElements[i].Sheet = sheet; - ascSheetMap[newSubSchematicElements[i].ElementName] = sheet; - - ascFileQueue.push( newSubSchematicElements[i] ); - ascFiles.push_back( newSubSchematicElements[i] ); + ascFileQueue.push( newSubSchematicElement.ElementName ); + ascFiles.push_back( newSubSchematicElement ); } ascFileQueue.pop(); @@ -107,7 +95,7 @@ void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, wxString buffer = SafeReadFile( mapOfAscFiles[ascFiles[i].ElementName], wxS( "r" ) ); // Getting the keywords to read - sourceFiles = GetSchematicElements( buffer ); + std::vector sourceFiles = GetSchematicElements( buffer ); m_fileCache[ wxS( "asyFiles" ) ] = ReadAsyFiles( sourceFiles, mapOfAsyFiles ); m_fileCache[ wxS( "ascFiles" ) ][ wxS( "parentFile" ) ] = buffer; @@ -177,18 +165,6 @@ void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, } -void LTSPICE_SCHEMATIC::SubSchematicCheck( std::vector& aSchematicElementsArray, - std::map& aMapOfAscFiles, - std::vector& aSubSchematicSet ) -{ - for( const LTSPICE_FILE& it : aSchematicElementsArray ) - { - if( aMapOfAscFiles[it.ElementName] != "" ) - aSubSchematicSet.push_back( it ); - } -} - - void LTSPICE_SCHEMATIC::GetAscAndAsyFilePaths( std::map& aMapOfAscFiles, std::map& aMapOfAsyFiles, const wxFileName& parentFileName ) diff --git a/eeschema/sch_plugins/ltspice/ltspice_schematic.h b/eeschema/sch_plugins/ltspice/ltspice_schematic.h index f494142c38..9b0b5ae522 100644 --- a/eeschema/sch_plugins/ltspice/ltspice_schematic.h +++ b/eeschema/sch_plugins/ltspice/ltspice_schematic.h @@ -294,17 +294,6 @@ public: */ void Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, const wxFileName& aLibraryFileName ); - /** - * Used to check if the given symbol is subschematic or not. - * - * @param aSchematicElementsArray array which stores which elements names. - * @param aMapOfAscFiles map of string containing content from asc files. - * @param aSubSchematicList list of subschematic elements. - */ - void SubSchematicCheck( std::vector& aSchematicElementsArray, - std::map& aMapOfAscFiles, - std::vector& aSubSchematicList ); - /** * Used to get file path for Asc and Asy files. *