Undo for Repeat Pin.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/18261
This commit is contained in:
parent
4bf8ed32cd
commit
0b4d0bcb6c
|
@ -29,6 +29,7 @@
|
||||||
#include <tool/tool_manager.h>
|
#include <tool/tool_manager.h>
|
||||||
#include <tools/ee_actions.h>
|
#include <tools/ee_actions.h>
|
||||||
#include <tools/ee_selection_tool.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,
|
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 )
|
if( !aSymbolCopy )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto* drawingTool = GetToolManager()->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
|
||||||
|
|
||||||
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
|
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
|
||||||
|
|
||||||
// Clear current flags (which can be temporary set by a current edit command).
|
// 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 );
|
aSymbolCopy->SetFlags( UR_TRANSIENT );
|
||||||
|
|
||||||
ITEM_PICKER wrapper( GetScreen(), aSymbolCopy, aUndoType );
|
ITEM_PICKER wrapper( GetScreen(), aSymbolCopy, aUndoType );
|
||||||
|
wrapper.SetGroupId( drawingTool->GetLastPin() );
|
||||||
lastcmd->PushItem( wrapper );
|
lastcmd->PushItem( wrapper );
|
||||||
lastcmd->SetDescription( aDescription );
|
lastcmd->SetDescription( aDescription );
|
||||||
PushCommandToUndoList( lastcmd );
|
PushCommandToUndoList( lastcmd );
|
||||||
|
@ -67,6 +71,8 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
|
||||||
if( GetRedoCommandCount() <= 0 )
|
if( GetRedoCommandCount() <= 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto* drawingTool = GetToolManager()->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
|
||||||
|
|
||||||
// Load the last redo entry
|
// Load the last redo entry
|
||||||
PICKED_ITEMS_LIST* redoCommand = PopCommandFromRedoList();
|
PICKED_ITEMS_LIST* redoCommand = PopCommandFromRedoList();
|
||||||
ITEM_PICKER redoWrapper = redoCommand->PopItem();
|
ITEM_PICKER redoWrapper = redoCommand->PopItem();
|
||||||
|
@ -75,6 +81,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
|
||||||
delete redoCommand;
|
delete redoCommand;
|
||||||
|
|
||||||
LIB_SYMBOL* symbol = (LIB_SYMBOL*) redoWrapper.GetItem();
|
LIB_SYMBOL* symbol = (LIB_SYMBOL*) redoWrapper.GetItem();
|
||||||
|
KIID lastPin = redoWrapper.GetGroupId();
|
||||||
UNDO_REDO undoRedoType = redoWrapper.GetStatus();
|
UNDO_REDO undoRedoType = redoWrapper.GetStatus();
|
||||||
wxCHECK( symbol, /* void */ );
|
wxCHECK( symbol, /* void */ );
|
||||||
symbol->ClearFlags( UR_TRANSIENT );
|
symbol->ClearFlags( UR_TRANSIENT );
|
||||||
|
@ -85,6 +92,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromRedoList()
|
||||||
|
|
||||||
oldSymbol->SetFlags( UR_TRANSIENT );
|
oldSymbol->SetFlags( UR_TRANSIENT );
|
||||||
ITEM_PICKER undoWrapper( GetScreen(), oldSymbol, undoRedoType );
|
ITEM_PICKER undoWrapper( GetScreen(), oldSymbol, undoRedoType );
|
||||||
|
undoWrapper.SetGroupId( drawingTool->GetLastPin() );
|
||||||
undoCommand->SetDescription( description );
|
undoCommand->SetDescription( description );
|
||||||
undoCommand->PushItem( undoWrapper );
|
undoCommand->PushItem( undoWrapper );
|
||||||
PushCommandToUndoList( undoCommand );
|
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
|
// <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
|
// Just set the current symbol to the symbol which come from the redo list
|
||||||
m_symbol = symbol;
|
m_symbol = symbol;
|
||||||
|
drawingTool->SetLastPin( lastPin );
|
||||||
|
|
||||||
if( undoRedoType == UNDO_REDO::LIB_RENAME )
|
if( undoRedoType == UNDO_REDO::LIB_RENAME )
|
||||||
{
|
{
|
||||||
|
@ -118,6 +127,8 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
|
||||||
if( GetUndoCommandCount() <= 0 )
|
if( GetUndoCommandCount() <= 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto* drawingTool = GetToolManager()->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
|
||||||
|
|
||||||
// Load the last undo entry
|
// Load the last undo entry
|
||||||
PICKED_ITEMS_LIST* undoCommand = PopCommandFromUndoList();
|
PICKED_ITEMS_LIST* undoCommand = PopCommandFromUndoList();
|
||||||
wxString description = undoCommand->GetDescription();
|
wxString description = undoCommand->GetDescription();
|
||||||
|
@ -126,6 +137,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
|
||||||
delete undoCommand;
|
delete undoCommand;
|
||||||
|
|
||||||
LIB_SYMBOL* symbol = (LIB_SYMBOL*) undoWrapper.GetItem();
|
LIB_SYMBOL* symbol = (LIB_SYMBOL*) undoWrapper.GetItem();
|
||||||
|
KIID lastPin = undoWrapper.GetGroupId();
|
||||||
UNDO_REDO undoRedoType = undoWrapper.GetStatus();
|
UNDO_REDO undoRedoType = undoWrapper.GetStatus();
|
||||||
wxCHECK( symbol, /* void */ );
|
wxCHECK( symbol, /* void */ );
|
||||||
symbol->ClearFlags( UR_TRANSIENT );
|
symbol->ClearFlags( UR_TRANSIENT );
|
||||||
|
@ -136,6 +148,7 @@ void SYMBOL_EDIT_FRAME::GetSymbolFromUndoList()
|
||||||
|
|
||||||
oldSymbol->SetFlags( UR_TRANSIENT );
|
oldSymbol->SetFlags( UR_TRANSIENT );
|
||||||
ITEM_PICKER redoWrapper( GetScreen(), oldSymbol, undoRedoType );
|
ITEM_PICKER redoWrapper( GetScreen(), oldSymbol, undoRedoType );
|
||||||
|
redoWrapper.SetGroupId( drawingTool->GetLastPin() );
|
||||||
redoCommand->PushItem( redoWrapper );
|
redoCommand->PushItem( redoWrapper );
|
||||||
redoCommand->SetDescription( description );
|
redoCommand->SetDescription( description );
|
||||||
PushCommandToRedoList( redoCommand );
|
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.
|
// <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
|
// Just set the current symbol to the symbol which come from the undo list
|
||||||
m_symbol = symbol;
|
m_symbol = symbol;
|
||||||
|
drawingTool->SetLastPin( lastPin );
|
||||||
|
|
||||||
if( undoRedoType == UNDO_REDO::LIB_RENAME )
|
if( undoRedoType == UNDO_REDO::LIB_RENAME )
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,7 +41,8 @@
|
||||||
#include <wx/msgdlg.h>
|
#include <wx/msgdlg.h>
|
||||||
#include <import_gfx/dialog_import_gfx_sch.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() :
|
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:
|
case SCH_PIN_T:
|
||||||
{
|
{
|
||||||
item = pinTool->CreatePin( cursorPos, symbol );
|
item = pinTool->CreatePin( cursorPos, symbol );
|
||||||
g_lastPinWeakPtr = item;
|
g_lastPin = item->m_Uuid;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SCH_TEXT_T:
|
case SCH_TEXT_T:
|
||||||
|
@ -831,10 +832,9 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem( const TOOL_EVENT& aEvent )
|
||||||
if( !symbol )
|
if( !symbol )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// See if we have a pin matching our weak ptr
|
|
||||||
for( SCH_PIN* test : symbol->GetAllLibPins() )
|
for( SCH_PIN* test : symbol->GetAllLibPins() )
|
||||||
{
|
{
|
||||||
if( (void*) test == g_lastPinWeakPtr )
|
if( test->m_Uuid == g_lastPin )
|
||||||
{
|
{
|
||||||
sourcePin = test;
|
sourcePin = test;
|
||||||
break;
|
break;
|
||||||
|
@ -844,7 +844,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem( const TOOL_EVENT& aEvent )
|
||||||
if( sourcePin )
|
if( sourcePin )
|
||||||
{
|
{
|
||||||
SCH_PIN* pin = pinTool->RepeatPin( sourcePin );
|
SCH_PIN* pin = pinTool->RepeatPin( sourcePin );
|
||||||
g_lastPinWeakPtr = pin;
|
g_lastPin = pin->m_Uuid;
|
||||||
|
|
||||||
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,9 @@ public:
|
||||||
void SetDrawSpecificUnit( bool aSpecific ) { m_drawSpecificUnit = aSpecific; }
|
void SetDrawSpecificUnit( bool aSpecific ) { m_drawSpecificUnit = aSpecific; }
|
||||||
bool GetDrawSpecificUnit() const { return m_drawSpecificUnit; }
|
bool GetDrawSpecificUnit() const { return m_drawSpecificUnit; }
|
||||||
|
|
||||||
|
KIID GetLastPin() { return g_lastPin; }
|
||||||
|
void SetLastPin( KIID aPin ) { g_lastPin = aPin; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int doDrawShape( const TOOL_EVENT& aEvent, std::optional<SHAPE_T> aDrawingShape );
|
int doDrawShape( const TOOL_EVENT& aEvent, std::optional<SHAPE_T> aDrawingShape );
|
||||||
|
|
||||||
|
@ -84,6 +87,9 @@ private:
|
||||||
///< Re-entrancy guards
|
///< Re-entrancy guards
|
||||||
bool m_inDrawShape;
|
bool m_inDrawShape;
|
||||||
bool m_inTwoClickPlace;
|
bool m_inTwoClickPlace;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static KIID g_lastPin;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SYMBOL_EDITOR_DRAWING_TOOLS_H */
|
#endif /* SYMBOL_EDITOR_DRAWING_TOOLS_H */
|
||||||
|
|
|
@ -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.
|
// 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_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() );
|
SCH_PIN* pin = static_cast<SCH_PIN*>( aSourcePin->Duplicate() );
|
||||||
VECTOR2I step;
|
VECTOR2I step;
|
||||||
|
|
||||||
|
@ -440,7 +445,10 @@ SCH_PIN* SYMBOL_EDITOR_PIN_TOOL::RepeatPin( const SCH_PIN* aSourcePin )
|
||||||
pin->SetFlags( IS_LINKED );
|
pin->SetFlags( IS_LINKED );
|
||||||
|
|
||||||
if( PlacePin( pin ) )
|
if( PlacePin( pin ) )
|
||||||
|
{
|
||||||
|
commit.Push( _( "Repeat Pin" ) );
|
||||||
return pin;
|
return pin;
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue