Treat undo as backspace and/or escape when drawing. Ignore redo.

Undo == backspace when drawing a polygon or chained lines.  Otherwise
it's an escape.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/14961

(cherry picked from commit ef6866757e)
This commit is contained in:
Jeff Young 2023-06-16 21:44:16 +01:00
parent e1e791fc75
commit 76f8b3df22
9 changed files with 107 additions and 26 deletions

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2017-2022 Kicad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2023 Kicad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -117,6 +117,12 @@ bool POLYGON_GEOM_MANAGER::IsPolygonInProgress() const
}
int POLYGON_GEOM_MANAGER::PolygonPointCount() const
{
return m_lockedPoints.PointCount();
}
bool POLYGON_GEOM_MANAGER::NewPointClosesOutline( const VECTOR2I& aPt ) const
{
return m_lockedPoints.PointCount() > 0 && m_lockedPoints.CPoint( 0 ) == aPt;

View File

@ -398,7 +398,7 @@ void SCH_EDIT_FRAME::setupUIConditions()
{
SCH_BASE_FRAME::setupUIConditions();
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
SCH_EDITOR_CONDITIONS cond( this );
wxASSERT( mgr );
@ -417,11 +417,20 @@ void SCH_EDIT_FRAME::setupUIConditions()
};
auto undoCond =
[ this ] (const SELECTION& aSel )
{
if( SCH_LINE_WIRE_BUS_TOOL::IsDrawingLineWireOrBus( aSel ) )
return true;
return GetUndoCommandCount() > 0;
};
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
#define CHECK( x ) ACTION_CONDITIONS().Check( x )
mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::undo, ENABLE( undoCond ) );
mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
mgr->SetConditions( EE_ACTIONS::showHierarchy, CHECK( hierarchyNavigatorCond ) );

View File

@ -249,7 +249,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
bool isSyntheticClick = symbol && evt->IsActivate() && evt->HasPosition()
&& evt->Matches( aEvent );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
m_frame->GetInfoBar()->Dismiss();
@ -443,6 +443,10 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
{
cleanup();
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -538,7 +542,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
bool isSyntheticClick = image && evt->IsActivate() && evt->HasPosition()
&& evt->Matches( aEvent );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
m_frame->GetInfoBar()->Dismiss();
@ -674,6 +678,10 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
{
cleanup();
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -783,7 +791,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
cursorPos = grid.BestSnapAnchor( cursorPos, LAYER_CONNECTABLE, nullptr );
controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
m_frame->PopTool( aEvent );
break;
@ -925,6 +933,10 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
evt->SetPassEvent();
}
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -1239,7 +1251,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
}
};
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
m_frame->GetInfoBar()->Dismiss();
@ -1478,6 +1490,10 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
{
cleanup();
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -1554,7 +1570,7 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition()
&& evt->Matches( aEvent );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
if( item )
{
@ -1698,6 +1714,10 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -1765,7 +1785,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
bool isSyntheticClick = sheet && evt->IsActivate() && evt->HasPosition()
&& evt->Matches( aEvent );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
m_frame->GetInfoBar()->Dismiss();
@ -1886,6 +1906,10 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent )
m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();

View File

@ -896,7 +896,7 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const TOOL_EVENT& aTool, int aType,
m_view->AddToPreview( wire->Clone() );
}
}
else if( evt->IsAction( &EE_ACTIONS::undoLastSegment ) )
else if( evt->IsAction( &EE_ACTIONS::undoLastSegment ) || evt->IsAction( &ACTIONS::undo ) )
{
if( ( currentMode == LINE_MODE::LINE_MODE_FREE && m_wires.size() > 1 )
|| ( LINE_MODE::LINE_MODE_90 && m_wires.size() > 2 ) )
@ -1009,6 +1009,10 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const TOOL_EVENT& aTool, int aType,
{
cleanup();
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2017-2022 Kicad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2023 Kicad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -141,6 +141,8 @@ public:
*/
bool IsPolygonInProgress() const;
int PolygonPointCount() const;
/**
* @return true if locking in the given point would close the current polygon.
*/

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -60,13 +60,10 @@ public:
void SetEnd( const VECTOR2I& aEnd )
{
if( m_angleSnap )
{
m_end = GetVectorSnapped45( aEnd - m_origin ) + m_origin;
}
else
{
m_end = aEnd;
}
setGeometryChanged();
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Ian McInerney <ian.s.mcinerney at ieee.org>
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -61,7 +61,7 @@ public:
*
* @return Functor testing if the undo queue has items.
*/
SELECTION_CONDITION UndoAvailable();
virtual SELECTION_CONDITION UndoAvailable();
/**
* Create a functor that tests if there are any items in the redo queue.

View File

@ -671,13 +671,24 @@ void PCB_EDIT_FRAME::setupUIConditions()
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
PCB_EDITOR_CONDITIONS cond( this );
auto undoCond =
[ this ] (const SELECTION& aSel )
{
DRAWING_TOOL* drawingTool = m_toolManager->GetTool<DRAWING_TOOL>();
if( drawingTool && drawingTool->GetDrawingMode() != DRAWING_TOOL::MODE::NONE )
return true;
return GetUndoCommandCount() > 0;
};
wxASSERT( mgr );
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
#define CHECK( x ) ACTION_CONDITIONS().Check( x )
mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::undo, ENABLE( undoCond ) );
mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );

View File

@ -629,7 +629,7 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent )
COORDS_PADDING );
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
if( image )
{
@ -770,6 +770,10 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent )
{
wxBell();
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -861,7 +865,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
COORDS_PADDING );
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
if( text )
{
@ -1041,6 +1045,10 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent )
evt->SetPassEvent();
}
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -1161,7 +1169,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
m_controls->SetAutoPan( false );
@ -1489,6 +1497,10 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
{
wxBell();
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -1905,7 +1917,7 @@ bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
COORDS_PADDING );
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
cleanup();
@ -2124,6 +2136,10 @@ bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
m_view->Update( &preview );
frame()->SetMsgPanel( graphic );
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else if( graphic && evt->IsAction( &PCB_ACTIONS::decWidth ) )
{
if( (unsigned) m_stroke.GetWidth() > WIDTH_STEP )
@ -2283,7 +2299,7 @@ bool DRAWING_TOOL::drawArc( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic ), COORDS_PADDING );
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
cleanup();
@ -2444,6 +2460,10 @@ bool DRAWING_TOOL::drawArc( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
{
wxBell();
}
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();
@ -2606,9 +2626,13 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
polyGeomMgr.SetLeaderMode( Is45Limited() ? POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45
: POLYGON_GEOM_MANAGER::LEADER_MODE::DIRECT );
if( evt->IsCancelInteractive() )
if( evt->IsCancelInteractive() || evt->IsAction( &ACTIONS::undo ) )
{
if( polyGeomMgr.IsPolygonInProgress() )
if( polyGeomMgr.PolygonPointCount() >= 2 && evt->IsAction( &ACTIONS::undo ) )
{
polyGeomMgr.DeleteLastCorner();
}
else if( polyGeomMgr.IsPolygonInProgress() )
{
cleanup();
}
@ -2730,6 +2754,10 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
// m_view->Update( &zoneAsst );
evt->SetPassEvent();
}*/
else if( evt->IsAction( &ACTIONS::redo ) )
{
wxBell();
}
else
{
evt->SetPassEvent();