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:
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
* 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 )
// handle color changes for transitions in and out of 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 )
redraw = true;
......@@ -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
// not show proper color when DisplayOpt.ContrastModeDisplay is true.
if( redraw && m_canvas)
if( redraw && m_canvas )
m_canvas->Refresh();
}
......
......@@ -1370,6 +1370,30 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
if( GetToolId() == id )
return;
if( IsGalCanvasActive() )
{
std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id );
if( !actionName.empty() )
{
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 );
}
m_toolManager.RunAction( actionName );
}
}
else
{
INSTALL_UNBUFFERED_DC( dc, m_canvas );
// Stop the current command and deselect the current tool.
......@@ -1465,14 +1489,5 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
break;
}
if( IsGalCanvasActive() )
{
std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id );
if( !actionName.empty() )
m_toolManager.RunAction( actionName );
return;
}
}
......@@ -27,6 +27,7 @@
#include <wxPcbStruct.h>
#include <id.h>
#include <pcbnew_id.h>
#include <view/view_controls.h>
#include <pcbcommon.h>
#include <pcb_painter.h>
......@@ -432,6 +433,7 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
// SetContextMenu ( m_menu );
// 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->ShowCursor( true );
......@@ -469,4 +471,3 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
return 0;
}
......@@ -28,6 +28,7 @@
#include <wxPcbStruct.h>
#include <id.h>
#include <pcbnew_id.h>
#include <confirm.h>
#include <view/view_group.h>
......@@ -69,12 +70,16 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason )
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 );
}
int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent )
{
m_frame->SetToolID( ID_PCB_CIRCLE_BUTT, wxCURSOR_PENCIL, _( "Add graphic circle" ) );
return drawSegment( S_CIRCLE, false );
}
......@@ -100,6 +105,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
m_controls->SetSnapping( true );
Activate();
m_frame->SetToolID( ID_PCB_ARC_BUTT, wxCURSOR_PENCIL, _( "Add graphic arc" ) );
enum ARC_STEPS
{
......@@ -286,6 +292,7 @@ int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent )
m_controls->SetAutoPan( true );
Activate();
m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) );
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
......@@ -390,6 +397,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
m_controls->SetSnapping( true );
Activate();
m_frame->SetToolID( ID_PCB_DIMENSION_BUTT, wxCURSOR_PENCIL, _( "Add dimension" ) );
enum DIMENSION_STEPS
{
......@@ -549,12 +557,16 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
{
m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zones" ) );
return drawZone( false );
}
int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
{
m_frame->SetToolID( ID_PCB_KEEPOUT_AREA_BUTT, wxCURSOR_PENCIL, _( "Add keepout" ) );
return drawZone( true );
}
......@@ -581,6 +593,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
m_controls->SetAutoPan( true );
Activate();
m_frame->SetToolID( ID_PCB_MIRE_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) );
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
......@@ -656,6 +669,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
m_controls->SetAutoPan( true );
Activate();
m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_HAND, _( "Add module" ) );
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
......
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