Make EDA_DRAW_FRAME::SetToolID and mouse cursor shape setting working in GAL canvases, and uses same mouse cursor shapes in legacy and gal canvases.

Starting fixing incorrect UI behavior of Zoom to selection in Pcbnew.
This commit is contained in:
jean-pierre charras 2017-06-12 15:10:43 +02:00
parent 18488342a5
commit 6ed4f9b208
18 changed files with 116 additions and 32 deletions

View File

@ -1,9 +1,9 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004-2015 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr * Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -541,6 +541,10 @@ void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
if( m_canvas && aCursor >= 0 ) if( m_canvas && aCursor >= 0 )
m_canvas->SetCurrentCursor( aCursor ); m_canvas->SetCurrentCursor( aCursor );
// Change GAL canvas cursor if requested.
if( IsGalCanvasActive() && aCursor >= 0 )
GetGalCanvas()->SetCurrentCursor( aCursor );
DisplayToolMsg( aToolMsg ); DisplayToolMsg( aToolMsg );
if( aId < 0 ) if( aId < 0 )
@ -553,6 +557,21 @@ void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
} }
void EDA_DRAW_FRAME::SetNoToolSelected()
{
// Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
int defaultCursor = wxCURSOR_DEFAULT;
// Change GAL canvas cursor if requested.
if( IsGalCanvasActive() )
defaultCursor = GetGalCanvas()->GetDefaultCursor();
else if( m_canvas )
defaultCursor = m_canvas->GetDefaultCursor();
SetToolID( ID_NO_TOOL_SELECTED, defaultCursor, wxEmptyString );
}
wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const
{ {
wxPoint pos = aPosition; wxPoint pos = aPosition;

View File

@ -60,6 +60,12 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_lostFocus = false; m_lostFocus = false;
m_stealsFocus = true; m_stealsFocus = true;
#ifdef __WXMAC__
m_defaultCursor = m_currentCursor = wxCURSOR_CROSS;
#else
m_defaultCursor = m_currentCursor = wxCURSOR_ARROW;
#endif
SetLayoutDirection( wxLayout_LeftToRight ); SetLayoutDirection( wxLayout_LeftToRight );
SwitchBackend( aGalType ); SwitchBackend( aGalType );

View File

@ -201,6 +201,29 @@ public:
return m_stealsFocus; return m_stealsFocus;
} }
/**
* Function SetCurrentCursor
* Set the current cursor shape for this panel
*/
void SetCurrentCursor( int aCursor )
{
m_currentCursor = aCursor;
SetCursor( (wxStockCursor) m_currentCursor );
}
/**
* Function GetDefaultCursor
* @return the default cursor shape
*/
int GetDefaultCursor() const { return m_defaultCursor; }
/**
* Function GetCurrentCursor
* @return the current cursor shape, depending on the current selected tool
*/
int GetCurrentCursor() const { return m_currentCursor; }
protected: protected:
void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
void onSize( wxSizeEvent& aEvent ); void onSize( wxSizeEvent& aEvent );
@ -212,6 +235,11 @@ protected:
static const int MinRefreshPeriod = 17; ///< 60 FPS. static const int MinRefreshPeriod = 17; ///< 60 FPS.
/// Current mouse cursor shape id.
int m_currentCursor;
/// The default mouse cursor shape id.
int m_defaultCursor;
/// Pointer to the parent window /// Pointer to the parent window
wxWindow* m_parent; wxWindow* m_parent;

View File

@ -445,13 +445,13 @@ public:
/** /**
* Function GetDefaultCursor * Function GetDefaultCursor
* return the default cursor shape * @return the default cursor shape
*/ */
int GetDefaultCursor() const { return m_defaultCursor; } int GetDefaultCursor() const { return m_defaultCursor; }
/** /**
* Function GetCurrentCursor * Function GetCurrentCursor
* return the current cursor shape, depending on the current selected tool * @return the current cursor shape, depending on the current selected tool
*/ */
int GetCurrentCursor() const { return m_currentCursor; } int GetCurrentCursor() const { return m_currentCursor; }

View File

@ -403,6 +403,16 @@ public:
*/ */
virtual void SetToolID( int aId, int aCursor, const wxString& aToolMsg ); virtual void SetToolID( int aId, int aCursor, const wxString& aToolMsg );
/**
* Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
*/
virtual void SetNoToolSelected();
/**
* @return the current tool ID
* when there is no active tool, the ID_NO_TOOL_SELECTED is returned
* (the id of the default Tool (idle tool) of the right vertical toolbar)
*/
int GetToolId() const { return m_toolId; } int GetToolId() const { return m_toolId; }
/* These 4 functions provide a basic way to show/hide grid /* These 4 functions provide a basic way to show/hide grid

View File

@ -246,7 +246,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
} }
if( id != ID_POPUP_CANCEL_CURRENT_COMMAND ) if( id != ID_POPUP_CANCEL_CURRENT_COMMAND )
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); SetNoToolSelected();
break; break;
} }
@ -940,8 +940,10 @@ void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform )
void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent ) void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent )
{ {
int id = aEvent.GetId(); int id = aEvent.GetId();
int lastToolID = GetToolId();
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); // Stop the current command and deselect the current tool.
SetNoToolSelected();
switch( id ) switch( id )
{ {
@ -949,7 +951,11 @@ void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent )
break; break;
case ID_ZOOM_SELECTION: case ID_ZOOM_SELECTION:
SetToolID( id, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) ); // This tool is located on the main toolbar: switch it on or off on click on it
if( lastToolID != ID_ZOOM_SELECTION )
SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
else
SetNoToolSelected();
break; break;
case ID_MODEDIT_LINE_TOOL: case ID_MODEDIT_LINE_TOOL:
@ -985,7 +991,7 @@ void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent )
{ {
SetToolID( id, wxCURSOR_ARROW, _( "Pad settings" ) ); SetToolID( id, wxCURSOR_ARROW, _( "Pad settings" ) );
InstallPadOptionsFrame( NULL ); InstallPadOptionsFrame( NULL );
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); SetNoToolSelected();
} }
break; break;
@ -995,12 +1001,12 @@ void FOOTPRINT_EDIT_FRAME::OnVerticalToolbar( wxCommandEvent& aEvent )
case ID_MODEDIT_MEASUREMENT_TOOL: case ID_MODEDIT_MEASUREMENT_TOOL:
DisplayError( this, wxT( "Unsupported tool in legacy canvas" ) ); DisplayError( this, wxT( "Unsupported tool in legacy canvas" ) );
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); SetNoToolSelected();
break; break;
default: default:
wxFAIL_MSG( wxT( "Unknown command id." ) ); wxFAIL_MSG( wxT( "Unknown command id." ) );
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); SetNoToolSelected();
} }
} }

View File

@ -175,7 +175,16 @@ public:
bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ) override; bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ) override;
void OnVerticalToolbar( wxCommandEvent& aEvent ); void OnVerticalToolbar( wxCommandEvent& aEvent );
/**
* handle ID_ZOOM_SELECTION and ID_NO_TOOL_SELECTED tools
*/
void OnUpdateSelectTool( wxUpdateUIEvent& aEvent );
/**
* handle most of tools og the vertical right toolbar ("Tools" toolbar)
*/
void OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent ); void OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent );
void OnUpdateOptionsToolbar( wxUpdateUIEvent& aEvent ); void OnUpdateOptionsToolbar( wxUpdateUIEvent& aEvent );
void OnUpdateLibSelected( wxUpdateUIEvent& aEvent ); void OnUpdateLibSelected( wxUpdateUIEvent& aEvent );
void OnUpdateModuleSelected( wxUpdateUIEvent& aEvent ); void OnUpdateModuleSelected( wxUpdateUIEvent& aEvent );

View File

@ -195,8 +195,8 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard ) FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard )
EVT_UPDATE_UI( ID_MODEDIT_UPDATE_MODULE_IN_BOARD, EVT_UPDATE_UI( ID_MODEDIT_UPDATE_MODULE_IN_BOARD,
FOOTPRINT_EDIT_FRAME::OnUpdateReplaceModuleInBoard ) FOOTPRINT_EDIT_FRAME::OnUpdateReplaceModuleInBoard )
EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar ) EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, FOOTPRINT_EDIT_FRAME::OnUpdateSelectTool )
EVT_UPDATE_UI( ID_ZOOM_SELECTION, FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar ) EVT_UPDATE_UI( ID_ZOOM_SELECTION, FOOTPRINT_EDIT_FRAME::OnUpdateSelectTool )
EVT_UPDATE_UI_RANGE( ID_MODEDIT_PAD_TOOL, ID_MODEDIT_MEASUREMENT_TOOL, EVT_UPDATE_UI_RANGE( ID_MODEDIT_PAD_TOOL, ID_MODEDIT_MEASUREMENT_TOOL,
FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar ) FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar )
@ -567,6 +567,12 @@ void FOOTPRINT_EDIT_FRAME::CloseModuleEditor( wxCommandEvent& Event )
} }
void FOOTPRINT_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent )
{
aEvent.Check( GetToolId() == aEvent.GetId() );
}
void FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent ) void FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent )
{ {
aEvent.Enable( GetBoard()->m_Modules != NULL ); aEvent.Enable( GetBoard()->m_Modules != NULL );

View File

@ -270,7 +270,7 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS::ROUTER_MODE aMode )
} }
} }
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
m_frame->UndoRedoBlock( false ); m_frame->UndoRedoBlock( false );
// Store routing settings till the next invocation // Store routing settings till the next invocation

View File

@ -888,7 +888,7 @@ int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode )
} }
} }
frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); frame->SetNoToolSelected();
SetContextMenu( nullptr ); SetContextMenu( nullptr );
// Store routing settings till the next invocation // Store routing settings till the next invocation

View File

@ -235,7 +235,7 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent )
line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
} }
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }
@ -264,7 +264,7 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent )
circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
} }
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }
@ -293,7 +293,7 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent )
arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT;
} }
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }
@ -458,7 +458,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
} }
m_view->Remove( &preview ); m_view->Remove( &preview );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
@ -635,7 +635,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
delete dimension; delete dimension;
m_view->Remove( &preview ); m_view->Remove( &preview );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }
@ -900,7 +900,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
break; break;
} }
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }
@ -1365,7 +1365,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
runPolygonEventLoop( polyGeomMgr ); runPolygonEventLoop( polyGeomMgr );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }

View File

@ -1112,7 +1112,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
view.SetVisible( &ruler, false ); view.SetVisible( &ruler, false );
view.Remove( &ruler ); view.Remove( &ruler );
frame()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); frame()->SetNoToolSelected();
return 0; return 0;
} }

View File

@ -218,7 +218,7 @@ int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent )
doInteractiveItemPlacement( moduleCreator, _( "Place microwave feature" ) ); doInteractiveItemPlacement( moduleCreator, _( "Place microwave feature" ) );
frame.SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); frame.SetNoToolSelected();
return 0; return 0;
} }
@ -375,7 +375,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
view.Remove( &previewRect ); view.Remove( &previewRect );
frame.SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); frame.SetNoToolSelected();
return 0; return 0;
} }

View File

@ -180,7 +180,7 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
} }
m_view->Remove( &preview ); m_view->Remove( &preview );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }

View File

@ -482,7 +482,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
} }
view->Remove( &preview ); view->Remove( &preview );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }
@ -626,7 +626,7 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
controls->SetSnapping( false ); controls->SetSnapping( false );
view->Remove( &preview ); view->Remove( &preview );
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }
@ -957,7 +957,7 @@ int PCB_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent )
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>(); PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
assert( picker ); assert( picker );
m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust zero" ) ); m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_HAND, _( "Adjust zero" ) );
picker->SetClickHandler( std::bind( setDrillOrigin, getView(), m_frame, m_placeOrigin.get(), _1 ) ); picker->SetClickHandler( std::bind( setDrillOrigin, getView(), m_frame, m_placeOrigin.get(), _1 ) );
picker->Activate(); picker->Activate();
Wait(); Wait();
@ -1046,7 +1046,7 @@ int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent )
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>(); PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
assert( picker ); assert( picker );
m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_PENCIL, _( "Highlight net" ) ); m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) );
picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, _1 ) ); picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, _1 ) );
picker->SetSnapping( false ); picker->SetSnapping( false );
picker->Activate(); picker->Activate();

View File

@ -767,7 +767,7 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
assert( picker ); assert( picker );
// TODO it will not check the toolbar button in the module editor, as it uses a different ID.. // TODO it will not check the toolbar button in the module editor, as it uses a different ID..
m_frame->SetToolID( ID_PCB_DELETE_ITEM_BUTT, wxCURSOR_PENCIL, _( "Delete item" ) ); m_frame->SetToolID( ID_PCB_DELETE_ITEM_BUTT, wxCURSOR_BULLSEYE, _( "Delete item" ) );
picker->SetSnapping( false ); picker->SetSnapping( false );
picker->SetClickHandler( std::bind( deleteItem, m_toolMgr, _1 ) ); picker->SetClickHandler( std::bind( deleteItem, m_toolMgr, _1 ) );
picker->Activate(); picker->Activate();

View File

@ -83,7 +83,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
} }
reset(); reset();
getEditFrame<PCB_BASE_FRAME>()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); getEditFrame<PCB_BASE_FRAME>()->SetNoToolSelected();
return 0; return 0;
} }

View File

@ -64,7 +64,7 @@ int ZOOM_TOOL::Main( const TOOL_EVENT& aEvent )
m_toolMgr->PassEvent(); m_toolMgr->PassEvent();
} }
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_frame->SetNoToolSelected();
return 0; return 0;
} }