diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 74946fc05c..569d3fae04 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -1956,6 +1956,29 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) } +void SCH_DRAWING_TOOLS::initSharedInstancePageNumbers( const SCH_SHEET_PATH& aAddedSheet ) +{ + SCH_SHEET_LIST fullHierarchy = m_frame->Schematic().GetFullHierarchy(); + SCH_SHEET_LIST instances = fullHierarchy.FindAllSheetsForScreen( aAddedSheet.LastScreen() ); + + long pageNo; + long addedSheetPageNo; + + if( aAddedSheet.GetPageNumber().ToLong( &addedSheetPageNo ) ) + pageNo = addedSheetPageNo + 1; + else + pageNo = (signed)( fullHierarchy.size() - instances.size() + 1 ); + + for( SCH_SHEET_PATH& sheet : instances ) + { + if( sheet == aAddedSheet ) + continue; + + sheet.SetPageNumber( wxString::Format( wxS( "%ld" ), pageNo++ ) ); + } +} + + int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) { SCH_SHEET* sheet = nullptr; @@ -2113,6 +2136,10 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) commit.Add( sheet, m_frame->GetScreen() ); commit.Push( "Draw Sheet" ); + SCH_SHEET_PATH newPath = m_frame->GetCurrentSheet(); + newPath.push_back( sheet ); + initSharedInstancePageNumbers( newPath ); + m_frame->UpdateHierarchyNavigator(); m_selectionTool->AddItemToSel( sheet ); } diff --git a/eeschema/tools/sch_drawing_tools.h b/eeschema/tools/sch_drawing_tools.h index fd47e53813..2211552e76 100644 --- a/eeschema/tools/sch_drawing_tools.h +++ b/eeschema/tools/sch_drawing_tools.h @@ -69,6 +69,8 @@ private: void sizeSheet( SCH_SHEET* aSheet, const VECTOR2I& aPos ); + void initSharedInstancePageNumbers( const SCH_SHEET_PATH& aAddedSheet ); + ///< Set up handlers for various events. void setTransitions() override;