From 2eaefb487496773f772679f9856182da76179c32 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Tue, 4 Feb 2020 23:37:14 +0100 Subject: [PATCH] Improve performance of schematic load and connectivity Store component paths and references efficiently Remove redundant calls to RecalculateConnections --- eeschema/files-io.cpp | 11 +++++------ eeschema/sch_component.h | 2 +- eeschema/sch_connection.cpp | 4 +++- eeschema/sch_edit_frame.cpp | 10 +++++++++- eeschema/sch_legacy_plugin.cpp | 1 - eeschema/sch_screen.cpp | 10 +++++----- eeschema/sch_screen.h | 12 ++++++------ 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 22ef0102e5..7496156eec 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -407,10 +407,12 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in RescueSymbolLibTableProject( false ); } + g_ConnectionGraph->Reset(); + + // Update all symbol library links for all sheets. + // NOTE: calls RecalculateConnections( GLOBAL_CLEANUP ) schematic.UpdateSymbolLinks( true ); // Update all symbol library links for all sheets. - g_ConnectionGraph->Reset(); - RecalculateConnections( GLOBAL_CLEANUP ); SetScreen( g_CurrentSheet->LastScreen() ); // Migrate conflicting bus definitions @@ -419,13 +421,11 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in { DIALOG_MIGRATE_BUSES dlg( this ); dlg.ShowQuasiModal(); - + RecalculateConnections( NO_CLEANUP ); OnModify(); } GetScreen()->TestDanglingEnds(); // Only perform the dangling end test on root sheet. - RecalculateConnections( GLOBAL_CLEANUP ); - GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 ); GetScreen()->m_Initialized = true; @@ -720,7 +720,6 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) } // Only perform the dangling end test on root sheet. GetScreen()->TestDanglingEnds(); - RecalculateConnections( GLOBAL_CLEANUP ); GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 ); diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 3ea2e0c9a2..b41786f9dc 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -329,7 +329,7 @@ public: * Do nothing if already exists. * In component lists shared by more than one sheet path, an entry for each * sheet path must exist to manage references - * @param aSheetPathName is the candidate sheet path name + * @param aSheetPath is the candidate sheet path * this sheet path is the sheet path of the sheet containing the component, * not the full component sheet path * @return false if the alternate reference was existing, true if added. diff --git a/eeschema/sch_connection.cpp b/eeschema/sch_connection.cpp index f85be41ac6..b6063b363a 100644 --- a/eeschema/sch_connection.cpp +++ b/eeschema/sch_connection.cpp @@ -390,7 +390,9 @@ void SCH_CONNECTION::AppendDebugInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const bool SCH_CONNECTION::IsBusLabel( const wxString& aLabel ) { - return IsBusVectorLabel( aLabel ) || IsBusGroupLabel( aLabel ); + //return IsBusVectorLabel( aLabel ) || IsBusGroupLabel( aLabel ); + // Weak heuristic for performance reasons. Stronger test will be used for connectivity + return aLabel.Contains( wxT( "[" ) ) || aLabel.Contains( wxT( "{" ) ); } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 0ef8ea0866..fd912fba4e 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1169,6 +1169,8 @@ void SCH_EDIT_FRAME::FixupJunctions() // Save the current sheet, to retrieve it later auto currSheet = GetCurrentSheet(); + bool modified = false; + SCH_SHEET_LIST sheetList; sheetList.BuildSheetList( g_RootSheet ); @@ -1197,9 +1199,15 @@ void SCH_EDIT_FRAME::FixupJunctions() } for( auto& pos : junctions ) - AddJunction( pos ); + AddJunction( pos, false, false ); + + if( junctions.size() ) + modified = true; } + if( modified ) + OnModify(); + // Reselect the initial sheet: SetCurrentSheet( currSheet ); GetCurrentSheet().UpdateAllScreenReferences(); diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index 573530c5a3..b4c18661bb 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -1985,7 +1985,6 @@ void SCH_LEGACY_PLUGIN::saveComponent( SCH_COMPONENT* aComponent ) { std::string name1; std::string name2; - wxArrayString reference_fields; static wxString delimiters( wxT( " " ) ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 2dcfec9aab..21eece1c45 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -745,7 +745,7 @@ void SCH_SCREEN::ClearAnnotation( SCH_SHEET_PATH* aSheetPath ) void SCH_SCREEN::EnsureAlternateReferencesExist() { - if( GetClientSheetPathsCount() <= 1 ) // No need for alternate reference + if( GetClientSheetPaths().size() <= 1 ) // No need for alternate reference return; for( SCH_ITEM* item : Items().OfType( SCH_COMPONENT_T ) ) @@ -753,8 +753,8 @@ void SCH_SCREEN::EnsureAlternateReferencesExist() auto component = static_cast( item ); // Add (when not existing) all sheet path entries - for( unsigned int ii = 0; ii < m_clientSheetPathList.GetCount(); ii++ ) - component->AddSheetPathReferenceEntryIfMissing( m_clientSheetPathList[ii] ); + for( const auto& sheet : GetClientSheetPaths() ) + component->AddSheetPathReferenceEntryIfMissing( sheet.Path() ); } } @@ -1299,7 +1299,7 @@ void SCH_SCREENS::BuildClientSheetPathList() SCH_SHEET_LIST sheetList( g_RootSheet ); for( SCH_SCREEN* curr_screen = GetFirst(); curr_screen; curr_screen = GetNext() ) - curr_screen->GetClientSheetPaths().Clear(); + curr_screen->GetClientSheetPaths().clear(); for( SCH_SHEET_PATH& sheetpath: sheetList ) { @@ -1310,7 +1310,7 @@ void SCH_SCREENS::BuildClientSheetPathList() { if( used_screen == curr_screen ) { - curr_screen->GetClientSheetPaths().Add( sheetpath.PathAsString() ); + curr_screen->GetClientSheetPaths().push_back( sheetpath ); break; } } diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 976b943dc3..c1b489d5ed 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -97,7 +97,7 @@ private: * can have many scheet paths sharing this screen, if this sheet is inside * an other sheet having many instances (one sheet path by parent sheet instance). */ - wxArrayString m_clientSheetPathList; + std::vector m_clientSheetPathList; /// The size of the paper to print or plot on PAGE_INFO m_paper; // keep with the MVC 'model' if this class gets split @@ -170,16 +170,16 @@ public: int GetRefCount() const { return m_refCount; } /** - * @return the sheet paths count sharing this screen + * @return the sheet paths sharing this screen * if 1 this screen is not in a complex hierarchy: the reference field can be * used to store the component reference * if > 1 this screen is in a complex hierarchy, and components must have * a full alternate reference management */ - int GetClientSheetPathsCount() { return (int) m_clientSheetPathList.GetCount(); } - - wxArrayString& GetClientSheetPaths() { return m_clientSheetPathList; } - + std::vector& GetClientSheetPaths() + { + return m_clientSheetPathList; + } void Append( SCH_ITEM* aItem );