A few baby steps in trying to straighten out LTSPICE_SCHEMATIC::Load().

This commit is contained in:
Jeff Young 2023-07-10 11:33:50 +01:00
parent 229dcde948
commit 3ba7e7e993
2 changed files with 22 additions and 57 deletions

View File

@ -36,64 +36,52 @@
void LTSPICE_SCHEMATIC::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
const wxFileName& aLibraryFileName )
{
std::vector<LTSPICE_FILE> sourceFiles;
std::map<wxString, wxString> mapOfAscFiles;
std::map<wxString, wxString> mapOfAsyFiles;
GetAscAndAsyFilePaths( mapOfAscFiles, mapOfAsyFiles, aLibraryFileName );
m_schematic = aSchematic;
std::queue<LTSPICE_FILE> ascFileQueue;
LTSPICE_FILE ascFileObject( aLibraryFileName.GetName(), { 0, 0 } );
std::queue<wxString> 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<LTSPICE_FILE> ascFiles;
ascFileObject.Sheet = aRootSheet;
ascFileObject.Screen = new SCH_SCREEN();
ascFiles.push_back( ascFileObject );
// Map stores sheetName and sheet
std::map<wxString, SCH_SHEET*> 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<LTSPICE_FILE> newSubSchematicElements;
std::vector<LTSPICE_FILE> newSubSchematicElements = GetSchematicElements( buffer );
// Getting the keywords to read
sourceFiles = GetSchematicElements( buffer );
SubSchematicCheck( sourceFiles, mapOfAscFiles, newSubSchematicElements );
for( unsigned int i = 0; i < newSubSchematicElements.size(); i++ )
alg::delete_if( newSubSchematicElements,
[&mapOfAscFiles]( const LTSPICE_FILE& ii )
{
newSubSchematicElements[i].ParentIndex = parentSheetIndex;
return mapOfAscFiles[ii.ElementName].IsEmpty();
} );
newSubSchematicElements[i].Screen = screen;
for( LTSPICE_FILE& newSubSchematicElement : newSubSchematicElements )
{
newSubSchematicElement.ParentIndex = parentSheetIndex;
newSubSchematicElement.Screen = screen;
newSubSchematicElement.Sheet = new SCH_SHEET();
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<LTSPICE_FILE> 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<LTSPICE_FILE>& aSchematicElementsArray,
std::map<wxString, wxString>& aMapOfAscFiles,
std::vector<LTSPICE_FILE>& aSubSchematicSet )
{
for( const LTSPICE_FILE& it : aSchematicElementsArray )
{
if( aMapOfAscFiles[it.ElementName] != "" )
aSubSchematicSet.push_back( it );
}
}
void LTSPICE_SCHEMATIC::GetAscAndAsyFilePaths( std::map<wxString, wxString>& aMapOfAscFiles,
std::map<wxString, wxString>& aMapOfAsyFiles,
const wxFileName& parentFileName )

View File

@ -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<LTSPICE_FILE>& aSchematicElementsArray,
std::map<wxString, wxString>& aMapOfAscFiles,
std::vector<LTSPICE_FILE>& aSubSchematicList );
/**
* Used to get file path for Asc and Asy files.
*