diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index 9795d4a736..521e069423 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -907,7 +907,7 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) KIID uuid( payload ); SCH_SHEET_PATH path; - if( SCH_ITEM* item = m_schematic->GetSheets().GetItem( uuid, &path ) ) + if( SCH_ITEM* item = m_schematic->GetItem( uuid, &path ) ) { if( item->Type() == SCH_SHEET_T ) payload = static_cast( item )->GetShownName( false ); diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 7beb985301..01e23d1864 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -513,7 +513,7 @@ void DIALOG_ERC::OnERCItemSelected( wxDataViewEvent& aEvent ) { const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() ); SCH_SHEET_PATH sheet; - SCH_ITEM* item = m_parent->Schematic().GetSheets().GetItem( itemID, &sheet ); + SCH_ITEM* item = m_parent->Schematic().GetItem( itemID, &sheet ); if( m_centerMarkerOnIdle ) { diff --git a/eeschema/dialogs/dialog_field_properties.cpp b/eeschema/dialogs/dialog_field_properties.cpp index cc280da838..c5a20b1974 100644 --- a/eeschema/dialogs/dialog_field_properties.cpp +++ b/eeschema/dialogs/dialog_field_properties.cpp @@ -677,7 +677,7 @@ void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* a int unit = symbol->GetUnit(); LIB_ID libId = symbol->GetLibId(); - for( SCH_SHEET_PATH& sheet : editFrame->Schematic().GetSheets() ) + for( SCH_SHEET_PATH& sheet : editFrame->Schematic().GetUnorderedSheets() ) { SCH_SCREEN* screen = sheet.LastScreen(); std::vector otherUnits; diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index de0968dbb5..70757ed820 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -792,7 +792,7 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow() int unit = m_symbol->GetUnit(); LIB_ID libId = m_symbol->GetLibId(); - for( SCH_SHEET_PATH& sheet : GetParent()->Schematic().GetSheets() ) + for( SCH_SHEET_PATH& sheet : GetParent()->Schematic().GetUnorderedSheets() ) { SCH_SCREEN* screen = sheet.LastScreen(); std::vector otherUnits; diff --git a/eeschema/dialogs/dialog_table_properties.cpp b/eeschema/dialogs/dialog_table_properties.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/eeschema/dialogs/dialog_text_properties.cpp b/eeschema/dialogs/dialog_text_properties.cpp index 9903a4dbc1..898aeaea10 100644 --- a/eeschema/dialogs/dialog_text_properties.cpp +++ b/eeschema/dialogs/dialog_text_properties.cpp @@ -150,7 +150,7 @@ DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_ITE m_separator5->SetIsSeparator(); - SCH_SHEET_LIST sheetList = m_frame->Schematic().GetSheets(); + SCH_SHEET_LIST sheetList = m_frame->Schematic().GetUnorderedSheets(); sheetList.SortByPageNumbers( false ); for( const SCH_SHEET_PATH& sheet : sheetList ) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index f3ff87ee8c..fefefdc5a7 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -1075,7 +1075,7 @@ bool SCH_EDIT_FRAME::SaveProject( bool aSaveAs ) // File doesn't exist yet; true if we just imported something updateFileHistory = true; } - else if( !Schematic().GetSheets().IsModified() ) + else if( !IsContentModified() ) { return true; } diff --git a/eeschema/net_navigator.cpp b/eeschema/net_navigator.cpp index ccbef688ce..48946f874a 100644 --- a/eeschema/net_navigator.cpp +++ b/eeschema/net_navigator.cpp @@ -171,7 +171,8 @@ static wxString GetNetNavigatorItemText( const SCH_ITEM* aItem, void SCH_EDIT_FRAME::MakeNetNavigatorNode( const wxString& aNetName, wxTreeItemId aParentId, - const NET_NAVIGATOR_ITEM_DATA* aSelection ) + const NET_NAVIGATOR_ITEM_DATA* aSelection, + bool aSingleSheetSchematic ) { wxCHECK( !aNetName.IsEmpty(), /* void */ ); wxCHECK( m_schematic, /* void */ ); @@ -206,7 +207,7 @@ void SCH_EDIT_FRAME::MakeNetNavigatorNode( const wxString& aNetName, wxTreeItemI m_netNavigator->SelectItem( sheetId ); // If there is only one sheet in the schematic, always expand the sheet tree. - if( Schematic().GetSheets().size() == 1 ) + if( aSingleSheetSchematic ) expandId = sheetId; for( const SCH_ITEM* item : subGraph->GetItems() ) @@ -243,6 +244,8 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect if( m_netNavigator->IsEmpty() && m_highlightedConn.IsEmpty() ) return; + bool singleSheetSchematic = m_schematic->GetUnorderedSheets().size() == 1; + if( !m_netNavigator->IsEmpty() && m_highlightedConn.IsEmpty() ) { m_netNavigator->DeleteAllItems(); @@ -259,7 +262,7 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect wxTreeItemId rootId = m_netNavigator->AddRoot( UnescapeString( m_highlightedConn ), 0 ); - MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection ); + MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection, singleSheetSchematic ); } else { @@ -273,14 +276,14 @@ void SCH_EDIT_FRAME::RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelect m_netNavigator->DeleteAllItems(); wxTreeItemId rootId = m_netNavigator->AddRoot( UnescapeString( m_highlightedConn ), 0 ); - MakeNetNavigatorNode( m_highlightedConn, rootId, itemData ); + MakeNetNavigatorNode( m_highlightedConn, rootId, itemData, singleSheetSchematic ); } } else { wxTreeItemId rootId = m_netNavigator->AddRoot( UnescapeString( m_highlightedConn ), 0 ); - MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection ); + MakeNetNavigatorNode( m_highlightedConn, rootId, aSelection, singleSheetSchematic ); } } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 9f25b6629c..aca56a6675 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -774,7 +774,7 @@ void SCH_EDIT_FRAME::AddCopyForRepeatItem( const SCH_ITEM* aItem ) EDA_ITEM* SCH_EDIT_FRAME::GetItem( const KIID& aId ) const { - return Schematic().GetSheets().GetItem( aId ); + return Schematic().GetItem( aId ); } @@ -894,7 +894,7 @@ bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) // Shutdown blocks must be determined and vetoed as early as possible if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION - && Schematic().GetSheets().IsModified() ) + && IsContentModified() ) { return false; } @@ -942,9 +942,7 @@ bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) if( !Schematic().IsValid() ) return false; - SCH_SHEET_LIST sheetlist = Schematic().GetSheets(); - - if( sheetlist.IsModified() ) + if( IsContentModified() ) { wxFileName fileName = Schematic().RootScreen()->GetFileName(); wxString msg = _( "Save changes to '%s' before closing?" ); @@ -965,7 +963,7 @@ bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) void SCH_EDIT_FRAME::doCloseWindow() { - SCH_SHEET_LIST sheetlist = Schematic().GetSheets(); + SCH_SHEET_LIST sheetlist = Schematic().GetUnorderedSheets(); // Shutdown all running tools if( m_toolManager ) @@ -2037,7 +2035,7 @@ const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const bool SCH_EDIT_FRAME::IsContentModified() const { - return Schematic().GetSheets().IsModified(); + return Schematic().GetUnorderedSheets().IsModified(); } @@ -2052,9 +2050,8 @@ void SCH_EDIT_FRAME::FocusOnItem( SCH_ITEM* aItem ) { static KIID lastBrightenedItemID( niluuid ); - SCH_SHEET_LIST sheetList = Schematic().GetSheets(); SCH_SHEET_PATH dummy; - SCH_ITEM* lastItem = sheetList.GetItem( lastBrightenedItemID, &dummy ); + SCH_ITEM* lastItem = Schematic().GetItem( lastBrightenedItemID, &dummy ); if( lastItem && lastItem != aItem ) { diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 77193b2a39..00a7564c4b 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -866,7 +866,8 @@ public: void RefreshNetNavigator( const NET_NAVIGATOR_ITEM_DATA* aSelection = nullptr ); void MakeNetNavigatorNode( const wxString& aNetName, wxTreeItemId aParentId, - const NET_NAVIGATOR_ITEM_DATA* aSelection = nullptr ); + const NET_NAVIGATOR_ITEM_DATA* aSelection, + bool aSingleSheetSchematic ); void SelectNetNavigatorItem( const NET_NAVIGATOR_ITEM_DATA* aSelection = nullptr ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 9ab30c91da..8aa12b2069 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -740,11 +740,10 @@ void SCH_FIELD::OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks, } else { - SCH_SHEET_LIST sheets = schematic->GetSheets(); SCH_REFERENCE_LIST refs; SCH_SYMBOL* refSymbol = nullptr; - sheets.GetSymbols( refs ); + schematic->GetUnorderedSheets().GetSymbols( refs ); for( size_t jj = 0; jj < refs.GetCount(); jj++ ) { diff --git a/eeschema/sch_marker.cpp b/eeschema/sch_marker.cpp index abdc530875..3650647957 100644 --- a/eeschema/sch_marker.cpp +++ b/eeschema/sch_marker.cpp @@ -108,7 +108,7 @@ wxString SCH_MARKER::Serialize() const } -SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data ) +SCH_MARKER* SCH_MARKER::Deserialize( const SCH_SHEET_LIST& aSheetList, const wxString& data ) { wxArrayString props = wxSplit( data, '|' ); VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ), @@ -131,13 +131,11 @@ SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data { isLegacyMarker = false; - SCH_SHEET_LIST sheetPaths = schematic->GetSheets(); - if( !props[5].IsEmpty() ) { KIID_PATH sheetSpecificKiidPath( props[5] ); std::optional sheetSpecificPath = - sheetPaths.GetSheetPathByKIIDPath( sheetSpecificKiidPath, true ); + aSheetList.GetSheetPathByKIIDPath( sheetSpecificKiidPath, true ); if( sheetSpecificPath.has_value() ) ercItem->SetSheetSpecificPath( sheetSpecificPath.value() ); } @@ -146,7 +144,7 @@ SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data { KIID_PATH mainItemKiidPath( props[6] ); std::optional mainItemPath = - sheetPaths.GetSheetPathByKIIDPath( mainItemKiidPath, true ); + aSheetList.GetSheetPathByKIIDPath( mainItemKiidPath, true ); if( mainItemPath.has_value() ) { if( props[7].IsEmpty() ) @@ -157,7 +155,7 @@ SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data { KIID_PATH auxItemKiidPath( props[7] ); std::optional auxItemPath = - sheetPaths.GetSheetPathByKIIDPath( auxItemKiidPath, true ); + aSheetList.GetSheetPathByKIIDPath( auxItemKiidPath, true ); if( auxItemPath.has_value() ) ercItem->SetItemsSheetPaths( mainItemPath.value(), auxItemPath.value() ); diff --git a/eeschema/sch_marker.h b/eeschema/sch_marker.h index db1f42f3c2..7fb96c6271 100644 --- a/eeschema/sch_marker.h +++ b/eeschema/sch_marker.h @@ -54,7 +54,7 @@ public: void SwapData( SCH_ITEM* aItem ) override; wxString Serialize() const; - static SCH_MARKER* Deserialize( SCHEMATIC* schematic, const wxString& data ); + static SCH_MARKER* Deserialize( const SCH_SHEET_LIST& aSheetList, const wxString& data ); void ViewGetLayers( int aLayers[], int& aCount ) const override; diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 8804efdb24..226856465c 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -283,8 +283,7 @@ bool SCH_SHEET::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, in } else if( token->IsSameAs( wxT( "##" ) ) ) { - SCH_SHEET_LIST sheetList = schematic->GetSheets(); - *token = wxString::Format( wxT( "%d" ), (int) sheetList.size() ); + *token = wxString::Format( wxT( "%d" ), (int) schematic->GetUnorderedSheets().size() ); return true; } else if( token->IsSameAs( wxT( "SHEETPATH" ) ) ) diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 0ecd086bc2..2bd03108bb 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -72,7 +72,7 @@ SCHEMATIC::SCHEMATIC( PROJECT* aPrj ) : int unit = symbol->GetUnit(); LIB_ID libId = symbol->GetLibId(); - for( SCH_SHEET_PATH& sheet : GetSheets() ) + for( SCH_SHEET_PATH& sheet : GetUnorderedSheets() ) { std::vector otherUnits; @@ -314,7 +314,7 @@ std::vector SCHEMATIC::ResolveERCExclusions() for( auto it = settings.m_ErcExclusions.begin(); it != settings.m_ErcExclusions.end(); ) { - SCH_MARKER* testMarker = SCH_MARKER::Deserialize( this, *it ); + SCH_MARKER* testMarker = SCH_MARKER::Deserialize( sheetList, *it ); if( testMarker->IsLegacyMarker() ) { @@ -361,7 +361,7 @@ std::vector SCHEMATIC::ResolveERCExclusions() for( const wxString& serialized : settings.m_ErcExclusions ) { - SCH_MARKER* marker = SCH_MARKER::Deserialize( this, serialized ); + SCH_MARKER* marker = SCH_MARKER::Deserialize( sheetList, serialized ); if( marker ) { @@ -378,7 +378,7 @@ std::vector SCHEMATIC::ResolveERCExclusions() std::shared_ptr SCHEMATIC::GetBusAlias( const wxString& aLabel ) const { - for( const SCH_SHEET_PATH& sheet : GetSheets() ) + for( const SCH_SHEET_PATH& sheet : GetUnorderedSheets() ) { for( const std::shared_ptr& alias : sheet.LastScreen()->GetBusAliases() ) { @@ -412,11 +412,10 @@ std::set SCHEMATIC::GetNetClassAssignmentCandidates() bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const { - SCH_SHEET_LIST sheetList = GetSheets(); wxString remainder; wxString ref = token->BeforeFirst( ':', &remainder ); SCH_SHEET_PATH sheetPath; - SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &sheetPath ); + SCH_ITEM* refItem = GetItem( KIID( ref ), &sheetPath ); if( refItem && refItem->Type() == SCH_SYMBOL_T ) { @@ -449,7 +448,7 @@ std::map SCHEMATIC::GetVirtualPageToSheetNamesMap() const { std::map namesMap; - for( const SCH_SHEET_PATH& sheet : GetSheets() ) + for( const SCH_SHEET_PATH& sheet : GetUnorderedSheets() ) { if( sheet.size() == 1 ) namesMap[sheet.GetVirtualPageNumber()] = _( "" ); @@ -465,7 +464,7 @@ std::map SCHEMATIC::GetVirtualPageToSheetPagesMap() const { std::map pagesMap; - for( const SCH_SHEET_PATH& sheet : GetSheets() ) + for( const SCH_SHEET_PATH& sheet : GetUnorderedSheets() ) pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber(); return pagesMap; @@ -509,12 +508,11 @@ wxString SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const if( isCrossRef ) { - SCH_SHEET_LIST sheetList = GetSheets(); wxString remainder; wxString ref = token.BeforeFirst( ':', &remainder ); SCH_REFERENCE_LIST references; - sheetList.GetSymbols( references ); + GetUnorderedSheets().GetSymbols( references ); for( size_t jj = 0; jj < references.GetCount(); jj++ ) { @@ -565,12 +563,11 @@ wxString SCHEMATIC::ConvertKIIDsToRefs( const wxString& aSource ) const if( isCrossRef ) { - SCH_SHEET_LIST sheetList = GetSheets(); - wxString remainder; - wxString ref = token.BeforeFirst( ':', &remainder ); + wxString remainder; + wxString ref = token.BeforeFirst( ':', &remainder ); SCH_SHEET_PATH refSheetPath; - SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &refSheetPath ); + SCH_ITEM* refItem = GetItem( KIID( ref ), &refSheetPath ); if( refItem && refItem->Type() == SCH_SYMBOL_T ) { @@ -739,10 +736,10 @@ wxString SCHEMATIC::GetOperatingPoint( const wxString& aNetName, int aPrecision, void SCHEMATIC::FixupJunctions() { - for( const SCH_SHEET_PATH& sheet : GetSheets() ) - { - SCH_SCREEN* screen = sheet.LastScreen(); + SCH_SCREENS screens( Root() ); + for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() ) + { std::deque allItems; for( auto item : screen->Items() ) @@ -836,7 +833,7 @@ void SCHEMATIC::RecordERCExclusions() void SCHEMATIC::ResolveERCExclusionsPostUpdate() { - SCH_SHEET_LIST sheetList = GetSheets(); + SCH_SHEET_LIST sheetList = GetUnorderedSheets(); for( SCH_MARKER* marker : ResolveERCExclusions() ) { diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 81186a744d..1ebc3cfe2f 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -102,6 +102,18 @@ public: return SCH_SHEET_LIST( m_rootSheet ); } + SCH_SHEET_LIST GetUnorderedSheets() const + { + SCH_SHEET_LIST sheets; + sheets.BuildSheetList( m_rootSheet, false ); + return sheets; + } + + SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const + { + return GetUnorderedSheets().GetItem( aID, aPathOut ); + } + SCH_SHEET& Root() const { return *m_rootSheet; diff --git a/eeschema/tools/sch_navigate_tool.cpp b/eeschema/tools/sch_navigate_tool.cpp index 5db86f1a22..f027eb2e0d 100644 --- a/eeschema/tools/sch_navigate_tool.cpp +++ b/eeschema/tools/sch_navigate_tool.cpp @@ -201,7 +201,7 @@ bool SCH_NAVIGATE_TOOL::CanGoPrevious() bool SCH_NAVIGATE_TOOL::CanGoNext() { return m_frame->GetCurrentSheet().GetVirtualPageNumber() - < (int) m_frame->Schematic().GetSheets().size(); + < (int) m_frame->Schematic().GetUnorderedSheets().size(); }