From 6ae8968a5b6d981938849c8e54f265c7d5e211eb Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Mon, 7 Aug 2023 13:49:27 -0400 Subject: [PATCH] Symbol Fields Table: add selection controls Allows cross-probing to other editors. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/8188 --- .../dialogs/dialog_symbol_fields_table.cpp | 82 +++++++----- eeschema/dialogs/dialog_symbol_fields_table.h | 2 +- .../dialog_symbol_fields_table_base.cpp | 14 +- .../dialog_symbol_fields_table_base.fbp | 120 +++++++++++------- .../dialogs/dialog_symbol_fields_table_base.h | 4 +- eeschema/eeschema_settings.cpp | 3 + eeschema/eeschema_settings.h | 1 + eeschema/sch_item.cpp | 2 +- eeschema/sch_reference_list.h | 5 + eeschema/tools/ee_selection_tool.cpp | 6 +- 10 files changed, 160 insertions(+), 79 deletions(-) diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index 624dbe9714..55da4ffbb7 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -280,6 +280,7 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent ) SetSize( dlgSize ); m_nbPages->SetSelection( cfg->m_FieldEditorPanel.page ); + m_radioSelect->SetSelection( cfg->m_FieldEditorPanel.selection_mode ); m_outputFileName->SetValue( cfg->m_FieldEditorPanel.export_filename ); @@ -290,8 +291,8 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent ) wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), nullptr, this ); m_grid->Connect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColMove ), nullptr, this ); - m_grid->Connect( wxEVT_GRID_RANGE_SELECT, - wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected ), + m_grid->Connect( wxEVT_GRID_RANGE_SELECTED, + wxGridRangeSelectEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected ), nullptr, this ); m_cbBomPresets->Bind( wxEVT_CHOICE, &DIALOG_SYMBOL_FIELDS_TABLE::onBomPresetChanged, this ); m_cbBomFmtPresets->Bind( wxEVT_CHOICE, &DIALOG_SYMBOL_FIELDS_TABLE::onBomFmtPresetChanged, this ); @@ -421,6 +422,8 @@ DIALOG_SYMBOL_FIELDS_TABLE::~DIALOG_SYMBOL_FIELDS_TABLE() cfg->m_FieldEditorPanel.height = GetSize().y; cfg->m_FieldEditorPanel.page = m_nbPages->GetSelection(); cfg->m_FieldEditorPanel.export_filename = m_outputFileName->GetValue(); + cfg->m_FieldEditorPanel.selection_mode = m_radioSelect->GetSelection(); + for( int i = 0; i < m_grid->GetNumberCols(); i++ ) { @@ -964,9 +967,9 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnTableCellClick( wxGridEvent& event ) if( m_dataModel->ColIsReference( event.GetCol() ) ) { m_grid->ClearSelection(); - m_grid->SetGridCursor( event.GetRow(), event.GetCol() ); m_dataModel->ExpandCollapseRow( event.GetRow() ); + m_grid->SetGridCursor( event.GetRow(), event.GetCol() ); } else { @@ -974,41 +977,58 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnTableCellClick( wxGridEvent& event ) } } -void DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected( wxGridEvent& event ) +void DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected( wxGridRangeSelectEvent& aEvent ) { - wxGridCellCoordsArray selectedCells = m_grid->GetSelectedCells(); + // Multi-select can grab the rows that are expanded child refs, and also the row + // containing the list of all child refs. Make sure we add refs/symbols uniquely + std::set refs; + std::set symbols; - if( selectedCells.GetCount() == 1 ) + // This handler handles selecting and deselecting + if( aEvent.Selecting() ) { - int row = selectedCells[0].GetRow(); - int flag = m_dataModel->GetRowFlags( row ); - std::vector refs = m_dataModel->GetRowReferences( row ); + for( int i = aEvent.GetTopRow(); i <= aEvent.GetBottomRow(); i++ ) + for( SCH_REFERENCE ref : m_dataModel->GetRowReferences( i ) ) + refs.insert( ref ); - // Focus Eeschema view on the symbol selected in the dialog - // TODO: Highlight or select more than one unit - if( ( flag == GROUP_SINGLETON || flag == CHILD_ITEM ) && refs.size() >= 1 ) - { - SCH_EDITOR_CONTROL* editor = m_parent->GetToolManager()->GetTool(); - - std::sort( refs.begin(), refs.end(), - []( const SCH_REFERENCE& a, const SCH_REFERENCE& b ) - { - return a.GetUnit() < b.GetUnit(); - } ); - - // search and highlight the symbol found by its full path. - // It allows select of not yet annotated or duplicaded symbols - wxString symbol_path = refs[0].GetFullPath(); - // wxString reference = refs[0].GetRef() + refs[0].GetRefNumber(); // Not used - editor->FindSymbolAndItem( &symbol_path, nullptr, true, HIGHLIGHT_SYMBOL, wxEmptyString ); - } - - return; + for( const SCH_REFERENCE& ref : refs ) + symbols.insert( ref.GetSymbol() ); } - event.Skip(); -} + switch( m_radioSelect->GetSelection() ) + { + case 0: + { + SCH_EDITOR_CONTROL* editor = m_parent->GetToolManager()->GetTool(); + // Use of full path based on UUID allows select of not yet annotated or duplicaded symbols + wxString symbol_path = refs.begin()->GetFullPath(); + + if( refs.size() > 0 ) + // Focus only handles on item at this time + editor->FindSymbolAndItem( &symbol_path, nullptr, true, HIGHLIGHT_SYMBOL, + wxEmptyString ); + else + m_parent->FocusOnItem( nullptr ); + + break; + } + case 1: + { + EE_SELECTION_TOOL* selTool = m_parent->GetToolManager()->GetTool(); + + std::vector items( symbols.begin(), symbols.end() ); + + if( refs.size() > 0 ) + selTool->SyncSelection( refs.begin()->GetSheetPath(), nullptr, items ); + else + selTool->ClearSelection(); + + break; + } + default: break; + } +} void DIALOG_SYMBOL_FIELDS_TABLE::OnTableItemContextMenu( wxGridEvent& event ) { // TODO: Option to select footprint if FOOTPRINT column selected diff --git a/eeschema/dialogs/dialog_symbol_fields_table.h b/eeschema/dialogs/dialog_symbol_fields_table.h index 81a574ade7..4db936fb0a 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.h +++ b/eeschema/dialogs/dialog_symbol_fields_table.h @@ -61,7 +61,7 @@ private: void OnColSort( wxGridEvent& aEvent ); void OnColMove( wxGridEvent& aEvent ); void OnColLabelChange( wxDataViewEvent& aEvent ); - void OnTableRangeSelected( wxGridEvent& event ); + void OnTableRangeSelected( wxGridRangeSelectEvent& aEvent ); void OnColumnItemToggled( wxDataViewEvent& event ) override; void OnGroupSymbolsToggled( wxCommandEvent& event ) override; diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.cpp b/eeschema/dialogs/dialog_symbol_fields_table_base.cpp index e371518309..0e82715fa1 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-282-g1fa54006) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -119,6 +119,18 @@ DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE( wxWindow* pare bRightSizer->Add( bControls, 0, wxEXPAND|wxLEFT, 5 ); + wxBoxSizer* bControls1; + bControls1 = new wxBoxSizer( wxHORIZONTAL ); + + wxString m_radioSelectChoices[] = { _("Highlight"), _("Select"), _("Off") }; + int m_radioSelectNChoices = sizeof( m_radioSelectChoices ) / sizeof( wxString ); + m_radioSelect = new wxRadioBox( m_rightPanel, wxID_ANY, _("Selection Control"), wxDefaultPosition, wxDefaultSize, m_radioSelectNChoices, m_radioSelectChoices, 3, wxRA_SPECIFY_COLS ); + m_radioSelect->SetSelection( 0 ); + bControls1->Add( m_radioSelect, 0, wxALL, 5 ); + + + bRightSizer->Add( bControls1, 0, wxEXPAND|wxLEFT, 5 ); + m_grid = new WX_GRID( m_rightPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); // Grid diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.fbp b/eeschema/dialogs/dialog_symbol_fields_table_base.fbp index 82a569a244..b4c025952b 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.fbp +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.fbp @@ -36,7 +36,6 @@ wxBOTH 1 - 0 1 impl_virtual @@ -89,7 +88,6 @@ Dock 0 Left - 0 1 1 @@ -147,7 +145,6 @@ Dock 0 Left - 0 1 1 @@ -208,7 +205,6 @@ Dock 0 Left - 0 1 1 @@ -267,7 +263,6 @@ Dock 0 Left - 0 1 1 @@ -337,7 +332,6 @@ Dock 0 Left - 0 1 1 @@ -400,7 +394,6 @@ Dock 0 Left - 0 1 1 @@ -449,7 +442,6 @@ 1 - 0 1 @@ -511,7 +503,6 @@ Dock 0 Left - 0 1 1 @@ -586,7 +577,6 @@ Dock 0 Left - 0 1 1 @@ -661,7 +651,6 @@ Dock 0 Left - 0 1 1 @@ -733,7 +722,6 @@ Dock 0 Left - 0 1 1 @@ -804,7 +792,6 @@ Dock 0 Left - 0 1 1 @@ -876,7 +863,6 @@ Dock 0 Left - 0 0 1 @@ -946,7 +932,6 @@ Dock 0 Left - 0 1 1 @@ -1016,7 +1001,6 @@ Dock 0 Left - 0 0 1 @@ -1086,7 +1070,6 @@ Dock 0 Left - 0 1 1 @@ -1156,7 +1139,6 @@ Dock 0 Left - 0 0 1 @@ -1230,7 +1212,6 @@ Dock 0 Left - 0 1 1 @@ -1277,6 +1258,83 @@ + + 5 + wxEXPAND|wxLEFT + 0 + + + bControls1 + wxHORIZONTAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "Highlight" "Select" "Off" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Selection Control + 3 + + 0 + + + 0 + + 1 + m_radioSelect + 1 + + + protected + 1 + + Resizable + 0 + 1 + + wxRA_SPECIFY_COLS + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT|wxTOP @@ -1315,7 +1373,6 @@ Dock 0 Left - 0 1 1 0 @@ -1404,7 +1461,6 @@ Dock 0 Left - 0 1 1 @@ -1490,7 +1546,6 @@ Dock 0 Left - 0 1 1 @@ -1553,7 +1608,6 @@ Dock 0 Left - 0 1 1 @@ -1617,7 +1671,6 @@ Dock 0 Left - 0 1 1 @@ -1679,7 +1732,6 @@ Dock 0 Left - 0 1 1 @@ -1745,7 +1797,6 @@ Dock 0 Left - 0 1 1 @@ -1807,7 +1858,6 @@ Dock 0 Left - 0 1 1 @@ -1873,7 +1923,6 @@ Dock 0 Left - 0 1 1 @@ -1935,7 +1984,6 @@ Dock 0 Left - 0 1 1 @@ -2001,7 +2049,6 @@ Dock 0 Left - 0 1 1 @@ -2063,7 +2110,6 @@ Dock 0 Left - 0 1 1 @@ -2129,7 +2175,6 @@ Dock 0 Left - 0 1 1 @@ -2192,7 +2237,6 @@ Dock 0 Left - 0 1 1 @@ -2257,7 +2301,6 @@ Dock 0 Left - 0 1 1 @@ -2320,7 +2363,6 @@ Dock 0 Left - 0 1 1 @@ -2399,7 +2441,6 @@ Dock 0 Left - 0 1 1 @@ -2461,7 +2502,6 @@ Dock 0 Left - 0 1 1 @@ -2531,7 +2571,6 @@ Dock 0 Left - 0 1 1 @@ -2615,7 +2654,6 @@ Dock 0 Left - 0 1 1 @@ -2692,7 +2730,6 @@ Dock 0 Left - 0 1 1 @@ -2767,7 +2804,6 @@ Dock 0 Left - 0 1 1 @@ -2861,7 +2897,6 @@ Dock 0 Left - 0 1 1 @@ -2936,7 +2971,6 @@ Dock 0 Left - 0 1 1 diff --git a/eeschema/dialogs/dialog_symbol_fields_table_base.h b/eeschema/dialogs/dialog_symbol_fields_table_base.h index b29f41bbe1..532ed3ed11 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table_base.h +++ b/eeschema/dialogs/dialog_symbol_fields_table_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-282-g1fa54006) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -31,6 +31,7 @@ class WX_GRID; #include #include #include +#include #include #include #include @@ -68,6 +69,7 @@ class DIALOG_SYMBOL_FIELDS_TABLE_BASE : public DIALOG_SHIM wxCheckBox* m_groupSymbolsBox; BITMAP_BUTTON* m_separator3; wxBitmapButton* m_bRefresh; + wxRadioBox* m_radioSelect; WX_GRID* m_grid; wxPanel* m_panelExport; wxStaticText* m_labelBomExportPresets; diff --git a/eeschema/eeschema_settings.cpp b/eeschema/eeschema_settings.cpp index 77d53a9b1b..4880006b58 100644 --- a/eeschema/eeschema_settings.cpp +++ b/eeschema/eeschema_settings.cpp @@ -459,6 +459,9 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() : m_params.emplace_back( new PARAM( "field_editor.export_filename", &m_FieldEditorPanel.export_filename, wxT( "" ) ) ); + m_params.emplace_back( new PARAM( "field_editor.selection_mode", + &m_FieldEditorPanel.selection_mode, 0 ) ); + m_params.emplace_back( new PARAM( "plot.background_color", &m_PlotPanel.background_color, false ) ); diff --git a/eeschema/eeschema_settings.h b/eeschema/eeschema_settings.h index 79e9c81895..4d31b0775f 100644 --- a/eeschema/eeschema_settings.h +++ b/eeschema/eeschema_settings.h @@ -220,6 +220,7 @@ public: int height; int page; wxString export_filename; + int selection_mode; }; struct PANEL_LIB_VIEW diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index f9b97bf7d5..8b311cfc39 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -381,4 +381,4 @@ static struct SCH_ITEM_DESC } } _SCH_ITEM_DESC; -IMPLEMENT_ENUM_TO_WXANY( SCH_LAYER_ID ) \ No newline at end of file +IMPLEMENT_ENUM_TO_WXANY( SCH_LAYER_ID ) diff --git a/eeschema/sch_reference_list.h b/eeschema/sch_reference_list.h index 8bd49e06c7..7316055d0e 100644 --- a/eeschema/sch_reference_list.h +++ b/eeschema/sch_reference_list.h @@ -126,6 +126,11 @@ public: return m_sheetPath.PathAsString() + m_symbolUuid.AsString(); } + /* + * Compares by full path to make std::set work + */ + bool operator<( const SCH_REFERENCE& aRef ) const { return GetFullPath() < aRef.GetFullPath(); } + /** * Update the annotation of the symbol according the current object state. */ diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 3acd3ae387..56b8be1455 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -1744,7 +1744,11 @@ void EE_SELECTION_TOOL::SyncSelection( const std::optional& targ // Perform individual selection of each item before processing the event. for( SCH_ITEM* item : items ) - select( item ); + { + // Make sure we only select items on the current screen + if( m_frame->GetScreen()->CheckIfOnDrawList( item ) ) + select( item ); + } BOX2I bbox = m_selection.GetBoundingBox();