Fix duplicate to work like paste to keep pins from getting duplicated.

Also fixes the post-duplicate move to start at the cursor pos.
Also fixes the fact that duplicate wasn't getting its hotkey.

Fixes: lp:1830596
* https://bugs.launchpad.net/kicad/+bug/1830596
This commit is contained in:
Jeff Young 2019-05-27 11:40:52 +01:00
parent 800cc1a11c
commit d24a2afaca
9 changed files with 73 additions and 63 deletions

View File

@ -46,7 +46,6 @@ enum hotkey_id_command {
HK_EDIT_COMPONENT_WITH_LIBEDIT,
HK_MIRROR_X,
HK_MIRROR_Y,
HK_DUPLICATE,
HK_MOVE,
HK_DRAG,
HK_SELECT_NODE,

View File

@ -131,6 +131,12 @@ void LIB_EDIT_FRAME::ReCreateMenuBar()
editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
editMenu->AddSeparator();
editMenu->AddItem( ACTIONS::cut, EE_CONDITIONS::NotEmpty );
editMenu->AddItem( ACTIONS::copy, EE_CONDITIONS::NotEmpty );
editMenu->AddItem( ACTIONS::paste, EE_CONDITIONS::Idle );
editMenu->AddItem( ACTIONS::duplicate, EE_CONDITIONS::NotEmpty );
editMenu->AddSeparator();
editMenu->AddItem( EE_ACTIONS::symbolProperties, havePartCondition );
editMenu->AddItem( EE_ACTIONS::pinTable, havePartCondition );

View File

@ -152,31 +152,29 @@ void SCH_EDIT_FRAME::ReCreateMenuBar()
auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
return GetScreen() && GetScreen()->GetRedoCommandCount() > 0;
};
auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) {
return GetToolId() == ID_NO_TOOL_SELECTED;
};
editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
editMenu->AddSeparator();
editMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty );
editMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty );
editMenu->AddItem( ACTIONS::paste, noActiveToolCondition );
editMenu->AddItem( ACTIONS::cut, EE_CONDITIONS::NotEmpty );
editMenu->AddItem( ACTIONS::copy, EE_CONDITIONS::NotEmpty );
editMenu->AddItem( ACTIONS::paste, EE_CONDITIONS::Idle );
editMenu->AddItem( ACTIONS::duplicate, EE_CONDITIONS::NotEmpty );
editMenu->AddSeparator();
editMenu->AddItem( EE_ACTIONS::deleteItemCursor, SELECTION_CONDITIONS::ShowAlways );
editMenu->AddItem( EE_ACTIONS::deleteItemCursor, EE_CONDITIONS::ShowAlways );
// Find
editMenu->AddSeparator();
editMenu->AddItem( ACTIONS::find, SELECTION_CONDITIONS::ShowAlways );
editMenu->AddItem( ACTIONS::findAndReplace, SELECTION_CONDITIONS::ShowAlways );
editMenu->AddItem( ACTIONS::find, EE_CONDITIONS::ShowAlways );
editMenu->AddItem( ACTIONS::findAndReplace, EE_CONDITIONS::ShowAlways );
editMenu->AddSeparator();
// Update field values
editMenu->AddItem( ID_UPDATE_FIELDS, _( "Update Fields from Library..." ),
_( "Sets symbol fields to original library values" ),
update_fields_xpm, SELECTION_CONDITIONS::ShowAlways );
update_fields_xpm, EE_CONDITIONS::ShowAlways );
//
// Menu View:

View File

@ -76,7 +76,6 @@ bool LIB_EDIT_TOOL::Init()
moveMenu.AddItem( EE_ACTIONS::rotateCW, EE_CONDITIONS::NotEmpty, 200 );
moveMenu.AddItem( EE_ACTIONS::mirrorX, EE_CONDITIONS::NotEmpty, 200 );
moveMenu.AddItem( EE_ACTIONS::mirrorY, EE_CONDITIONS::NotEmpty, 200 );
moveMenu.AddItem( EE_ACTIONS::duplicate, EE_CONDITIONS::NotEmpty, 200 );
moveMenu.AddItem( EE_ACTIONS::doDelete, EE_CONDITIONS::NotEmpty, 200 );
moveMenu.AddItem( EE_ACTIONS::properties, EE_CONDITIONS::Count( 1 ), 200 );
@ -84,6 +83,7 @@ bool LIB_EDIT_TOOL::Init()
moveMenu.AddSeparator( EE_CONDITIONS::IdleSelection, 300 );
moveMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 );
moveMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 );
moveMenu.AddItem( ACTIONS::duplicate, EE_CONDITIONS::NotEmpty, 300 );
}
//
@ -108,7 +108,6 @@ bool LIB_EDIT_TOOL::Init()
selToolMenu.AddItem( EE_ACTIONS::rotateCW, EE_CONDITIONS::NotEmpty, 200 );
selToolMenu.AddItem( EE_ACTIONS::mirrorX, EE_CONDITIONS::NotEmpty, 200 );
selToolMenu.AddItem( EE_ACTIONS::mirrorY, EE_CONDITIONS::NotEmpty, 200 );
selToolMenu.AddItem( EE_ACTIONS::duplicate, EE_CONDITIONS::NotEmpty, 200 );
selToolMenu.AddItem( EE_ACTIONS::doDelete, EE_CONDITIONS::NotEmpty, 200 );
selToolMenu.AddItem( EE_ACTIONS::properties, EE_CONDITIONS::Count( 1 ), 200 );
@ -117,6 +116,7 @@ bool LIB_EDIT_TOOL::Init()
selToolMenu.AddItem( ACTIONS::cut, EE_CONDITIONS::IdleSelection, 300 );
selToolMenu.AddItem( ACTIONS::copy, EE_CONDITIONS::IdleSelection, 300 );
selToolMenu.AddItem( ACTIONS::paste, EE_CONDITIONS::Idle, 300 );
selToolMenu.AddItem( ACTIONS::duplicate, EE_CONDITIONS::NotEmpty, 300 );
return true;
}
@ -222,43 +222,6 @@ static KICAD_T nonFields[] =
};
int LIB_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
{
LIB_PART* part = m_frame->GetCurPart();
SELECTION& selection = m_selectionTool->RequestSelection( nonFields );
if( selection.GetSize() == 0 )
return 0;
// Doing a duplicate of a new object doesn't really make any sense; we'd just end
// up dragging around a stack of objects...
if( selection.Front()->IsNew() )
return 0;
if( !selection.Front()->IsMoving() )
saveCopyInUndoList( m_frame->GetCurPart(), UR_LIBEDIT );
EDA_ITEMS newItems;
for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
{
LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
newItem->SetFlags( IS_NEW );
newItems.push_back( newItem );
part->GetDrawItems().push_back( newItem );
getView()->Add( newItem );
}
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &newItems );
m_toolMgr->RunAction( EE_ACTIONS::move, false );
return 0;
}
int LIB_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
{
LIB_PART* part = m_frame->GetCurPart();
@ -667,7 +630,51 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
{
LIB_ITEM* item = (LIB_ITEM*) selection.GetTopLeftItem();
selection.SetReferencePoint( item->GetPosition() );
selection.SetReferencePoint( wxPoint( item->GetPosition().x, -item->GetPosition().y ) );
m_toolMgr->RunAction( EE_ACTIONS::move, false );
}
return 0;
}
int LIB_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
{
LIB_PART* part = m_frame->GetCurPart();
SELECTION& selection = m_selectionTool->RequestSelection( nonFields );
if( selection.GetSize() == 0 )
return 0;
// Doing a duplicate of a new object doesn't really make any sense; we'd just end
// up dragging around a stack of objects...
if( selection.Front()->IsNew() )
return 0;
if( !selection.Front()->IsMoving() )
saveCopyInUndoList( m_frame->GetCurPart(), UR_LIBEDIT );
EDA_ITEMS newItems;
for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
{
LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
oldItem->ClearFlags( SELECTED );
newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
newItems.push_back( newItem );
part->GetDrawItems().push_back( newItem );
getView()->Add( newItem );
}
m_selectionTool->RebuildSelection();
if( !selection.Empty() )
{
LIB_ITEM* item = (LIB_ITEM*) selection.GetTopLeftItem();
selection.SetReferencePoint( wxPoint( item->GetPosition().x, -item->GetPosition().y ) );
m_toolMgr->RunAction( EE_ACTIONS::move, false );
}
@ -677,7 +684,7 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
void LIB_EDIT_TOOL::setTransitions()
{
Go( &LIB_EDIT_TOOL::Duplicate, EE_ACTIONS::duplicate.MakeEvent() );
Go( &LIB_EDIT_TOOL::Duplicate, ACTIONS::duplicate.MakeEvent() );
Go( &LIB_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCW.MakeEvent() );
Go( &LIB_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCCW.MakeEvent() );
Go( &LIB_EDIT_TOOL::Mirror, EE_ACTIONS::mirrorX.MakeEvent() );

View File

@ -221,7 +221,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
// Exit on a remove operation; there is no further processing for removed items.
break;
}
else if( evt->IsAction( &EE_ACTIONS::duplicate ) )
else if( evt->IsAction( &ACTIONS::duplicate ) )
{
if( selection.Front()->IsNew() )
{

View File

@ -341,7 +341,6 @@ bool SCH_EDIT_TOOL::Init()
moveMenu.AddItem( EE_ACTIONS::rotateCW, orientCondition );
moveMenu.AddItem( EE_ACTIONS::mirrorX, orientCondition );
moveMenu.AddItem( EE_ACTIONS::mirrorY, orientCondition );
moveMenu.AddItem( EE_ACTIONS::duplicate, duplicateCondition );
moveMenu.AddItem( EE_ACTIONS::doDelete, E_C::NotEmpty );
moveMenu.AddItem( EE_ACTIONS::properties, propertiesCondition );
@ -358,6 +357,7 @@ bool SCH_EDIT_TOOL::Init()
moveMenu.AddSeparator( E_C::IdleSelection );
moveMenu.AddItem( ACTIONS::cut, E_C::IdleSelection );
moveMenu.AddItem( ACTIONS::copy, E_C::IdleSelection );
moveMenu.AddItem( ACTIONS::duplicate, duplicateCondition );
}
//
@ -401,7 +401,6 @@ bool SCH_EDIT_TOOL::Init()
selToolMenu.AddItem( EE_ACTIONS::rotateCW, orientCondition, 200 );
selToolMenu.AddItem( EE_ACTIONS::mirrorX, orientCondition, 200 );
selToolMenu.AddItem( EE_ACTIONS::mirrorY, orientCondition, 200 );
selToolMenu.AddItem( EE_ACTIONS::duplicate, duplicateCondition, 200 );
selToolMenu.AddItem( EE_ACTIONS::doDelete, E_C::NotEmpty, 200 );
selToolMenu.AddItem( EE_ACTIONS::properties, propertiesCondition, 200 );
@ -430,6 +429,7 @@ bool SCH_EDIT_TOOL::Init()
selToolMenu.AddItem( ACTIONS::cut, E_C::IdleSelection, 300 );
selToolMenu.AddItem( ACTIONS::copy, E_C::IdleSelection, 300 );
selToolMenu.AddItem( ACTIONS::paste, E_C::Idle, 300 );
selToolMenu.AddItem( ACTIONS::duplicate, duplicateCondition, 300 );
return true;
}
@ -1336,7 +1336,7 @@ int SCH_EDIT_TOOL::CleanupSheetPins( const TOOL_EVENT& aEvent )
void SCH_EDIT_TOOL::setTransitions()
{
Go( &SCH_EDIT_TOOL::Duplicate, EE_ACTIONS::duplicate.MakeEvent() );
Go( &SCH_EDIT_TOOL::Duplicate, ACTIONS::duplicate.MakeEvent() );
Go( &SCH_EDIT_TOOL::RepeatDrawItem, EE_ACTIONS::repeatDrawItem.MakeEvent() );
Go( &SCH_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCW.MakeEvent() );
Go( &SCH_EDIT_TOOL::Rotate, EE_ACTIONS::rotateCCW.MakeEvent() );

View File

@ -378,7 +378,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
// Exit on a remove operation; there is no further processing for removed items.
break;
}
else if( evt->IsAction( &EE_ACTIONS::duplicate ) )
else if( evt->IsAction( &ACTIONS::duplicate ) )
{
if( selection.Front()->IsNew() )
{

View File

@ -270,6 +270,7 @@ enum common_hotkey_id_command {
HK_CUT,
HK_COPY,
HK_PASTE,
HK_DUPLICATE,
HK_DELETE,
HK_FIND,
HK_FIND_NEXT,

View File

@ -66,7 +66,6 @@ enum hotkey_id_command {
HK_3D_VIEWER,
HK_EDIT_ITEM,
HK_EDIT_MODULE_WITH_MODEDIT,
HK_DUPLICATE,
HK_DUPLICATE_ITEM_AND_INCREMENT,
HK_CREATE_ARRAY,
HK_PLACE_ITEM,