Improve selection behavior of DRC markers in DRC dialog list

This commit is contained in:
Jon Evans 2019-03-25 22:38:18 -04:00
parent 2d43fcf9ee
commit 227333239f
6 changed files with 97 additions and 55 deletions

View File

@ -378,22 +378,8 @@ void DIALOG_DRC_CONTROL::OnLeftDClickClearance( wxMouseEvent& event )
if( selection != wxNOT_FOUND )
{
// Find the selected MARKER in the PCB, position cursor there.
// Then close the dialog.
const DRC_ITEM* item = m_ClearanceListBox->GetItem( selection );
if( item )
if( focusOnItem( m_ClearanceListBox->GetItem( selection ) ) )
{
auto pos = item->GetPointA();
if( auto marker = item->GetParent() )
pos = marker->GetPos();
// When selecting a item, center it on GAL and just move the graphic
// cursor in legacy mode gives the best result
bool center = m_brdEditor->IsGalCanvasActive() ? true : false;
m_brdEditor->FocusOnLocation( pos, true, center );
if( !IsModal() )
{
// turn control over to m_brdEditor, hide this DIALOG_DRC_CONTROL window,
@ -409,11 +395,49 @@ void DIALOG_DRC_CONTROL::OnLeftDClickClearance( wxMouseEvent& event )
}
void DIALOG_DRC_CONTROL::OnLeftUpClearance( wxMouseEvent& event )
{
int selection = m_ClearanceListBox->GetSelection();
if( selection != wxNOT_FOUND )
focusOnItem( m_ClearanceListBox->GetItem( selection ) );
}
bool DIALOG_DRC_CONTROL::focusOnItem( const DRC_ITEM* aItem )
{
if( !aItem )
return false;
auto toolmgr = m_brdEditor->GetToolManager();
auto pos = aItem->GetPointA();
auto marker = static_cast<MARKER_PCB*>( aItem->GetParent() );
if( marker )
{
pos = marker->GetPos();
toolmgr->RunAction( PCB_ACTIONS::selectionClear, true );
toolmgr->RunAction( PCB_ACTIONS::selectItem, true, marker );
}
toolmgr->GetView()->SetCenter( pos );
m_brdEditor->GetCanvas()->Refresh();
return true;
}
void DIALOG_DRC_CONTROL::OnRightUpUnconnected( wxMouseEvent& event )
{
// popup menu to go to either of the items listed in the DRC_ITEM.
// Check if user right-clicked on a different item
int selection = m_UnconnectedListBox->HitTest( event.GetPosition() );
int selection = m_UnconnectedListBox->GetSelection();
if( selection == wxNOT_FOUND )
selection = m_UnconnectedListBox->GetSelection();
else
m_UnconnectedListBox->SetSelection( selection );
if( selection != wxNOT_FOUND )
doSelectionMenu( m_UnconnectedListBox->GetItem( selection ) );
@ -423,8 +447,13 @@ void DIALOG_DRC_CONTROL::OnRightUpUnconnected( wxMouseEvent& event )
void DIALOG_DRC_CONTROL::OnRightUpClearance( wxMouseEvent& event )
{
// popup menu to go to either of the items listed in the DRC_ITEM.
// Check if user right-clicked on a different item
int selection = m_ClearanceListBox->HitTest( event.GetPosition() );
int selection = m_ClearanceListBox->GetSelection();
if( selection == wxNOT_FOUND )
selection = m_ClearanceListBox->GetSelection();
else
m_ClearanceListBox->SetSelection( selection );
if( selection != wxNOT_FOUND )
doSelectionMenu( m_ClearanceListBox->GetItem( selection ) );
@ -434,15 +463,29 @@ void DIALOG_DRC_CONTROL::OnRightUpClearance( wxMouseEvent& event )
void DIALOG_DRC_CONTROL::doSelectionMenu( const DRC_ITEM* aItem )
{
// popup menu to go to either of the items listed in the DRC_ITEM.
BOARD_ITEM* first = aItem->GetMainItem( m_brdEditor->GetBoard() );
BOARD_ITEM* second = nullptr;
GENERAL_COLLECTOR items;
items.Append( aItem->GetMainItem( m_brdEditor->GetBoard() ) );
items.Append( first );
if( aItem->HasSecondItem() )
items.Append( aItem->GetAuxiliaryItem( m_brdEditor->GetBoard() ) );
{
second = aItem->GetAuxiliaryItem( m_brdEditor->GetBoard() );
items.Append( second );
}
WINDOW_THAWER thawer( m_brdEditor );
m_brdEditor->GetToolManager()->RunAction( PCB_ACTIONS::selectionMenu, true, &items );
// If we got an item, focus on it
BOARD_ITEM* selection = m_brdEditor->GetCurItem();
if( selection && ( selection == first || selection == second ) )
m_brdEditor->GetToolManager()->GetView()->SetCenter( selection->GetPosition() );
m_brdEditor->GetCanvas()->Refresh();
}
@ -455,18 +498,12 @@ void DIALOG_DRC_CONTROL::OnLeftDClickUnconnected( wxMouseEvent& event )
if( selection != wxNOT_FOUND )
{
// Find the selected DRC_ITEM in the listbox, position cursor there.
// Then hide the dialog.
const DRC_ITEM* item = m_UnconnectedListBox->GetItem( selection );
if( item )
if( focusOnItem( m_UnconnectedListBox->GetItem( selection ) ) )
{
// When selecting a item, center it on GAL and just move the graphic
// cursor in legacy mode gives the best result
bool center = m_brdEditor->IsGalCanvasActive() ? true : false;
m_brdEditor->FocusOnLocation( item->GetPointA(), true, center );
if( !IsModal() )
{
// turn control over to m_brdEditor, hide this DIALOG_DRC_CONTROL window,
// no destruction so we can preserve listbox cursor
Show( false );
// We do not want the clarify selection popup when releasing the
@ -478,6 +515,15 @@ void DIALOG_DRC_CONTROL::OnLeftDClickUnconnected( wxMouseEvent& event )
}
void DIALOG_DRC_CONTROL::OnLeftUpUnconnected( wxMouseEvent& event )
{
int selection = m_UnconnectedListBox->GetSelection();
if( selection != wxNOT_FOUND )
focusOnItem( m_UnconnectedListBox->GetItem( selection ) );
}
/* called when switching from Error list to Unconnected list
* To avoid mistakes, the current marker is selection is cleared
*/
@ -502,20 +548,7 @@ void DIALOG_DRC_CONTROL::OnMarkerSelectionEvent( wxCommandEvent& event )
m_DeleteCurrentMarkerButton->Enable( true );
// Find the selected DRC_ITEM in the listbox, position cursor there.
const DRC_ITEM* item = m_ClearanceListBox->GetItem( selection );
if( item )
{
auto pos = item->GetPointA();
if( auto marker = item->GetParent() )
pos = marker->GetPos();
// When selecting a item, center it on GAL and just move the graphic
// cursor in legacy mode gives the best result
bool center = m_brdEditor->IsGalCanvasActive() ? true : false;
m_brdEditor->FocusOnLocation( pos, false, center );
RedrawDrawPanel();
}
focusOnItem( m_ClearanceListBox->GetItem( selection ) );
}
event.Skip();
@ -532,16 +565,7 @@ void DIALOG_DRC_CONTROL::OnUnconnectedSelectionEvent( wxCommandEvent& event )
m_DeleteCurrentMarkerButton->Enable( true );
// Find the selected DRC_ITEM in the listbox, position cursor there.
const DRC_ITEM* item = m_UnconnectedListBox->GetItem( selection );
if( item )
{
// When selecting a item, center it on GAL and just move the graphic
// cursor in legacy mode gives the best result
bool center = m_brdEditor->IsGalCanvasActive() ? true : false;
m_brdEditor->FocusOnLocation( item->GetPointA(), false, center );
RedrawDrawPanel();
}
focusOnItem( m_UnconnectedListBox->GetItem( selection ) );
}
event.Skip();

View File

@ -118,12 +118,18 @@ private:
/// wxEVT_LEFT_DCLICK event handler for ID_CLEARANCE_LIST
void OnLeftDClickClearance( wxMouseEvent& event ) override;
/// wxEVT_LEFT_UP event handler for ID_CLEARANCE_LIST
void OnLeftUpClearance( wxMouseEvent& event ) override;
/// wxEVT_RIGHT_UP event handler for ID_CLEARANCE_LIST
void OnRightUpClearance( wxMouseEvent& event ) override;
/// wxEVT_LEFT_DCLICK event handler for ID_UNCONNECTED_LIST
void OnLeftDClickUnconnected( wxMouseEvent& event ) override;
/// wxEVT_LEFT_UP event handler for ID_UNCONNECTED_LIST
void OnLeftUpUnconnected( wxMouseEvent& event ) override;
/// wxEVT_RIGHT_UP event handler for ID_UNCONNECTED_LIST
void OnRightUpUnconnected( wxMouseEvent& event ) override;
@ -145,6 +151,8 @@ private:
/// in the DRC_ITEM.
void doSelectionMenu( const DRC_ITEM* aItem );
bool focusOnItem( const DRC_ITEM* aItem );
BOARD* m_currentBoard; // the board currently on test
DRC* m_tester;
PCB_EDIT_FRAME* m_brdEditor;

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 1 2018)
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -229,9 +229,11 @@ DIALOG_DRC_CONTROL_BASE::DIALOG_DRC_CONTROL_BASE( wxWindow* parent, wxWindowID i
m_BrowseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DRC_CONTROL_BASE::OnButtonBrowseRptFileClick ), NULL, this );
m_Notebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( DIALOG_DRC_CONTROL_BASE::OnChangingMarkerList ), NULL, this );
m_ClearanceListBox->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnLeftDClickClearance ), NULL, this );
m_ClearanceListBox->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnLeftUpClearance ), NULL, this );
m_ClearanceListBox->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_DRC_CONTROL_BASE::OnMarkerSelectionEvent ), NULL, this );
m_ClearanceListBox->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnRightUpClearance ), NULL, this );
m_UnconnectedListBox->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnLeftDClickUnconnected ), NULL, this );
m_UnconnectedListBox->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnLeftUpUnconnected ), NULL, this );
m_UnconnectedListBox->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_DRC_CONTROL_BASE::OnUnconnectedSelectionEvent ), NULL, this );
m_UnconnectedListBox->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnRightUpUnconnected ), NULL, this );
m_DeleteCurrentMarkerButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DRC_CONTROL_BASE::OnDeleteOneClick ), NULL, this );
@ -250,9 +252,11 @@ DIALOG_DRC_CONTROL_BASE::~DIALOG_DRC_CONTROL_BASE()
m_BrowseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DRC_CONTROL_BASE::OnButtonBrowseRptFileClick ), NULL, this );
m_Notebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( DIALOG_DRC_CONTROL_BASE::OnChangingMarkerList ), NULL, this );
m_ClearanceListBox->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnLeftDClickClearance ), NULL, this );
m_ClearanceListBox->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnLeftUpClearance ), NULL, this );
m_ClearanceListBox->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_DRC_CONTROL_BASE::OnMarkerSelectionEvent ), NULL, this );
m_ClearanceListBox->Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnRightUpClearance ), NULL, this );
m_UnconnectedListBox->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnLeftDClickUnconnected ), NULL, this );
m_UnconnectedListBox->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnLeftUpUnconnected ), NULL, this );
m_UnconnectedListBox->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_DRC_CONTROL_BASE::OnUnconnectedSelectionEvent ), NULL, this );
m_UnconnectedListBox->Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( DIALOG_DRC_CONTROL_BASE::OnRightUpUnconnected ), NULL, this );
m_DeleteCurrentMarkerButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_DRC_CONTROL_BASE::OnDeleteOneClick ), NULL, this );

View File

@ -1547,6 +1547,7 @@
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnLeftDClick">OnLeftDClickClearance</event>
<event name="OnLeftUp">OnLeftUpClearance</event>
<event name="OnListBox">OnMarkerSelectionEvent</event>
<event name="OnRightUp">OnRightUpClearance</event>
</object>
@ -1676,6 +1677,7 @@
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnLeftDClick">OnLeftDClickUnconnected</event>
<event name="OnLeftUp">OnLeftUpUnconnected</event>
<event name="OnListBox">OnUnconnectedSelectionEvent</event>
<event name="OnRightUp">OnRightUpUnconnected</event>
</object>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 1 2018)
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -82,9 +82,11 @@ class DIALOG_DRC_CONTROL_BASE : public DIALOG_SHIM
virtual void OnButtonBrowseRptFileClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnChangingMarkerList( wxNotebookEvent& event ) { event.Skip(); }
virtual void OnLeftDClickClearance( wxMouseEvent& event ) { event.Skip(); }
virtual void OnLeftUpClearance( wxMouseEvent& event ) { event.Skip(); }
virtual void OnMarkerSelectionEvent( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRightUpClearance( wxMouseEvent& event ) { event.Skip(); }
virtual void OnLeftDClickUnconnected( wxMouseEvent& event ) { event.Skip(); }
virtual void OnLeftUpUnconnected( wxMouseEvent& event ) { event.Skip(); }
virtual void OnUnconnectedSelectionEvent( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRightUpUnconnected( wxMouseEvent& event ) { event.Skip(); }
virtual void OnDeleteOneClick( wxCommandEvent& event ) { event.Skip(); }

View File

@ -579,7 +579,6 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag,
if( item )
{
toggleSelection( item );
return true;
}
else
@ -1518,6 +1517,9 @@ BOARD_ITEM* SELECTION_TOOL::doSelectionMenu( GENERAL_COLLECTOR* aCollector,
}
getView()->Remove( &highlightGroup );
if( current )
toggleSelection( current );
return current;
}