Undo for Repeat Pin.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18261
This commit is contained in:
Jeff Young 2024-06-23 22:36:24 +01:00
parent 4bf8ed32cd
commit 0b4d0bcb6c
4 changed files with 33 additions and 5 deletions

View File

@ -29,6 +29,7 @@
#include <tool/tool_manager.h>
#include <tools/ee_actions.h>
#include <tools/ee_selection_tool.h>
#include <tools/symbol_editor_drawing_tools.h>
void SYMBOL_EDIT_FRAME::PushSymbolToUndoList( const wxString& aDescription, LIB_SYMBOL* aSymbolCopy,
@ -37,6 +38,8 @@ void SYMBOL_EDIT_FRAME::PushSymbolToUndoList( const wxString& aDescription, LIB_
if( !aSymbolCopy )
return;
auto* drawingTool = GetToolManager()->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
// Clear current flags (which can be temporary set by a current edit command).
@ -45,6 +48,7 @@ void SYMBOL_EDIT_FRAME::PushSymbolToUndoList( const wxString& aDescription, LIB_
aSymbolCopy->SetFlags( UR_TRANSIENT );
ITEM_PICKER wrapper( GetScreen(), aSymbolCopy, aUndoType );
wrapper.SetGroupId( drawingTool->GetLastPin() );
lastcmd->PushItem( wrapper );
lastcmd->SetDescription( aDescription );
PushCommandToUndoList( lastcmd );
@ -67,6 +71,8 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
if( GetRedoCommandCount() <= 0 )
return;
auto* drawingTool = GetToolManager()->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
// Load the last redo entry
PICKED_ITEMS_LIST* redoCommand = PopCommandFromRedoList();
ITEM_PICKER redoWrapper = redoCommand->PopItem();
@ -75,6 +81,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
delete redoCommand;
LIB_SYMBOL* symbol = (LIB_SYMBOL*) redoWrapper.GetItem();
KIID lastPin = redoWrapper.GetGroupId();
UNDO_REDO undoRedoType = redoWrapper.GetStatus();
wxCHECK( symbol, /* void */ );
symbol->ClearFlags( UR_TRANSIENT );
@ -85,6 +92,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
oldSymbol->SetFlags( UR_TRANSIENT );
ITEM_PICKER undoWrapper( GetScreen(), oldSymbol, undoRedoType );
undoWrapper.SetGroupId( drawingTool->GetLastPin() );
undoCommand->SetDescription( description );
undoCommand->PushItem( undoWrapper );
PushCommandToUndoList( undoCommand );
@ -94,6 +102,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
// <previous symbol> is now put in undo list and is owned by this list
// Just set the current symbol to the symbol which come from the redo list
m_symbol = symbol;
drawingTool->SetLastPin( lastPin );
if( undoRedoType == UNDO_REDO::LIB_RENAME )
{
@ -118,6 +127,8 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
if( GetUndoCommandCount() <= 0 )
return;
auto* drawingTool = GetToolManager()->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
// Load the last undo entry
PICKED_ITEMS_LIST* undoCommand = PopCommandFromUndoList();
wxString description = undoCommand->GetDescription();
@ -126,6 +137,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
delete undoCommand;
LIB_SYMBOL* symbol = (LIB_SYMBOL*) undoWrapper.GetItem();
KIID lastPin = undoWrapper.GetGroupId();
UNDO_REDO undoRedoType = undoWrapper.GetStatus();
wxCHECK( symbol, /* void */ );
symbol->ClearFlags( UR_TRANSIENT );
@ -136,6 +148,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
oldSymbol->SetFlags( UR_TRANSIENT );
ITEM_PICKER redoWrapper( GetScreen(), oldSymbol, undoRedoType );
redoWrapper.SetGroupId( drawingTool->GetLastPin() );
redoCommand->PushItem( redoWrapper );
redoCommand->SetDescription( description );
PushCommandToRedoList( redoCommand );
@ -145,6 +158,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
// <previous symbol> is now put in redo list and is owned by this list.
// Just set the current symbol to the symbol which come from the undo list
m_symbol = symbol;
drawingTool->SetLastPin( lastPin );
if( undoRedoType == UNDO_REDO::LIB_RENAME )
{

View File

@ -41,7 +41,8 @@
#include <wx/msgdlg.h>
#include <import_gfx/dialog_import_gfx_sch.h>
static void* g_lastPinWeakPtr;
KIID SYMBOL_EDITOR_DRAWING_TOOLS::g_lastPin;
SYMBOL_EDITOR_DRAWING_TOOLS::SYMBOL_EDITOR_DRAWING_TOOLS() :
@ -212,7 +213,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
case SCH_PIN_T:
{
item = pinTool->CreatePin( cursorPos, symbol );
g_lastPinWeakPtr = item;
g_lastPin = item->m_Uuid;
break;
}
case SCH_TEXT_T:
@ -831,10 +832,9 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem( const TOOL_EVENT& aEvent )
if( !symbol )
return 0;
// See if we have a pin matching our weak ptr
for( SCH_PIN* test : symbol->GetAllLibPins() )
{
if( (void*) test == g_lastPinWeakPtr )
if( test->m_Uuid == g_lastPin )
{
sourcePin = test;
break;
@ -844,7 +844,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem( const TOOL_EVENT& aEvent )
if( sourcePin )
{
SCH_PIN* pin = pinTool->RepeatPin( sourcePin );
g_lastPinWeakPtr = pin;
g_lastPin = pin->m_Uuid;
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );

View File

@ -65,6 +65,9 @@ public:
void SetDrawSpecificUnit( bool aSpecific ) { m_drawSpecificUnit = aSpecific; }
bool GetDrawSpecificUnit() const { return m_drawSpecificUnit; }
KIID GetLastPin() { return g_lastPin; }
void SetLastPin( KIID aPin ) { g_lastPin = aPin; }
private:
int doDrawShape( const TOOL_EVENT& aEvent, std::optional<SHAPE_T> aDrawingShape );
@ -84,6 +87,9 @@ private:
///< Re-entrancy guards
bool m_inDrawShape;
bool m_inTwoClickPlace;
private:
static KIID g_lastPin;
};
#endif /* SYMBOL_EDITOR_DRAWING_TOOLS_H */

View File

@ -409,6 +409,11 @@ int SYMBOL_EDITOR_PIN_TOOL::PushPinProperties( const TOOL_EVENT& aEvent )
// Create a new pin based on the previous pin with an incremented pin number.
SCH_PIN* SYMBOL_EDITOR_PIN_TOOL::RepeatPin( const SCH_PIN* aSourcePin )
{
SCH_COMMIT commit( m_frame );
LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
commit.Modify( symbol );
SCH_PIN* pin = static_cast<SCH_PIN*>( aSourcePin->Duplicate() );
VECTOR2I step;
@ -440,7 +445,10 @@ SCH_PIN* SYMBOL_EDITOR_PIN_TOOL::RepeatPin( const SCH_PIN* aSourcePin )
pin->SetFlags( IS_LINKED );
if( PlacePin( pin ) )
{
commit.Push( _( "Repeat Pin" ) );
return pin;
}
return nullptr;
}