Move ERC marker focusing to GAL architecture.

Fixes: lp:1802537
* https://bugs.launchpad.net/kicad/+bug/1802537
This commit is contained in:
Jeff Young 2018-11-14 23:34:32 +00:00
parent 228ea64016
commit 4050991d28
9 changed files with 154 additions and 108 deletions

View File

@ -1555,6 +1555,42 @@ void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
} }
// Find the first child dialog.
wxWindow* findDialog( wxWindowList& aList )
{
for( wxWindow* window : aList )
{
if( dynamic_cast<DIALOG_SHIM*>( window ) )
return window;
}
return NULL;
}
void EDA_DRAW_FRAME::FocusOnLocation( const wxPoint& aPos, bool aWarpCursor, bool aCenterView )
{
if( aCenterView )
{
wxWindow* dialog = findDialog( GetChildren() );
// If a dialog partly obscures the window, then center on the uncovered area.
if( dialog )
{
wxRect dialogRect( GetGalCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
dialog->GetSize() );
GetGalCanvas()->GetView()->SetCenter( aPos, dialogRect );
}
else
GetGalCanvas()->GetView()->SetCenter( aPos );
}
if( aWarpCursor )
GetGalCanvas()->GetViewControls()->SetCursorPosition( aPos );
else
GetGalCanvas()->GetViewControls()->SetCrossHairCursorPosition( aPos );
}
static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame ); static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame );

View File

@ -1863,6 +1863,69 @@ void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
} }
// Find the first child dialog.
wxWindow* findDialog( wxWindowList& aList )
{
for( wxWindow* window : aList )
{
if( dynamic_cast<DIALOG_SHIM*>( window ) )
return window;
}
return NULL;
}
void EDA_DRAW_FRAME::FocusOnLocation( const wxPoint& aPos, bool aWarpCursor, bool aCenterView )
{
if( IsGalCanvasActive() )
{
if( aCenterView )
{
wxWindow* dialog = findDialog( GetChildren() );
// If a dialog partly obscures the window, then center on the uncovered area.
if( dialog )
{
wxRect dialogRect( GetGalCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
dialog->GetSize() );
GetGalCanvas()->GetView()->SetCenter( aPos, dialogRect );
}
else
GetGalCanvas()->GetView()->SetCenter( aPos );
}
if( aWarpCursor )
GetGalCanvas()->GetViewControls()->SetCursorPosition( aPos );
else
GetGalCanvas()->GetViewControls()->SetCrossHairCursorPosition( aPos );
}
else
{
INSTALL_UNBUFFERED_DC( dc, m_canvas );
// There may be need to reframe the drawing.
if( aCenterView || !m_canvas->IsPointOnDisplay( aPos ) )
{
SetCrossHairPosition( aPos );
RedrawScreen( aPos, aWarpCursor );
}
else
{
// Put cursor on item position
m_canvas->CrossHairOff( &dc );
SetCrossHairPosition( aPos );
if( aWarpCursor )
m_canvas->MoveCursorToCrossHair();
}
// Be sure cross hair cursor is ON:
m_canvas->CrossHairOn( &dc );
m_canvas->CrossHairOn( &dc );
}
}
static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame ); static bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame );

View File

@ -198,6 +198,14 @@ void DIALOG_ERC::OnErcCmpClick( wxCommandEvent& event )
} }
void DIALOG_ERC::RedrawDrawPanel()
{
WINDOW_THAWER thawer( m_parent );
m_parent->GetCanvas()->Refresh();
}
void DIALOG_ERC::OnLeftClickMarkersList( wxHtmlLinkEvent& event ) void DIALOG_ERC::OnLeftClickMarkersList( wxHtmlLinkEvent& event )
{ {
wxString link = event.GetLinkInfo().GetHref(); wxString link = event.GetLinkInfo().GetHref();
@ -253,8 +261,9 @@ void DIALOG_ERC::OnLeftClickMarkersList( wxHtmlLinkEvent& event )
} }
m_lastMarkerFound = marker; m_lastMarkerFound = marker;
m_parent->FocusOnLocation( marker->m_Pos, false, true );
m_parent->SetCrossHairPosition( marker->m_Pos ); m_parent->SetCrossHairPosition( marker->m_Pos );
m_parent->RedrawScreen( marker->m_Pos, false); RedrawDrawPanel();
} }
@ -265,8 +274,9 @@ void DIALOG_ERC::OnLeftDblClickMarkersList( wxMouseEvent& event )
// (NULL if not found) // (NULL if not found)
if( m_lastMarkerFound ) if( m_lastMarkerFound )
{ {
m_parent->FocusOnLocation( m_lastMarkerFound->m_Pos, false, true );
m_parent->SetCrossHairPosition( m_lastMarkerFound->m_Pos ); m_parent->SetCrossHairPosition( m_lastMarkerFound->m_Pos );
m_parent->RedrawScreen( m_lastMarkerFound->m_Pos, true ); RedrawDrawPanel();
// prevent a mouse left button release event in // prevent a mouse left button release event in
// coming from the ERC dialog double click // coming from the ERC dialog double click
// ( the button is released after closing this dialog and will generate // ( the button is released after closing this dialog and will generate

View File

@ -64,6 +64,8 @@ private:
void OnButtonCloseClick( wxCommandEvent& event ) override; void OnButtonCloseClick( wxCommandEvent& event ) override;
void OnResetMatrixClick( wxCommandEvent& event ) override; void OnResetMatrixClick( wxCommandEvent& event ) override;
void RedrawDrawPanel();
// Click on a marker info: // Click on a marker info:
void OnLeftClickMarkersList( wxHtmlLinkEvent& event ) override; void OnLeftClickMarkersList( wxHtmlLinkEvent& event ) override;

View File

@ -31,6 +31,35 @@
struct WINDOW_THAWER
{
WINDOW_THAWER( wxWindow* aWindow )
{
m_window = aWindow;
m_freezeCount = 0;
while( m_window->IsFrozen() )
{
m_window->Thaw();
m_freezeCount++;
}
}
~WINDOW_THAWER()
{
while( m_freezeCount > 0 )
{
m_window->Freeze();
m_freezeCount--;
}
}
protected:
wxWindow* m_window;
int m_freezeCount;
};
class WDO_ENABLE_DISABLE; class WDO_ENABLE_DISABLE;
class WX_EVENT_LOOP; class WX_EVENT_LOOP;

View File

@ -709,6 +709,16 @@ public:
/** Return the zoom level which displays the full page on screen */ /** Return the zoom level which displays the full page on screen */
virtual double BestZoom() = 0; virtual double BestZoom() = 0;
/**
* Useful to focus on a particular location, in find functions
* Move the graphic cursor (crosshair cursor) at a given coordinate and reframes
* the drawing if the requested point is out of view or if center on location is requested.
* @param aPos is the point to go to.
* @param aWarpCursor is true if the pointer should be warped to the new position.
* @param aCenterView is true if the new cursor position should be centered on canvas.
*/
void FocusOnLocation( const wxPoint& aPos, bool aWarpCursor = true, bool aCenterView = false );
/** /**
* @return The current zoom level. * @return The current zoom level.
*/ */

View File

@ -280,17 +280,6 @@ public:
*/ */
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide(); GENERAL_COLLECTORS_GUIDE GetCollectorsGuide();
/**
* Useful to focus on a particular location, in find functions
* Move the graphic cursor (crosshair cursor) at a given coordinate and reframes
* the drawing if the requested point is out of view or if center on location is requested.
* @param aPos is the point to go to.
* @param aWarpMouseCursor is true if the pointer should be warped to the new position.
* @param aCenterView is true if the new cursor position should be centered on canvas.
*/
void FocusOnLocation( const wxPoint& aPos, bool aWarpMouseCursor = true,
bool aCenterView = false );
/** /**
* Function SelectLibrary * Function SelectLibrary
* puts up a dialog and allows the user to pick a library, for unspecified use. * puts up a dialog and allows the user to pick a library, for unspecified use.

View File

@ -54,35 +54,6 @@
#define RefillZonesBeforeDrc wxT( "RefillZonesBeforeDrc" ) #define RefillZonesBeforeDrc wxT( "RefillZonesBeforeDrc" )
struct BOARD_THAWER
{
BOARD_THAWER( PCB_EDIT_FRAME* aBoardEditor )
{
m_boardEditor = aBoardEditor;
m_freezeCount = 0;
while( m_boardEditor->IsFrozen() )
{
m_boardEditor->Thaw();
m_freezeCount++;
}
}
~BOARD_THAWER()
{
while( m_freezeCount > 0 )
{
m_boardEditor->Freeze();
m_freezeCount--;
}
}
protected:
PCB_EDIT_FRAME* m_boardEditor;
int m_freezeCount;
};
DIALOG_DRC_CONTROL::DIALOG_DRC_CONTROL( DRC* aTester, PCB_EDIT_FRAME* aEditorFrame, DIALOG_DRC_CONTROL::DIALOG_DRC_CONTROL( DRC* aTester, PCB_EDIT_FRAME* aEditorFrame,
wxWindow* aParent ) : wxWindow* aParent ) :
DIALOG_DRC_CONTROL_BASE( aParent ), DIALOG_DRC_CONTROL_BASE( aParent ),
@ -465,7 +436,7 @@ void DIALOG_DRC_CONTROL::doSelectionMenu( const DRC_ITEM* aItem )
if( aItem->HasSecondItem() ) if( aItem->HasSecondItem() )
items.Append( aItem->GetAuxiliaryItem( m_brdEditor->GetBoard() ) ); items.Append( aItem->GetAuxiliaryItem( m_brdEditor->GetBoard() ) );
BOARD_THAWER thawer( m_brdEditor ); WINDOW_THAWER thawer( m_brdEditor );
m_brdEditor->GetToolManager()->RunAction( PCB_ACTIONS::selectionMenu, true, &items ); m_brdEditor->GetToolManager()->RunAction( PCB_ACTIONS::selectionMenu, true, &items );
m_brdEditor->GetCanvas()->Refresh(); m_brdEditor->GetCanvas()->Refresh();
} }
@ -574,7 +545,7 @@ void DIALOG_DRC_CONTROL::OnUnconnectedSelectionEvent( wxCommandEvent& event )
void DIALOG_DRC_CONTROL::RedrawDrawPanel() void DIALOG_DRC_CONTROL::RedrawDrawPanel()
{ {
BOARD_THAWER thawer( m_brdEditor ); WINDOW_THAWER thawer( m_brdEditor );
m_brdEditor->GetCanvas()->Refresh(); m_brdEditor->GetCanvas()->Refresh();
} }

View File

@ -400,70 +400,6 @@ double PCB_BASE_FRAME::BestZoom()
} }
// Find the first child dialog.
wxWindow* findDialog( wxWindowList& aList )
{
for( wxWindow* window : aList )
{
if( dynamic_cast<DIALOG_SHIM*>( window ) )
return window;
}
return NULL;
}
void PCB_BASE_FRAME::FocusOnLocation( const wxPoint& aPos,
bool aWarpMouseCursor, bool aCenterView )
{
if( IsGalCanvasActive() )
{
if( aCenterView )
{
wxWindow* dialog = findDialog( GetChildren() );
// If a dialog partly obscures the window, then center on the uncovered area.
if( dialog )
{
wxRect dialogRect( GetGalCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
dialog->GetSize() );
GetGalCanvas()->GetView()->SetCenter( aPos, dialogRect );
}
else
GetGalCanvas()->GetView()->SetCenter( aPos );
}
if( aWarpMouseCursor )
GetGalCanvas()->GetViewControls()->SetCursorPosition( aPos );
else
GetGalCanvas()->GetViewControls()->SetCrossHairCursorPosition( aPos );
}
else
{
INSTALL_UNBUFFERED_DC( dc, m_canvas );
// There may be need to reframe the drawing.
if( aCenterView || !m_canvas->IsPointOnDisplay( aPos ) )
{
SetCrossHairPosition( aPos );
RedrawScreen( aPos, aWarpMouseCursor );
}
else
{
// Put cursor on item position
m_canvas->CrossHairOff( &dc );
SetCrossHairPosition( aPos );
if( aWarpMouseCursor )
m_canvas->MoveCursorToCrossHair();
}
// Be sure cross hair cursor is ON:
m_canvas->CrossHairOn( &dc );
m_canvas->CrossHairOn( &dc );
}
}
// Virtual function // Virtual function
void PCB_BASE_FRAME::ReCreateMenuBar() void PCB_BASE_FRAME::ReCreateMenuBar()
{ {