diff --git a/common/dialogs/dialog_assign_netclass.cpp b/common/dialogs/dialog_assign_netclass.cpp index 7e71076bdb..bb9861a659 100644 --- a/common/dialogs/dialog_assign_netclass.cpp +++ b/common/dialogs/dialog_assign_netclass.cpp @@ -29,10 +29,12 @@ DIALOG_ASSIGN_NETCLASS::DIALOG_ASSIGN_NETCLASS( EDA_BASE_FRAME* aParent, const wxString aNetName, - const std::set aCandidateNetNames ) : + const std::set aCandidateNetNames, + const std::function& )>& aPreviewer ) : DIALOG_ASSIGN_NETCLASS_BASE( aParent ), m_frame( aParent ), - m_netCandidates( aCandidateNetNames ) + m_netCandidates( aCandidateNetNames ), + m_previewer( aPreviewer ) { std::shared_ptr& netSettings = m_frame->Prj().GetProjectFile().m_NetSettings; @@ -79,25 +81,37 @@ void DIALOG_ASSIGN_NETCLASS::OnUpdateUI( wxUpdateUIEvent& event ) if( pattern != m_lastPattern ) { - m_matchingNets->Clear(); + CallAfter( + [this, pattern]() + { + m_matchingNets->Clear(); - if( !pattern.IsEmpty() ) - { - EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS ); + std::vector matchingNetNames; - m_matchingNets->Report( _( "Currently matching nets:" ) ); + if( !pattern.IsEmpty() ) + { + EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS ); - for( const wxString& net : m_netCandidates ) - { - int matches; - int offset; + m_matchingNets->Report( _( "Currently matching nets:" ) ); - if( matcher.Find( net, matches, offset ) && offset == 0 ) - m_matchingNets->Report( net ); - } - } + for( const wxString& net : m_netCandidates ) + { + int matches; + int offset; + + if( matcher.Find( net, matches, offset ) && offset == 0 ) + { + m_matchingNets->Report( net ); + matchingNetNames.push_back( net ); + } + } + } + + m_matchingNets->Flush(); + + m_previewer( matchingNetNames ); + } ); - m_matchingNets->Flush(); m_lastPattern = pattern; } } diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index 99ae6f14b2..4c6b2cab90 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -580,10 +580,12 @@ void ACTION_MENU::runOnSubmenus( std::function aFunction ) { try { - std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) { - aFunction( m ); - m->runOnSubmenus( aFunction ); - } ); + std::for_each( m_submenus.begin(), m_submenus.end(), + [&]( ACTION_MENU* m ) + { + aFunction( m ); + m->runOnSubmenus( aFunction ); + } ); } catch( std::exception& ) { @@ -595,15 +597,17 @@ OPT_TOOL_EVENT ACTION_MENU::findToolAction( int aId ) { OPT_TOOL_EVENT evt; - auto findFunc = [&]( ACTION_MENU* m ) { - if( evt ) - return; + auto findFunc = + [&]( ACTION_MENU* m ) + { + if( evt ) + return; - const auto it = m->m_toolActions.find( aId ); + const auto it = m->m_toolActions.find( aId ); - if( it != m->m_toolActions.end() ) - evt = it->second->MakeEvent(); - }; + if( it != m->m_toolActions.end() ) + evt = it->second->MakeEvent(); + }; findFunc( this ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index c1abfdba1f..1a9914315c 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -1110,6 +1110,8 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent ) EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() ); + SCHEMATIC& schematic = m_frame->Schematic(); + SCH_SCREEN* screen = m_frame->GetCurrentSheet().LastScreen(); // TODO remove once real-time connectivity is a given if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime ) @@ -1142,30 +1144,79 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent ) return 0; } - wxArrayString netNames; + wxString netName; - if( conn->IsBus() ) + if( conn->IsBus() && conn->Members().size() ) { - for( const std::shared_ptr& member : conn->Members() ) - { - if( member->IsBus() ) - { - for( const std::shared_ptr& subMember : member->Members() ) - netNames.Add( subMember->Name() ); - } - else - { - netNames.Add( member->Name() ); - } - } + const std::shared_ptr& member = conn->Members()[0]; + + if( member->IsBus() && member->Members().size() ) + netName = member->Members()[0]->Name(); + else + netName = member->Name(); } else { - netNames.Add( conn->Name() ); + netName = conn->Name(); } - DIALOG_ASSIGN_NETCLASS dlg( m_frame, netNames.front(), - m_frame->Schematic().GetNetClassAssignmentCandidates() ); + DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, schematic.GetNetClassAssignmentCandidates(), + [&]( const std::vector& aNetNames ) + { + for( SCH_ITEM* item : screen->Items() ) + { + bool redraw = item->IsBrightened(); + SCH_CONNECTION* itemConn = item->Connection(); + + if( itemConn && alg::contains( aNetNames, itemConn->Name() ) ) + item->SetBrightened(); + else + item->ClearBrightened(); + + redraw |= item->IsBrightened(); + + if( item->Type() == SCH_SYMBOL_T ) + { + SCH_SYMBOL* symbol = static_cast( item ); + + redraw |= symbol->HasBrightenedPins(); + + symbol->ClearBrightenedPins(); + + for( SCH_PIN* pin : symbol->GetPins() ) + { + SCH_CONNECTION* pin_conn = pin->Connection(); + + if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) ) + { + pin->SetBrightened(); + redraw = true; + } + } + } + else if( item->Type() == SCH_SHEET_T ) + { + for( SCH_SHEET_PIN* pin : static_cast( item )->GetPins() ) + { + SCH_CONNECTION* pin_conn = pin->Connection(); + + redraw |= pin->IsBrightened(); + + if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) ) + pin->SetBrightened(); + else + pin->ClearBrightened(); + + redraw |= pin->IsBrightened(); + } + } + + if( redraw ) + getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT ); + } + + m_frame->GetCanvas()->ForceRefresh(); + } ); dlg.ShowModal(); } diff --git a/include/dialogs/dialog_assign_netclass.h b/include/dialogs/dialog_assign_netclass.h index fbdec47c92..a319c824b8 100644 --- a/include/dialogs/dialog_assign_netclass.h +++ b/include/dialogs/dialog_assign_netclass.h @@ -34,7 +34,8 @@ class DIALOG_ASSIGN_NETCLASS : public DIALOG_ASSIGN_NETCLASS_BASE { public: DIALOG_ASSIGN_NETCLASS( EDA_BASE_FRAME* aParent, const wxString aNetName, - const std::set aCandidateNetNames ); + const std::set aCandidateNetNames, + const std::function& )>& aPreviewer ); ~DIALOG_ASSIGN_NETCLASS() override {} private: @@ -46,6 +47,8 @@ private: EDA_BASE_FRAME* m_frame; std::set m_netCandidates; + const std::function& )>& m_previewer; + wxString m_lastPattern; }; diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 4a2e68f2fe..eb1cf3f52e 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -1485,16 +1485,28 @@ int BOARD_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent ) return 0; } - // Remove selection in favor of highlighting so the whole net is highlighted selectionTool->ClearSelection(); - m_toolMgr->RunAction( PCB_ACTIONS::highlightNet, true, (void*) netCode ); - wxSafeYield(); + m_toolMgr->RunAction( PCB_ACTIONS::selectNet, true, (void*) netCode ); + canvas()->ForceRefresh(); - DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, board()->GetNetClassAssignmentCandidates() ); + DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, board()->GetNetClassAssignmentCandidates(), + [&]( const std::vector& aNetNames ) + { + selectionTool->ClearSelection(); + + for( const wxString& netName : aNetNames ) + { + int netCode = board()->GetNetInfo().GetNetItem( netName )->GetNetCode(); + + if( netCode > 0 ) + selectionTool->SelectAllItemsOnNet( netCode ); + } + + canvas()->ForceRefresh(); + } ); dlg.ShowModal(); - m_toolMgr->RunAction( PCB_ACTIONS::clearHighlight, true ); return 0; } diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 5458cafbf3..334d80dbcf 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -1348,7 +1348,7 @@ void PCB_SELECTION_TOOL::selectAllConnectedTracks( } -void PCB_SELECTION_TOOL::selectAllItemsOnNet( int aNetCode, bool aSelect ) +void PCB_SELECTION_TOOL::SelectAllItemsOnNet( int aNetCode, bool aSelect ) { std::shared_ptr conn = board()->GetConnectivity(); @@ -1369,7 +1369,7 @@ int PCB_SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent ) if( netcode > 0 ) { - selectAllItemsOnNet( netcode, select ); + SelectAllItemsOnNet( netcode, select ); return 0; } @@ -1384,7 +1384,7 @@ int PCB_SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent ) BOARD_CONNECTED_ITEM* connItem = dynamic_cast( i ); if( connItem ) - selectAllItemsOnNet( connItem->GetNetCode(), select ); + SelectAllItemsOnNet( connItem->GetNetCode(), select ); } // Inform other potentially interested tools @@ -1789,7 +1789,7 @@ void PCB_SELECTION_TOOL::FindItem( BOARD_ITEM* aItem ) if( netCode > 0 ) { - selectAllItemsOnNet( netCode, true ); + SelectAllItemsOnNet( netCode, true ); m_frame->FocusOnLocation( aItem->GetCenter() ); } break; diff --git a/pcbnew/tools/pcb_selection_tool.h b/pcbnew/tools/pcb_selection_tool.h index 1ec8602280..34b0343c63 100644 --- a/pcbnew/tools/pcb_selection_tool.h +++ b/pcbnew/tools/pcb_selection_tool.h @@ -131,6 +131,14 @@ public: */ bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const; + /** + * Select all items with the given net code. + * + * @param aNetCode is the target net to select + * @param aSelect is true to add the items to the selection, false to remove them (deselect) + */ + void SelectAllItemsOnNet( int aNetCode, bool aSelect = true ); + /** * Try to guess best selection candidates in case multiple items are clicked, by doing * some brain-dead heuristics. @@ -306,14 +314,6 @@ private: void selectAllConnectedTracks( const std::vector& aStartItems, STOP_CONDITION aStopCondition ); - /** - * Select all items with the given net code. - * - * @param aNetCode is the target net to select - * @param aSelect is true to add the items to the selection, false to remove them (deselect) - */ - void selectAllItemsOnNet( int aNetCode, bool aSelect = true ); - /* * Select tracks and vias connected to specified board items. */ diff --git a/qa/qa_utils/mocks.cpp b/qa/qa_utils/mocks.cpp index cbf5f49c37..6ce49a161f 100644 --- a/qa/qa_utils/mocks.cpp +++ b/qa/qa_utils/mocks.cpp @@ -301,7 +301,7 @@ void PCB_SELECTION_TOOL::selectAllConnectedTracks( } -void PCB_SELECTION_TOOL::selectAllItemsOnNet( int aNetCode, bool aSelect ) +void PCB_SELECTION_TOOL::SelectAllItemsOnNet( int aNetCode, bool aSelect ) { }