Initialize shared sheet instance page no's in drawing tool.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16580
This commit is contained in:
Jeff Young 2024-01-19 18:45:08 +00:00
parent 7c3f8cbb79
commit ac4f9dc97a
2 changed files with 29 additions and 0 deletions

View File

@ -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 ) int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
{ {
SCH_SHEET* sheet = nullptr; SCH_SHEET* sheet = nullptr;
@ -2113,6 +2136,10 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
commit.Add( sheet, m_frame->GetScreen() ); commit.Add( sheet, m_frame->GetScreen() );
commit.Push( "Draw Sheet" ); commit.Push( "Draw Sheet" );
SCH_SHEET_PATH newPath = m_frame->GetCurrentSheet();
newPath.push_back( sheet );
initSharedInstancePageNumbers( newPath );
m_frame->UpdateHierarchyNavigator(); m_frame->UpdateHierarchyNavigator();
m_selectionTool->AddItemToSel( sheet ); m_selectionTool->AddItemToSel( sheet );
} }

View File

@ -69,6 +69,8 @@ private:
void sizeSheet( SCH_SHEET* aSheet, const VECTOR2I& aPos ); void sizeSheet( SCH_SHEET* aSheet, const VECTOR2I& aPos );
void initSharedInstancePageNumbers( const SCH_SHEET_PATH& aAddedSheet );
///< Set up handlers for various events. ///< Set up handlers for various events.
void setTransitions() override; void setTransitions() override;