HIERARCHY_PANE: Update tree labels when editing a sheet name or number

Fixes #16650
https://gitlab.com/kicad/code/kicad/-/issues/16650
This commit is contained in:
jean-pierre charras 2024-01-25 18:20:43 +01:00
parent a2b204572d
commit 2e760483b0
6 changed files with 80 additions and 3 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2016 Wayne Stambaugh, stambaughw@gmail.com
* Copyright (C) 2004-2023 KiCad Developers, see AITHORS.txt for contributors.
* Copyright (C) 2004-2024 KiCad Developers, see AITHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -617,6 +617,12 @@ void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* a
// convert any text variable cross-references to their UUIDs
m_text = aField->Schematic()->ConvertRefsToKIIDs( m_text );
// Changing a sheetname need to update the hierarchy navigator
bool needUpdateHierNav = false;
if( parent && parent->Type() == SCH_SHEET_T && fieldType == SHEETNAME )
needUpdateHierNav = m_text != aField->GetText();
aField->SetText( m_text );
updateText( aField );
aField->SetPosition( m_position );
@ -676,4 +682,8 @@ void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* a
if( positioningModified && parent )
parent->ClearFieldsAutoplaced();
//Update the hierarchy navigator labels if needed
if( needUpdateHierNav )
editFrame->UpdateLabelsHierarchyNavigator();
}

View File

@ -1143,6 +1143,14 @@ void SCH_EDIT_FRAME::UpdateHierarchyNavigator()
}
void SCH_EDIT_FRAME::UpdateLabelsHierarchyNavigator()
{
// Update only the hierarchy navigation tree labels.
// The tree list is expectyed to be up to date
m_hierarchy->UpdateLabelsHierarchyTree();
}
void SCH_EDIT_FRAME::UpdateHierarchySelection()
{
m_hierarchy->UpdateHierarchySelection();

View File

@ -4,7 +4,7 @@
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2023 CERN (www.cern.ch)
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -233,6 +233,13 @@ public:
*/
void UpdateHierarchyNavigator();
/**
* Update the hierarchy navigation tree labels.
* No change for the tree, only the labels are updated, after editing a sheet
* name or a sheet number.
*/
void UpdateLabelsHierarchyNavigator();
/**
* Update the hierarchy navigation tree selection (cross-probe from schematic to hierarchy
* pane).

View File

@ -2496,6 +2496,10 @@ int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent )
m_frame->OnModify();
// Update the hierarchy navigator labels if needed
if( pageNumber != dlg.GetValue() )
m_frame->UpdateLabelsHierarchyNavigator();
return 0;
}

View File

@ -263,6 +263,45 @@ void HIERARCHY_PANE::onSelectSheetPath( wxTreeEvent& aEvent )
}
void HIERARCHY_PANE::UpdateLabelsHierarchyTree()
{
// Update the labels of the hierarchical tree of the schematic.
// Must be called only for an up to date tree, to update displayed labels after
// a sheet name or a sheet number change.
std::function<void( const wxTreeItemId& )> updateLabel =
[&]( const wxTreeItemId& id )
{
TREE_ITEM_DATA* itemData = static_cast<TREE_ITEM_DATA*>( m_tree->GetItemData( id ) );
SCH_SHEET* sheet = itemData->m_SheetPath.Last();
wxString sheetNameLabel = formatPageString( sheet->GetFields()[SHEETNAME].GetShownText( false ),
itemData->m_SheetPath.GetPageNumber() );
if( m_tree->GetItemText( id ) != sheetNameLabel )
m_tree->SetItemText( id, sheetNameLabel );
};
wxTreeItemId rootId = m_tree->GetRootItem();
updateLabel( rootId );
std::function<void( const wxTreeItemId& )> recursiveDescent =
[&]( const wxTreeItemId& id )
{
wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) );
wxTreeItemIdValue cookie;
wxTreeItemId child = m_tree->GetFirstChild( id, cookie );
while( child.IsOk() )
{
updateLabel( child );
recursiveDescent( child );
child = m_tree->GetNextChild( id, cookie );
}
};
recursiveDescent( rootId );
}
void HIERARCHY_PANE::onRightClick( wxTreeEvent& aEvent )
{
wxTreeItemId itemSel = aEvent.GetItem();
@ -310,6 +349,8 @@ void HIERARCHY_PANE::onRightClick( wxTreeEvent& aEvent )
}
m_frame->OnModify();
UpdateLabelsHierarchyTree();
}
}
}

View File

@ -4,7 +4,7 @@
* Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2022 Mike Williams <mike at mikebwilliams.com>
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -81,6 +81,13 @@ public:
*/
void UpdateHierarchySelection();
/**
* Update the labels of the hierarchical tree of the schematic.
* Must be called only for an up to date tree, to update displayed labels after
* a sheet name or a sheet number change.
*/
void UpdateLabelsHierarchyTree();
private:
/**
* Create the hierarchical tree of the schematic.