diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 1ea600f9be..4c39a6860c 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -343,7 +343,7 @@ void DIALOG_ERC::OnCancelClick( wxCommandEvent& aEvent ) return; } - m_parent->FocusOnItem( nullptr ); + m_parent->ClearFocus(); aEvent.Skip(); } @@ -351,7 +351,7 @@ void DIALOG_ERC::OnCancelClick( wxCommandEvent& aEvent ) void DIALOG_ERC::OnCloseErcDialog( wxCloseEvent& aEvent ) { - m_parent->FocusOnItem( nullptr ); + m_parent->ClearFocus(); // Dialog is mode-less so let the parent know that it needs to be destroyed. if( !IsModal() && !IsQuasiModal() ) diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index fe7b1b9d63..5b60bbf644 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -877,7 +877,7 @@ DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE() WINDOW_THAWER thawer( m_editFrame ); - m_editFrame->FocusOnItem( nullptr ); + m_editFrame->ClearFocus(); m_editFrame->GetCanvas()->Refresh(); } diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index 190792c5ca..99db878a50 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -1201,7 +1201,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected( wxGridRangeSelectEvent& a } else { - m_parent->FocusOnItem( nullptr ); + m_parent->ClearFocus(); } } else if( m_radioSelect->GetValue() ) @@ -1553,7 +1553,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnClose( wxCloseEvent& aEvent ) } } - m_parent->FocusOnItem( nullptr ); + m_parent->ClearFocus(); wxCommandEvent* evt = new wxCommandEvent( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, wxID_ANY ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 5acfd0d1b7..93bbebc500 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -926,7 +926,7 @@ void SCH_EDIT_FRAME::SetCurrentSheet( const SCH_SHEET_PATH& aSheet ) { if( aSheet != GetCurrentSheet() ) { - FocusOnItem( nullptr ); + ClearFocus(); Schematic().SetCurrentSheet( aSheet ); GetCanvas()->DisplaySheet( aSheet.LastScreen() ); @@ -950,7 +950,7 @@ void SCH_EDIT_FRAME::HardRedraw() if( Schematic().Settings().m_IntersheetRefsShow ) RecomputeIntersheetRefs(); - FocusOnItem( nullptr ); + ClearFocus(); GetCanvas()->DisplaySheet( GetCurrentSheet().LastScreen() ); @@ -2285,8 +2285,12 @@ bool SCH_EDIT_FRAME::GetShowAllPins() const } -void SCH_EDIT_FRAME::FocusOnItem( SCH_ITEM* aItem ) +void SCH_EDIT_FRAME::FocusOnItem( EDA_ITEM* aItem ) { + // nullptr will clear the current focus + if( aItem != nullptr && !aItem->IsSCH_ITEM() ) + return; + static KIID lastBrightenedItemID( niluuid ); SCH_SHEET_PATH dummy; diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index a59147a890..b7e4c53be8 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -814,7 +814,7 @@ public: int GetSchematicJunctionSize(); - void FocusOnItem( SCH_ITEM* aItem ); + void FocusOnItem( EDA_ITEM* aItem ) override; bool IsSyncingSelection() { return m_syncingPcbToSchSelection; } diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 8717432dde..c5ccd07499 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -1496,12 +1496,16 @@ const BOX2I SYMBOL_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) con } -void SYMBOL_EDIT_FRAME::FocusOnItem( SCH_ITEM* aItem ) +void SYMBOL_EDIT_FRAME::FocusOnItem( EDA_ITEM* aItem ) { static KIID lastBrightenedItemID( niluuid ); SCH_ITEM* lastItem = nullptr; + // nullptr will clear the current focus + if( aItem != nullptr && !aItem->IsSCH_ITEM() ) + return; + if( m_symbol ) { for( SCH_PIN* pin : m_symbol->GetPins() ) diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index 337fe26f85..1396d5b027 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -372,7 +372,7 @@ public: void KiwayMailIn( KIWAY_EXPRESS& mail ) override; - void FocusOnItem( SCH_ITEM* aItem ); + void FocusOnItem( EDA_ITEM* aItem ) override; /** * Load a symbol from the schematic to edit in place. diff --git a/eeschema/tools/sch_navigate_tool.cpp b/eeschema/tools/sch_navigate_tool.cpp index 76e3079aa0..e50c3cef49 100644 --- a/eeschema/tools/sch_navigate_tool.cpp +++ b/eeschema/tools/sch_navigate_tool.cpp @@ -306,7 +306,7 @@ void SCH_NAVIGATE_TOOL::changeSheet( SCH_SHEET_PATH aPath ) pushToHistory( aPath ); - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); m_frame->Schematic().SetCurrentSheet( aPath ); m_frame->DisplayCurrentSheet(); } diff --git a/eeschema/tools/sch_selection_tool.cpp b/eeschema/tools/sch_selection_tool.cpp index 4e8efc1568..7e7fe28982 100644 --- a/eeschema/tools/sch_selection_tool.cpp +++ b/eeschema/tools/sch_selection_tool.cpp @@ -471,7 +471,7 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) m_disambiguateTimer.Stop(); if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) ) - schframe->FocusOnItem( nullptr ); + schframe->ClearFocus(); // Collect items at the clicked location (doesn't select them yet) SCH_COLLECTOR collector; @@ -558,7 +558,7 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // double click? Display the properties window if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) ) - schframe->FocusOnItem( nullptr ); + schframe->ClearFocus(); if( m_selection.Empty() ) SelectPoint( evt->Position() ); @@ -594,7 +594,7 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // drag with LMB? Select multiple objects (or at least draw a selection box) or // drag them if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) ) - schframe->FocusOnItem( nullptr ); + schframe->ClearFocus(); SCH_COLLECTOR collector; @@ -940,7 +940,7 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) getViewControls()->CaptureCursor( false ); if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) ) - schframe->FocusOnItem( nullptr ); + schframe->ClearFocus(); if( !GetSelection().Empty() ) { @@ -957,7 +957,7 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) else if( evt->Action() == TA_UNDO_REDO_PRE ) { if( SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) ) - schframe->FocusOnItem( nullptr ); + schframe->ClearFocus(); } else if( evt->IsMotion() && !m_isSymbolEditor && evt->FirstResponder() == this ) { diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index 808652a586..011c1ef1f7 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -305,6 +305,15 @@ public: */ void FocusOnLocation( const VECTOR2I& aPos ); + /** + * Focus on a particular canvas item. + * + * @param aItem is the item to focus on. nullptr clears the focus. + */ + virtual void FocusOnItem( EDA_ITEM* aItem ) {} + + virtual void ClearFocus() { FocusOnItem( nullptr ); } + /** * Construct a "basic" menu for a tool, containing only items that apply to all tools * (e.g. zoom and grid). diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 9042e12c80..53bf3d5a62 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -216,6 +216,7 @@ public: EDA_ITEM* GetItem( const KIID& aId ) const override; + void FocusOnItem( EDA_ITEM* aItem ) override; void FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer = UNDEFINED_LAYER ); void FocusOnItems( std::vector<BOARD_ITEM*> aItems, PCB_LAYER_ID aLayer = UNDEFINED_LAYER ); diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index 934b2f13e7..9f104478ff 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -163,7 +163,7 @@ DIALOG_DRC::DIALOG_DRC( PCB_EDIT_FRAME* aEditorFrame, wxWindow* aParent ) : DIALOG_DRC::~DIALOG_DRC() { - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); g_lastDRCBoard = m_currentBoard; g_lastDRCRun = m_drcRun; @@ -1097,7 +1097,7 @@ void DIALOG_DRC::OnCancelClick( wxCommandEvent& aEvent ) return; } - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); SetReturnCode( wxID_CANCEL ); diff --git a/pcbnew/dialogs/dialog_footprint_checker.cpp b/pcbnew/dialogs/dialog_footprint_checker.cpp index 58cb4882c7..cca6e6fe00 100644 --- a/pcbnew/dialogs/dialog_footprint_checker.cpp +++ b/pcbnew/dialogs/dialog_footprint_checker.cpp @@ -69,7 +69,7 @@ DIALOG_FOOTPRINT_CHECKER::DIALOG_FOOTPRINT_CHECKER( FOOTPRINT_EDIT_FRAME* aParen DIALOG_FOOTPRINT_CHECKER::~DIALOG_FOOTPRINT_CHECKER() { - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); g_lastFootprint = m_frame->GetBoard()->GetFirstFootprint(); g_lastChecksRun = m_checksRun; @@ -364,7 +364,7 @@ void DIALOG_FOOTPRINT_CHECKER::OnSeverity( wxCommandEvent& aEvent ) void DIALOG_FOOTPRINT_CHECKER::OnCancelClick( wxCommandEvent& aEvent ) { - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); SetReturnCode( wxID_CANCEL ); diff --git a/pcbnew/dialogs/dialog_group_properties.cpp b/pcbnew/dialogs/dialog_group_properties.cpp index 43ebf4458e..939c360e30 100644 --- a/pcbnew/dialogs/dialog_group_properties.cpp +++ b/pcbnew/dialogs/dialog_group_properties.cpp @@ -65,7 +65,7 @@ DIALOG_GROUP_PROPERTIES::~DIALOG_GROUP_PROPERTIES() if( m_brdEditor->IsBeingDeleted() ) return; - m_brdEditor->FocusOnItem( nullptr ); + m_brdEditor->ClearFocus(); m_brdEditor->GetCanvas()->Refresh(); } @@ -162,7 +162,7 @@ void DIALOG_GROUP_PROPERTIES::OnRemoveMember( wxCommandEvent& event ) if( selected >= 0 ) m_membersList->Delete( selected ); - m_brdEditor->FocusOnItem( nullptr ); + m_brdEditor->ClearFocus(); m_brdEditor->GetCanvas()->Refresh(); } diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 70558b9bdb..797e7c7cfe 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -247,6 +247,14 @@ EDA_ITEM* PCB_BASE_FRAME::GetItem( const KIID& aId ) const return GetBoard()->GetItem( aId ); } +void PCB_BASE_FRAME::FocusOnItem( EDA_ITEM* aItem ) +{ + // nullptr will clear the current focus + if( aItem != nullptr && !aItem->IsBOARD_ITEM() ) + return; + + FocusOnItem( static_cast<BOARD_ITEM*>( aItem ), UNDEFINED_LAYER ); +} void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer ) { diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index ff8ee2f67c..621271f077 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -336,7 +336,7 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } else { - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); selectPoint( evt->Position() ); } } @@ -377,7 +377,7 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } // Double click? Display the properties window - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); if( m_selection.Empty() ) selectPoint( evt->Position() ); @@ -429,7 +429,7 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // Drag with LMB? Select multiple objects (or at least draw a selection box) // or drag them - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); m_toolMgr->ProcessEvent( EVENTS::InhibitSelectionEditing ); GENERAL_COLLECTORS_GUIDE guide = getCollectorsGuide(); @@ -539,7 +539,7 @@ int PCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) else if( evt->IsCancel() ) { m_disambiguateTimer.Stop(); - m_frame->FocusOnItem( nullptr ); + m_frame->ClearFocus(); if( !GetSelection().Empty() ) {