From d063eb431b768b29774836bc7f420176e4f78f9b Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Thu, 18 Aug 2022 23:19:28 +0200 Subject: [PATCH] Move FixupJunctions to SCHEMATIC --- eeschema/eeschema.cpp | 1 - eeschema/files-io.cpp | 15 ++++---- eeschema/sch_edit_frame.cpp | 36 ------------------- eeschema/sch_edit_frame.h | 2 -- .../cadstar/cadstar_sch_archive_plugin.cpp | 3 ++ eeschema/schematic.cpp | 32 ++++++++++++++++- eeschema/schematic.h | 6 ++++ qa/unittests/eeschema/eeschema_test_utils.cpp | 1 - 8 files changed, 46 insertions(+), 50 deletions(-) diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 0c8cfd7308..ce8e5262d0 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -102,7 +102,6 @@ static std::unique_ptr readSchematicFromFile( const std::string& aFil sheets.AnnotatePowerSymbols(); // NOTE: This is required for multi-unit symbols to be correct - // Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored for( SCH_SHEET_PATH& sheet : sheets ) sheet.UpdateAllScreenReferences(); diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index ff7bed6399..c53c99afd8 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -487,12 +487,16 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in RecomputeIntersheetRefs(); GetCurrentSheet().UpdateAllScreenReferences(); - // re-create junctions if needed. Eeschema optimizes wires by merging + // Re-create junctions if needed. Eeschema optimizes wires by merging // colinear segments. If a schematic is saved without a valid // cache library or missing installed libraries, this can cause connectivity errors // unless junctions are added. + // + // TODO: (RFB) This really needs to be put inside the Load() function of the SCH_LEGACY_PLUGIN + // I can't put it right now because of the extra code that is above to convert legacy bus-bus + // entries to bus wires if( schFileType == SCH_IO_MGR::SCH_LEGACY ) - FixupJunctions(); + Schematic().FixupJunctions(); SyncView(); GetScreen()->ClearDrawingState(); @@ -1254,13 +1258,6 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) GetScreen()->SetFileName( newfilename.GetFullPath() ); GetScreen()->SetContentModified(); - // Only fix junctions for CADSTAR importer for now as it may cause issues with - // other importers - if( fileType == SCH_IO_MGR::SCH_CADSTAR_ARCHIVE ) - { - FixupJunctions(); - } - RecalculateConnections( GLOBAL_CLEANUP ); // Only perform the dangling end test on root sheet. diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index b24b02d787..fbee35f941 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1651,42 +1651,6 @@ const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const } -void SCH_EDIT_FRAME::FixupJunctions() -{ - // Save the current sheet, to retrieve it later - SCH_SHEET_PATH oldsheetpath = GetCurrentSheet(); - - SCH_SHEET_LIST sheetList = Schematic().GetSheets(); - - for( const SCH_SHEET_PATH& sheet : sheetList ) - { - size_t num_undos = m_undoList.m_CommandsList.size(); - - SetCurrentSheet( sheet ); - GetCurrentSheet().UpdateAllScreenReferences(); - - SCH_SCREEN* screen = GetCurrentSheet().LastScreen(); - - EE_SELECTION allItems; - - for( auto item : screen->Items() ) - allItems.Add( item ); - - m_toolManager->GetTool()->AddJunctionsIfNeeded( &allItems ); - - // Check if we modified anything during this routine - // Needs to happen for every sheet to set the proper modified flag - if( m_undoList.m_CommandsList.size() > num_undos ) - OnModify(); - } - - // Reselect the initial sheet: - SetCurrentSheet( oldsheetpath ); - GetCurrentSheet().UpdateAllScreenReferences(); - SetScreen( GetCurrentSheet().LastScreen() ); -} - - bool SCH_EDIT_FRAME::IsContentModified() const { return Schematic().GetSheets().IsModified(); diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index dbb0f1f9d1..498a4e3cb4 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -770,8 +770,6 @@ public: const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override; - void FixupJunctions(); - int GetSchematicJunctionSize(); void FocusOnItem( SCH_ITEM* aItem ); diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp index d3e00f0297..f5c6df4140 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp @@ -140,6 +140,9 @@ SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::Load( const wxString& aFileName, SCHEMATI sch_plugin->SaveLibrary( libFileName.GetFullPath() ); + // Need to fix up junctions after import to retain connectivity + aSchematic->FixupJunctions(); + return rootSheet; } diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 4c81f6f02b..b513d75901 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -558,4 +560,32 @@ void SCHEMATIC::RecomputeIntersheetRefs( const std::function allItems; + + for( auto item : screen->Items() ) + allItems.push_back( item ); + + // Add missing junctions and breakup wires as needed + for( const VECTOR2I& point : screen->GetNeededJunctions( allItems ) ) + { + SCH_JUNCTION* junction = new SCH_JUNCTION( point ); + screen->Append( junction ); + + // Breakup wires + for( SCH_LINE* wire : screen->GetBusesAndWires( point, true ) ) + { + SCH_LINE* newSegment = wire->BreakAt( point ); + screen->Append( newSegment ); + } + } + } +} diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 027e0c7b50..43ecb340a3 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -202,6 +202,12 @@ public: */ void RecomputeIntersheetRefs( const std::function& aItemCallback ); + /** + * Add junctions to this schematic where required. This function is needed for some plugins + * (e.g. Legacy and Cadstar) in order to retain connectivity after loading. + */ + void FixupJunctions(); + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override {} #endif diff --git a/qa/unittests/eeschema/eeschema_test_utils.cpp b/qa/unittests/eeschema/eeschema_test_utils.cpp index fa3f53b7a7..8e3065141c 100644 --- a/qa/unittests/eeschema/eeschema_test_utils.cpp +++ b/qa/unittests/eeschema/eeschema_test_utils.cpp @@ -107,7 +107,6 @@ void KI_TEST::SCHEMATIC_TEST_FIXTURE::LoadSchematic( const wxString& aBaseName ) sheets.AnnotatePowerSymbols(); // NOTE: This is required for multi-unit symbols to be correct - // Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored for( SCH_SHEET_PATH& sheet : sheets ) sheet.UpdateAllScreenReferences();