From d80759efb8bc1ab9bf62f0319fd2b6b15259a023 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Thu, 20 Jun 2019 23:27:58 +0100 Subject: [PATCH] cvpcb: Implement delete/cut/copy/paste for individual associations Fixes: lp:1794883 * https://bugs.launchpad.net/kicad/+bug/1794883 --- cvpcb/components_listbox.cpp | 19 ++++++- cvpcb/cvpcb_id.h | 8 ++- cvpcb/cvpcb_mainframe.cpp | 96 ++++++++++++++++++++++++++++++++++-- cvpcb/cvpcb_mainframe.h | 33 +++++++++++-- cvpcb/toolbars_cvpcb.cpp | 2 +- 5 files changed, 145 insertions(+), 13 deletions(-) diff --git a/cvpcb/components_listbox.cpp b/cvpcb/components_listbox.cpp index f8a97191d1..729efeb846 100644 --- a/cvpcb/components_listbox.cpp +++ b/cvpcb/components_listbox.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 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 @@ -113,6 +113,8 @@ void COMPONENTS_LISTBOX::OnChar( wxKeyEvent& event ) { int key = event.GetKeyCode(); + wxCommandEvent dummy; + switch( key ) { case WXK_TAB: @@ -135,6 +137,21 @@ void COMPONENTS_LISTBOX::OnChar( wxKeyEvent& event ) event.Skip(); return; + case WXK_DELETE: + GetParent()->DelAssociation( dummy ); + return; + + case WXK_CONTROL_X: + GetParent()->CutAssociation( dummy ); + return; + + case WXK_CONTROL_C: + GetParent()->CopyAssociation( dummy ); + return; + + case WXK_CONTROL_V: + GetParent()->PasteAssociation( dummy ); + return; default: break; diff --git a/cvpcb/cvpcb_id.h b/cvpcb/cvpcb_id.h index c46e9b15de..12a6820c9d 100644 --- a/cvpcb/cvpcb_id.h +++ b/cvpcb/cvpcb_id.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2014-2019 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 @@ -42,7 +42,11 @@ enum id_cvpcb_frm ID_CVPCB_CREATE_SCREENCMP = ID_END_LIST, ID_CVPCB_GOTO_FIRSTNA, ID_CVPCB_GOTO_PREVIOUSNA, - ID_CVPCB_DEL_ASSOCIATIONS, + ID_CVPCB_DEL_ALL_ASSOCIATIONS, + ID_CVPCB_DEL_ASSOCIATION, + ID_CVPCB_CUT_ASSOCIATION, + ID_CVPCB_COPY_ASSOCIATION, + ID_CVPCB_PASTE_ASSOCIATION, ID_CVPCB_AUTO_ASSOCIE, ID_CVPCB_COMPONENT_LIST, ID_CVPCB_FOOTPRINT_LIST, diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 4f1456300d..af735059b1 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 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 @@ -75,7 +75,11 @@ BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER ) EVT_TOOL( ID_CVPCB_CREATE_SCREENCMP, CVPCB_MAINFRAME::DisplayModule ) EVT_TOOL( ID_CVPCB_GOTO_FIRSTNA, CVPCB_MAINFRAME::ToFirstNA ) EVT_TOOL( ID_CVPCB_GOTO_PREVIOUSNA, CVPCB_MAINFRAME::ToPreviousNA ) - EVT_TOOL( ID_CVPCB_DEL_ASSOCIATIONS, CVPCB_MAINFRAME::DelAssociations ) + EVT_TOOL( ID_CVPCB_DEL_ALL_ASSOCIATIONS, CVPCB_MAINFRAME::DelAllAssociations ) + EVT_TOOL( ID_CVPCB_DEL_ASSOCIATION, CVPCB_MAINFRAME::DelAssociation ) + EVT_TOOL( ID_CVPCB_CUT_ASSOCIATION, CVPCB_MAINFRAME::CutAssociation ) + EVT_TOOL( ID_CVPCB_COPY_ASSOCIATION, CVPCB_MAINFRAME::CopyAssociation ) + EVT_TOOL( ID_CVPCB_PASTE_ASSOCIATION, CVPCB_MAINFRAME::PasteAssociation ) EVT_TOOL( ID_CVPCB_AUTO_ASSOCIE, CVPCB_MAINFRAME::AutomaticFootprintMatching ) EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, CVPCB_MAINFRAME::OnSelectFilteringFootprint ) @@ -432,9 +436,81 @@ void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event ) } -void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event ) +void CVPCB_MAINFRAME::CutAssociation( wxCommandEvent& event ) { - if( IsOK( this, _( "Delete selections" ) ) ) + int itmIdx = m_compListBox->GetFirstSelected(); + + if( itmIdx == -1 ) + return; + + if( m_netlist.IsEmpty() ) + return; + + COMPONENT* component = m_netlist.GetComponent( itmIdx ); + + if( component && component->GetFPID().IsValid() ) + { + m_clipboardBuffer = component->GetFPID().Format().wx_str(); + + SetNewPkg( wxEmptyString, itmIdx ); + m_compListBox->RefreshItem( itmIdx ); + } +} + + +void CVPCB_MAINFRAME::CopyAssociation( wxCommandEvent& event ) +{ + int itmIdx = m_compListBox->GetFirstSelected(); + + if( itmIdx == -1 ) + return; + + if( m_netlist.IsEmpty() ) + return; + + COMPONENT* component = m_netlist.GetComponent( itmIdx ); + + if( component && component->GetFPID().IsValid() ) + m_clipboardBuffer = component->GetFPID().Format().wx_str(); +} + + +void CVPCB_MAINFRAME::PasteAssociation( wxCommandEvent& event ) +{ + if( m_clipboardBuffer.IsEmpty() ) + return; + + int itmIdx = m_compListBox->GetFirstSelected(); + + while( itmIdx != -1 ) + { + SetNewPkg( m_clipboardBuffer, itmIdx ); + m_compListBox->RefreshItem( itmIdx ); + + itmIdx = m_compListBox->GetNextSelected( itmIdx ); + } + + DisplayStatus(); +} + +void CVPCB_MAINFRAME::DelAssociation( wxCommandEvent& event ) +{ + int itmIdx = m_compListBox->GetFirstSelected(); + + while( itmIdx != -1 ) + { + SetNewPkg( wxEmptyString, itmIdx ); + m_compListBox->RefreshItem( itmIdx ); + + itmIdx = m_compListBox->GetNextSelected( itmIdx ); + } + + DisplayStatus(); +} + +void CVPCB_MAINFRAME::DelAllAssociations( wxCommandEvent& event ) +{ + if( IsOK( this, _( "Delete all footprint assocations?" ) ) ) { m_skipComponentSelect = true; @@ -489,7 +565,17 @@ void CVPCB_MAINFRAME::OnComponentRightClick( wxMouseEvent& event ) wxMenu menu; menu.Append( ID_CVPCB_CREATE_SCREENCMP, _( "View Footprint" ), - _( "Show the assigned footprint in the footprint viewer" ) ); + _( "Show the assigned footprint in the footprint viewer" ) ); + + menu.Append( ID_CVPCB_CUT_ASSOCIATION, _( "Cut Footprint Association" ), + _( "Cut the assigned footprint" ) ); + menu.Append( ID_CVPCB_COPY_ASSOCIATION, _( "Copy Footprint Association" ), + _( "Copy the assigned footprint" ) ); + menu.Append( ID_CVPCB_PASTE_ASSOCIATION, _( "Paste Footprint Association" ), + _( "Paste a footprint assignment" ) ); + + menu.Append( ID_CVPCB_DEL_ASSOCIATION, _( "Delete Footprint Association" ), + _( "Delete the assigned footprint" ) ); PopupMenu( &menu ); } diff --git a/cvpcb/cvpcb_mainframe.h b/cvpcb/cvpcb_mainframe.h index cbdd4e5c9f..1cb86b28c6 100644 --- a/cvpcb/cvpcb_mainframe.h +++ b/cvpcb/cvpcb_mainframe.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2019 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 @@ -70,6 +70,7 @@ class CVPCB_MAINFRAME : public KIWAY_PLAYER wxStaticText* m_statusLine2; wxStaticText* m_statusLine3; wxButton* m_saveAndContinue; + wxString m_clipboardBuffer; public: wxArrayString m_ModuleLibNames; @@ -133,10 +134,34 @@ public: void ToPreviousNA( wxCommandEvent& event ); /** - * Function DelAssociations - * removes all component footprint associations already made + * Function DelAllAssociations + * Removes all component footprint associations already made */ - void DelAssociations( wxCommandEvent& event ); + void DelAllAssociations( wxCommandEvent& event ); + + /** + * Function DelAssociation + * Removes association from selected footprints + */ + void DelAssociation( wxCommandEvent& event ); + + /** + * Function CutAssociation + * Cuts the footprint name for the 1st selected component to the clipboard + */ + void CutAssociation( wxCommandEvent& event ); + + /** + * Function CopyAssociation + * Copies the footprint name for the 1st selected component to the clipboard + */ + void CopyAssociation( wxCommandEvent& event ); + + /** + * Function PasteAssociation + * Paste the footprint from the clipboard onto the selected components + */ + void PasteAssociation( wxCommandEvent& event ); void OnConfigurePaths( wxCommandEvent& aEvent ); diff --git a/cvpcb/toolbars_cvpcb.cpp b/cvpcb/toolbars_cvpcb.cpp index 6334c53ad4..482f9e16f6 100644 --- a/cvpcb/toolbars_cvpcb.cpp +++ b/cvpcb/toolbars_cvpcb.cpp @@ -63,7 +63,7 @@ void CVPCB_MAINFRAME::ReCreateHToolbar() KiScaledBitmap( auto_associe_xpm, this ), _( "Perform automatic footprint association" ) ); - m_mainToolBar->AddTool( ID_CVPCB_DEL_ASSOCIATIONS, wxEmptyString, + m_mainToolBar->AddTool( ID_CVPCB_DEL_ALL_ASSOCIATIONS, wxEmptyString, KiScaledBitmap( delete_association_xpm, this ), _( "Delete all footprint associations" ) );