diff --git a/common/preview_items/polygon_geom_manager.cpp b/common/preview_items/polygon_geom_manager.cpp index 59f3e908ea..126393586e 100644 --- a/common/preview_items/polygon_geom_manager.cpp +++ b/common/preview_items/polygon_geom_manager.cpp @@ -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; diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 7972d5f37f..557886f7c5 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -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 ) ); diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 78d02e741c..7605ddd0c9 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -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(); diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 20af158e42..510bc35858 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -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(); diff --git a/include/preview_items/polygon_geom_manager.h b/include/preview_items/polygon_geom_manager.h index 4325a9755c..e8913f77a4 100644 --- a/include/preview_items/polygon_geom_manager.h +++ b/include/preview_items/polygon_geom_manager.h @@ -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. */ diff --git a/include/preview_items/two_point_geom_manager.h b/include/preview_items/two_point_geom_manager.h index 775d18b348..a7302830d7 100644 --- a/include/preview_items/two_point_geom_manager.h +++ b/include/preview_items/two_point_geom_manager.h @@ -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(); } diff --git a/include/tool/editor_conditions.h b/include/tool/editor_conditions.h index f542f069ea..a3eacfdda9 100644 --- a/include/tool/editor_conditions.h +++ b/include/tool/editor_conditions.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Ian McInerney - * 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. diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 1306e155ac..1f3ef70bc2 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -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(); + + 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() ) ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 1c51e2b650..b60dfc21ea 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -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();