From 30cbfc794f2162b78960e64e07e5aca8f088c7b3 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 7 Jun 2023 12:46:10 +0100 Subject: [PATCH] Cross-probing from Pin Table to Symbol Editor canvas. Fixes https://gitlab.com/kicad/code/kicad/-/issues/8301 --- .../dialogs/dialog_lib_edit_pin_table.cpp | 38 +++++++++++++++ eeschema/dialogs/dialog_lib_edit_pin_table.h | 3 +- .../dialog_lib_edit_pin_table_base.cpp | 4 ++ .../dialog_lib_edit_pin_table_base.fbp | 2 + .../dialogs/dialog_lib_edit_pin_table_base.h | 1 + eeschema/symbol_editor/symbol_edit_frame.cpp | 48 +++++++++++++++++++ eeschema/symbol_editor/symbol_edit_frame.h | 2 + 7 files changed, 97 insertions(+), 1 deletion(-) diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index fcefb2c402..142983a485 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -649,6 +649,11 @@ public: return removedRow; } + LIB_PINS GetRowPins( int aRow ) + { + return m_rows[ aRow ]; + } + bool IsEdited() { return m_edited; @@ -856,6 +861,11 @@ DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE() // m_pins will already be empty. for( LIB_PIN* pin : m_pins ) delete pin; + + WINDOW_THAWER thawer( m_editFrame ); + + m_editFrame->FocusOnItem( nullptr ); + m_editFrame->GetCanvas()->Refresh(); } @@ -1018,6 +1028,34 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnCellEdited( wxGridEvent& event ) } +void DIALOG_LIB_EDIT_PIN_TABLE::OnCellSelected( wxGridEvent& event ) +{ + LIB_PIN* pin = nullptr; + + if( event.GetRow() >= 0 && event.GetRow() < m_dataModel->GetNumberRows() ) + { + const LIB_PINS& pins = m_dataModel->GetRowPins( event.GetRow() ); + + if( pins.size() == 1 && m_editFrame->GetCurSymbol() ) + { + for( LIB_PIN* candidate : m_editFrame->GetCurSymbol()->GetAllLibPins() ) + { + if( candidate->GetNumber() == pins.at( 0 )->GetNumber() ) + { + pin = candidate; + break; + } + } + } + } + + WINDOW_THAWER thawer( m_editFrame ); + + m_editFrame->FocusOnItem( pin ); + m_editFrame->GetCanvas()->Refresh(); +} + + bool DIALOG_LIB_EDIT_PIN_TABLE::IsDisplayGrouped() { return m_cbGroup->GetValue(); diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.h b/eeschema/dialogs/dialog_lib_edit_pin_table.h index f9f0094d64..48d5bcb028 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.h +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.h @@ -65,6 +65,7 @@ public: void OnDeleteRow( wxCommandEvent& event ) override; void OnSize( wxSizeEvent& event ) override; void OnCellEdited( wxGridEvent& event ) override; + void OnCellSelected( wxGridEvent& event ) override; void OnRebuildRows( wxCommandEvent& event ) override; void OnGroupSelected( wxCommandEvent& event ) override; void OnFilterCheckBox( wxCommandEvent& event ) override; @@ -77,10 +78,10 @@ public: bool IsDisplayGrouped(); protected: - void updateSummary(); void adjustGridColumns(); +protected: SYMBOL_EDIT_FRAME* m_editFrame; bool m_initialized = false; int m_originalColWidths[ COL_COUNT ]; diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp index 0bdf4030cc..459f51c023 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp @@ -185,6 +185,8 @@ DIALOG_LIB_EDIT_PIN_TABLE_BASE::DIALOG_LIB_EDIT_PIN_TABLE_BASE( wxWindow* parent this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnClose ) ); this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnUpdateUI ) ); m_grid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCellEdited ), NULL, this ); + m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCellSelected ), NULL, this ); + m_grid->Connect( wxEVT_GRID_EDITOR_SHOWN, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCellSelected ), NULL, this ); m_grid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnSize ), NULL, this ); m_addButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnAddRow ), NULL, this ); m_deleteButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnDeleteRow ), NULL, this ); @@ -202,6 +204,8 @@ DIALOG_LIB_EDIT_PIN_TABLE_BASE::~DIALOG_LIB_EDIT_PIN_TABLE_BASE() this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnClose ) ); this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnUpdateUI ) ); m_grid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCellEdited ), NULL, this ); + m_grid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCellSelected ), NULL, this ); + m_grid->Disconnect( wxEVT_GRID_EDITOR_SHOWN, wxGridEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnCellSelected ), NULL, this ); m_grid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnSize ), NULL, this ); m_addButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnAddRow ), NULL, this ); m_deleteButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnDeleteRow ), NULL, this ); diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp b/eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp index 1aac172991..d24436ae8a 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp @@ -556,6 +556,8 @@ OnCellEdited + OnCellSelected + OnCellSelected OnSize diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table_base.h b/eeschema/dialogs/dialog_lib_edit_pin_table_base.h index 95dca0fcde..ad9fcb04ed 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table_base.h +++ b/eeschema/dialogs/dialog_lib_edit_pin_table_base.h @@ -67,6 +67,7 @@ class DIALOG_LIB_EDIT_PIN_TABLE_BASE : public DIALOG_SHIM virtual void OnClose( wxCloseEvent& event ) = 0; virtual void OnUpdateUI( wxUpdateUIEvent& event ) = 0; virtual void OnCellEdited( wxGridEvent& event ) = 0; + virtual void OnCellSelected( wxGridEvent& event ) = 0; virtual void OnSize( wxSizeEvent& event ) = 0; virtual void OnAddRow( wxCommandEvent& event ) = 0; virtual void OnDeleteRow( wxCommandEvent& event ) = 0; diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index d3d2f366e2..f167bec1a4 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -1303,6 +1303,54 @@ const BOX2I SYMBOL_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) con } +void SYMBOL_EDIT_FRAME::FocusOnItem( LIB_ITEM* aItem ) +{ + static KIID lastBrightenedItemID( niluuid ); + + LIB_ITEM* lastItem = nullptr; + + if( m_symbol ) + { + for( LIB_PIN* pin : m_symbol->GetAllLibPins() ) + { + if( pin->m_Uuid == lastBrightenedItemID ) + lastItem = pin; + } + + std::vector fields; + + m_symbol->GetFields( fields ); + + for( LIB_FIELD* field : fields ) + { + if( field->m_Uuid == lastBrightenedItemID ) + lastItem = field; + } + } + + if( lastItem && lastItem != aItem ) + { + lastItem->ClearBrightened(); + + UpdateItem( lastItem ); + lastBrightenedItemID = niluuid; + } + + if( aItem ) + { + if( !aItem->IsBrightened() ) + { + aItem->SetBrightened(); + + UpdateItem( aItem ); + lastBrightenedItemID = aItem->m_Uuid; + } + + FocusOnLocation( VECTOR2I( aItem->GetFocusPosition().x, -aItem->GetFocusPosition().y ) ); + } +} + + void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) { const std::string& payload = mail.GetPayload(); diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index b363f26a21..b3fa43408f 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -374,6 +374,8 @@ public: void KiwayMailIn( KIWAY_EXPRESS& mail ) override; + void FocusOnItem( LIB_ITEM* aItem ); + /** * Load a symbol from the schematic to edit in place. *