diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 228fc3ae62..2f9fddecfe 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -409,7 +409,7 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet ) { case SCH_SYMBOL_T: m_out->Print( 0, "\n" ); - saveSymbol( static_cast( item ), nullptr, 1, false ); + saveSymbol( static_cast( item ), *m_schematic, 1, false ); break; case SCH_BITMAP_T: @@ -499,12 +499,13 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet ) void SCH_SEXPR_PLUGIN::Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelectionPath, - SCH_SHEET_LIST* aFullSheetHierarchy, - OUTPUTFORMATTER* aFormatter, bool aForClipboard ) + const SCHEMATIC& aSchematic, OUTPUTFORMATTER* aFormatter, + bool aForClipboard ) { - wxCHECK( aSelection && aSelectionPath && aFullSheetHierarchy && aFormatter, /* void */ ); + wxCHECK( aSelection && aSelectionPath && aFormatter, /* void */ ); LOCALE_IO toggle; + SCH_SHEET_LIST fullHierarchy = aSchematic.GetSheets(); m_out = aFormatter; @@ -560,7 +561,7 @@ void SCH_SEXPR_PLUGIN::Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelect switch( item->Type() ) { case SCH_SYMBOL_T: - saveSymbol( static_cast( item ), aSelectionPath, 0, aForClipboard ); + saveSymbol( static_cast( item ), aSchematic, 0, aForClipboard ); aSelectionPath->AppendSymbol( selectedSymbols, static_cast( item ), true, true ); @@ -577,9 +578,8 @@ void SCH_SEXPR_PLUGIN::Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelect SCH_SHEET_PATH subSheetPath = *aSelectionPath; subSheetPath.push_back( static_cast( item ) ); - aFullSheetHierarchy->GetSheetsWithinPath( selectedSheets, subSheetPath ); - aFullSheetHierarchy->GetSymbolsWithinPath( selectedSymbols, subSheetPath, true, - true ); + fullHierarchy.GetSheetsWithinPath( selectedSheets, subSheetPath ); + fullHierarchy.GetSymbolsWithinPath( selectedSymbols, subSheetPath, true, true ); } break; @@ -634,7 +634,6 @@ void SCH_SEXPR_PLUGIN::Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelect "Sheet is not inside the selection path?" ); } - selectedSymbols.SortByReferenceOnly(); std::vector symbolInstances = selectedSymbols.GetSymbolInstances(); @@ -648,7 +647,7 @@ void SCH_SEXPR_PLUGIN::Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelect } -void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPath, +void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchematic, int aNestLevel, bool aForClipboard ) { wxCHECK_RET( aSymbol != nullptr && m_out != nullptr, "" ); @@ -797,7 +796,8 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa m_out->Print( aNestLevel + 1, "(instances\n" ); KIID lastProjectUuid; - SCH_SHEET_LIST fullHierarchy = m_schematic->GetSheets(); + KIID rootSheetUuid = aSchematic.Root().m_Uuid; + SCH_SHEET_LIST fullHierarchy = aSchematic.GetSheets(); for( size_t i = 0; i < aSymbol->GetInstanceReferences().size(); i++ ) { @@ -807,7 +807,7 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa // // Keep all instance data when copying to the clipboard. It may be needed on paste. if( !aForClipboard - && ( aSymbol->GetInstanceReferences()[i].m_Path[0] == m_schematic->RootScreen()->GetUuid() ) + && ( aSymbol->GetInstanceReferences()[i].m_Path[0] == rootSheetUuid ) && !fullHierarchy.GetSheetPathByKIIDPath( aSymbol->GetInstanceReferences()[i].m_Path ) ) { if( ( i + 1 == aSymbol->GetInstanceReferences().size() ) @@ -821,8 +821,8 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa { wxString projectName; - if( aSymbol->GetInstanceReferences()[i].m_Path[0] == m_schematic->RootScreen()->GetUuid() ) - projectName = m_schematic->Prj().GetProjectName(); + if( aSymbol->GetInstanceReferences()[i].m_Path[0] == rootSheetUuid ) + projectName = aSchematic.Prj().GetProjectName(); else projectName = aSymbol->GetInstanceReferences()[i].m_ProjectName; diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.h b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.h index d02790f999..15917be73c 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.h +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.h @@ -108,8 +108,7 @@ public: void Format( SCH_SHEET* aSheet ); void Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelectionPath, - SCH_SHEET_LIST* aFullSheetHierarchy, OUTPUTFORMATTER* aFormatter, - bool aForClipboard ); + const SCHEMATIC& aSchematic, OUTPUTFORMATTER* aFormatter, bool aForClipboard ); void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath, @@ -146,7 +145,7 @@ private: void loadHierarchy( const SCH_SHEET_PATH& aParentSheetPath, SCH_SHEET* aSheet ); void loadFile( const wxString& aFileName, SCH_SHEET* aSheet ); - void saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPath, int aNestLevel, + void saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchematic, int aNestLevel, bool aForClipboard ); void saveField( SCH_FIELD* aField, int aNestLevel ); void saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 1c5df6a053..5a6bdaa17a 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -1606,7 +1606,7 @@ bool SCH_EDITOR_CONTROL::doCopy( bool aUseLocalClipboard ) SCH_SHEET_LIST hierarchy = schematic.GetSheets(); SCH_SHEET_PATH selPath = m_frame->GetCurrentSheet(); - plugin.Format( &selection, &selPath, &hierarchy, &formatter, true ); + plugin.Format( &selection, &selPath, schematic, &formatter, true ); if( aUseLocalClipboard ) {