Push/pop tools even when selected from the toolbar.

This commit is contained in:
Jeff Young 2019-06-18 18:56:40 +01:00
parent 7dd247f1dc
commit dcbd897a95
35 changed files with 266 additions and 412 deletions

View File

@ -419,19 +419,14 @@ void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
}
void EDA_DRAW_FRAME::SetTool( const std::string& actionName )
{
if( !m_toolStack.empty() )
m_toolStack.pop_back();
PushTool( actionName );
}
void EDA_DRAW_FRAME::PushTool( const std::string& actionName )
{
m_toolStack.push_back( actionName );
// Human cognitive stacking is very shallow; deeper tool stacks just get annoying
if( m_toolStack.size() > 3 )
m_toolStack.pop_front();
TOOL_ACTION* action = m_toolManager->GetActionManager()->FindAction( actionName );
if( action )
@ -451,6 +446,9 @@ void EDA_DRAW_FRAME::PopTool()
if( action )
{
// Pop the action as running it will push it back onto the stack
m_toolStack.pop_back();
TOOL_EVENT evt = action->MakeEvent();
evt.SetHasPosition( false );
GetToolManager()->PostEvent( evt );

View File

@ -176,9 +176,7 @@ bool TOOL_EVENT::IsDblClick( int aButtonMask ) const
bool TOOL_EVT_UTILS::IsCancelInteractive( const TOOL_EVENT& aEvt )
{
return aEvt.IsAction( &ACTIONS::cancelInteractive )
|| aEvt.IsActivate()
|| aEvt.IsCancel();
return aEvt.IsAction( &ACTIONS::cancelInteractive ) || aEvt.IsCancel();
}

View File

@ -25,6 +25,7 @@
#include <bitmaps.h>
#include <tools/ee_actions.h>
#include <core/typeinfo.h>
#include <layers_id_colors_and_visibility.h>
// Actions, being statically-defined, require specialized I18N handling. We continue to
@ -612,13 +613,13 @@ TOOL_ACTION EE_ACTIONS::drawWire( "eeschema.InteractiveDrawingLineWireBus.drawWi
AS_GLOBAL,
'W', LEGACY_HK_NAME( "Begin Wire" ),
_( "Add Wire" ), _( "Add a wire" ),
add_line_xpm, AF_ACTIVATE );
add_line_xpm, AF_ACTIVATE, (void*) LAYER_WIRE );
TOOL_ACTION EE_ACTIONS::drawBus( "eeschema.InteractiveDrawingLineWireBus.drawBusses",
AS_GLOBAL,
'B', LEGACY_HK_NAME( "Begin Bus" ),
_( "Add Bus" ), _( "Add a bus" ),
add_bus_xpm, AF_ACTIVATE );
add_bus_xpm, AF_ACTIVATE, (void*) LAYER_BUS );
TOOL_ACTION EE_ACTIONS::unfoldBus( "eeschema.InteractiveDrawingLineWireBus.unfoldBus",
AS_GLOBAL,
@ -630,7 +631,7 @@ TOOL_ACTION EE_ACTIONS::drawLines( "eeschema.InteractiveDrawingLineWireBus.drawL
AS_GLOBAL,
'I', LEGACY_HK_NAME( "Add Graphic PolyLine" ),
_( "Add Lines" ), _( "Add connected graphic lines" ),
add_dashed_line_xpm, AF_ACTIVATE );
add_dashed_line_xpm, AF_ACTIVATE, (void*) LAYER_NOTES );
TOOL_ACTION EE_ACTIONS::finishLineWireOrBus( "eeschema.InteractiveDrawingLineWireBus.finish",
AS_GLOBAL,

View File

@ -88,7 +88,7 @@ int EE_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
}
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( m_cancelHandler )
{

View File

@ -301,16 +301,18 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
inDrag = false;
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( inDrag ) // Restore the last change
{
rollbackFromUndo();
inDrag = false;
modified = false;
}
// ESC should clear selection along with edit points
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
break;
}

View File

@ -406,7 +406,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
}
else if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsCancel() )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
{
ClearSelection();
m_toolMgr->RunAction( EE_ACTIONS::clearHighlight, true );
@ -653,7 +653,7 @@ bool EE_SELECTION_TOOL::selectMultiple()
while( TOOL_EVENT* evt = Wait() )
{
if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsActivate() || evt->IsCancel() )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
cancelled = true;
break;

View File

@ -66,55 +66,22 @@ bool LIB_DRAWING_TOOLS::Init()
}
int LIB_DRAWING_TOOLS::PlacePin( const TOOL_EVENT& aEvent )
int LIB_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
{
if( aEvent.HasPosition() )
{
m_frame->PushTool( aEvent.GetCommandStr().get() );
doTwoClickPlace( LIB_PIN_T, true );
m_frame->PopTool();
}
else
{
m_frame->SetTool( aEvent.GetCommandStr().get() );
doTwoClickPlace( LIB_PIN_T, false );
}
return 0;
}
int LIB_DRAWING_TOOLS::PlaceText( const TOOL_EVENT& aEvent )
{
if( aEvent.HasPosition() )
{
m_frame->PushTool( aEvent.GetCommandStr().get() );
doTwoClickPlace( LIB_TEXT_T, true );
m_frame->PopTool();
}
else
{
m_frame->SetTool( aEvent.GetCommandStr().get() );
doTwoClickPlace( LIB_TEXT_T, false );
}
return 0;
}
int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
{
LIB_PIN_TOOL* pinTool = aType == LIB_PIN_T ? m_toolMgr->GetTool<LIB_PIN_TOOL>() : nullptr;
KICAD_T type = aEvent.Parameter<KICAD_T>();
bool immediateMode = aEvent.HasPosition();
LIB_PIN_TOOL* pinTool = type == LIB_PIN_T ? m_toolMgr->GetTool<LIB_PIN_TOOL>() : nullptr;
VECTOR2I cursorPos;
EDA_ITEM* item = nullptr;
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
// Prime the pump
if( aImmediateMode )
if( immediateMode )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events
@ -122,7 +89,7 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
{
cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( item )
{
@ -131,14 +98,16 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
delete item;
item = nullptr;
if( !evt->IsActivate() && !aImmediateMode )
continue;
if( evt->IsActivate() || immediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
if( !evt->IsActivate() && !aImmediateMode )
m_frame->PopTool();
break;
break;
}
}
else if( evt->IsClick( BUT_LEFT ) )
@ -153,7 +122,7 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
switch( aType )
switch( type )
{
case LIB_PIN_T:
{
@ -178,7 +147,7 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
break;
}
default:
wxFAIL_MSG( "doTwoClickPlace(): unknown type" );
wxFAIL_MSG( "TwoClickPlace(): unknown type" );
}
// Restore cursor after dialog
@ -210,7 +179,7 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
item->ClearEditFlags();
break;
default:
wxFAIL_MSG( "doTwoClickPlace(): unknown type" );
wxFAIL_MSG( "TwoClickPlace(): unknown type" );
}
item = nullptr;
@ -219,8 +188,11 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
m_frame->RebuildView();
m_frame->OnModify();
if( aImmediateMode )
if( immediateMode )
{
m_frame->PopTool();
break;
}
}
}
else if( evt->IsClick( BUT_RIGHT ) )
@ -240,8 +212,8 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
}
// Enable autopanning and cursor capture only when there is an item to be placed
getViewControls()->SetAutoPan( !!item );
getViewControls()->CaptureCursor( !!item );
getViewControls()->SetAutoPan( item != nullptr );
getViewControls()->CaptureCursor( item != nullptr );
}
return 0;
@ -251,6 +223,7 @@ int LIB_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType, bool aImmediateMode )
int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
{
KICAD_T type = aEvent.Parameter<KICAD_T>();
bool immediateMode = aEvent.HasPosition();
// We might be running as the same shape in another co-routine. Make sure that one
// gets whacked.
@ -259,19 +232,22 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
LIB_PART* part = m_frame->GetCurPart();
LIB_ITEM* item = nullptr;
// Prime the pump
if( immediateMode )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events
while( auto evt = Wait() )
{
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_view->ClearPreview();
@ -281,14 +257,16 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
delete item;
item = nullptr;
if( !evt->IsActivate() )
continue;
if( evt->IsActivate() || immediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
if( !evt->IsActivate() )
m_frame->PopTool();
break;
break;
}
}
else if( evt->IsClick( BUT_LEFT ) && !item )
@ -341,6 +319,12 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_frame->RebuildView();
m_frame->OnModify();
if( immediateMode )
{
m_frame->PopTool();
break;
}
}
}
@ -367,8 +351,8 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
}
// Enable autopanning and cursor capture only when there is a shape being drawn
getViewControls()->SetAutoPan( !!item );
getViewControls()->CaptureCursor( !!item );
getViewControls()->SetAutoPan( item != nullptr );
getViewControls()->CaptureCursor( item != nullptr );
}
return 0;
@ -377,17 +361,16 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
{
m_frame->PushTool( aEvent.GetCommandStr().get() );
getViewControls()->ShowCursor( true );
getViewControls()->SetSnapping( true );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
break;
}
@ -418,7 +401,6 @@ int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
}
m_frame->PopTool();
return 0;
}
@ -456,8 +438,8 @@ int LIB_DRAWING_TOOLS::RepeatDrawItem( const TOOL_EVENT& aEvent )
void LIB_DRAWING_TOOLS::setTransitions()
{
Go( &LIB_DRAWING_TOOLS::PlacePin, EE_ACTIONS::placeSymbolPin.MakeEvent() );
Go( &LIB_DRAWING_TOOLS::PlaceText, EE_ACTIONS::placeSymbolText.MakeEvent() );
Go( &LIB_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSymbolPin.MakeEvent() );
Go( &LIB_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSymbolText.MakeEvent() );
Go( &LIB_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawSymbolRectangle.MakeEvent() );
Go( &LIB_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawSymbolCircle.MakeEvent() );
Go( &LIB_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawSymbolArc.MakeEvent() );

View File

@ -45,8 +45,7 @@ public:
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init() override;
int PlacePin( const TOOL_EVENT& aEvent );
int PlaceText( const TOOL_EVENT& aEvent );
int TwoClickPlace( const TOOL_EVENT& aEvent );
int DrawShape( const TOOL_EVENT& aEvent );
int PlaceAnchor( const TOOL_EVENT& aEvent );

View File

@ -293,17 +293,17 @@ static bool deleteItem( SCH_BASE_FRAME* aFrame, const VECTOR2D& aPosition )
int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
{
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
wxCHECK( picker, 0 );
picker->SetClickHandler( std::bind( deleteItem, m_frame, std::placeholders::_1 ) );
picker->SetCancelHandler( [this]() { m_frame->ClearToolStack(); } );
picker->Activate();
Wait();
m_frame->PopTool();
return 0;
}

View File

@ -84,8 +84,8 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
return 0;
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
controls->ShowCursor( true );
controls->SetAutoPan( true );
@ -193,7 +193,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
//------------------------------------------------------------------------
// Handle cancel
//
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( m_moveInProgress )
restore_state = true;
@ -279,7 +279,6 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
m_moveInProgress = false;
m_frame->PopTool();
return 0;
}

View File

@ -100,10 +100,7 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
m_selectionTool->AddItemToSel( component );
}
if( immediateMode )
m_frame->PushTool( aEvent.GetCommandStr().get() );
else
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
@ -121,7 +118,7 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
{
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( component )
{
@ -130,14 +127,16 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
delete component;
component = nullptr;
if( !evt->IsActivate() && !immediateMode )
continue;
if( evt->IsActivate() || immediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
if( !evt->IsActivate() && !immediateMode )
m_frame->PopTool();
break;
break;
}
}
else if( evt->IsClick( BUT_LEFT ) )
{
@ -178,6 +177,12 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
component = nullptr;
m_view->ClearPreview();
if( immediateMode )
{
m_frame->PopTool();
break;
}
}
}
else if( evt->IsClick( BUT_RIGHT ) )
@ -211,13 +216,10 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
}
// Enable autopanning and cursor capture only when there is a module to be placed
getViewControls()->SetAutoPan( !!component );
getViewControls()->CaptureCursor( !!component );
getViewControls()->SetAutoPan( component != nullptr );
getViewControls()->CaptureCursor( component != nullptr );
}
if( immediateMode )
m_frame->PopTool();
return 0;
}
@ -227,10 +229,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
SCH_BITMAP* image = aEvent.Parameter<SCH_BITMAP*>();
bool immediateMode = image || aEvent.HasPosition();
if( immediateMode )
m_frame->PushTool( aEvent.GetCommandStr().get() );
else
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
@ -258,7 +257,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
{
cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( image )
{
@ -267,14 +266,16 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
delete image;
image = nullptr;
if( !evt->IsActivate() && !immediateMode )
continue;
if( evt->IsActivate() || immediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
if( !evt->IsActivate() && !immediateMode )
m_frame->PopTool();
break;
break;
}
}
else if( evt->IsClick( BUT_LEFT ) )
{
@ -323,7 +324,10 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
m_view->ClearPreview();
if( immediateMode )
{
m_frame->PopTool();
break;
}
}
}
else if( evt->IsClick( BUT_RIGHT ) )
@ -344,13 +348,10 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
}
// Enable autopanning and cursor capture only when there is a module to be placed
getViewControls()->SetAutoPan( !!image );
getViewControls()->CaptureCursor( !!image );
getViewControls()->SetAutoPan( image != nullptr );
getViewControls()->CaptureCursor( image != nullptr );
}
if( immediateMode )
m_frame->PopTool();
return 0;
}
@ -384,11 +385,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
getViewControls()->ShowCursor( true );
getViewControls()->SetSnapping( true );
if( immediateMode )
m_frame->PushTool( aEvent.GetCommandStr().get() );
else
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
// Prime the pump
@ -400,9 +397,9 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
{
cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( !evt->IsActivate() && !immediateMode )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
break;
@ -445,7 +442,10 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
}
if( immediateMode )
{
m_frame->PopTool();
break;
}
}
else if( evt->IsClick( BUT_RIGHT ) )
{
@ -453,9 +453,6 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
}
}
if( immediateMode )
m_frame->PopTool();
return 0;
}
@ -469,10 +466,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
if( immediateMode )
m_frame->PushTool( aEvent.GetCommandStr().get() );
else
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
@ -485,7 +479,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
{
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( item )
{
@ -494,14 +488,16 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
delete item;
item = nullptr;
if( !evt->IsActivate() && !immediateMode )
continue;
if( evt->IsActivate() || immediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
if( !evt->IsActivate() && !immediateMode )
m_frame->PopTool();
break;
break;
}
}
else if( evt->IsClick( BUT_LEFT ) )
{
@ -583,7 +579,10 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
m_view->ClearPreview();
if( immediateMode )
{
m_frame->PopTool();
break;
}
}
}
else if( evt->IsClick( BUT_RIGHT ) )
@ -621,9 +620,6 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
getViewControls()->CaptureCursor( item != nullptr );
}
if( immediateMode )
m_frame->PopTool();
return 0;
}
@ -636,10 +632,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
if( immediateMode )
m_frame->PushTool( aEvent.GetCommandStr().get() );
else
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
@ -652,7 +645,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
{
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_view->ClearPreview();
@ -662,14 +655,16 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
delete sheet;
sheet = nullptr;
if( !evt->IsActivate() && !immediateMode )
continue;
if( evt->IsActivate() || immediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
if( !evt->IsActivate() && !immediateMode )
m_frame->PopTool();
break;
break;
}
}
else if( evt->IsClick( BUT_LEFT ) && !sheet )
@ -705,7 +700,10 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
sheet = nullptr;
if( immediateMode )
{
m_frame->PopTool();
break;
}
}
else if( sheet && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
@ -726,13 +724,10 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
}
// Enable autopanning and cursor capture only when there is a sheet to be placed
getViewControls()->SetAutoPan( !!sheet );
getViewControls()->CaptureCursor( !!sheet );
getViewControls()->SetAutoPan( sheet != nullptr );
getViewControls()->CaptureCursor( sheet != nullptr);
}
if( immediateMode )
m_frame->PopTool();
return 0;
}

View File

@ -935,7 +935,7 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
{
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
@ -985,16 +985,13 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
}
} );
picker->SetCancelHandler( [this] () {
m_frame->ClearToolStack();
} );
picker->Activate();
Wait();
if( m_pickerItem )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
m_frame->PopTool();
return 0;
}

View File

@ -692,17 +692,17 @@ int SCH_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent )
if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
m_frame->RecalculateConnections();
m_frame->SetTool( aEvent.GetCommandStr().get() );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
EE_PICKER_TOOL* picker = m_toolMgr->GetTool<EE_PICKER_TOOL>();
wxCHECK( picker, 0 );
picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, std::placeholders::_1 ) );
picker->SetCancelHandler( [this]() { m_frame->ClearToolStack(); } );
picker->Activate();
Wait();
m_frame->PopTool();
return 0;
}

View File

@ -82,7 +82,7 @@ private:
{
frame->RecalculateConnections();
// Have to pick up the pointer again because it may have been changed by SchematicCleanUp
// Pick up the pointer again because it may have been changed by SchematicCleanUp
selection = selTool->RequestSelection( busType );
bus = (SCH_LINE*) selection.Front();
}
@ -250,43 +250,15 @@ bool SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( const SELECTION& aSelection
}
int SCH_LINE_WIRE_BUS_TOOL::DrawWires( const TOOL_EVENT& aEvent )
int SCH_LINE_WIRE_BUS_TOOL::DrawSegments( const TOOL_EVENT& aEvent )
{
if( aEvent.HasPosition() ) // Start drawing
{
SCH_LAYER_ID layer = aEvent.Parameter<SCH_LAYER_ID>();
if( aEvent.HasPosition() )
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
m_frame->PushTool( aEvent.GetCommandStr().get() );
doDrawSegments( LAYER_WIRE, nullptr, true );
m_frame->PopTool();
}
else // Invoke the tool
{
m_frame->SetTool( aEvent.GetCommandStr().get() );
doDrawSegments( LAYER_WIRE, nullptr, false );
}
return 0;
}
int SCH_LINE_WIRE_BUS_TOOL::DrawBusses( const TOOL_EVENT& aEvent )
{
if( aEvent.HasPosition() ) // Start drawing
{
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
m_frame->PushTool( aEvent.GetCommandStr().get() );
doDrawSegments( LAYER_BUS, nullptr, true );
m_frame->PopTool();
}
else // Invoke the tool
{
m_frame->SetTool( aEvent.GetCommandStr().get() );
doDrawSegments( LAYER_BUS, nullptr, false );
}
return 0;
m_frame->PushTool( aEvent.GetCommandStr().get() );
return doDrawSegments( layer, nullptr, aEvent.HasPosition() );
}
@ -298,6 +270,7 @@ int SCH_LINE_WIRE_BUS_TOOL::UnfoldBus( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
if( netPtr )
@ -327,20 +300,15 @@ int SCH_LINE_WIRE_BUS_TOOL::UnfoldBus( const TOOL_EVENT& aEvent )
}
}
// Break a wire for the given net out of the bus
if( !net.IsEmpty() )
{
// Break a wire for the given net out of the bus
segment = doUnfoldBus( net );
}
// If we have an unfolded wire to draw, then draw it
if( segment )
{
m_frame->PushTool( aEvent.GetCommandStr().get() );
doDrawSegments( LAYER_WIRE, segment, true );
m_frame->PopTool();
}
m_frame->PopTool();
return 0;
}
@ -368,26 +336,6 @@ SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet )
}
int SCH_LINE_WIRE_BUS_TOOL::DrawLines( const TOOL_EVENT& aEvent)
{
if( aEvent.HasPosition() ) // Start drawing
{
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
m_frame->PushTool( aEvent.GetCommandStr().get() );
doDrawSegments( LAYER_NOTES, nullptr, true );
m_frame->PopTool();
}
else // Invoke the tool
{
m_frame->SetTool( aEvent.GetCommandStr().get() );
doDrawSegments( LAYER_NOTES, nullptr, false );
}
return 0;
}
// Storage for the line segments while drawing
static DLIST<SCH_LINE> s_wires;
@ -491,6 +439,7 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment, bool
Activate();
// Prime the pump
if( aImmediateMode && !aSegment )
m_toolMgr->RunAction( ACTIONS::cursorClick );
@ -502,7 +451,7 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment, bool
//------------------------------------------------------------------------
// Handle cancel:
//
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( aSegment || m_busUnfold.in_progress )
{
@ -524,14 +473,16 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment, bool
m_view->ClearPreview();
m_view->ShowPreview( false );
if( !evt->IsActivate() && !aImmediateMode )
continue;
if( evt->IsActivate() || aImmediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
if( !evt->IsActivate() && !aImmediateMode )
m_frame->PopTool();
break;
break;
}
}
//------------------------------------------------------------------------
// Handle finish:
@ -548,7 +499,10 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment, bool
}
if( aImmediateMode )
{
m_frame->PopTool();
break;
}
}
//------------------------------------------------------------------------
// Handle click:
@ -688,8 +642,8 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment, bool
}
// Enable autopanning and cursor capture only when there is a segment to be placed
getViewControls()->SetAutoPan( !!aSegment );
getViewControls()->CaptureCursor( !!aSegment );
getViewControls()->SetAutoPan( aSegment != nullptr );
getViewControls()->CaptureCursor( aSegment != nullptr );
}
return 0;
@ -889,9 +843,9 @@ void SCH_LINE_WIRE_BUS_TOOL::finishSegments()
void SCH_LINE_WIRE_BUS_TOOL::setTransitions()
{
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawWires, EE_ACTIONS::drawWire.MakeEvent() );
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawBusses, EE_ACTIONS::drawBus.MakeEvent() );
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawLines, EE_ACTIONS::drawLines.MakeEvent() );
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawSegments, EE_ACTIONS::drawWire.MakeEvent() );
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawSegments, EE_ACTIONS::drawBus.MakeEvent() );
Go( &SCH_LINE_WIRE_BUS_TOOL::DrawSegments, EE_ACTIONS::drawLines.MakeEvent() );
Go( &SCH_LINE_WIRE_BUS_TOOL::UnfoldBus, EE_ACTIONS::unfoldBus.MakeEvent() );
Go( &SCH_LINE_WIRE_BUS_TOOL::UnfoldBus, EE_ACTIONS::unfoldBus.MakeEvent() );
}

View File

@ -65,10 +65,7 @@ public:
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init() override;
int DrawWires( const TOOL_EVENT& aEvent );
int DrawBusses( const TOOL_EVENT& aEvent );
int DrawLines( const TOOL_EVENT& aEvent );
int DrawSegments( const TOOL_EVENT& aEvent );
int UnfoldBus( const TOOL_EVENT& aEvent );
// SELECTION_CONDITIONs:

View File

@ -445,7 +445,6 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
m_dragAdditions.clear();
m_moveInProgress = false;
m_frame->PopTool();
return 0;
}

View File

@ -300,7 +300,6 @@ public:
* a single TOOL_BASE derived class to implement several user "tools", such as rectangle
* and circle, or wire and bus. So each user-level tool is actually a TOOL_ACTION.
*/
virtual void SetTool( const std::string& actionName );
virtual void PushTool( const std::string& actionName );
virtual void PopTool();
virtual void ClearToolStack();

View File

@ -24,6 +24,7 @@
#include <tool/tool_action.h>
#include <bitmaps.h>
#include <tools/pl_actions.h>
#include <ws_data_item.h>
// Actions, being statically-defined, require specialized I18N handling. We continue to
@ -39,42 +40,22 @@
TOOL_ACTION PL_ACTIONS::drawLine( "plEditor.InteractiveDrawing.drawLine",
AS_GLOBAL, 0, "",
_( "Add Line" ), _( "Add a line" ),
add_graphical_segments_xpm, AF_ACTIVATE );
add_graphical_segments_xpm, AF_ACTIVATE, (void*) WS_DATA_ITEM::WS_SEGMENT );
TOOL_ACTION PL_ACTIONS::drawRectangle( "plEditor.InteractiveDrawing.drawRectangle",
AS_GLOBAL, 0, "",
_( "Add Rectangle" ), _( "Add a rectangle" ),
add_rectangle_xpm, AF_ACTIVATE );
add_rectangle_xpm, AF_ACTIVATE, (void*) WS_DATA_ITEM::WS_RECT );
TOOL_ACTION PL_ACTIONS::placeText( "plEditor.InteractiveDrawing.placeText",
AS_GLOBAL, 0, "",
_( "Add Text" ), _( "Add a text item" ),
text_xpm, AF_ACTIVATE );
text_xpm, AF_ACTIVATE, (void*) WS_DATA_ITEM::WS_TEXT );
TOOL_ACTION PL_ACTIONS::placeImage( "plEditor.InteractiveDrawing.placeImage",
AS_GLOBAL, 0, "",
_( "Add Bitmap" ), _( "Add a bitmap image" ),
image_xpm, AF_ACTIVATE );
TOOL_ACTION PL_ACTIONS::addLine( "plEditor.InteractiveDrawing.addLine",
AS_GLOBAL, 0, "",
_( "Add Line" ), _( "Add a line" ),
add_dashed_line_xpm, AF_ACTIVATE );
TOOL_ACTION PL_ACTIONS::addRectangle( "plEditor.InteractiveDrawing.addRectangle",
AS_GLOBAL, 0, "",
_( "Add Rectangle" ), _( "Add a rectangle" ),
add_rectangle_xpm, AF_ACTIVATE );
TOOL_ACTION PL_ACTIONS::addText( "plEditor.InteractiveDrawing.addText",
AS_GLOBAL, 0, "",
_( "Add Text" ), _( "Add a text item" ),
text_xpm, AF_ACTIVATE );
TOOL_ACTION PL_ACTIONS::addImage( "plEditor.InteractiveDrawing.addImage",
AS_GLOBAL, 0, "",
_( "Add Bitmap" ), _( "Add a bitmap image" ),
image_xpm, AF_ACTIVATE );
image_xpm, AF_ACTIVATE, (void*) WS_DATA_ITEM::WS_BITMAP );
// PL_EDIT_TOOL

View File

@ -64,10 +64,6 @@ public:
static TOOL_ACTION placeImage;
static TOOL_ACTION drawRectangle;
static TOOL_ACTION drawLine;
static TOOL_ACTION addText;
static TOOL_ACTION addImage;
static TOOL_ACTION addRectangle;
static TOOL_ACTION addLine;
static TOOL_ACTION appendImportedWorksheet;
// Editing

View File

@ -73,46 +73,27 @@ void PL_DRAWING_TOOLS::Reset( RESET_REASON aReason )
int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
{
bool isText;
bool isImmediate = false;
if( aEvent.IsAction( &PL_ACTIONS::placeText ) )
{
isText = true;
m_frame->SetToolID( ID_PL_TEXT_TOOL, wxCURSOR_PENCIL, _( "Add text" ) );
}
else if( aEvent.IsAction( &PL_ACTIONS::placeImage ) )
{
isText = false;
m_frame->SetToolID( ID_PL_IMAGE_TOOL, wxCURSOR_PENCIL, _( "Add image" ) );
}
else if( aEvent.IsAction( & PL_ACTIONS::addText ) )
{
isText = true;
isImmediate = true;
}
else if( aEvent.IsAction( & PL_ACTIONS::addImage ) )
{
isText = false;
isImmediate = true;
}
else
wxCHECK_MSG( false, 0, "Unknown action in PL_DRAWING_TOOLS::PlaceItem()" );
VECTOR2I cursorPos;
WS_DRAW_ITEM_BASE* item = nullptr;
WS_DATA_ITEM::WS_ITEM_TYPE type = aEvent.Parameter<WS_DATA_ITEM::WS_ITEM_TYPE>();
bool immediateMode = aEvent.HasPosition();
VECTOR2I cursorPos;
WS_DRAW_ITEM_BASE* item = nullptr;
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
// Prime the pump
if( immediateMode )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( item )
{
@ -123,14 +104,19 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
// There's nothing to roll-back, but we still need to pop the undo stack
m_frame->RollbackFromUndo();
if( !evt->IsActivate() && !isImmediate )
continue;
if( evt->IsActivate() || immediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
break;
break;
}
}
else if( evt->IsClick( BUT_LEFT ) || ( isImmediate && !item ) )
else if( evt->IsClick( BUT_LEFT ) )
{
// First click creates...
if( !item )
@ -140,8 +126,7 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
WS_DATA_ITEM* dataItem;
dataItem = m_frame->AddPageLayoutItem( isText ? WS_DATA_ITEM::WS_TEXT
: WS_DATA_ITEM::WS_BITMAP );
dataItem = m_frame->AddPageLayoutItem( type );
item = dataItem->GetDrawItems()[0];
item->SetFlags( IS_NEW | IS_MOVED );
m_selectionTool->AddItemToSel( item );
@ -159,8 +144,11 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
m_frame->OnModify();
if( isImmediate )
if( immediateMode )
{
m_frame->PopTool();
break;
}
}
}
else if( evt->IsClick( BUT_RIGHT ) )
@ -180,61 +168,40 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
}
// Enable autopanning and cursor capture only when there is an item to be placed
getViewControls()->SetAutoPan( !!item );
getViewControls()->CaptureCursor( !!item );
getViewControls()->SetAutoPan( item != nullptr );
getViewControls()->CaptureCursor( item != nullptr );
}
m_frame->SetNoToolSelected();
return 0;
}
int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
{
WS_DATA_ITEM::WS_ITEM_TYPE type = aEvent.Parameter<WS_DATA_ITEM::WS_ITEM_TYPE>();
bool immediateMode = aEvent.HasPosition();
WS_DRAW_ITEM_BASE* item = nullptr;
// We might be running as the same shape in another co-routine. Make sure that one
// gets whacked.
m_toolMgr->DeactivateTool();
bool isDrawLine;
bool isImmediate = false;
if( aEvent.IsAction( &PL_ACTIONS::drawLine ) )
{
isDrawLine = true;
m_frame->SetToolID( ID_PL_LINE_TOOL, wxCURSOR_PENCIL, _( "Draw line" ) );
}
else if( aEvent.IsAction( &PL_ACTIONS::drawRectangle ) )
{
isDrawLine = false;
m_frame->SetToolID( ID_PL_RECTANGLE_TOOL, wxCURSOR_PENCIL, _( "Draw rectangle" ) );
}
else if( aEvent.IsAction( &PL_ACTIONS::addLine ) )
{
isDrawLine = true;
isImmediate = true;
}
else if( aEvent.IsAction( &PL_ACTIONS::addRectangle ) )
{
isDrawLine = false;
isImmediate = true;
}
else
wxCHECK_MSG( false, 0, "Unknown action in PL_DRAWING_TOOLS::DrawShape()" );
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
WS_DRAW_ITEM_BASE* item = nullptr;
// Prime the pump
if( immediateMode )
m_toolMgr->RunAction( ACTIONS::cursorClick );
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
@ -243,28 +210,26 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
item = nullptr;
m_frame->RollbackFromUndo();
if( !evt->IsActivate() && !isImmediate )
continue;
if( evt->IsActivate() || immediateMode )
break;
}
else
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_frame->PopTool();
break;
break;
}
}
else if( evt->IsClick( BUT_LEFT ) || ( isImmediate && !item ) )
else if( evt->IsClick( BUT_LEFT ) )
{
if( !item ) // start drawing
{
m_frame->SaveCopyInUndoList();
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
WS_DATA_ITEM::WS_ITEM_TYPE dataType;
if( isDrawLine )
dataType = WS_DATA_ITEM::WS_SEGMENT;
else
dataType = WS_DATA_ITEM::WS_RECT;
WS_DATA_ITEM* dataItem = m_frame->AddPageLayoutItem( dataType );
WS_DATA_ITEM* dataItem = m_frame->AddPageLayoutItem( type );
dataItem->MoveToUi( (wxPoint) cursorPos );
item = dataItem->GetDrawItems()[0];
@ -278,8 +243,9 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_frame->OnModify();
if( isImmediate )
if( immediateMode )
{
m_frame->PopTool();
m_toolMgr->RunAction( ACTIONS::activatePointEditor );
break;
}
@ -306,12 +272,10 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
}
// Enable autopanning and cursor capture only when there is a shape being drawn
getViewControls()->SetAutoPan( !!item );
getViewControls()->CaptureCursor( !!item );
getViewControls()->SetAutoPan( item != nullptr );
getViewControls()->CaptureCursor( item != nullptr );
}
m_frame->SetNoToolSelected();
return 0;
}
@ -322,9 +286,4 @@ void PL_DRAWING_TOOLS::setTransitions()
Go( &PL_DRAWING_TOOLS::DrawShape, PL_ACTIONS::drawRectangle.MakeEvent() );
Go( &PL_DRAWING_TOOLS::PlaceItem, PL_ACTIONS::placeText.MakeEvent() );
Go( &PL_DRAWING_TOOLS::PlaceItem, PL_ACTIONS::placeImage.MakeEvent() );
Go( &PL_DRAWING_TOOLS::DrawShape, PL_ACTIONS::addLine.MakeEvent() );
Go( &PL_DRAWING_TOOLS::DrawShape, PL_ACTIONS::addRectangle.MakeEvent() );
Go( &PL_DRAWING_TOOLS::PlaceItem, PL_ACTIONS::addText.MakeEvent() );
Go( &PL_DRAWING_TOOLS::PlaceItem, PL_ACTIONS::addImage.MakeEvent() );
}

View File

@ -101,9 +101,9 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
if( selection.Empty() )
return 0;
m_frame->SetToolID( ID_PL_MOVE_TOOL, wxCURSOR_DEFAULT, _( "Move Items" ) );
m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate();
controls->ShowCursor( true );
controls->SetAutoPan( true );
@ -184,7 +184,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
//------------------------------------------------------------------------
// Handle cancel
//
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( m_moveInProgress )
restore_state = true;
@ -232,9 +232,6 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
if( !chain_commands )
m_moveOffset = { 0, 0 };
m_moveInProgress = false;
m_frame->SetNoToolSelected();
selection.ClearReferencePoint();
for( auto item : selection )
@ -248,6 +245,8 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
else
m_frame->OnModify();
m_moveInProgress = false;
m_frame->PopTool();
return 0;
}

View File

@ -103,7 +103,7 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
setControls();
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( m_cancelHandler )
{

View File

@ -192,7 +192,6 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
{
m_frame->SaveCopyInUndoList();
controls->ForceCursorPosition( false );
m_frame->PushTool( _( "Drag Point" ).ToStdString() );
inDrag = true;
modified = true;
}
@ -206,22 +205,21 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
else if( inDrag && evt->IsMouseUp( BUT_LEFT ) )
{
controls->SetAutoPan( false );
m_frame->PopTool();
inDrag = false;
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( inDrag ) // Restore the last change
{
m_frame->PopTool();
m_frame->RollbackFromUndo();
inDrag = false;
modified = false;
}
// ESC should clear selection along with edit points
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
break;
}

View File

@ -71,10 +71,10 @@ bool PL_SELECTION_TOOL::Init()
auto& menu = m_menu.GetMenu();
menu.AddSeparator( 200 );
menu.AddItem( PL_ACTIONS::addLine, PL_CONDITIONS::Idle, 250 );
menu.AddItem( PL_ACTIONS::addRectangle, PL_CONDITIONS::Idle, 250 );
menu.AddItem( PL_ACTIONS::addText, PL_CONDITIONS::Idle, 250 );
menu.AddItem( PL_ACTIONS::addImage, PL_CONDITIONS::Idle, 250 );
menu.AddItem( PL_ACTIONS::drawLine, PL_CONDITIONS::Idle, 250 );
menu.AddItem( PL_ACTIONS::drawRectangle, PL_CONDITIONS::Idle, 250 );
menu.AddItem( PL_ACTIONS::placeText, PL_CONDITIONS::Idle, 250 );
menu.AddItem( PL_ACTIONS::placeImage, PL_CONDITIONS::Idle, 250 );
menu.AddItem( PL_ACTIONS::appendImportedWorksheet, PL_CONDITIONS::Idle, 250 );
menu.AddSeparator( 1000 );
@ -305,7 +305,7 @@ bool PL_SELECTION_TOOL::selectMultiple()
while( TOOL_EVENT* evt = Wait() )
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
cancelled = true;
break;

View File

@ -189,7 +189,7 @@ void LENGTH_TUNER_TOOL::performTuning()
while( TOOL_EVENT* evt = Wait() )
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
break;
else if( evt->IsMotion() )
{
@ -295,7 +295,7 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS::ROUTER_MODE aMode )
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
break; // Finish
}

View File

@ -808,7 +808,7 @@ void ROUTER_TOOL::performRouting()
still_routing = m_router->FixRoute( m_endSnapPoint, m_endItem );
break;
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate()
|| evt->IsUndoRedo()
|| evt->IsAction( &PCB_ACTIONS::routerInlineDrag ) )
break;
@ -916,7 +916,7 @@ int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode )
// Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() )
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
break; // Finish
}
@ -1014,7 +1014,8 @@ void ROUTER_TOOL::performDragging( int aMode )
if( m_router->FixRoute( m_endSnapPoint, m_endItem ) )
break;
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsUndoRedo() )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate()
|| evt->IsUndoRedo() )
{
break;
}

View File

@ -294,7 +294,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
if( reselect && text )
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, text );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( text )
{
@ -490,7 +490,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), nullptr );
m_controls->ForceCursorPosition( true, cursorPos );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
m_controls->SetAutoPan( false );
@ -803,7 +803,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
m_view->Update( &preview );
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
preview.FreeItems();
break;
@ -874,7 +874,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
{
m_menu.ShowContextMenu( selection() );
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
break;
}
@ -961,7 +961,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPT<VECTOR2D
frame()->SetMsgPanel( aGraphic );
}
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
preview.Clear();
m_view->Update( &preview );
@ -1185,7 +1185,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
// update, but don't step the manager state
arcManager.AddPoint( cursorPos, false );
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
preview.Clear();
delete aGraphic;
@ -1340,7 +1340,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode )
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), layers );
m_controls->ForceCursorPosition( true, cursorPos );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
// pre-empted by another tool, give up
// cancelled without an inprogress polygon, give up

View File

@ -1131,7 +1131,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
controls.ForceCursorPosition(true, cursorPos );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
break;
}

View File

@ -254,7 +254,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
{
VECTOR2I cursorPos = controls.GetCursorPosition();
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
// overriding action, or we're cancelling without
// an in-progress preview area

View File

@ -482,7 +482,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
}
// Now that cancel-current-action has been handled, check for cancel-tool.
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
commit.Push( _( "Renumber pads" ) );
break;

View File

@ -542,7 +542,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
if( reselect && module )
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( module )
{
@ -719,7 +719,7 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
break;
else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )

View File

@ -76,7 +76,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer
VECTOR2I cursorPos = controls()->GetCursorPosition();
aPlacer->m_modifiers = evt->Modifier();
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( newItem )
{

View File

@ -83,7 +83,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
setControls();
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( m_cancelHandler )
{

View File

@ -382,7 +382,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
m_refill = true;
}
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
if( inDrag ) // Restore the last change
commit.Revert();

View File

@ -525,7 +525,7 @@ bool SELECTION_TOOL::selectMultiple()
while( TOOL_EVENT* evt = Wait() )
{
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) )
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
{
cancelled = true;
break;