From 6c9d8f1ae7224bbe09935b2a240089fc0f7df069 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 24 Oct 2022 23:00:10 +0100 Subject: [PATCH] GUI improvements to hierarchy navigator. (1) and (3) from the linked issue. Fixes https://gitlab.com/kicad/code/kicad/issues/11762 --- eeschema/hierarch.cpp | 25 ++++++++++++++++++++----- eeschema/sch_edit_frame.cpp | 6 ++++++ eeschema/sch_edit_frame.h | 6 ++++++ eeschema/tools/ee_inspection_tool.cpp | 3 +++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index d65758264a..a56a91d522 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -47,7 +47,7 @@ class TREE_ITEM_DATA : public wxTreeItemData public: SCH_SHEET_PATH m_SheetPath; - TREE_ITEM_DATA( SCH_SHEET_PATH& sheet ) : + TREE_ITEM_DATA( SCH_SHEET_PATH& sheet ) : wxTreeItemData() { m_SheetPath = sheet; @@ -151,7 +151,9 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection() m_events_bound = false; } - std::function selectSheet = + bool sheetSelected = false; + + std::function recursiveDescent = [&]( const wxTreeItemId& id ) { wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) ); @@ -159,9 +161,20 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection() TREE_ITEM_DATA* itemData = static_cast( m_tree->GetItemData( id ) ); if( itemData->m_SheetPath == m_frame->GetCurrentSheet() ) + { + m_tree->EnsureVisible( id ); + m_tree->SetItemBold( id, true ); + } + else + { + m_tree->SetItemBold( id, false ); + } + + if( itemData->m_SheetPath.Last()->IsSelected() ) { m_tree->EnsureVisible( id ); m_tree->SelectItem( id ); + sheetSelected = true; } wxTreeItemIdValue cookie; @@ -169,12 +182,15 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection() while( child.IsOk() ) { - selectSheet( child ); + recursiveDescent( child ); child = m_tree->GetNextChild( id, cookie ); } }; - selectSheet( m_tree->GetRootItem() ); + recursiveDescent( m_tree->GetRootItem() ); + + if( !sheetSelected && m_tree->GetSelection() ) + m_tree->SelectItem( m_tree->GetSelection(), false ); if( eventsWereBound ) { @@ -210,7 +226,6 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchyTree() m_tree->DeleteAllItems(); wxTreeItemId root = m_tree->AddRoot( getRootString(), 0, 1 ); - m_tree->SetItemBold( root, true ); m_tree->SetItemData( root, new TREE_ITEM_DATA( m_list ) ); buildHierarchyTree( &m_list, root ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 7981acb9d2..dd2b03d367 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1029,6 +1029,12 @@ void SCH_EDIT_FRAME::UpdateHierarchyNavigator() } +void SCH_EDIT_FRAME::UpdateHierarchySelection() +{ + m_hierarchy->UpdateHierarchySelection(); +} + + void SCH_EDIT_FRAME::ShowFindReplaceDialog( bool aReplace ) { wxString findString; diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index e9f5dd3ea4..68ef5402a9 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -209,6 +209,12 @@ public: */ void UpdateHierarchyNavigator(); + /** + * Update the hierarchy navigation tree selection (cross-probe from schematic to hierarchy + * pane). + */ + void UpdateHierarchySelection(); + void ShowFindReplaceStatus( const wxString& aMsg, int aStatusTime ); void ClearFindReplaceStatus(); diff --git a/eeschema/tools/ee_inspection_tool.cpp b/eeschema/tools/ee_inspection_tool.cpp index 5604111845..1d7ddb2077 100644 --- a/eeschema/tools/ee_inspection_tool.cpp +++ b/eeschema/tools/ee_inspection_tool.cpp @@ -325,7 +325,10 @@ int EE_INSPECTION_TOOL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) } if( SCH_EDIT_FRAME* editFrame = dynamic_cast( m_frame ) ) + { editFrame->UpdateNetHighlightStatus(); + editFrame->UpdateHierarchySelection(); + } return 0; }