cvpcb: Split control tool in two and add cut/copy/paste

This commit is contained in:
Ian McInerney 2019-08-10 00:13:17 +02:00 committed by Wayne Stambaugh
parent 95430e131e
commit c3b2885f88
8 changed files with 426 additions and 159 deletions

View File

@ -41,6 +41,7 @@ set( CVPCB_SRCS
readwrite_dlgs.cpp
toolbars_cvpcb.cpp
tools/cvpcb_actions.cpp
tools/cvpcb_association_tool.cpp
tools/cvpcb_control.cpp
tools/cvpcb_fpviewer_control.cpp
tools/cvpcb_fpviewer_selection_tool.cpp

View File

@ -45,6 +45,7 @@
#include <display_footprints_frame.h>
#include <listboxes.h>
#include <tools/cvpcb_actions.h>
#include <tools/cvpcb_association_tool.h>
#include <tools/cvpcb_control.h>
wxSize const FRAME_MIN_SIZE_DU( 350, 250 );
@ -212,6 +213,7 @@ void CVPCB_MAINFRAME::setupTools()
// Register tools
m_toolManager->RegisterTool( new COMMON_CONTROL );
m_toolManager->RegisterTool( new CVPCB_CONTROL );
m_toolManager->RegisterTool( new CVPCB_ASSOCIATION_TOOL );
m_toolManager->InitTools();
CVPCB_CONTROL* tool = m_toolManager->GetTool<CVPCB_CONTROL>();
@ -221,6 +223,10 @@ void CVPCB_MAINFRAME::setupTools()
m_componentContextMenu->SetTool( tool );
m_componentContextMenu->Add( CVPCB_ACTIONS::showFootprintViewer );
m_componentContextMenu->AppendSeparator();
m_componentContextMenu->Add( ACTIONS::cut );
m_componentContextMenu->Add( ACTIONS::copy );
m_componentContextMenu->Add( ACTIONS::paste );
m_componentContextMenu->AppendSeparator();
m_componentContextMenu->Add( CVPCB_ACTIONS::deleteAssoc );
// Create the context menu for the footprint list box

View File

@ -62,8 +62,12 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
return m_redoList.size() > 0;
};
editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
editMenu->AddSeparator();
editMenu->AddItem( ACTIONS::cut, SELECTION_CONDITIONS::ShowAlways );
editMenu->AddItem( ACTIONS::copy, SELECTION_CONDITIONS::ShowAlways );
editMenu->AddItem( ACTIONS::paste, SELECTION_CONDITIONS::ShowAlways );
editMenu->Resolve();

View File

@ -100,25 +100,25 @@ TOOL_ACTION CVPCB_ACTIONS::gotoPreviousNA( "cvpcb.Control.GotoPreviousNA", AS_GL
// Actions to modify component associations
TOOL_ACTION CVPCB_ACTIONS::associate( "cvpcb.Control.Associate", AS_GLOBAL,
TOOL_ACTION CVPCB_ACTIONS::associate( "cvpcb.Association.Associate", AS_GLOBAL,
WXK_RETURN, "",
_( "Associate footprint" ),
_( "Associate selected footprint with selected components" ),
auto_associe_xpm );
TOOL_ACTION CVPCB_ACTIONS::autoAssociate( "cvpcb.Control.AutoAssociate", AS_GLOBAL,
TOOL_ACTION CVPCB_ACTIONS::autoAssociate( "cvpcb.Association.AutoAssociate", AS_GLOBAL,
0, "",
_( "Automatically associate footprints" ),
_( "Perform automatic footprint association" ),
auto_associe_xpm );
TOOL_ACTION CVPCB_ACTIONS::deleteAssoc( "cvpcb.Control.Delete", AS_GLOBAL,
TOOL_ACTION CVPCB_ACTIONS::deleteAssoc( "cvpcb.Association.Delete", AS_GLOBAL,
WXK_DELETE, "",
_( "Delete association" ),
_( "Delete selected footprint associations" ),
delete_association_xpm );
TOOL_ACTION CVPCB_ACTIONS::deleteAll( "cvpcb.Control.DeleteAll", AS_GLOBAL,
TOOL_ACTION CVPCB_ACTIONS::deleteAll( "cvpcb.Association.DeleteAll", AS_GLOBAL,
0, "",
_( "Delete all footprint associations" ),
_( "Delete all footprint associations" ),

View File

@ -0,0 +1,293 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 Ian McInerney <Ian.S.McInerney@ieee.org>
* Copyright (C) 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 as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <confirm.h>
#include <cstdint>
#include <functional>
#include <kiface_i.h>
#include <kiway_express.h>
#include <lib_id.h>
#include <tool/actions.h>
#include <tool/tool_manager.h>
#include <wx/clipbrd.h>
#include <cvpcb_association.h>
#include <cvpcb_mainframe.h>
#include <dialogs/dialog_config_equfiles.h>
#include <display_footprints_frame.h>
#include <listboxes.h>
#include <tools/cvpcb_actions.h>
#include <tools/cvpcb_association_tool.h>
using namespace std::placeholders;
CVPCB_ASSOCIATION_TOOL::CVPCB_ASSOCIATION_TOOL() :
TOOL_INTERACTIVE( "cvpcb.Association" ),
m_frame( nullptr )
{
}
int CVPCB_ASSOCIATION_TOOL::CopyAssoc( const TOOL_EVENT& aEvent )
{
COMPONENT* comp;
LIB_ID fpid;
switch( m_frame->GetFocusedControl() )
{
case CVPCB_MAINFRAME::CONTROL_FOOTPRINT:
fpid.Parse( m_frame->GetSelectedFootprint(), LIB_ID::ID_PCB );
break;
case CVPCB_MAINFRAME::CONTROL_COMPONENT:
// Get the selection
comp = m_frame->GetSelectedComponent();
if( !comp )
return 0;
// Get the fpid and save it to the clipboard
fpid = comp->GetFPID();
break;
default:
// Do nothing
break;
}
// if no valid fpid, then skip
if( !fpid.IsValid() )
return 0;
if( wxTheClipboard->Open() )
{
if( !wxTheClipboard->SetData( new wxTextDataObject( fpid.GetUniStringLibId() ) ) )
wxLogDebug( "Failed to copy data to clipboard" );
wxTheClipboard->Flush();
wxTheClipboard->Close();
}
return 0;
}
int CVPCB_ASSOCIATION_TOOL::CutAssoc( const TOOL_EVENT& aEvent )
{
// Only cut when in the component frame
if( m_frame->GetFocusedControl() != CVPCB_MAINFRAME::CONTROL_COMPONENT )
return 0;
// Get the selection, but only use the first one
COMPONENT* comp = m_frame->GetSelectedComponent();
std::vector<unsigned int> idx = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
if( idx.empty() || !comp )
return 0;
// Get the fpid
LIB_ID fpid;
fpid = comp->GetFPID();
// if no valid fpid, then skip
if( !fpid.IsValid() )
return 0;
// Save it to the clipboard
if( wxTheClipboard->Open() )
{
if( !wxTheClipboard->SetData( new wxTextDataObject( fpid.GetUniStringLibId() ) ) )
{
wxLogDebug( "Failed to cut data to clipboard" );
wxTheClipboard->Close();
return 0;
}
wxTheClipboard->Flush();
wxTheClipboard->Close();
}
// Remove the association
m_frame->AssociateFootprint( CVPCB_ASSOCIATION( idx.front(), "" ) );
return 0;
}
int CVPCB_ASSOCIATION_TOOL::PasteAssoc( const TOOL_EVENT& aEvent )
{
// Get the selection
std::vector<unsigned int> idx = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
if( idx.empty() )
return 0;
// Get the clipboard data and ensure it is valid
LIB_ID fpid;
wxTextDataObject data;
if( wxTheClipboard->Open() )
{
wxTheClipboard->GetData( data );
wxTheClipboard->Close();
}
if( fpid.Parse( data.GetText(), LIB_ID::ID_PCB ) >= 0 )
return 0;
// Assign the fpid to the selections
bool firstAssoc = true;
for( auto i : idx )
{
m_frame->AssociateFootprint( CVPCB_ASSOCIATION( i, fpid ), firstAssoc );
firstAssoc = false;
}
return 0;
}
void CVPCB_ASSOCIATION_TOOL::Reset( RESET_REASON aReason )
{
m_frame = getEditFrame<CVPCB_MAINFRAME>();
}
int CVPCB_ASSOCIATION_TOOL::Undo( const TOOL_EVENT& aEvent )
{
m_frame->UndoAssociation();
return 0;
}
int CVPCB_ASSOCIATION_TOOL::Redo( const TOOL_EVENT& aEvent )
{
m_frame->RedoAssociation();
return 0;
}
int CVPCB_ASSOCIATION_TOOL::Associate( const TOOL_EVENT& aEvent )
{
// Get the currently selected footprint
LIB_ID fpid;
wxString fp = m_frame->GetSelectedFootprint();
fpid.Parse( fp, LIB_ID::ID_PCB );
// Ignore the action if the footprint is empty (nothing selected)
if( fpid.empty() )
return 0;
// Test for validity of the requested footprint
if( !fpid.IsValid() )
{
wxString msg =
wxString::Format( _( "\"%s\" is not a valid footprint." ), fpid.Format().wx_str() );
DisplayErrorMessage( m_frame, msg );
}
// Get all the components that are selected and associate them with the current footprint
std::vector<unsigned int> sel = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
bool firstAssoc = true;
for( auto i : sel )
{
CVPCB_ASSOCIATION newfp( i, fpid );
m_frame->AssociateFootprint( newfp, firstAssoc );
firstAssoc = false;
}
return 0;
}
int CVPCB_ASSOCIATION_TOOL::AutoAssociate( const TOOL_EVENT& aEvent )
{
m_frame->AutomaticFootprintMatching();
return 0;
}
int CVPCB_ASSOCIATION_TOOL::DeleteAssoc( const TOOL_EVENT& aEvent )
{
// Get all the components that are selected
std::vector<unsigned int> sel = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
// Delete the association
bool firstAssoc = true;
for( auto i : sel )
{
m_frame->AssociateFootprint( CVPCB_ASSOCIATION( i, LIB_ID() ), firstAssoc );
firstAssoc = false;
}
return 0;
}
int CVPCB_ASSOCIATION_TOOL::DeleteAll( const TOOL_EVENT& aEvent )
{
if( IsOK( m_frame, _( "Delete all associations?" ) ) )
{
// Remove all selections to avoid issues when setting the fpids
m_frame->SetSelectedComponent( -1, true );
std::vector<unsigned int> idx =
m_frame->GetComponentIndices( CVPCB_MAINFRAME::ALL_COMPONENTS );
bool firstAssoc = true;
for( auto i : idx )
{
m_frame->AssociateFootprint( CVPCB_ASSOCIATION( i, LIB_ID() ), firstAssoc );
firstAssoc = false;
}
// Remove all selections after setting the fpids and select the first component
m_frame->SetSelectedComponent( -1, true );
m_frame->SetSelectedComponent( 0 );
}
// Update the status display
m_frame->DisplayStatus();
return 0;
}
void CVPCB_ASSOCIATION_TOOL::setTransitions()
{
// Association
Go( &CVPCB_ASSOCIATION_TOOL::Associate, CVPCB_ACTIONS::associate.MakeEvent() );
Go( &CVPCB_ASSOCIATION_TOOL::AutoAssociate, CVPCB_ACTIONS::autoAssociate.MakeEvent() );
// Deletion
Go( &CVPCB_ASSOCIATION_TOOL::DeleteAll, CVPCB_ACTIONS::deleteAll.MakeEvent() );
Go( &CVPCB_ASSOCIATION_TOOL::DeleteAssoc, CVPCB_ACTIONS::deleteAssoc.MakeEvent() );
// Helpers
Go( &CVPCB_ASSOCIATION_TOOL::Undo, ACTIONS::undo.MakeEvent() );
Go( &CVPCB_ASSOCIATION_TOOL::Redo, ACTIONS::redo.MakeEvent() );
// Clipboard
Go( &CVPCB_ASSOCIATION_TOOL::CutAssoc, ACTIONS::cut.MakeEvent() );
Go( &CVPCB_ASSOCIATION_TOOL::CopyAssoc, ACTIONS::copy.MakeEvent() );
Go( &CVPCB_ASSOCIATION_TOOL::PasteAssoc, ACTIONS::paste.MakeEvent() );
}

View File

@ -0,0 +1,116 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 Ian McInerney <Ian.S.McInerney@ieee.org>
* Copyright (C) 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 as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CVPCB_ASSOCIATION_TOOL_H_
#define CVPCB_ASSOCIATION_TOOL_H_
#include <tool/tool_interactive.h>
#include <cvpcb_mainframe.h>
/**
* Class CVPCB_CONTROL
*
* Handles actions in main cvpcb window.
*/
class CVPCB_ASSOCIATION_TOOL : public TOOL_INTERACTIVE
{
public:
CVPCB_ASSOCIATION_TOOL();
~CVPCB_ASSOCIATION_TOOL() {}
/// @copydoc TOOL_INTERACTIVE::Reset()
void Reset( RESET_REASON aReason ) override;
/**
* Undo the footprint associations most recently done.
*
* @param aEvent is the event generated by the tool framework
*/
int Undo( const TOOL_EVENT& aEvent );
/**
* Redo the footprint associations most recently done.
*
* @param aEvent is the event generated by the tool framework
*/
int Redo( const TOOL_EVENT& aEvent );
/**
* Associate the selected footprint with the currently selected components.
*
* @param aEvent is the event generated by the tool framework
*/
int Associate( const TOOL_EVENT& aEvent );
/**
* Perform automatic footprint association.
*
* @param aEvent is the event generated by the tool framework
*/
int AutoAssociate( const TOOL_EVENT& aEvent );
/**
* Delete all associations.
*
* @param aEvent is the event generated by the tool framework
*/
int DeleteAll( const TOOL_EVENT& aEvent );
/**
* Delete the selected associations.
*
* @param aEvent is the event generated by the tool framework
*/
int DeleteAssoc( const TOOL_EVENT& aEvent );
/**
* Copy the selected associations to the clipboard.
*
* @param aEvent is the event generated by the tool framework
*/
int CopyAssoc( const TOOL_EVENT& aEvent );
/**
* Cut the selected associations to the clipboard.
*
* @param aEvent is the event generated by the tool framework
*/
int CutAssoc( const TOOL_EVENT& aEvent );
/**
* Paste the clipboard onto the current selection.
*
* @param aEvent is the event generated by the tool framework
*/
int PasteAssoc( const TOOL_EVENT& aEvent );
/*
* Sets up handlers for various events.
*/
void setTransitions() override;
private:
CVPCB_MAINFRAME* m_frame;
};
#endif

View File

@ -204,109 +204,6 @@ int CVPCB_CONTROL::ToggleFootprintFilter( const TOOL_EVENT& aEvent )
}
int CVPCB_CONTROL::Undo( const TOOL_EVENT& aEvent )
{
m_frame->UndoAssociation();
return 0;
}
int CVPCB_CONTROL::Redo( const TOOL_EVENT& aEvent )
{
m_frame->RedoAssociation();
return 0;
}
int CVPCB_CONTROL::Associate( const TOOL_EVENT& aEvent )
{
// Get the currently selected footprint
LIB_ID fpid;
wxString fp = m_frame->GetSelectedFootprint();
fpid.Parse( fp, LIB_ID::ID_PCB );
// Ignore the action if the footprint is empty (nothing selected)
if( fpid.empty() )
return 0;
// Test for validity of the requested footprint
if( !fpid.IsValid() )
{
wxString msg =
wxString::Format( _( "\"%s\" is not a valid footprint." ), fpid.Format().wx_str() );
DisplayErrorMessage( m_frame, msg );
}
// Get all the components that are selected and associate them with the current footprint
std::vector<unsigned int> sel = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
bool firstAssoc = true;
for( auto i : sel )
{
CVPCB_ASSOCIATION newfp( i, fpid );
m_frame->AssociateFootprint( newfp, firstAssoc );
firstAssoc = false;
}
return 0;
}
int CVPCB_CONTROL::AutoAssociate( const TOOL_EVENT& aEvent )
{
m_frame->AutomaticFootprintMatching();
return 0;
}
int CVPCB_CONTROL::DeleteAssoc( const TOOL_EVENT& aEvent )
{
// Get all the components that are selected
std::vector<unsigned int> sel = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
// Delete the association
bool firstAssoc = true;
for( auto i : sel )
{
m_frame->AssociateFootprint( CVPCB_ASSOCIATION( i, LIB_ID() ), firstAssoc );
firstAssoc = false;
}
return 0;
}
int CVPCB_CONTROL::DeleteAll( const TOOL_EVENT& aEvent )
{
if( IsOK( m_frame, _( "Delete all associations?" ) ) )
{
// Remove all selections to avoid issues when setting the fpids
m_frame->SetSelectedComponent( -1, true );
std::vector<unsigned int> idx
= m_frame->GetComponentIndices( CVPCB_MAINFRAME::ALL_COMPONENTS );
bool firstAssoc = true;
for( auto i : idx )
{
m_frame->AssociateFootprint( CVPCB_ASSOCIATION( i, LIB_ID() ), firstAssoc );
firstAssoc = false;
}
// Remove all selections after setting the fpids and select the first component
m_frame->SetSelectedComponent( -1, true );
m_frame->SetSelectedComponent( 0 );
}
// Update the status display
m_frame->DisplayStatus();
return 0;
}
int CVPCB_CONTROL::ShowEquFileTable( const TOOL_EVENT& aEvent )
{
DIALOG_CONFIG_EQUFILES dlg( m_frame );
@ -417,19 +314,11 @@ void CVPCB_CONTROL::setTransitions()
// Management actions
Go( &CVPCB_CONTROL::ShowEquFileTable, CVPCB_ACTIONS::showEquFileTable.MakeEvent() );
Go( &CVPCB_CONTROL::SaveAssociations, CVPCB_ACTIONS::saveAssociations.MakeEvent() );
Go( &CVPCB_CONTROL::DeleteAll, CVPCB_ACTIONS::deleteAll.MakeEvent() );
Go( &CVPCB_CONTROL::DeleteAssoc, CVPCB_ACTIONS::deleteAssoc.MakeEvent() );
// Navigation actions
Go( &CVPCB_CONTROL::ToNA, CVPCB_ACTIONS::gotoNextNA.MakeEvent() );
Go( &CVPCB_CONTROL::ToNA, CVPCB_ACTIONS::gotoPreviousNA.MakeEvent() );
// Footprint association actions
Go( &CVPCB_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
Go( &CVPCB_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
Go( &CVPCB_CONTROL::Associate, CVPCB_ACTIONS::associate.MakeEvent() );
Go( &CVPCB_CONTROL::AutoAssociate, CVPCB_ACTIONS::autoAssociate.MakeEvent() );
// Filter the footprints
Go( &CVPCB_CONTROL::ToggleFootprintFilter, CVPCB_ACTIONS::filterFPbyKeywords.MakeEvent() );
Go( &CVPCB_CONTROL::ToggleFootprintFilter, CVPCB_ACTIONS::filterFPbyLibrary.MakeEvent() );

View File

@ -56,48 +56,6 @@ public:
*/
int ChangeFocus( const TOOL_EVENT& aEvent );
/**
* Undo the footprint associations most recently done.
*
* @param aEvent is the event generated by the tool framework
*/
int Undo( const TOOL_EVENT& aEvent );
/**
* Redo the footprint associations most recently done.
*
* @param aEvent is the event generated by the tool framework
*/
int Redo( const TOOL_EVENT& aEvent );
/**
* Associate the selected footprint with the currently selected components.
*
* @param aEvent is the event generated by the tool framework
*/
int Associate( const TOOL_EVENT& aEvent );
/**
* Perform automatic footprint association.
*
* @param aEvent is the event generated by the tool framework
*/
int AutoAssociate( const TOOL_EVENT& aEvent );
/**
* Delete all associations.
*
* @param aEvent is the event generated by the tool framework
*/
int DeleteAll( const TOOL_EVENT& aEvent );
/**
* Delete the selected associations.
*
* @param aEvent is the event generated by the tool framework
*/
int DeleteAssoc( const TOOL_EVENT& aEvent );
/**
* Move the selected component to the not associated one in the specified direction.
*