Code cleanup for readibility.

This commit is contained in:
Jeff Young 2020-01-11 21:14:09 +00:00
parent 116e3d6816
commit b343391723
7 changed files with 60 additions and 116 deletions

View File

@ -117,7 +117,7 @@ void HOTKEY_STORE::Init( std::vector<TOOL_MANAGER*> aToolManagerList, bool aIncl
TOOL_ACTION* entryAction = entry.second.m_Actions[ 0 ]; TOOL_ACTION* entryAction = entry.second.m_Actions[ 0 ];
wxString entryApp = GetAppName( entryAction ); wxString entryApp = GetAppName( entryAction );
if( entryApp != currentApp ) if( !currentSection || entryApp != currentApp )
{ {
m_hk_sections.emplace_back( HOTKEY_SECTION() ); m_hk_sections.emplace_back( HOTKEY_SECTION() );
currentApp = entryApp; currentApp = entryApp;

View File

@ -32,9 +32,8 @@
#include <cvpcb_id.h> #include <cvpcb_id.h>
COMPONENTS_LISTBOX::COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id, COMPONENTS_LISTBOX::COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id ) :
const wxPoint& loc, const wxSize& size ) : ITEMS_LISTBOX_BASE( parent, id )
ITEMS_LISTBOX_BASE( parent, id, loc, size, 0 )
{ {
} }

View File

@ -439,13 +439,10 @@ void CVPCB_MAINFRAME::RedoAssociation()
void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation, void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation,
bool aNewEntry, bool aAddUndoItem ) bool aNewEntry, bool aAddUndoItem )
{ {
// Ensure there is data to work with
COMPONENT* component;
if( m_netlist.IsEmpty() ) if( m_netlist.IsEmpty() )
return; return;
component = m_netlist.GetComponent( aAssociation.GetComponentIndex() ); COMPONENT* component = m_netlist.GetComponent( aAssociation.GetComponentIndex() );
if( component == NULL ) if( component == NULL )
return; return;
@ -466,9 +463,11 @@ void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation,
component->SetFPID( fpid ); component->SetFPID( fpid );
// create the new component description and set it // create the new component description and set it
wxString description = wxString::Format( CMP_FORMAT, aAssociation.GetComponentIndex() + 1, wxString description = wxString::Format( CMP_FORMAT,
GetChars( component->GetReference() ), GetChars( component->GetValue() ), aAssociation.GetComponentIndex() + 1,
GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) ); component->GetReference(),
component->GetValue(),
component->GetFPID().Format().wx_str() );
m_compListBox->SetString( aAssociation.GetComponentIndex(), description ); m_compListBox->SetString( aAssociation.GetComponentIndex(), description );
// Mark the data as being modified // Mark the data as being modified
@ -487,7 +486,7 @@ void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation,
// Create a new entry for this association // Create a new entry for this association
CVPCB_UNDO_REDO_ENTRIES newEntry; CVPCB_UNDO_REDO_ENTRIES newEntry;
newEntry.emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(), oldFpid, newEntry.emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(), oldFpid,
aAssociation.GetNewFootprint() ) ); aAssociation.GetNewFootprint() ) );
m_undoList.emplace_back( newEntry ); m_undoList.emplace_back( newEntry );
// Clear the redo list // Clear the redo list
@ -495,7 +494,7 @@ void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation,
} }
else else
m_undoList.back().emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(), m_undoList.back().emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(),
oldFpid, aAssociation.GetNewFootprint() ) ); oldFpid, aAssociation.GetNewFootprint() ) );
} }
@ -554,27 +553,15 @@ void CVPCB_MAINFRAME::refreshAfterComponentSearch( COMPONENT* component )
} }
void CVPCB_MAINFRAME::SetFootprintFilter( void CVPCB_MAINFRAME::SetFootprintFilter( FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter,
FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction ) CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction )
{ {
int option = FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST; int option = aFilter;
// Extract the needed information about the filter // Extract the current search patten when needed
switch( aFilter ) if( option == FOOTPRINTS_LISTBOX::FILTERING_BY_TEXT_PATTERN )
{
case FOOTPRINTS_LISTBOX::FILTERING_BY_TEXT_PATTERN:
// Extract the current search patten when needed
m_currentSearchPattern = m_tcFilterString->GetValue(); m_currentSearchPattern = m_tcFilterString->GetValue();
// Intentionally fall through since this uses the filter options passed in
case FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST:
case FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT:
case FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY:
case FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_FP_FILTERS:
option = aFilter;
}
// Apply the filter accordingly // Apply the filter accordingly
switch( aAction ) switch( aAction )
{ {
@ -812,12 +799,9 @@ void CVPCB_MAINFRAME::BuildFOOTPRINTS_LISTBOX()
if( m_footprintListBox == NULL ) if( m_footprintListBox == NULL )
{ {
m_footprintListBox = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST, m_footprintListBox = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST );
wxDefaultPosition, wxDefaultSize ); m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
} }
m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL, m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL,
@ -834,12 +818,9 @@ void CVPCB_MAINFRAME::BuildCmpListBox()
if( m_compListBox == NULL ) if( m_compListBox == NULL )
{ {
m_compListBox = new COMPONENTS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST, m_compListBox = new COMPONENTS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST );
wxDefaultPosition, wxDefaultSize ); m_compListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
m_compListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
} }
m_compListBox->m_ComponentList.Clear(); m_compListBox->m_ComponentList.Clear();
@ -848,10 +829,11 @@ void CVPCB_MAINFRAME::BuildCmpListBox()
{ {
component = m_netlist.GetComponent( i ); component = m_netlist.GetComponent( i );
msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1, msg.Printf( CMP_FORMAT,
GetChars( component->GetReference() ), m_compListBox->GetCount() + 1,
GetChars( component->GetValue() ), component->GetReference(),
GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) ); component->GetValue(),
component->GetFPID().Format().wx_str() );
m_compListBox->m_ComponentList.Add( msg ); m_compListBox->m_ComponentList.Add( msg );
} }
@ -871,12 +853,9 @@ void CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX()
if( m_libListBox == NULL ) if( m_libListBox == NULL )
{ {
m_libListBox = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST, m_libListBox = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST );
wxDefaultPosition, wxDefaultSize ); m_libListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
m_libListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
wxFONTFAMILY_MODERN,
wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL ) );
} }
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() ); FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
@ -887,8 +866,8 @@ void CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX()
std::vector< wxString > libNickNames = tbl->GetLogicalLibs(); std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
for( unsigned ii = 0; ii < libNickNames.size(); ii++ ) for( const wxString& libNickName : libNickNames )
libNames.Add( libNickNames[ii] ); libNames.Add( libNickName );
m_libListBox->SetLibraryList( libNames ); m_libListBox->SetLibraryList( libNames );
} }
@ -1021,20 +1000,10 @@ void CVPCB_MAINFRAME::SetFocusedControl( CVPCB_MAINFRAME::CONTROL_TYPE aLB )
{ {
switch( aLB ) switch( aLB )
{ {
case CVPCB_MAINFRAME::CONTROL_LIBRARY: case CVPCB_MAINFRAME::CONTROL_LIBRARY: m_libListBox->SetFocus(); break;
m_libListBox->SetFocus(); case CVPCB_MAINFRAME::CONTROL_COMPONENT: m_compListBox->SetFocus(); break;
break; case CVPCB_MAINFRAME::CONTROL_FOOTPRINT: m_footprintListBox->SetFocus(); break;
default: break;
case CVPCB_MAINFRAME::CONTROL_COMPONENT:
m_compListBox->SetFocus();
break;
case CVPCB_MAINFRAME::CONTROL_FOOTPRINT:
m_footprintListBox->SetFocus();
break;
default:
break;
} }
} }
@ -1051,20 +1020,10 @@ void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
{ {
switch( aNumber ) switch( aNumber )
{ {
case 0: case 0: m_statusLine1->SetLabel( aText ); break;
m_statusLine1->SetLabel( aText ); case 1: m_statusLine2->SetLabel( aText ); break;
break; case 2: m_statusLine3->SetLabel( aText ); break;
default: wxFAIL_MSG( "Invalid status row number" ); break;
case 1:
m_statusLine2->SetLabel( aText );
break;
case 2:
m_statusLine3->SetLabel( aText );
break;
default:
wxASSERT_MSG( false, "Invalid status row number" );
} }
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -22,11 +22,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file footprints_listbox.cpp
* class to display the list of available footprints
*/
#include <footprint_filter.h> #include <footprint_filter.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <trace_helpers.h> #include <trace_helpers.h>
@ -37,10 +32,8 @@
#include <listboxes.h> #include <listboxes.h>
#include <tools/cvpcb_actions.h> #include <tools/cvpcb_actions.h>
FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id ) :
wxWindowID id, const wxPoint& loc, ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL|wxNO_BORDER )
const wxSize& size ) :
ITEMS_LISTBOX_BASE( parent, id, loc, size, wxLC_SINGLE_SEL | wxNO_BORDER )
{ {
} }
@ -63,6 +56,7 @@ void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
{ {
if( linecount >= count ) if( linecount >= count )
linecount = count - 1; linecount = count - 1;
m_footprintList[linecount] = text; m_footprintList[linecount] = text;
} }
UpdateWidth( linecount ); UpdateWidth( linecount );
@ -120,9 +114,7 @@ void FOOTPRINTS_LISTBOX::SetSelection( int index, bool State )
void FOOTPRINTS_LISTBOX::SetSelectedFootprint( const LIB_ID& aFPID ) void FOOTPRINTS_LISTBOX::SetSelectedFootprint( const LIB_ID& aFPID )
{ {
wxString id = wxString::Format( "%s:%s", wxString id = aFPID.Format().wx_str();
GetChars( aFPID.GetLibNickname() ),
GetChars( aFPID.GetLibItemName() ) );
for( int i = 0; i < GetCount(); ++i ) for( int i = 0; i < GetCount(); ++i )
{ {
@ -165,9 +157,10 @@ void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& a
for( auto& i: filter ) for( auto& i: filter )
{ {
msg.Printf( "%3d %s:%s", int( newList.GetCount() + 1 ), msg.Printf( "%3d %s:%s",
GetChars( i.GetLibNickname() ), int( newList.GetCount() + 1 ),
GetChars( i.GetFootprintName() ) ); i.GetLibNickname(),
i.GetFootprintName() );
newList.Add( msg ); newList.Add( msg );
} }

View File

@ -37,9 +37,8 @@
/* ListBox handling the library list */ /* ListBox handling the library list */
/***************************************/ /***************************************/
LIBRARY_LISTBOX::LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id, LIBRARY_LISTBOX::LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id ) :
const wxPoint& loc, const wxSize& size ) : ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL )
ITEMS_LISTBOX_BASE( parent, id, loc, size, wxLC_SINGLE_SEL )
{ {
} }

View File

@ -38,7 +38,8 @@
ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId, ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
const wxPoint& aLocation, const wxSize& aSize, const wxPoint& aLocation, const wxSize& aSize,
long aStyle) : long aStyle) :
wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ), columnWidth(0) wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ),
columnWidth( 0 )
{ {
InsertColumn( 0, wxEmptyString ); InsertColumn( 0, wxEmptyString );
} }

View File

@ -21,10 +21,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file listboxes.h
*/
#ifndef LISTBOXES_H #ifndef LISTBOXES_H
#define LISTBOXES_H #define LISTBOXES_H
@ -46,8 +42,8 @@ class ITEMS_LISTBOX_BASE : public wxListView
{ {
public: public:
ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId, ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
const wxPoint& aLocation, const wxSize& aSize, const wxPoint& aLocation = wxDefaultPosition,
long aStyle = 0 ); const wxSize& aSize = wxDefaultSize, long aStyle = 0 );
~ITEMS_LISTBOX_BASE(); ~ITEMS_LISTBOX_BASE();
@ -104,8 +100,7 @@ public:
FILTERING_BY_TEXT_PATTERN = 0x0008 FILTERING_BY_TEXT_PATTERN = 0x0008
}; };
FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id, FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
const wxPoint& loc, const wxSize& size );
~FOOTPRINTS_LISTBOX(); ~FOOTPRINTS_LISTBOX();
int GetCount(); int GetCount();
@ -126,8 +121,8 @@ public:
* @param aFootPrintFilterPattern = a filter used to filter list by names * @param aFootPrintFilterPattern = a filter used to filter list by names
* @param aFilterType defines the criteria to filter \a aList. * @param aFilterType defines the criteria to filter \a aList.
*/ */
void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName, void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName, COMPONENT* aComponent,
COMPONENT* aComponent, const wxString &aFootPrintFilterPattern, int aFilterType ); const wxString &aFootPrintFilterPattern, int aFilterType );
wxString GetSelectedFootprint(); wxString GetSelectedFootprint();
@ -155,8 +150,7 @@ class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
wxArrayString m_libraryList; wxArrayString m_libraryList;
public: public:
LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id, LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
const wxPoint& loc, const wxSize& size );
~LIBRARY_LISTBOX(); ~LIBRARY_LISTBOX();
int GetCount(); int GetCount();
@ -201,8 +195,7 @@ public:
public: public:
COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id, COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
const wxPoint& loc, const wxSize& size );
~COMPONENTS_LISTBOX(); ~COMPONENTS_LISTBOX();