Commit 4c5afc46 authored by Maciej Suminski's avatar Maciej Suminski

Added possibility of switching tools by the right toolbar buttons, without...

Added possibility of switching tools by the right toolbar buttons, without deactivating the current tool first (previously tools did not switch if there was one active).
parent bad6cdaa
...@@ -186,6 +186,26 @@ public: ...@@ -186,6 +186,26 @@ public:
return m_editFrame; return m_editFrame;
} }
/**
* Returns id of the tool that is on the top of the active tools stack
* (was invoked the most recently).
* @return Id of the currently used tool.
*/
int GetCurrentToolId() const
{
return m_activeTools.front();
}
/**
* Returns the tool that is on the top of the active tools stack
* (was invoked the most recently).
* @return Pointer to the currently used tool.
*/
TOOL_BASE* GetCurrentTool() const
{
return FindTool( GetCurrentToolId() );
}
/** /**
* Defines a state transition - the events that cause a given handler method in the tool * Defines a state transition - the events that cause a given handler method in the tool
* to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context. * to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context.
......
...@@ -633,7 +633,7 @@ void PCB_BASE_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg ) ...@@ -633,7 +633,7 @@ void PCB_BASE_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
// handle color changes for transitions in and out of ID_TRACK_BUTT // handle color changes for transitions in and out of ID_TRACK_BUTT
if( ( GetToolId() == ID_TRACK_BUTT && aId != ID_TRACK_BUTT ) if( ( GetToolId() == ID_TRACK_BUTT && aId != ID_TRACK_BUTT )
|| ( GetToolId() != ID_TRACK_BUTT && aId== ID_TRACK_BUTT ) ) || ( GetToolId() != ID_TRACK_BUTT && aId == ID_TRACK_BUTT ) )
{ {
if( DisplayOpt.ContrastModeDisplay ) if( DisplayOpt.ContrastModeDisplay )
redraw = true; redraw = true;
...@@ -641,7 +641,7 @@ void PCB_BASE_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg ) ...@@ -641,7 +641,7 @@ void PCB_BASE_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
// must do this after the tool has been set, otherwise pad::Draw() does // must do this after the tool has been set, otherwise pad::Draw() does
// not show proper color when DisplayOpt.ContrastModeDisplay is true. // not show proper color when DisplayOpt.ContrastModeDisplay is true.
if( redraw && m_canvas) if( redraw && m_canvas )
m_canvas->Refresh(); m_canvas->Refresh();
} }
......
...@@ -1370,109 +1370,124 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) ...@@ -1370,109 +1370,124 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
if( GetToolId() == id ) if( GetToolId() == id )
return; return;
INSTALL_UNBUFFERED_DC( dc, m_canvas ); if( IsGalCanvasActive() )
{
std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id );
// Stop the current command and deselect the current tool. if( !actionName.empty() )
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); {
const int MAX_TRIALS = 10;
int trials = 0;
// Cancel the current tool
// TODO while sending a lot of cancel events works for sure, it is not the most
// elegant way to cancel a tool, this should be probably done another way
while( m_toolManager.GetCurrentTool()->GetName() != "pcbnew.InteractiveSelection" &&
trials++ < MAX_TRIALS )
{
TOOL_EVENT cancel( TC_ANY, TA_CANCEL_TOOL );
m_toolManager.ProcessEvent( cancel );
}
switch( id ) m_toolManager.RunAction( actionName );
}
}
else
{ {
case ID_NO_TOOL_SELECTED: INSTALL_UNBUFFERED_DC( dc, m_canvas );
SetToolID( id, m_canvas->GetDefaultCursor(), wxEmptyString );
break;
case ID_TRACK_BUTT: // Stop the current command and deselect the current tool.
if( g_Drc_On ) m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
SetToolID( id, wxCURSOR_PENCIL, _( "Add tracks" ) );
else
SetToolID( id, wxCURSOR_QUESTION_ARROW, _( "Add tracks" ) );
if( (GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) switch( id )
{ {
Compile_Ratsnest( &dc, true ); case ID_NO_TOOL_SELECTED:
} SetToolID( id, m_canvas->GetDefaultCursor(), wxEmptyString );
break;
break;
case ID_PCB_MODULE_BUTT: case ID_TRACK_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add module" ) ); if( g_Drc_On )
break; SetToolID( id, wxCURSOR_PENCIL, _( "Add tracks" ) );
else
SetToolID( id, wxCURSOR_QUESTION_ARROW, _( "Add tracks" ) );
case ID_PCB_ZONES_BUTT: if( (GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
SetToolID( id, wxCURSOR_PENCIL, _( "Add zones" ) ); {
Compile_Ratsnest( &dc, true );
}
if( DisplayOpt.DisplayZonesMode != 0 ) break;
DisplayInfoMessage( this, _( "Warning: zone display is OFF!!!" ) );
if( !GetBoard()->IsHighLightNetON() && (GetBoard()->GetHighLightNetCode() > 0 ) ) case ID_PCB_MODULE_BUTT:
HighLight( &dc ); SetToolID( id, wxCURSOR_PENCIL, _( "Add module" ) );
break;
break; case ID_PCB_ZONES_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add zones" ) );
case ID_PCB_KEEPOUT_AREA_BUTT: if( DisplayOpt.DisplayZonesMode != 0 )
SetToolID( id, wxCURSOR_PENCIL, _( "Add keepout" ) ); DisplayInfoMessage( this, _( "Warning: zone display is OFF!!!" ) );
break;
case ID_PCB_MIRE_BUTT: if( !GetBoard()->IsHighLightNetON() && (GetBoard()->GetHighLightNetCode() > 0 ) )
SetToolID( id, wxCURSOR_PENCIL, _( "Add layer alignment target" ) ); HighLight( &dc );
break;
case ID_PCB_PLACE_OFFSET_COORD_BUTT: break;
SetToolID( id, wxCURSOR_PENCIL, _( "Adjust zero" ) );
break;
case ID_PCB_PLACE_GRID_COORD_BUTT: case ID_PCB_KEEPOUT_AREA_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Adjust grid origin" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Add keepout" ) );
break; break;
case ID_PCB_ADD_LINE_BUTT: case ID_PCB_MIRE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic line" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Add layer alignment target" ) );
break; break;
case ID_PCB_ARC_BUTT: case ID_PCB_PLACE_OFFSET_COORD_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic arc" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Adjust zero" ) );
break; break;
case ID_PCB_CIRCLE_BUTT: case ID_PCB_PLACE_GRID_COORD_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic circle" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );
break; break;
case ID_PCB_ADD_TEXT_BUTT: case ID_PCB_ADD_LINE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic line" ) );
break; break;
case ID_COMPONENT_BUTT: case ID_PCB_ARC_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Add module" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic arc" ) );
break; break;
case ID_PCB_DIMENSION_BUTT: case ID_PCB_CIRCLE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add dimension" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic circle" ) );
break; break;
case ID_PCB_DELETE_ITEM_BUTT: case ID_PCB_ADD_TEXT_BUTT:
SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
break; break;
case ID_PCB_HIGHLIGHT_BUTT: case ID_COMPONENT_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Highlight net" ) ); SetToolID( id, wxCURSOR_HAND, _( "Add module" ) );
break; break;
case ID_PCB_SHOW_1_RATSNEST_BUTT: case ID_PCB_DIMENSION_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Select rats nest" ) ); SetToolID( id, wxCURSOR_PENCIL, _( "Add dimension" ) );
break;
if( ( GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 ) case ID_PCB_DELETE_ITEM_BUTT:
Compile_Ratsnest( &dc, true ); SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
break;
break; case ID_PCB_HIGHLIGHT_BUTT:
} SetToolID( id, wxCURSOR_HAND, _( "Highlight net" ) );
break;
if( IsGalCanvasActive() ) case ID_PCB_SHOW_1_RATSNEST_BUTT:
{ SetToolID( id, wxCURSOR_HAND, _( "Select rats nest" ) );
std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id );
if( !actionName.empty() ) if( ( GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 )
m_toolManager.RunAction( actionName ); Compile_Ratsnest( &dc, true );
return; break;
}
} }
} }
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <id.h> #include <id.h>
#include <pcbnew_id.h>
#include <view/view_controls.h> #include <view/view_controls.h>
#include <pcbcommon.h> #include <pcbcommon.h>
#include <pcb_painter.h> #include <pcb_painter.h>
...@@ -432,6 +433,7 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -432,6 +433,7 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
// SetContextMenu ( m_menu ); // SetContextMenu ( m_menu );
// setMsgPanel(true, 0, wxT("KiRouter"), wxT("Pick an item to start routing")); // setMsgPanel(true, 0, wxT("KiRouter"), wxT("Pick an item to start routing"));
getEditFrame<PCB_EDIT_FRAME>()->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Add tracks" ) );
ctls->SetSnapping( true ); ctls->SetSnapping( true );
ctls->ShowCursor( true ); ctls->ShowCursor( true );
...@@ -469,4 +471,3 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -469,4 +471,3 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
return 0; return 0;
} }
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <id.h> #include <id.h>
#include <pcbnew_id.h>
#include <confirm.h> #include <confirm.h>
#include <view/view_group.h> #include <view/view_group.h>
...@@ -69,12 +70,16 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason ) ...@@ -69,12 +70,16 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason )
int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent )
{ {
m_frame->SetToolID( ID_PCB_ADD_LINE_BUTT, wxCURSOR_PENCIL, _( "Add graphic line" ) );
return drawSegment( S_SEGMENT, true ); return drawSegment( S_SEGMENT, true );
} }
int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent )
{ {
m_frame->SetToolID( ID_PCB_CIRCLE_BUTT, wxCURSOR_PENCIL, _( "Add graphic circle" ) );
return drawSegment( S_CIRCLE, false ); return drawSegment( S_CIRCLE, false );
} }
...@@ -100,6 +105,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -100,6 +105,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
m_controls->SetSnapping( true ); m_controls->SetSnapping( true );
Activate(); Activate();
m_frame->SetToolID( ID_PCB_ARC_BUTT, wxCURSOR_PENCIL, _( "Add graphic arc" ) );
enum ARC_STEPS enum ARC_STEPS
{ {
...@@ -286,6 +292,7 @@ int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent ) ...@@ -286,6 +292,7 @@ int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent )
m_controls->SetAutoPan( true ); m_controls->SetAutoPan( true );
Activate(); Activate();
m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) );
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
...@@ -390,6 +397,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) ...@@ -390,6 +397,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
m_controls->SetSnapping( true ); m_controls->SetSnapping( true );
Activate(); Activate();
m_frame->SetToolID( ID_PCB_DIMENSION_BUTT, wxCURSOR_PENCIL, _( "Add dimension" ) );
enum DIMENSION_STEPS enum DIMENSION_STEPS
{ {
...@@ -549,12 +557,16 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent ) ...@@ -549,12 +557,16 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
{ {
m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zones" ) );
return drawZone( false ); return drawZone( false );
} }
int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent ) int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
{ {
m_frame->SetToolID( ID_PCB_KEEPOUT_AREA_BUTT, wxCURSOR_PENCIL, _( "Add keepout" ) );
return drawZone( true ); return drawZone( true );
} }
...@@ -581,6 +593,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent ) ...@@ -581,6 +593,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
m_controls->SetAutoPan( true ); m_controls->SetAutoPan( true );
Activate(); Activate();
m_frame->SetToolID( ID_PCB_MIRE_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) );
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
...@@ -656,6 +669,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent ) ...@@ -656,6 +669,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
m_controls->SetAutoPan( true ); m_controls->SetAutoPan( true );
Activate(); Activate();
m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_HAND, _( "Add module" ) );
// Main loop: keep receiving events // Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() )
......
...@@ -68,7 +68,7 @@ void PCB_EDIT_FRAME::setupTools() ...@@ -68,7 +68,7 @@ void PCB_EDIT_FRAME::setupTools()
m_toolManager.RegisterTool( new PCBNEW_CONTROL ); m_toolManager.RegisterTool( new PCBNEW_CONTROL );
m_toolManager.SetEnvironment( NULL, GetGalCanvas()->GetView(), m_toolManager.SetEnvironment( NULL, GetGalCanvas()->GetView(),
GetGalCanvas()->GetViewControls(), this ); GetGalCanvas()->GetViewControls(), this );
m_toolManager.ResetTools( TOOL_BASE::RUN ); m_toolManager.ResetTools( TOOL_BASE::RUN );
// Run the selection tool, it is supposed to be always active // Run the selection tool, it is supposed to be always active
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment