From 813de6a1f304310a75a86c5706dbda64ecb984ab Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 18 May 2019 14:11:34 +0100 Subject: [PATCH] Implement brightening for Eeschema Find/Replace. --- eeschema/ee_collectors.cpp | 2 ++ eeschema/find.cpp | 31 +++++++++++++++------------- eeschema/tools/ee_selection_tool.cpp | 25 ++++++++++++++++++++++ eeschema/tools/ee_selection_tool.h | 3 +++ 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/eeschema/ee_collectors.cpp b/eeschema/ee_collectors.cpp index 95575fdbaf..0ab4c489d2 100644 --- a/eeschema/ee_collectors.cpp +++ b/eeschema/ee_collectors.cpp @@ -389,6 +389,8 @@ SEARCH_RESULT SCH_FIND_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData ) } Append( aItem ); + aItem->SetBrightened(); + m_data.push_back( SCH_FIND_COLLECTOR_DATA( position, m_currentSheetPath->PathHumanReadable(), (SCH_ITEM*) aTestData ) ); diff --git a/eeschema/find.cpp b/eeschema/find.cpp index de89c58fcc..dc55b4ef5a 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -55,7 +55,8 @@ #include #include - +#include +#include void SCH_EDIT_FRAME::OnFindDrcMarker( wxFindDialogEvent& event ) { @@ -263,6 +264,7 @@ bool SCH_EDIT_FRAME::IsSearchCacheObsolete( const SCH_FIND_REPLACE_DATA& aSearch void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent ) { + EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool(); SCH_FIND_REPLACE_DATA searchCriteria; SCH_FIND_COLLECTOR_DATA data; @@ -274,17 +276,18 @@ void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent ) { if( m_foundItems.GetCount() == 0 ) return; + + selectionTool->ClearBrightening(); } else if( IsSearchCacheObsolete( searchCriteria ) ) { if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 ) - { m_foundItems.Collect( searchCriteria, g_CurrentSheet ); - } else - { m_foundItems.Collect( searchCriteria ); - } + + for( EDA_ITEM* item : m_foundItems ) + selectionTool->BrightenItem( item ); } else { @@ -302,7 +305,8 @@ void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent ) void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) { - SCH_ITEM* item; + EE_SELECTION_TOOL* selectionTool = m_toolManager->GetTool(); + EDA_ITEM* item; SCH_SHEET_PATH* sheet; SCH_SHEET_LIST schematic( g_RootSheet ); SCH_FIND_COLLECTOR_DATA data; @@ -316,24 +320,23 @@ void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) if( IsSearchCacheObsolete( searchCriteria ) ) { if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 ) - { m_foundItems.Collect( searchCriteria, g_CurrentSheet ); - } else - { m_foundItems.Collect( searchCriteria ); - } + + for( EDA_ITEM* foundItem : m_foundItems ) + selectionTool->BrightenItem( foundItem ); } if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_REPLACE_ALL ) { - while( ( item = (SCH_ITEM*) m_foundItems.GetItem( data ) ) != NULL ) + while( ( item = m_foundItems.GetItem( data ) ) != NULL ) { SCH_ITEM* undoItem = data.GetParent(); // Don't save child items in undo list. if( undoItem == NULL ) - undoItem = item; + undoItem = (SCH_ITEM*) item; sheet = schematic.GetSheetByPath( data.GetSheetPath() ); @@ -355,14 +358,14 @@ void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) } else { - item = (SCH_ITEM*) m_foundItems.GetItem( data ); + item = m_foundItems.GetItem( data ); wxCHECK_RET( item != NULL, wxT( "Invalid replace item in find collector list." ) ); SCH_ITEM* undoItem = data.GetParent(); if( undoItem == NULL ) - undoItem = item; + undoItem = (SCH_ITEM*) item; sheet = schematic.GetSheetByPath( data.GetSheetPath() ); diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 68d279f1be..1dfb161df5 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -829,6 +829,31 @@ void EE_SELECTION_TOOL::RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode ) } +void EE_SELECTION_TOOL::BrightenItem( EDA_ITEM* aItem ) +{ + highlight( aItem, BRIGHTENED ); +} + + +void EE_SELECTION_TOOL::ClearBrightening() +{ + EDA_ITEM* start = nullptr; + + if( m_isLibEdit ) + start = static_cast( m_frame )->GetCurPart(); + else + start = m_frame->GetScreen()->GetDrawItems(); + + INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData ) + { + unhighlight( item, BRIGHTENED ); + return SEARCH_CONTINUE; + }; + + EDA_ITEM::IterateForward( start, inspector, nullptr, EE_COLLECTOR::AllItems ); +} + + int EE_SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent ) { clearSelection(); diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index 2c120a3a1c..e25020542e 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -116,6 +116,9 @@ public: int RemoveItemsFromSel( const TOOL_EVENT& aEvent ); void RemoveItemsFromSel( EDA_ITEMS* aList, bool aQuietMode = false ); + void BrightenItem( EDA_ITEM* aItem ); + void ClearBrightening(); + ///> Find (but don't select) node under cursor EDA_ITEM* GetNode( VECTOR2I aPosition );