Better feedback for netclass assignment patterns.

This commit is contained in:
Jeff Young 2022-09-03 21:33:56 +01:00
parent c30a557810
commit efae2bbb4c
8 changed files with 147 additions and 63 deletions

View File

@ -29,10 +29,12 @@
DIALOG_ASSIGN_NETCLASS::DIALOG_ASSIGN_NETCLASS( EDA_BASE_FRAME* aParent, const wxString aNetName,
const std::set<wxString> aCandidateNetNames ) :
const std::set<wxString> aCandidateNetNames,
const std::function<void( const std::vector<wxString>& )>& aPreviewer ) :
DIALOG_ASSIGN_NETCLASS_BASE( aParent ),
m_frame( aParent ),
m_netCandidates( aCandidateNetNames )
m_netCandidates( aCandidateNetNames ),
m_previewer( aPreviewer )
{
std::shared_ptr<NET_SETTINGS>& 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<wxString> matchingNetNames;
m_matchingNets->Report( _( "<b>Currently matching nets:</b>" ) );
if( !pattern.IsEmpty() )
{
EDA_COMBINED_MATCHER matcher( pattern, CTX_NETCLASS );
for( const wxString& net : m_netCandidates )
{
int matches;
int offset;
m_matchingNets->Report( _( "<b>Currently matching nets:</b>" ) );
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;
}
}

View File

@ -580,10 +580,12 @@ void ACTION_MENU::runOnSubmenus( std::function<void(ACTION_MENU*)> 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 );

View File

@ -1110,6 +1110,8 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent )
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
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<SCH_CONNECTION>& member : conn->Members() )
{
if( member->IsBus() )
{
for( const std::shared_ptr<SCH_CONNECTION>& subMember : member->Members() )
netNames.Add( subMember->Name() );
}
else
{
netNames.Add( member->Name() );
}
}
const std::shared_ptr<SCH_CONNECTION>& 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<wxString>& 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<SCH_SYMBOL*>( 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<SCH_SHEET*>( 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();
}

View File

@ -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<wxString> aCandidateNetNames );
const std::set<wxString> aCandidateNetNames,
const std::function<void( const std::vector<wxString>& )>& aPreviewer );
~DIALOG_ASSIGN_NETCLASS() override {}
private:
@ -46,6 +47,8 @@ private:
EDA_BASE_FRAME* m_frame;
std::set<wxString> m_netCandidates;
const std::function<void( const std::vector<wxString>& )>& m_previewer;
wxString m_lastPattern;
};

View File

@ -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<wxString>& 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;
}

View File

@ -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<CONNECTIVITY_DATA> 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<BOARD_CONNECTED_ITEM*>( 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;

View File

@ -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<BOARD_CONNECTED_ITEM*>& 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.
*/

View File

@ -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 )
{
}