From 6b764f893a8e1780c6be703ecebe0fd2908eac9d Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Fri, 21 May 2021 18:24:38 +0100 Subject: [PATCH] Assign a page number to all sheet instances when adding a sheet Fixes https://gitlab.com/kicad/code/kicad/-/issues/8208 --- eeschema/dialogs/dialog_sheet_properties.cpp | 7 +------ eeschema/tools/sch_drawing_tools.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index 1eff396706..0c599189f7 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -166,12 +166,7 @@ bool DIALOG_SHEET_PROPERTIES::TransferDataToWindow() instance.push_back( m_sheet ); - wxString nextPageNumber; - - if( m_sheet->IsNew() ) - nextPageNumber.Printf( "%d", static_cast( hierarchy.size() ) + 1 ); - else - nextPageNumber = m_sheet->GetPageNumber( instance ); + wxString nextPageNumber = m_sheet->GetPageNumber( instance ); m_pageNumberTextCtrl->ChangeValue( nextPageNumber ); diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index c2559ef7bf..3fec4651ff 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -1345,6 +1345,24 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) getViewControls()->SetAutoPan( false ); getViewControls()->CaptureCursor( false ); + // Find the list of paths in the hierarchy that refer to the destination sheet where + // the new sheet will be drawn + SCH_SCREEN* currentScreen = m_frame->GetCurrentSheet().LastScreen(); + SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets(); + SCH_SHEET_LIST instances = hierarchy.FindAllSheetsForScreen( currentScreen ); + instances.SortByPageNumbers(); + + int pageNum = static_cast( hierarchy.size() ) + 1; + + // Set a page number for all the instances of the new sheet in the hierarchy + for( SCH_SHEET_PATH& instance : instances ) + { + SCH_SHEET_PATH sheetPath = instance; + sheetPath.push_back( sheet ); + sheet->AddInstance( sheetPath.Path() ); + sheet->SetPageNumber( sheetPath, wxString::Format( "%d", pageNum++ ) ); + } + if( m_frame->EditSheetProperties( static_cast( sheet ), &m_frame->GetCurrentSheet(), nullptr ) ) {