diff --git a/common/commit.cpp b/common/commit.cpp index 27a0d8fbce..2d0e7871fe 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -72,7 +72,10 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType, BASE_SCREEN* aS makeEntry( aItem, CHT_REMOVE | flags, makeImage( aItem ), aScreen ); if( EDA_GROUP* parentGroup = aItem->GetParentGroup() ) - Modify( parentGroup->AsEdaItem(), aScreen, RECURSE_MODE::NO_RECURSE ); + { + if( parentGroup->AsEdaItem()->GetFlags() & STRUCT_DELETED ) + Modify( parentGroup->AsEdaItem(), aScreen, RECURSE_MODE::NO_RECURSE ); + } break; diff --git a/pcbnew/generators/pcb_tuning_pattern.cpp b/pcbnew/generators/pcb_tuning_pattern.cpp index e6f7ff4cc2..b57fd3cfec 100644 --- a/pcbnew/generators/pcb_tuning_pattern.cpp +++ b/pcbnew/generators/pcb_tuning_pattern.cpp @@ -926,8 +926,6 @@ void PCB_TUNING_PATTERN::Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COM for( BOARD_ITEM* item : routerAddedItems ) aCommit->Add( item ); } - - aCommit->Push( "Remove Tuning Pattern" ); } @@ -1233,8 +1231,7 @@ bool PCB_TUNING_PATTERN::Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COM } -void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit, - const wxString& aCommitMsg, int aCommitFlags ) +void PCB_TUNING_PATTERN::EditFinish( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) { if( !( GetFlags() & IN_EDIT ) ) return; @@ -1291,15 +1288,10 @@ void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_C } } } - - if( aCommitMsg.IsEmpty() ) - aCommit->Push( _( "Edit Tuning Pattern" ), aCommitFlags ); - else - aCommit->Push( aCommitMsg, aCommitFlags ); } -void PCB_TUNING_PATTERN::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) +void PCB_TUNING_PATTERN::EditCancel( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) { if( !( GetFlags() & IN_EDIT ) ) return; @@ -1320,9 +1312,6 @@ void PCB_TUNING_PATTERN::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD } aTool->Router()->StopRouting(); - - if( aCommit ) - aCommit->Revert(); } @@ -1825,7 +1814,9 @@ void PCB_TUNING_PATTERN::ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame ) GENERATOR_TOOL* generatorTool = aEditFrame->GetToolManager()->GetTool(); EditStart( generatorTool, GetBoard(), &commit ); Update( generatorTool, GetBoard(), &commit ); - EditPush( generatorTool, GetBoard(), &commit ); + EditFinish( generatorTool, GetBoard(), &commit ); + + commit.Push( _( "Edit Tuning Pattern" ) ); } } @@ -2248,7 +2239,7 @@ int DRAWING_TOOL::PlaceTuningPattern( const TOOL_EVENT& aEvent ) if( m_tuningPattern ) { // First click already made; clean up tuning pattern preview - m_tuningPattern->EditRevert( generatorTool, m_board, nullptr ); + m_tuningPattern->EditCancel( generatorTool, m_board, nullptr ); delete m_tuningPattern; m_tuningPattern = nullptr; @@ -2364,7 +2355,9 @@ int DRAWING_TOOL::PlaceTuningPattern( const TOOL_EVENT& aEvent ) m_tuningPattern->EditStart( generatorTool, m_board, &commit ); m_tuningPattern->Update( generatorTool, m_board, &commit ); - m_tuningPattern->EditPush( generatorTool, m_board, &commit, _( "Tune" ) ); + m_tuningPattern->EditFinish( generatorTool, m_board, &commit ); + + commit.Push( _( "Tune" ) ); m_tuningPattern = nullptr; m_pickerItem = nullptr; diff --git a/pcbnew/generators/pcb_tuning_pattern.h b/pcbnew/generators/pcb_tuning_pattern.h index ea5ad90835..506b8260db 100644 --- a/pcbnew/generators/pcb_tuning_pattern.h +++ b/pcbnew/generators/pcb_tuning_pattern.h @@ -99,17 +99,22 @@ public: wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override { - return wxString( _( "Tuning Pattern" ) ); + return _( "Tuning Pattern" ); } wxString GetFriendlyName() const override { - return wxString( _( "Tuning Pattern" ) ); + return _( "Tuning Pattern" ); } wxString GetPluralName() const override { - return wxString( _( "Tuning Patterns" ) ); + return _( "Tuning Patterns" ); + } + + wxString GetCommitMessage() const override + { + return _( "Edit Tuning Pattern" ); } BITMAPS GetMenuImage() const override @@ -129,13 +134,9 @@ public: LENGTH_TUNING_MODE aMode ); void EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override; - bool Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override; - - void EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit, - const wxString& aCommitMsg = wxEmptyString, int aCommitFlags = 0 ) override; - - void EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override; + void EditFinish( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override; + void EditCancel( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override; void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override; diff --git a/pcbnew/pcb_generator.cpp b/pcbnew/pcb_generator.cpp index aecb498e5b..50ea185871 100644 --- a/pcbnew/pcb_generator.cpp +++ b/pcbnew/pcb_generator.cpp @@ -56,37 +56,6 @@ PCB_GENERATOR* PCB_GENERATOR::DeepClone() const } -void PCB_GENERATOR::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) -{ - aCommit->Modify( this, nullptr, RECURSE_MODE::NO_RECURSE ); -} - - -void PCB_GENERATOR::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit, - const wxString& aCommitMsg, int aCommitFlags ) -{ - aCommit->Push( aCommitMsg, aCommitFlags ); -} - - -void PCB_GENERATOR::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) -{ - aCommit->Revert(); -} - - -void PCB_GENERATOR::Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) -{ - aCommit->Remove( this ); -} - - -bool PCB_GENERATOR::Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) -{ - return true; -} - - std::vector PCB_GENERATOR::GetPreviewItems( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame, bool aStatusItemsOnly ) diff --git a/pcbnew/pcb_generator.h b/pcbnew/pcb_generator.h index d702d72f7a..eea8550f2e 100644 --- a/pcbnew/pcb_generator.h +++ b/pcbnew/pcb_generator.h @@ -53,16 +53,12 @@ public: */ PCB_GENERATOR* DeepClone() const; - virtual void EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ); + virtual void EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0; + virtual bool Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0; + virtual void EditFinish( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0; + virtual void EditCancel( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0; - virtual void EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit, - const wxString& aCommitMsg = wxEmptyString, int aCommitFlags = 0 ); - - virtual void EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ); - - virtual void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ); - - virtual bool Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ); + virtual void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) = 0; #define STATUS_ITEMS_ONLY true @@ -106,6 +102,7 @@ public: wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override; virtual wxString GetPluralName() const = 0; + virtual wxString GetCommitMessage() const = 0; #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 58efd9d610..6efc68eff3 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -2557,6 +2557,7 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut ) { PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); BOARD_COMMIT commit( this ); + int commitFlags = 0; // As we are about to remove items, they have to be removed from the selection first m_toolMgr->RunAction( ACTIONS::selectionClear ); @@ -2680,6 +2681,8 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut ) if( SELECTION_CONDITIONS::OnlyTypes( { PCB_GENERATOR_T } ) ) { m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genRemove, &commit, generator ); + commit.Push( _( "Delete" ), commitFlags ); + commitFlags |= APPEND_UNDO; } else { @@ -2708,20 +2711,20 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut ) if( aIsCut ) { - commit.Push( _( "Cut" ) ); + commit.Push( _( "Cut" ), commitFlags ); } else if( itemsDeleted == 0 ) { if( fieldsHidden == 1 ) - commit.Push( _( "Hide Field" ) ); + commit.Push( _( "Hide Field" ), commitFlags ); else if( fieldsHidden > 1 ) - commit.Push( _( "Hide Fields" ) ); + commit.Push( _( "Hide Fields" ), commitFlags ); else if( fieldsAlreadyHidden > 0 ) editFrame->ShowInfoBarError( _( "Use the Footprint Properties dialog to remove fields." ) ); } else { - commit.Push( _( "Delete" ) ); + commit.Push( _( "Delete" ), commitFlags ); } } diff --git a/pcbnew/tools/edit_tool_move_fct.cpp b/pcbnew/tools/edit_tool_move_fct.cpp index e7824827d6..9fb6610a06 100644 --- a/pcbnew/tools/edit_tool_move_fct.cpp +++ b/pcbnew/tools/edit_tool_move_fct.cpp @@ -827,7 +827,7 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit { if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T ) { - m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genRevertEdit, aCommit, + m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genCancelEdit, aCommit, static_cast( sel_items.back() ) ); } } @@ -835,7 +835,7 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit { if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T ) { - m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genPushEdit, aCommit, + m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genFinishEdit, aCommit, static_cast( sel_items.back() ) ); } diff --git a/pcbnew/tools/generator_tool.cpp b/pcbnew/tools/generator_tool.cpp index e8762d7072..d227266ee5 100644 --- a/pcbnew/tools/generator_tool.cpp +++ b/pcbnew/tools/generator_tool.cpp @@ -62,7 +62,7 @@ GENERATOR_TOOL::GENERATOR_TOOL() : PROPERTY_MANAGER::Instance().RegisterListener( TYPE_HASH( PCB_GENERATOR ), [&]( INSPECTABLE* aItem, PROPERTY_BASE* aProperty, COMMIT* aCommit ) { - // Special case: regenerator generators when their properties change + // Special case: regenerate generators when their properties change if( PCB_GENERATOR* generator = dynamic_cast( aItem ) ) { @@ -70,7 +70,7 @@ GENERATOR_TOOL::GENERATOR_TOOL() : generator->EditStart( this, board(), commit ); generator->Update( this, board(), commit ); - generator->EditPush( this, board(), commit ); + generator->EditFinish( this, board(), commit ); } } ); } @@ -181,8 +181,9 @@ int GENERATOR_TOOL::RegenerateAllOfType( const TOOL_EVENT& aEvent ) generator->EditStart( this, board(), &commit ); generator->Update( this, board(), &commit ); - generator->EditPush( this, board(), &commit, commitMsg, commitFlags ); + generator->EditFinish( this, board(), &commit ); + commit.Push( commitMsg, commitFlags ); commitFlags |= APPEND_UNDO; } } @@ -232,8 +233,9 @@ int GENERATOR_TOOL::RegenerateSelected( const TOOL_EVENT& aEvent ) { gen->EditStart( this, board(), &commit ); gen->Update( this, board(), &commit ); - gen->EditPush( this, board(), &commit, _( "Regenerate Selected" ), commitFlags ); + gen->EditFinish( this, board(), &commit ); + commit.Push( _( "Regenerate Selected" ), commitFlags ); commitFlags |= APPEND_UNDO; } @@ -245,13 +247,14 @@ int GENERATOR_TOOL::RegenerateSelected( const TOOL_EVENT& aEvent ) int GENERATOR_TOOL::RegenerateItem( const TOOL_EVENT& aEvent ) { BOARD_COMMIT commit( this ); - int commitFlags = 0; PCB_GENERATOR* gen = aEvent.Parameter(); gen->EditStart( this, board(), &commit ); gen->Update( this, board(), &commit ); - gen->EditPush( this, board(), &commit, _( "Regenerate Item" ), commitFlags ); + gen->EditFinish( this, board(), &commit ); + + commit.Push( gen->GetCommitMessage() ); frame()->RefreshCanvas(); return 0; @@ -274,15 +277,15 @@ int GENERATOR_TOOL::GenEditAction( const TOOL_EVENT& aEvent ) { gen->Update( this, board(), commit ); } - else if( aEvent.IsAction( &PCB_ACTIONS::genPushEdit ) ) + else if( aEvent.IsAction( &PCB_ACTIONS::genFinishEdit ) ) { - gen->EditPush( this, board(), commit, wxEmptyString ); + gen->EditFinish( this, board(), commit ); wxASSERT( commit->Empty() ); } - else if( aEvent.IsAction( &PCB_ACTIONS::genRevertEdit ) ) + else if( aEvent.IsAction( &PCB_ACTIONS::genCancelEdit ) ) { - gen->EditRevert( this, board(), commit ); + gen->EditCancel( this, board(), commit ); wxASSERT( commit->Empty() ); } @@ -306,7 +309,7 @@ void GENERATOR_TOOL::setTransitions() Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genStartEdit.MakeEvent() ); Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genUpdateEdit.MakeEvent() ); - Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genPushEdit.MakeEvent() ); - Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genRevertEdit.MakeEvent() ); + Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genFinishEdit.MakeEvent() ); + Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genCancelEdit.MakeEvent() ); Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genRemove.MakeEvent() ); } diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index d9917618cd..d69a1d204c 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -2634,12 +2634,12 @@ TOOL_ACTION PCB_ACTIONS::genUpdateEdit( TOOL_ACTION_ARGS() .Name( "pcbnew.Generator.genUpdateEdit" ) .Scope( AS_CONTEXT ) ); -TOOL_ACTION PCB_ACTIONS::genPushEdit( TOOL_ACTION_ARGS() - .Name( "pcbnew.Generator.genPushEdit" ) +TOOL_ACTION PCB_ACTIONS::genFinishEdit( TOOL_ACTION_ARGS() + .Name( "pcbnew.Generator.genFinishEdit" ) .Scope( AS_CONTEXT ) ); -TOOL_ACTION PCB_ACTIONS::genRevertEdit( TOOL_ACTION_ARGS() - .Name( "pcbnew.Generator.genRevertEdit" ) +TOOL_ACTION PCB_ACTIONS::genCancelEdit( TOOL_ACTION_ARGS() + .Name( "pcbnew.Generator.genCacnelEdit" ) .Scope( AS_CONTEXT ) ); TOOL_ACTION PCB_ACTIONS::genRemove( TOOL_ACTION_ARGS() diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index f878a6db73..ebbc53a882 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -276,8 +276,8 @@ public: static TOOL_ACTION regenerateItem; static TOOL_ACTION genStartEdit; static TOOL_ACTION genUpdateEdit; - static TOOL_ACTION genPushEdit; - static TOOL_ACTION genRevertEdit; + static TOOL_ACTION genFinishEdit; + static TOOL_ACTION genCancelEdit; static TOOL_ACTION genRemove; static TOOL_ACTION generatorsShowManager; diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 2765ca177e..697f9da8bb 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -1957,9 +1957,12 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) if( item->Type() == PCB_GENERATOR_T ) { + PCB_GENERATOR* generator = static_cast( item ); + m_preview.FreeItems(); - m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genPushEdit, &commit, - static_cast( item ) ); + m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genFinishEdit, &commit, generator ); + + commit.Push( generator->GetCommitMessage() ); } else if( item->Type() == PCB_TABLECELL_T ) { @@ -1979,8 +1982,7 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) inDrag = false; frame()->UndoRedoBlock( false ); - m_toolMgr->PostAction( ACTIONS::reselectItem, - item ); // FIXME: Needed for generators + m_toolMgr->PostAction( ACTIONS::reselectItem, item ); // FIXME: Needed for generators } else if( evt->IsCancelInteractive() || evt->IsActivate() ) { @@ -1988,9 +1990,10 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) { if( item->Type() == PCB_GENERATOR_T ) { - m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genRevertEdit, &commit, + m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genCancelEdit, &commit, static_cast( item ) ); } + commit.Revert(); if( PCB_SHAPE* shape= dynamic_cast( item ) )