cvpcb: Move some more tasks to a tool

This commit is contained in:
Ian McInerney 2019-08-08 23:10:37 +02:00 committed by Wayne Stambaugh
parent 06abda254a
commit d428d5fecf
5 changed files with 190 additions and 136 deletions

View File

@ -36,6 +36,7 @@
#include <kiway_express.h>
#include <macros.h>
#include <netlist_reader.h>
#include <numeric>
#include <tool/action_toolbar.h>
#include <tool/common_control.h>
#include <tool/conditional_menu.h>
@ -321,66 +322,6 @@ void CVPCB_MAINFRAME::ChangeFocus( bool aMoveRight )
}
void CVPCB_MAINFRAME::ToNextNA()
{
if( m_netlist.IsEmpty() )
return;
int first_selected = m_compListBox->GetFirstSelected();
if( first_selected < 0 )
first_selected = -1; // We will start to 0 for the first search , if no item selected
int candidate = -1;
for( int jj = first_selected+1; jj < (int)m_netlist.GetCount(); jj++ )
{
if( m_netlist.GetComponent( jj )->GetFPID().empty() )
{
candidate = jj;
break;
}
}
if( candidate >= 0 )
{
m_compListBox->DeselectAll();
m_compListBox->SetSelection( candidate );
SendMessageToEESCHEMA();
}
}
void CVPCB_MAINFRAME::ToPreviousNA()
{
if( m_netlist.IsEmpty() )
return;
int first_selected = m_compListBox->GetFirstSelected();
if( first_selected < 0 )
first_selected = m_compListBox->GetCount();
int candidate = -1;
for( int jj = first_selected-1; jj >= 0; jj-- )
{
if( m_netlist.GetComponent( jj )->GetFPID().empty() )
{
candidate = jj;
break;
}
}
if( candidate >= 0 )
{
m_compListBox->DeselectAll();
m_compListBox->SetSelection( candidate );
SendMessageToEESCHEMA();
}
}
void CVPCB_MAINFRAME::OnOK( wxCommandEvent& aEvent )
{
SaveFootprintAssociation( false );
@ -506,33 +447,6 @@ void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation,
}
void CVPCB_MAINFRAME::DeleteAll()
{
if( IsOK( this, _( "Delete all associations?" ) ) )
{
m_skipComponentSelect = true;
// Remove all selections to avoid issues when setting the fpids
m_compListBox->DeselectAll();
bool firstAssoc = true;
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
AssociateFootprint( CVPCB_ASSOCIATION( i, LIB_ID() ), firstAssoc );
firstAssoc = false;
}
// Remove all selections after setting the fpids
m_compListBox->DeselectAll();
m_skipComponentSelect = false;
m_compListBox->SetSelection( 0 );
}
DisplayStatus();
}
bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
{
return true;
@ -955,23 +869,77 @@ COMPONENT* CVPCB_MAINFRAME::GetSelectedComponent()
}
std::vector<unsigned int> CVPCB_MAINFRAME::GetSelectedComponentIndices()
void CVPCB_MAINFRAME::SetSelectedComponent( int aIndex, bool aSkipUpdate )
{
m_skipComponentSelect = aSkipUpdate;
if( aIndex < 0 )
{
m_compListBox->DeselectAll();
}
else if( aIndex < m_compListBox->GetCount() )
{
m_compListBox->DeselectAll();
m_compListBox->SetSelection( aIndex );
SendMessageToEESCHEMA();
}
m_skipComponentSelect = false;
}
std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
CVPCB_MAINFRAME::CRITERIA aCriteria )
{
std::vector<unsigned int> idx;
// Check to see if anything is selected
if( m_compListBox->GetSelectedItemCount() < 1 )
// Make sure a netlist has been loaded and the box has contents
if( m_netlist.IsEmpty() || m_compListBox->GetCount() == 0 )
return idx;
// Get the components
int lastIdx = m_compListBox->GetFirstSelected();
idx.emplace_back( lastIdx );
lastIdx = m_compListBox->GetNextSelected( lastIdx );
while( lastIdx > 0 )
switch( aCriteria )
{
case CVPCB_MAINFRAME::ALL_COMPONENTS:
idx.resize( m_netlist.GetCount() );
std::iota( idx.begin(), idx.end(), 0 );
break;
case CVPCB_MAINFRAME::SEL_COMPONENTS:
{
// Check to see if anything is selected
if( m_compListBox->GetSelectedItemCount() < 1 )
break;
// Get the components
int lastIdx = m_compListBox->GetFirstSelected();
idx.emplace_back( lastIdx );
lastIdx = m_compListBox->GetNextSelected( lastIdx );
while( lastIdx > 0 )
{
idx.emplace_back( lastIdx );
lastIdx = m_compListBox->GetNextSelected( lastIdx );
}
break;
}
case CVPCB_MAINFRAME::NA_COMPONENTS:
for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
{
if( m_netlist.GetComponent( i )->GetFPID().empty() )
idx.emplace_back( i );
}
break;
case CVPCB_MAINFRAME::ASOC_COMPONENTS:
for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
{
if( !m_netlist.GetComponent( i )->GetFPID().empty() )
idx.emplace_back( i );
}
break;
default:
wxASSERT_MSG( false, "Invalid component selection criteria" );
}
return idx;

View File

@ -104,6 +104,15 @@ public:
FILTER_TOGGLE ///< Toggle the filter state
};
/**
* Directions to move when selecting items
*/
enum ITEM_DIR
{
ITEM_NEXT, ///< The next item
ITEM_PREV ///< The previous item
};
/**
* @return a pointer on the Footprint Viewer frame, if exists, or NULL
*/
@ -130,22 +139,6 @@ public:
void ChangeFocus( bool aMoveRight );
/**
* Move to the next not associated component.
*/
void ToNextNA();
/**
* Move to the previous not associated component.
*/
void ToPreviousNA();
/**
* Function DeleteAll
* removes all component footprint associations already made
*/
void DeleteAll();
void OnComponentRightClick( wxMouseEvent& event );
void OnFootprintRightClick( wxMouseEvent& event );
@ -299,14 +292,41 @@ public:
*/
void SendMessageToEESCHEMA( bool aClearHighligntOnly = false );
/**
* Get the selected component from the component listbox.
*
* @return the selected component
*/
COMPONENT* GetSelectedComponent();
/**
* Get the indices for all the selected components in the components listbox.
* Set the currently selected component in the components listbox
*
* @param aIndex the index of the component to select, -1 to clear selection
* @param aSkipUpdate skips running the OnSelectComponent event to update the other windows
*/
void SetSelectedComponent( int aIndex, bool aSkipUpdate = false );
/**
* Criteria to use to identify sets of components
*/
enum CRITERIA
{
ALL_COMPONENTS, ///< All components
SEL_COMPONENTS, ///< Selected components
NA_COMPONENTS, ///< Not associated components
ASOC_COMPONENTS ///< Associated components
};
/**
* Get the indices for all the components meeting the specified criteria in the components
* listbox.
*
* @param aCriteria is the criteria to use for finding the indices
* @return a vector containing all the indices
*/
std::vector<unsigned int> GetSelectedComponentIndices();
std::vector<unsigned int> GetComponentIndices(
CVPCB_MAINFRAME::CRITERIA aCriteria = CVPCB_MAINFRAME::ALL_COMPONENTS );
/**
* @return the LIB_ID of the selected footprint in footprint listview

View File

@ -22,6 +22,7 @@
#include <frame_type.h>
#include <tool/tool_manager.h>
#include <cvpcb_mainframe.h>
#include <listboxes.h>
#include <tools/cvpcb_actions.h>
@ -68,13 +69,15 @@ TOOL_ACTION CVPCB_ACTIONS::gotoNextNA( "cvpcb.Control.GotoNextNA", AS_GLOBAL,
0, "",
_( "Select next unassociated symbol" ),
_( "Select next unassociated symbol" ),
right_xpm );
right_xpm, AF_NONE,
(void*) CVPCB_MAINFRAME::ITEM_NEXT );
TOOL_ACTION CVPCB_ACTIONS::gotoPreviousNA( "cvpcb.Control.GotoPreviousNA", AS_GLOBAL,
0, "",
_( "Select previous unassociated symbol" ),
_( "Select previous unassociated symbol" ),
left_xpm );
left_xpm, AF_NONE,
(void*) CVPCB_MAINFRAME::ITEM_PREV );
// Actions to modify component associations

View File

@ -132,7 +132,7 @@ int CVPCB_CONTROL::Associate( const TOOL_EVENT& aEvent )
}
// Get all the components that are selected and associate them with the current footprint
std::vector<unsigned int> sel = m_frame->GetSelectedComponentIndices();
std::vector<unsigned int> sel = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
bool firstAssoc = true;
for( auto i : sel )
@ -156,7 +156,27 @@ int CVPCB_CONTROL::AutoAssociate( const TOOL_EVENT& aEvent )
int CVPCB_CONTROL::DeleteAll( const TOOL_EVENT& aEvent )
{
m_frame->DeleteAll();
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;
}
@ -178,16 +198,66 @@ int CVPCB_CONTROL::SaveAssociations( const TOOL_EVENT& aEvent )
}
int CVPCB_CONTROL::ToNextNA( const TOOL_EVENT& aEvent )
int CVPCB_CONTROL::ToNA( const TOOL_EVENT& aEvent )
{
m_frame->ToNextNA();
return 0;
}
int tmp = aEvent.Parameter<intptr_t>();
CVPCB_MAINFRAME::ITEM_DIR dir =
static_cast<CVPCB_MAINFRAME::ITEM_DIR>( tmp );
std::vector<unsigned int> naComp = m_frame->GetComponentIndices( CVPCB_MAINFRAME::NA_COMPONENTS );
std::vector<unsigned int> tempSel = m_frame->GetComponentIndices( CVPCB_MAINFRAME::SEL_COMPONENTS );
// No unassociated components
if( naComp.empty() )
return 0;
// Extract the current selection
unsigned int curSel = -1;
unsigned int newSel = -1;
switch( dir )
{
case CVPCB_MAINFRAME::ITEM_NEXT:
if( !tempSel.empty() )
newSel = tempSel.front();
// Find the next index in the component list
for( unsigned int i : naComp )
{
if( i > newSel )
{
newSel = i;
break;
}
}
break;
case CVPCB_MAINFRAME::ITEM_PREV:
if( !tempSel.empty() )
{
newSel = tempSel.front();
curSel = newSel - 1; // Break one before the current selection
}
break;
default:
wxASSERT_MSG( false, "Invalid direction" );
}
// Find the next index in the component list
for( unsigned int i : naComp )
{
if( i >= curSel )
{
newSel = i;
break;
}
}
// Set the component selection
m_frame->SetSelectedComponent( newSel );
int CVPCB_CONTROL::ToPreviousNA( const TOOL_EVENT& aEvent )
{
m_frame->ToPreviousNA();
return 0;
}
@ -222,8 +292,8 @@ void CVPCB_CONTROL::setTransitions()
Go( &CVPCB_CONTROL::DeleteAll, CVPCB_ACTIONS::deleteAll.MakeEvent() );
// Navigation actions
Go( &CVPCB_CONTROL::ToNextNA, CVPCB_ACTIONS::gotoNextNA.MakeEvent() );
Go( &CVPCB_CONTROL::ToPreviousNA, CVPCB_ACTIONS::gotoPreviousNA.MakeEvent() );
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() );

View File

@ -77,18 +77,11 @@ public:
int DeleteAll( const TOOL_EVENT& aEvent );
/**
* Move the selected component to the next not associated one.
* Move the selected component to the not associated one in the specified direction.
*
* @param aEvent is the event generated by the tool framework
*/
int ToNextNA( const TOOL_EVENT& aEvent );
/**
* Move the selected component to the previous not associated one.
*
* @param aEvent is the event generated by the tool framework
*/
int ToPreviousNA( const TOOL_EVENT& aEvent );
int ToNA( const TOOL_EVENT& aEvent );
/**
* Show the dialog to modify the included footprint association files (.equ)