Formatting and naming conventions.

This commit is contained in:
Jeff Young 2020-11-07 14:31:50 +00:00
parent 0a0a51471c
commit bfd8a62852
36 changed files with 317 additions and 304 deletions

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2011 Jean-Pierre Charras, <jp.charras@wanadoo.fr> * Copyright (C) 2011 Jean-Pierre Charras, <jp.charras@wanadoo.fr>
* Copyright (C) 2013-2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2013-2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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
@ -31,35 +31,31 @@
#include <footprint_info.h> #include <footprint_info.h>
#include <fp_lib_table.h> #include <fp_lib_table.h>
#include <dialogs/html_messagebox.h> #include <dialogs/html_messagebox.h>
#include <io_mgr.h>
#include <kicad_string.h> #include <kicad_string.h>
#include <kiface_ids.h> #include <kiface_ids.h>
#include <kiway.h> #include <kiway.h>
#include <lib_id.h> #include <lib_id.h>
#include <pgm_base.h>
#include <thread> #include <thread>
#include <utility> #include <utility>
#include <wildcards_and_files_ext.h>
#include <wx/textfile.h>
FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aLibNickname, FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aLibNickname,
const wxString& aFootprintName ) const wxString& aFootprintName )
{ {
if( aFootprintName.IsEmpty() ) if( aFootprintName.IsEmpty() )
return NULL; return NULL;
for( auto& fp : m_list ) for( std::unique_ptr<FOOTPRINT_INFO>& fp : m_list )
{ {
if( aLibNickname == fp->GetLibNickname() && aFootprintName == fp->GetFootprintName() ) if( aLibNickname == fp->GetLibNickname() && aFootprintName == fp->GetFootprintName() )
return &*fp; return fp.get();
} }
return NULL; return NULL;
} }
FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintName ) FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aFootprintName )
{ {
if( aFootprintName.IsEmpty() ) if( aFootprintName.IsEmpty() )
return NULL; return NULL;
@ -69,7 +65,7 @@ FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintName )
wxCHECK_MSG( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) < 0, NULL, wxCHECK_MSG( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) < 0, NULL,
wxString::Format( wxT( "\"%s\" is not a valid LIB_ID." ), aFootprintName ) ); wxString::Format( wxT( "\"%s\" is not a valid LIB_ID." ), aFootprintName ) );
return GetModuleInfo( fpid.GetLibNickname(), fpid.GetLibItemName() ); return GetFootprintInfo( fpid.GetLibNickname(), fpid.GetLibItemName());
} }
@ -79,9 +75,6 @@ bool FOOTPRINT_INFO::InLibrary( const wxString& aLibrary ) const
} }
/**
* Less than operator implementation for FOOTPRINT_INFO
*/
bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs ) bool operator<( const FOOTPRINT_INFO& lhs, const FOOTPRINT_INFO& rhs )
{ {
int retv = StrNumCmp( lhs.m_nickname, rhs.m_nickname, false ); int retv = StrNumCmp( lhs.m_nickname, rhs.m_nickname, false );
@ -110,7 +103,7 @@ void FOOTPRINT_LIST::DisplayErrors( wxTopLevelWindow* aWindow )
wxString msg; wxString msg;
while( auto error = PopError() ) while( const std::unique_ptr<IO_ERROR>& error = PopError() )
{ {
wxString tmp = error->Problem(); wxString tmp = error->Problem();
@ -180,8 +173,8 @@ void FOOTPRINT_ASYNC_LOADER::SetList( FOOTPRINT_LIST* aList )
} }
void FOOTPRINT_ASYNC_LOADER::Start( void FOOTPRINT_ASYNC_LOADER::Start( FP_LIB_TABLE* aTable, wxString const* aNickname,
FP_LIB_TABLE* aTable, wxString const* aNickname, unsigned aNThreads ) unsigned aNThreads )
{ {
// Capture the FP_LIB_TABLE into m_last_table. Formatting it as a string instead of storing the // Capture the FP_LIB_TABLE into m_last_table. Formatting it as a string instead of storing the
// raw data avoids having to pull in the FP-specific parts. // raw data avoids having to pull in the FP-specific parts.

View File

@ -97,12 +97,6 @@ class EDA_BASE_FRAME;
class LIB_TREE_MODEL_ADAPTER: public wxDataViewModel class LIB_TREE_MODEL_ADAPTER: public wxDataViewModel
{ {
public: public:
/**
* Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
*/
typedef wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> PTR;
/** /**
* Destructor. Do NOT delete this class manually; it is reference-counted * Destructor. Do NOT delete this class manually; it is reference-counted
* by wxObject. * by wxObject.

View File

@ -32,7 +32,8 @@
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAPTER::PTR& aAdapter, LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable,
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
WIDGETS aWidgets, wxHtmlWindow* aDetails ) WIDGETS aWidgets, wxHtmlWindow* aDetails )
: wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, : wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ), wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),

View File

@ -55,7 +55,8 @@ public:
* @param aDetails if not null, a custom wxHtmlWindow to hold symbol details. If null this * @param aDetails if not null, a custom wxHtmlWindow to hold symbol details. If null this
* will be created inside the LIB_TREE. * will be created inside the LIB_TREE.
*/ */
LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, LIB_TREE_MODEL_ADAPTER::PTR& aAdapter, LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable,
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
WIDGETS aWidgets = ALL, wxHtmlWindow *aDetails = nullptr ); WIDGETS aWidgets = ALL, wxHtmlWindow *aDetails = nullptr );
~LIB_TREE() override; ~LIB_TREE() override;
@ -166,12 +167,13 @@ protected:
void onContextMenu( wxDataViewEvent& aEvent ); void onContextMenu( wxDataViewEvent& aEvent );
protected: protected:
LIB_TABLE* m_lib_table; LIB_TABLE* m_lib_table;
LIB_TREE_MODEL_ADAPTER::PTR m_adapter;
wxTextCtrl* m_query_ctrl; wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
wxDataViewCtrl* m_tree_ctrl;
wxHtmlWindow* m_details_ctrl; wxTextCtrl* m_query_ctrl;
wxDataViewCtrl* m_tree_ctrl;
wxHtmlWindow* m_details_ctrl;
}; };
///> Custom event sent when a new component is preselected ///> Custom event sent when a new component is preselected

View File

@ -76,7 +76,8 @@ bool sortListbyCmpValue( const FOOTPRINT_EQUIVALENCE& ref, const FOOTPRINT_EQUIV
// read the .equ files and populate the list of equivalents // read the .equ files and populate the list of equivalents
int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wxString * aErrorMessages ) int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList,
wxString* aErrorMessages )
{ {
char line[1024]; char line[1024];
int error_count = 0; int error_count = 0;
@ -89,7 +90,7 @@ int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wx
// Find equivalences in all available files, and populates the // Find equivalences in all available files, and populates the
// equiv_List with all equivalences found in .equ files // equiv_List with all equivalences found in .equ files
for( const auto& equfile : project.m_EquivalenceFiles ) for( const wxString& equfile : project.m_EquivalenceFiles )
{ {
fn = wxExpandEnvVars( equfile ); fn = wxExpandEnvVars( equfile );
@ -103,7 +104,7 @@ int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wx
{ {
error_msg.Printf( _( "Equivalence file \"%s\" could not be found in the " error_msg.Printf( _( "Equivalence file \"%s\" could not be found in the "
"default search paths." ), "default search paths." ),
fn.GetFullName() ); fn.GetFullName() );
if( ! aErrorMessages->IsEmpty() ) if( ! aErrorMessages->IsEmpty() )
*aErrorMessages << wxT("\n\n"); *aErrorMessages << wxT("\n\n");
@ -166,26 +167,25 @@ int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wx
void CVPCB_MAINFRAME::AutomaticFootprintMatching() void CVPCB_MAINFRAME::AutomaticFootprintMatching()
{ {
FOOTPRINT_EQUIVALENCE_LIST equiv_List; FOOTPRINT_EQUIVALENCE_LIST equivList;
wxString msg, error_msg; wxString msg;
wxString error_msg;
if( m_netlist.IsEmpty() ) if( m_netlist.IsEmpty() )
return; return;
if( buildEquivalenceList( equiv_List, &error_msg ) ) if( buildEquivalenceList( equivList, &error_msg ) )
wxMessageBox( error_msg, _( "Equivalence File Load Error" ), wxOK | wxICON_WARNING, this ); wxMessageBox( error_msg, _( "Equivalence File Load Error" ), wxOK | wxICON_WARNING, this );
// Sort the association list by component value. // Sort the association list by symbol value. When sorted, finding duplicate definitions
// When sorted, find duplicate definitions (i.e. 2 or more items // (i.e. 2 or more items having the same symbol value) is easier.
// having the same component value) is more easy. std::sort( equivList.begin(), equivList.end(), sortListbyCmpValue );
std::sort( equiv_List.begin(), equiv_List.end(), sortListbyCmpValue );
// Display the number of footprint/component equivalences. // Display the number of footprint/symbol equivalences.
msg.Printf( _( "%lu footprint/cmp equivalences found." ), (unsigned long)equiv_List.size() ); msg.Printf( _( "%lu footprint/symbol equivalences found." ), (unsigned long)equivList.size() );
SetStatusText( msg, 0 ); SetStatusText( msg, 0 );
// Now, associate each free component with a footprint, when the association // Now, associate each free component with a footprint
// is found in list
m_skipComponentSelect = true; m_skipComponentSelect = true;
error_msg.Empty(); error_msg.Empty();
@ -201,36 +201,40 @@ void CVPCB_MAINFRAME::AutomaticFootprintMatching()
// Here a first attempt is made. We can have multiple equivItem of the same value. // Here a first attempt is made. We can have multiple equivItem of the same value.
// When happens, using the footprint filter of components can remove the ambiguity by // When happens, using the footprint filter of components can remove the ambiguity by
// filtering equivItem so one can use multiple equiv_List (for polar and // filtering equivItem so one can use multiple equivList (for polar and non-polar caps
// non-polar caps for example) // for example)
wxString fpid_candidate; wxString fpid_candidate;
for( unsigned idx = 0; idx < equiv_List.size(); idx++ ) for( unsigned idx = 0; idx < equivList.size(); idx++ )
{ {
FOOTPRINT_EQUIVALENCE& equivItem = equiv_List[idx]; FOOTPRINT_EQUIVALENCE& equivItem = equivList[idx];
if( equivItem.m_ComponentValue.CmpNoCase( component->GetValue() ) != 0 ) if( equivItem.m_ComponentValue.CmpNoCase( component->GetValue() ) != 0 )
continue; continue;
const FOOTPRINT_INFO *module = m_FootprintsList->GetModuleInfo( equivItem.m_FootprintFPID ); const FOOTPRINT_INFO *fp = m_FootprintsList->GetFootprintInfo( equivItem.m_FootprintFPID );
bool equ_is_unique = true; bool equ_is_unique = true;
unsigned next = idx+1; unsigned next = idx+1;
int previous = idx-1; int previous = idx-1;
if( next < equiv_List.size() && if( next < equivList.size()
equivItem.m_ComponentValue == equiv_List[next].m_ComponentValue ) && equivItem.m_ComponentValue == equivList[next].m_ComponentValue )
{
equ_is_unique = false; equ_is_unique = false;
}
if( previous >= 0 && if( previous >= 0
equivItem.m_ComponentValue == equiv_List[previous].m_ComponentValue ) && equivItem.m_ComponentValue == equivList[previous].m_ComponentValue )
{
equ_is_unique = false; equ_is_unique = false;
}
// If the equivalence is unique, no ambiguity: use the association // If the equivalence is unique, no ambiguity: use the association
if( module && equ_is_unique ) if( fp && equ_is_unique )
{ {
AssociateFootprint( CVPCB_ASSOCIATION( kk, equivItem.m_FootprintFPID ), AssociateFootprint( CVPCB_ASSOCIATION( kk, equivItem.m_FootprintFPID ),
firstAssoc ); firstAssoc );
firstAssoc = false; firstAssoc = false;
found = true; found = true;
break; break;
@ -238,27 +242,25 @@ void CVPCB_MAINFRAME::AutomaticFootprintMatching()
// Store the first candidate found in list, when equivalence is not unique // Store the first candidate found in list, when equivalence is not unique
// We use it later. // We use it later.
if( module && fpid_candidate.IsEmpty() ) if( fp && fpid_candidate.IsEmpty() )
fpid_candidate = equivItem.m_FootprintFPID; fpid_candidate = equivItem.m_FootprintFPID;
// The equivalence is not unique: use the footprint filter to try to remove // The equivalence is not unique: use the footprint filter to try to remove
// ambiguity // ambiguity
// if the footprint filter does not remove ambiguity, we will use fpid_candidate // if the footprint filter does not remove ambiguity, we will use fpid_candidate
if( module ) if( fp )
{ {
size_t filtercount = component->GetFootprintFilters().GetCount(); size_t filtercount = component->GetFootprintFilters().GetCount();
found = ( 0 == filtercount ); // if no entries, do not filter found = ( 0 == filtercount ); // if no entries, do not filter
for( size_t jj = 0; jj < filtercount && !found; jj++ ) for( size_t jj = 0; jj < filtercount && !found; jj++ )
{ found = fp->GetFootprintName().Matches( component->GetFootprintFilters()[jj] );
found = module->GetFootprintName().Matches( component->GetFootprintFilters()[jj] );
}
} }
else else
{ {
msg.Printf( _( "Component %s: footprint %s not found in any of the project " msg.Printf( _( "Component %s: footprint %s not found in any of the project "
"footprint libraries." ), "footprint libraries." ),
component->GetReference(), equivItem.m_FootprintFPID ); component->GetReference(), equivItem.m_FootprintFPID );
if( ! error_msg.IsEmpty() ) if( ! error_msg.IsEmpty() )
error_msg << wxT("\n\n"); error_msg << wxT("\n\n");
@ -268,14 +270,17 @@ void CVPCB_MAINFRAME::AutomaticFootprintMatching()
if( found ) if( found )
{ {
AssociateFootprint( CVPCB_ASSOCIATION( kk, equivItem.m_FootprintFPID ), firstAssoc ); AssociateFootprint( CVPCB_ASSOCIATION( kk, equivItem.m_FootprintFPID ),
firstAssoc );
firstAssoc = false; firstAssoc = false;
break; break;
} }
} }
if( found ) if( found )
{
continue; continue;
}
else if( !fpid_candidate.IsEmpty() ) else if( !fpid_candidate.IsEmpty() )
{ {
AssociateFootprint( CVPCB_ASSOCIATION( kk, fpid_candidate ), firstAssoc ); AssociateFootprint( CVPCB_ASSOCIATION( kk, fpid_candidate ), firstAssoc );
@ -288,12 +293,10 @@ void CVPCB_MAINFRAME::AutomaticFootprintMatching()
{ {
// we do not need to analyze wildcards: single footprint do not // we do not need to analyze wildcards: single footprint do not
// contain them and if there are wildcards it just will not match any // contain them and if there are wildcards it just will not match any
const FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( component->GetFootprintFilters()[0] ); if( m_FootprintsList->GetFootprintInfo( component->GetFootprintFilters()[0] ) )
if( module )
{ {
AssociateFootprint( CVPCB_ASSOCIATION( kk, component->GetFootprintFilters()[0] ), AssociateFootprint( CVPCB_ASSOCIATION( kk, component->GetFootprintFilters()[0] ),
firstAssoc ); firstAssoc );
firstAssoc = false; firstAssoc = false;
} }
} }

View File

@ -280,25 +280,23 @@ void CVPCB_MAINFRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) ); mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) ); mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
#define filterActive( filter ) ( m_filteringOptions & filter )
auto compFilter = auto compFilter =
[this] ( const SELECTION& ) [this] ( const SELECTION& )
{ {
return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_FP_FILTERS; return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_FP_FILTERS;
}; };
auto libFilter = auto libFilter =
[this] ( const SELECTION& ) [this] ( const SELECTION& )
{ {
return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY; return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY;
}; };
auto pinFilter = auto pinFilter =
[this] ( const SELECTION& ) [this] ( const SELECTION& )
{ {
return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT; return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT;
}; };
mgr->SetConditions( CVPCB_ACTIONS::FilterFPbyFPFilters, CHECK( compFilter ) ); mgr->SetConditions( CVPCB_ACTIONS::FilterFPbyFPFilters, CHECK( compFilter ) );
mgr->SetConditions( CVPCB_ACTIONS::FilterFPbyLibrary, CHECK( libFilter ) ); mgr->SetConditions( CVPCB_ACTIONS::FilterFPbyLibrary, CHECK( libFilter ) );
@ -363,10 +361,10 @@ void CVPCB_MAINFRAME::setupEventHandlers()
// Just skip the resize events // Just skip the resize events
Bind( wxEVT_SIZE, Bind( wxEVT_SIZE,
[]( wxSizeEvent& aEvent ) []( wxSizeEvent& aEvent )
{ {
aEvent.Skip(); aEvent.Skip();
} ); } );
// Attach the events to the tool dispatcher // Attach the events to the tool dispatcher
Bind( wxEVT_TOOL, &TOOL_DISPATCHER::DispatchWxCommand, m_toolDispatcher ); Bind( wxEVT_TOOL, &TOOL_DISPATCHER::DispatchWxCommand, m_toolDispatcher );
@ -388,7 +386,10 @@ bool CVPCB_MAINFRAME::canCloseWindow( wxCloseEvent& aEvent )
if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified. " if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified. "
"Save changes?" ), "Save changes?" ),
[&]()->bool { return SaveFootprintAssociation( false ); } ) ) [&]() -> bool
{
return SaveFootprintAssociation( false );
} ) )
{ {
return false; return false;
} }
@ -400,7 +401,6 @@ bool CVPCB_MAINFRAME::canCloseWindow( wxCloseEvent& aEvent )
void CVPCB_MAINFRAME::doCloseWindow() void CVPCB_MAINFRAME::doCloseWindow()
{ {
// Close module display frame
if( GetFootprintViewerFrame() ) if( GetFootprintViewerFrame() )
GetFootprintViewerFrame()->Close( true ); GetFootprintViewerFrame()->Close( true );
@ -447,7 +447,7 @@ void CVPCB_MAINFRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{ {
EDA_BASE_FRAME::LoadSettings( aCfg ); EDA_BASE_FRAME::LoadSettings( aCfg );
auto cfg = static_cast<CVPCB_SETTINGS*>( aCfg ); CVPCB_SETTINGS* cfg = static_cast<CVPCB_SETTINGS*>( aCfg );
m_filteringOptions = cfg->m_FilterFootprint; m_filteringOptions = cfg->m_FilterFootprint;
} }
@ -457,7 +457,7 @@ void CVPCB_MAINFRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
{ {
EDA_BASE_FRAME::SaveSettings( aCfg ); EDA_BASE_FRAME::SaveSettings( aCfg );
auto cfg = static_cast<CVPCB_SETTINGS*>( aCfg ); CVPCB_SETTINGS* cfg = static_cast<CVPCB_SETTINGS*>( aCfg );
cfg->m_FilterFootprint = m_filteringOptions; cfg->m_FilterFootprint = m_filteringOptions;
cfg->m_LibrariesWidth = m_libListBox->GetSize().x; cfg->m_LibrariesWidth = m_libListBox->GetSize().x;
@ -496,6 +496,7 @@ void CVPCB_MAINFRAME::RedoAssociation()
// Iterate over the entries to undo // Iterate over the entries to undo
bool firstAssoc = true; bool firstAssoc = true;
for( const auto& assoc : curEntry ) for( const auto& assoc : curEntry )
{ {
AssociateFootprint( assoc, firstAssoc ); AssociateFootprint( assoc, firstAssoc );
@ -564,16 +565,19 @@ 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
m_redoList.clear(); m_redoList.clear();
} }
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() ) );
}
} }
@ -588,8 +592,7 @@ void CVPCB_MAINFRAME::refreshAfterComponentSearch( COMPONENT* component )
{ {
// Tell AuiMgr that objects are changed ! // Tell AuiMgr that objects are changed !
if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
// (could be not the case when starting CvPcb m_auimgr.Update(); // (could be not the case when starting CvPcb)
m_auimgr.Update();
if( component == NULL ) if( component == NULL )
{ {
@ -604,19 +607,19 @@ void CVPCB_MAINFRAME::refreshAfterComponentSearch( COMPONENT* component )
// selected footprint. // selected footprint.
if( FindFocus() == m_compListBox || FindFocus() == m_libListBox ) if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
{ {
wxString module = FROM_UTF8( component->GetFPID().Format().c_str() ); wxString footprintName = FROM_UTF8( component->GetFPID().Format().c_str() );
m_footprintListBox->SetSelection( m_footprintListBox->GetSelection(), false ); m_footprintListBox->SetSelection( m_footprintListBox->GetSelection(), false );
for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ ) for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
{ {
wxString footprintName; wxString candidateName;
wxString msg = m_footprintListBox->OnGetItemText( ii, 0 ); wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
msg.Trim( true ); msg.Trim( true );
msg.Trim( false ); msg.Trim( false );
footprintName = msg.AfterFirst( wxChar( ' ' ) ); candidateName = msg.AfterFirst( wxChar( ' ' ) );
if( module.Cmp( footprintName ) == 0 ) if( footprintName.Cmp( candidateName ) == 0 )
{ {
m_footprintListBox->SetSelection( ii, true ); m_footprintListBox->SetSelection( ii, true );
break; break;
@ -731,13 +734,13 @@ void CVPCB_MAINFRAME::DisplayStatus()
msg.Empty(); msg.Empty();
wxString footprintName = GetSelectedFootprint(); wxString footprintName = GetSelectedFootprint();
FOOTPRINT_INFO* module = m_FootprintsList->GetModuleInfo( footprintName ); FOOTPRINT_INFO* fp = m_FootprintsList->GetFootprintInfo( footprintName );
if( module ) // can be NULL if no netlist loaded if( fp ) // can be NULL if no netlist loaded
{ {
msg = wxString::Format( _( "Description: %s; Keywords: %s" ), msg = wxString::Format( _( "Description: %s; Keywords: %s" ),
module->GetDescription(), fp->GetDescription(),
module->GetKeywords() ); fp->GetKeywords() );
} }
SetStatusText( msg, 1 ); SetStatusText( msg, 1 );
@ -746,10 +749,10 @@ void CVPCB_MAINFRAME::DisplayStatus()
wxString lib; wxString lib;
// Choose the footprint to get the information on // Choose the footprint to get the information on
if( module ) if( fp )
{ {
// Use the footprint in the footprint viewer // Use the footprint in the footprint viewer
lib = module->GetLibNickname(); lib = fp->GetLibNickname();
} }
else if( GetFocusedControl() == CVPCB_MAINFRAME::CONTROL_COMPONENT ) else if( GetFocusedControl() == CVPCB_MAINFRAME::CONTROL_COMPONENT )
{ {
@ -882,8 +885,8 @@ void CVPCB_MAINFRAME::BuildFOOTPRINTS_LISTBOX()
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) ); wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
} }
m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL, m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL, wxEmptyString,
wxEmptyString, FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST ); FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST );
DisplayStatus(); DisplayStatus();
} }
@ -986,6 +989,7 @@ std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
CVPCB_MAINFRAME::CRITERIA aCriteria ) CVPCB_MAINFRAME::CRITERIA aCriteria )
{ {
std::vector<unsigned int> idx; std::vector<unsigned int> idx;
int lastIdx;
// Make sure a netlist has been loaded and the box has contents // Make sure a netlist has been loaded and the box has contents
if( m_netlist.IsEmpty() || m_compListBox->GetCount() == 0 ) if( m_netlist.IsEmpty() || m_compListBox->GetCount() == 0 )
@ -999,13 +1003,12 @@ std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
break; break;
case CVPCB_MAINFRAME::SEL_COMPONENTS: case CVPCB_MAINFRAME::SEL_COMPONENTS:
{
// Check to see if anything is selected // Check to see if anything is selected
if( m_compListBox->GetSelectedItemCount() < 1 ) if( m_compListBox->GetSelectedItemCount() < 1 )
break; break;
// Get the components // Get the components
int lastIdx = m_compListBox->GetFirstSelected(); lastIdx = m_compListBox->GetFirstSelected();
idx.emplace_back( lastIdx ); idx.emplace_back( lastIdx );
lastIdx = m_compListBox->GetNextSelected( lastIdx ); lastIdx = m_compListBox->GetNextSelected( lastIdx );
@ -1015,7 +1018,7 @@ std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
lastIdx = m_compListBox->GetNextSelected( lastIdx ); lastIdx = m_compListBox->GetNextSelected( lastIdx );
} }
break; break;
}
case CVPCB_MAINFRAME::NA_COMPONENTS: case CVPCB_MAINFRAME::NA_COMPONENTS:
for( unsigned int i = 0; i < m_netlist.GetCount(); i++ ) for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
{ {
@ -1043,8 +1046,8 @@ std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
DISPLAY_FOOTPRINTS_FRAME* CVPCB_MAINFRAME::GetFootprintViewerFrame() const DISPLAY_FOOTPRINTS_FRAME* CVPCB_MAINFRAME::GetFootprintViewerFrame() const
{ {
// returns the Footprint Viewer frame, if exists, or NULL // returns the Footprint Viewer frame, if exists, or NULL
return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*> wxWindow* window = wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME );
( wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME ) ); return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>( window );
} }

View File

@ -206,10 +206,10 @@ void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions()
auto autoZoomCond = auto autoZoomCond =
[this] ( const SELECTION& aSel ) [this] ( const SELECTION& aSel )
{ {
return GetAutoZoom(); return GetAutoZoom();
}; };
mgr->SetConditions( PCB_ACTIONS::zoomFootprintAutomatically, CHECK( autoZoomCond ) ); mgr->SetConditions( PCB_ACTIONS::zoomFootprintAutomatically, CHECK( autoZoomCond ) );
mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( cond.PadNumbersDisplay() ) ); mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( cond.PadNumbersDisplay() ) );
@ -241,7 +241,8 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar()
} }
else else
{ {
m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize, m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
m_optionsToolBar->SetAuiManager( &m_auimgr ); m_optionsToolBar->SetAuiManager( &m_auimgr );
} }
@ -301,8 +302,7 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar()
// Grid selection choice box. // Grid selection choice box.
if( !m_gridSelectBox ) if( !m_gridSelectBox )
m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT, m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT );
wxDefaultPosition, wxDefaultSize, 0, NULL );
UpdateGridSelectBox(); UpdateGridSelectBox();
m_mainToolBar->AddControl( m_gridSelectBox ); m_mainToolBar->AddControl( m_gridSelectBox );
@ -311,8 +311,7 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar()
// Zoom selection choice box. // Zoom selection choice box.
if( !m_zoomSelectBox ) if( !m_zoomSelectBox )
m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT, m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT );
wxDefaultPosition, wxDefaultSize, 0, NULL );
UpdateZoomSelectBox(); UpdateZoomSelectBox();
m_mainToolBar->AddControl( m_zoomSelectBox ); m_mainToolBar->AddControl( m_zoomSelectBox );
@ -339,7 +338,7 @@ void DISPLAY_FOOTPRINTS_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
{ {
auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg ); CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );
wxCHECK( cfg, /* void */ ); wxCHECK( cfg, /* void */ );
PCB_BASE_FRAME::SaveSettings( cfg ); PCB_BASE_FRAME::SaveSettings( cfg );
@ -352,7 +351,7 @@ void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
WINDOW_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg ) WINDOW_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
{ {
auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg ); CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );
wxCHECK( cfg, nullptr ); wxCHECK( cfg, nullptr );
return &cfg->m_FootprintViewer; return &cfg->m_FootprintViewer;
} }
@ -360,7 +359,7 @@ WINDOW_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetWindowSettings( APP_SETTINGS_BASE*
MAGNETIC_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetMagneticItemsSettings() MAGNETIC_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetMagneticItemsSettings()
{ {
auto cfg = dynamic_cast<CVPCB_SETTINGS*>( Kiface().KifaceSettings() ); CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( Kiface().KifaceSettings() );
wxCHECK( cfg, nullptr ); wxCHECK( cfg, nullptr );
return &cfg->m_FootprintViewerMagneticSettings; return &cfg->m_FootprintViewerMagneticSettings;
} }
@ -372,11 +371,11 @@ COLOR4D DISPLAY_FOOTPRINTS_FRAME::GetGridColor()
} }
MODULE* DISPLAY_FOOTPRINTS_FRAME::GetModule( const wxString& aFootprintName, REPORTER& aReporter ) MODULE* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintName,
REPORTER& aReporter )
{ {
MODULE* footprint = NULL; MODULE* footprint = NULL;
LIB_ID fpid;
LIB_ID fpid;
if( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) >= 0 ) if( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) >= 0 )
{ {
@ -435,8 +434,8 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::GetModule( const wxString& aFootprintName, REP
void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() void DISPLAY_FOOTPRINTS_FRAME::InitDisplay()
{ {
CVPCB_MAINFRAME* parentframe = (CVPCB_MAINFRAME *) GetParent(); CVPCB_MAINFRAME* parentframe = (CVPCB_MAINFRAME *) GetParent();
MODULE* module = nullptr; MODULE* footprint = nullptr;
const FOOTPRINT_INFO* module_info = nullptr; const FOOTPRINT_INFO* fpInfo = nullptr;
GetBoard()->DeleteAllModules(); GetBoard()->DeleteAllModules();
GetCanvas()->GetView()->Clear(); GetCanvas()->GetView()->Clear();
@ -458,16 +457,16 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay()
{ {
SetTitle( wxString::Format( _( "Footprint: %s" ), footprintName ) ); SetTitle( wxString::Format( _( "Footprint: %s" ), footprintName ) );
module = GetModule( footprintName, infoReporter ); footprint = GetFootprint( footprintName, infoReporter );
module_info = parentframe->m_FootprintsList->GetModuleInfo( footprintName ); fpInfo = parentframe->m_FootprintsList->GetFootprintInfo( footprintName );
} }
if( module ) if( footprint )
GetBoard()->Add( module ); GetBoard()->Add( footprint );
if( module_info ) if( fpInfo )
SetStatusText( wxString::Format( _( "Lib: %s" ), module_info->GetLibNickname() ), 0 ); SetStatusText( wxString::Format( _( "Lib: %s" ), fpInfo->GetLibNickname() ), 0 );
else else
SetStatusText( wxEmptyString, 0 ); SetStatusText( wxEmptyString, 0 );

View File

@ -87,7 +87,7 @@ public:
*/ */
COLOR4D GetGridColor() override; COLOR4D GetGridColor() override;
MODULE* GetModule( const wxString& CmpName, REPORTER& aReporter ); MODULE* GetFootprint( const wxString& aFootprintName, REPORTER& aReporter );
/* SaveCopyInUndoList() virtual /* SaveCopyInUndoList() virtual
* currently: do nothing in CvPcb. * currently: do nothing in CvPcb.

View File

@ -48,7 +48,7 @@ std::mutex DIALOG_CHOOSE_COMPONENT::g_Mutex;
DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle, DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle,
SYMBOL_TREE_MODEL_ADAPTER::PTR& aAdapter, wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
int aDeMorganConvert, bool aAllowFieldEdits, int aDeMorganConvert, bool aAllowFieldEdits,
bool aShowFootprints, bool aAllowBrowser ) bool aShowFootprints, bool aAllowBrowser )
: DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize, : DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,

View File

@ -104,8 +104,9 @@ public:
* @param aAllowBrowser show a Select with Browser button * @param aAllowBrowser show a Select with Browser button
*/ */
DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle, DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle,
SYMBOL_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert, wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
bool aAllowFieldEdits, bool aShowFootprints, bool aAllowBrowser ); int aDeMorganConvert, bool aAllowFieldEdits, bool aShowFootprints,
bool aAllowBrowser );
~DIALOG_CHOOSE_COMPONENT(); ~DIALOG_CHOOSE_COMPONENT();

View File

@ -669,8 +669,8 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow )
#if 0 #if 0
// Use dialog symbol selector to choose a symbol // Use dialog symbol selector to choose a symbol
SCH_BASE_FRAME::HISTORY_LIST dummy; SCH_BASE_FRAME::HISTORY_LIST dummy;
SCH_BASE_FRAME::COMPONENT_SELECTION sel = SCH_BASE_FRAME::PICKED_SYMBOL sel = m_frame->SelectComponentFromLibrary( NULL, dummy, true,
m_frame->SelectComponentFromLibrary( NULL, dummy, true, 0, 0, false ); 0, 0, false );
#else #else
// Use library viewer to choose a symbol // Use library viewer to choose a symbol
LIB_ID aPreselectedLibid; LIB_ID aPreselectedLibid;
@ -682,8 +682,8 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow )
if( !current.IsEmpty() ) if( !current.IsEmpty() )
aPreselectedLibid.Parse( current, LIB_ID::ID_SCH, true ); aPreselectedLibid.Parse( current, LIB_ID::ID_SCH, true );
COMPONENT_SELECTION sel = PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibBrowser( this, NULL, aPreselectedLibid,
GetParent()->SelectComponentFromLibBrowser( this, NULL, aPreselectedLibid, 0, 0 ); 0, 0 );
#endif #endif
if( sel.LibId.empty() ) // command aborted if( sel.LibId.empty() ) // command aborted

View File

@ -40,8 +40,10 @@
#include <dialog_choose_component.h> #include <dialog_choose_component.h>
#include <symbol_tree_model_adapter.h> #include <symbol_tree_model_adapter.h>
COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowser( wxTopLevelWindow* aParent, PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibBrowser( wxTopLevelWindow* aParent,
const SCHLIB_FILTER* aFilter, const LIB_ID& aPreselectedLibId, int aUnit, int aConvert ) const SCHLIB_FILTER* aFilter,
const LIB_ID& aPreselectedLibId,
int aUnit, int aConvert )
{ {
// Close any open non-modal Lib browser, and open a new one, in "modal" mode: // Close any open non-modal Lib browser, and open a new one, in "modal" mode:
LIB_VIEW_FRAME* viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false ); LIB_VIEW_FRAME* viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
@ -64,8 +66,8 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowser( wxTopLevelWin
viewlibFrame->Refresh(); viewlibFrame->Refresh();
COMPONENT_SELECTION sel; PICKED_SYMBOL sel;
wxString symbol; wxString symbol;
if( viewlibFrame->ShowModal( &symbol, aParent ) ) if( viewlibFrame->ShowModal( &symbol, aParent ) )
{ {
@ -84,9 +86,13 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowser( wxTopLevelWin
} }
COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( const SCHLIB_FILTER* aFilter, PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibTree( const SCHLIB_FILTER* aFilter,
std::vector<COMPONENT_SELECTION>& aHistoryList, bool aUseLibBrowser, int aUnit, std::vector<PICKED_SYMBOL>& aHistoryList,
int aConvert, bool aShowFootprints, const LIB_ID* aHighlight, bool aAllowFields ) bool aUseLibBrowser,
int aUnit, int aConvert,
bool aShowFootprints,
const LIB_ID* aHighlight,
bool aAllowFields )
{ {
std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock ); std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
wxString dialogTitle; wxString dialogTitle;
@ -94,10 +100,9 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( const SCHLIB_FILTER*
// One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway. // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway.
if( !dialogLock.try_lock() ) if( !dialogLock.try_lock() )
return COMPONENT_SELECTION(); return PICKED_SYMBOL();
auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs ) ); wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> adapter = SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs );
auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
bool loaded = false; bool loaded = false;
if( aFilter ) if( aFilter )
@ -109,7 +114,7 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( const SCHLIB_FILTER*
if( libs->HasLibrary( liblist[ii], true ) ) if( libs->HasLibrary( liblist[ii], true ) )
{ {
loaded = true; loaded = true;
adapter->AddLibrary( liblist[ii] ); static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapter.get() )->AddLibrary( liblist[ii] );
} }
} }
@ -121,7 +126,7 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( const SCHLIB_FILTER*
std::vector< LIB_TREE_ITEM* > history_list; std::vector< LIB_TREE_ITEM* > history_list;
for( auto const& i : aHistoryList ) for( const PICKED_SYMBOL& i : aHistoryList )
{ {
LIB_PART* symbol = GetLibPart( i.LibId ); LIB_PART* symbol = GetLibPart( i.LibId );
@ -130,8 +135,7 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( const SCHLIB_FILTER*
history_list.push_back( symbol ); history_list.push_back( symbol );
} }
adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, history_list, adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, history_list, true );
true );
if( !aHistoryList.empty() ) if( !aHistoryList.empty() )
adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit ); adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );
@ -139,7 +143,7 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( const SCHLIB_FILTER*
const std::vector< wxString > libNicknames = libs->GetLogicalLibs(); const std::vector< wxString > libNicknames = libs->GetLogicalLibs();
if( !loaded ) if( !loaded )
adapter->AddLibraries( libNicknames, this ); static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapter.get() )->AddLibraries( libNicknames, this );
if( aHighlight && aHighlight->IsValid() ) if( aHighlight && aHighlight->IsValid() )
adapter->SetPreselectNode( *aHighlight, /* aUnit */ 0 ); adapter->SetPreselectNode( *aHighlight, /* aUnit */ 0 );
@ -149,25 +153,25 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( const SCHLIB_FILTER*
else else
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() ); dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, aConvert, DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, aConvert, aAllowFields,
aAllowFields, aShowFootprints, aUseLibBrowser ); aShowFootprints, aUseLibBrowser );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return COMPONENT_SELECTION(); return PICKED_SYMBOL();
COMPONENT_SELECTION sel; PICKED_SYMBOL sel;
LIB_ID id = dlg.GetSelectedLibId( &sel.Unit ); LIB_ID id = dlg.GetSelectedLibId( &sel.Unit );
if( dlg.IsExternalBrowserSelected() ) // User requested component browser. if( dlg.IsExternalBrowserSelected() ) // User requested component browser.
{ {
sel = SelectComponentFromLibBrowser( this, aFilter, id, sel.Unit, sel.Convert ); sel = PickSymbolFromLibBrowser( this, aFilter, id, sel.Unit, sel.Convert );
id = sel.LibId; id = sel.LibId;
} }
if( !id.IsValid() ) // Dialog closed by OK button, if( !id.IsValid() ) // Dialog closed by OK button,
// or the selection by lib browser was requested, // or the selection by lib browser was requested,
// but no symbol selected // but no symbol selected
return COMPONENT_SELECTION(); return PICKED_SYMBOL();
if( sel.Unit == 0 ) if( sel.Unit == 0 )
sel.Unit = 1; sel.Unit = 1;
@ -178,7 +182,7 @@ COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( const SCHLIB_FILTER*
if( sel.LibId.IsValid() ) if( sel.LibId.IsValid() )
{ {
aHistoryList.erase( std::remove_if( aHistoryList.begin(), aHistoryList.end(), aHistoryList.erase( std::remove_if( aHistoryList.begin(), aHistoryList.end(),
[ &sel ]( COMPONENT_SELECTION const& i ) [ &sel ]( PICKED_SYMBOL const& i )
{ {
return i.LibId == sel.LibId; return i.LibId == sel.LibId;
} ), } ),

View File

@ -812,11 +812,10 @@ void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
// Container doing search-as-you-type. // Container doing search-as-you-type.
SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable(); SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs ) ); wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> adapter = SYMBOL_TREE_MODEL_ADAPTER::Create( this, libs );
auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() );
const auto libNicknames = libs->GetLogicalLibs(); const auto libNicknames = libs->GetLogicalLibs();
adapter->AddLibraries( libNicknames, this ); static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapter.get() )->AddLibraries( libNicknames, this );
LIB_PART* current = GetSelectedSymbol(); LIB_PART* current = GetSelectedSymbol();
LIB_ID id; LIB_ID id;
@ -831,7 +830,7 @@ void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
wxString dialogTitle; wxString dialogTitle;
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() ); dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, m_convert, false, false, false ); DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, m_convert, false, false, false );
if( dlg.ShowQuasiModal() == wxID_CANCEL ) if( dlg.ShowQuasiModal() == wxID_CANCEL )
return; return;

View File

@ -145,7 +145,7 @@ public:
void UpdateStatusBar() override; void UpdateStatusBar() override;
/** /**
* Function SelectComponentFromLib * Function PickSymbolFromLibTree
* Calls the library viewer to select component to import into schematic. * Calls the library viewer to select component to import into schematic.
* if the library viewer is currently running, it is closed and reopened * if the library viewer is currently running, it is closed and reopened
* in modal mode. * in modal mode.
@ -168,15 +168,14 @@ public:
* *
* @return the selected component * @return the selected component
*/ */
COMPONENT_SELECTION SelectCompFromLibTree( PICKED_SYMBOL PickSymbolFromLibTree( const SCHLIB_FILTER* aFilter,
const SCHLIB_FILTER* aFilter, std::vector<PICKED_SYMBOL>& aHistoryList,
std::vector<COMPONENT_SELECTION>& aHistoryList, bool aUseLibBrowser,
bool aUseLibBrowser, int aUnit,
int aUnit, int aConvert,
int aConvert, bool aShowFootprints,
bool aShowFootprints, const LIB_ID* aHighlight = nullptr,
const LIB_ID* aHighlight = nullptr, bool aAllowFields = true );
bool aAllowFields = true );
/** /**
* Load symbol from symbol library table. * Load symbol from symbol library table.
@ -193,7 +192,7 @@ public:
LIB_PART* GetFlattenedLibPart( const LIB_ID& aLibId, bool aShowErrorMsg = false ); LIB_PART* GetFlattenedLibPart( const LIB_ID& aLibId, bool aShowErrorMsg = false );
/** /**
* Function SelectComponentFromLibBrowser * Function PickSymbolFromLibBrowser
* Calls the library viewer to select component to import into schematic. * Calls the library viewer to select component to import into schematic.
* if the library viewer is currently running, it is closed and reopened * if the library viewer is currently running, it is closed and reopened
* in modal mode. * in modal mode.
@ -205,10 +204,10 @@ public:
* @param aConvert preselected deMorgan conversion * @param aConvert preselected deMorgan conversion
* @return the selected component * @return the selected component
*/ */
COMPONENT_SELECTION SelectComponentFromLibBrowser( wxTopLevelWindow* aParent, PICKED_SYMBOL PickSymbolFromLibBrowser( wxTopLevelWindow* aParent,
const SCHLIB_FILTER* aFilter, const SCHLIB_FILTER* aFilter,
const LIB_ID& aPreselectedLibid, const LIB_ID& aPreselectedLibId,
int aUnit, int aConvert ); int aUnit, int aConvert );
virtual void RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ); virtual void RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer );

View File

@ -129,7 +129,7 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* sh
} }
SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet, COMPONENT_SELECTION& aSel, SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet, PICKED_SYMBOL& aSel,
const wxPoint& pos ) : const wxPoint& pos ) :
SCH_COMPONENT( aPart, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, pos ) SCH_COMPONENT( aPart, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, pos )
{ {

View File

@ -51,7 +51,7 @@
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
#include <transform.h> #include <transform.h>
struct COMPONENT_SELECTION; struct PICKED_SYMBOL;
class SCH_SCREEN; class SCH_SCREEN;
class LIB_ITEM; class LIB_ITEM;
class LIB_PIN; class LIB_PIN;
@ -137,7 +137,7 @@ public:
int unit = 0, int convert = 0, int unit = 0, int convert = 0,
const wxPoint& pos = wxPoint( 0, 0 ) ); const wxPoint& pos = wxPoint( 0, 0 ) );
SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet, COMPONENT_SELECTION& aSel, SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet, PICKED_SYMBOL& aSel,
const wxPoint& pos = wxPoint( 0, 0 ) ); const wxPoint& pos = wxPoint( 0, 0 ) );
/** /**
* Clones \a aComponent into a new schematic symbol object. * Clones \a aComponent into a new schematic symbol object.

View File

@ -77,7 +77,7 @@ enum SCH_LINE_TEST_T
/// Max number of sheets in a hierarchy project /// Max number of sheets in a hierarchy project
#define NB_MAX_SHEET 500 #define NB_MAX_SHEET 500
struct COMPONENT_SELECTION struct PICKED_SYMBOL
{ {
LIB_ID LibId; LIB_ID LibId;
int Unit; int Unit;
@ -85,7 +85,7 @@ struct COMPONENT_SELECTION
std::vector<std::pair<int, wxString>> Fields; std::vector<std::pair<int, wxString>> Fields;
COMPONENT_SELECTION() : Unit( 1 ), Convert( 1 ) PICKED_SYMBOL() : Unit( 1 ), Convert( 1 )
{ {
} }
}; };

View File

@ -273,7 +273,7 @@ public:
/** /**
* Returns the adapter object that provides the stored data. * Returns the adapter object that provides the stored data.
*/ */
LIB_TREE_MODEL_ADAPTER::PTR& GetAdapter() { return m_adapter; } wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& GetAdapter() { return m_adapter; }
/** /**
* Returns the currently modified library name. * Returns the currently modified library name.
@ -315,6 +315,11 @@ private:
///> Returns the current Symbol Library Table ///> Returns the current Symbol Library Table
SYMBOL_LIB_TABLE* symTable() const; SYMBOL_LIB_TABLE* symTable() const;
SYMBOL_TREE_SYNCHRONIZING_ADAPTER* getAdapter()
{
return static_cast<SYMBOL_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
}
///> Class to store a working copy of a LIB_PART object and editor context. ///> Class to store a working copy of a LIB_PART object and editor context.
class PART_BUFFER class PART_BUFFER
{ {
@ -454,28 +459,29 @@ private:
int m_hash; int m_hash;
}; };
///> Returns a set of LIB_PART objects belonging to the original library /**
* Returns a set of LIB_PART objects belonging to the original library
*/
std::set<LIB_PART*> getOriginalParts( const wxString& aLibrary ); std::set<LIB_PART*> getOriginalParts( const wxString& aLibrary );
///> Returns an existing library buffer or creates one to using /**
///> Symbol Library Table to get the original data. * Returns an existing library buffer or creates one to using Symbol Library Table to get
* the original data.
*/
LIB_BUFFER& getLibraryBuffer( const wxString& aLibrary ); LIB_BUFFER& getLibraryBuffer( const wxString& aLibrary );
///> The library buffers ///> The library buffers
std::map<wxString, LIB_BUFFER> m_libs; std::map<wxString, LIB_BUFFER> m_libs;
SYMBOL_EDIT_FRAME& m_frame; // Parent frame SYMBOL_EDIT_FRAME& m_frame; ///< Parent frame
LIB_LOGGER m_logger; LIB_LOGGER m_logger;
int m_syncHash; // Symbol Lib Table hash value from the last synchronization int m_syncHash; ///< Symbol lib table hash value from last synchronization
wxString m_currentLib; // Currently modified part wxString m_currentLib; ///< Currently modified part
wxString m_currentPart; // Currently modified library wxString m_currentPart; ///< Currently modified library
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter;
SYMBOL_TREE_SYNCHRONIZING_ADAPTER* getAdapter()
{
return static_cast<SYMBOL_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
}
}; };
#endif /* SYMBOL_LIBRARY_MANAGER_H */ #endif /* SYMBOL_LIBRARY_MANAGER_H */

View File

@ -36,10 +36,11 @@ bool SYMBOL_TREE_MODEL_ADAPTER::m_show_progress = true;
#define PROGRESS_INTERVAL_MILLIS 66 #define PROGRESS_INTERVAL_MILLIS 66
SYMBOL_TREE_MODEL_ADAPTER::PTR SYMBOL_TREE_MODEL_ADAPTER::Create( EDA_BASE_FRAME* aParent, wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
LIB_TABLE* aLibs ) SYMBOL_TREE_MODEL_ADAPTER::Create( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs )
{ {
return PTR( new SYMBOL_TREE_MODEL_ADAPTER( aParent, aLibs ) ); auto* adapter = new SYMBOL_TREE_MODEL_ADAPTER( aParent, aLibs );
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
} }

View File

@ -40,7 +40,8 @@ public:
* *
* @param aLibs library set from which parts will be loaded * @param aLibs library set from which parts will be loaded
*/ */
static PTR Create( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs ); static wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> Create( EDA_BASE_FRAME* aParent,
LIB_TABLE* aLibs );
/** /**
* Add all the libraries in a SYMBOL_LIB_TABLE to the model. * Add all the libraries in a SYMBOL_LIB_TABLE to the model.

View File

@ -30,10 +30,12 @@
#include <tools/lib_control.h> #include <tools/lib_control.h>
LIB_TREE_MODEL_ADAPTER::PTR SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create( SYMBOL_EDIT_FRAME* aParent, wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
SYMBOL_LIBRARY_MANAGER* aLibMgr ) SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create( SYMBOL_EDIT_FRAME* aParent,
SYMBOL_LIBRARY_MANAGER* aLibMgr )
{ {
return PTR( new SYMBOL_TREE_SYNCHRONIZING_ADAPTER( aParent, aLibMgr ) ); auto* adapter = new SYMBOL_TREE_SYNCHRONIZING_ADAPTER( aParent, aLibMgr );
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
} }

View File

@ -34,7 +34,8 @@ class SYMBOL_LIBRARY_MANAGER;
class SYMBOL_TREE_SYNCHRONIZING_ADAPTER : public LIB_TREE_MODEL_ADAPTER class SYMBOL_TREE_SYNCHRONIZING_ADAPTER : public LIB_TREE_MODEL_ADAPTER
{ {
public: public:
static PTR Create( SYMBOL_EDIT_FRAME* aParent, SYMBOL_LIBRARY_MANAGER* aLibs ); static wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> Create( SYMBOL_EDIT_FRAME* aParent,
SYMBOL_LIBRARY_MANAGER* aLibs );
bool IsContainer( const wxDataViewItem& aItem ) const override; bool IsContainer( const wxDataViewItem& aItem ) const override;

View File

@ -79,9 +79,9 @@ bool SCH_DRAWING_TOOLS::Init()
int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent ) int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
{ {
SCH_COMPONENT* component = aEvent.Parameter<SCH_COMPONENT*>(); SCH_COMPONENT* component = aEvent.Parameter<SCH_COMPONENT*>();
SCHLIB_FILTER filter; SCHLIB_FILTER filter;
std::vector<COMPONENT_SELECTION>* historyList = nullptr; std::vector<PICKED_SYMBOL>* historyList = nullptr;
if( aEvent.IsAction( &EE_ACTIONS::placeSymbol ) ) if( aEvent.IsAction( &EE_ACTIONS::placeSymbol ) )
historyList = &m_symbolHistoryList; historyList = &m_symbolHistoryList;
@ -173,9 +173,8 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
// Pick the module to be placed // Pick the module to be placed
bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview; bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview;
COMPONENT_SELECTION sel = m_frame->SelectCompFromLibTree( &filter, *historyList, PICKED_SYMBOL sel = m_frame->PickSymbolFromLibTree( &filter, *historyList, true,
true, 1, 1, 1, 1, footprintPreviews );
footprintPreviews );
// Restore cursor after dialog // Restore cursor after dialog
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true ); getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );

View File

@ -76,14 +76,14 @@ private:
private: private:
// History lists for PlaceComponent() // History lists for PlaceComponent()
std::vector<COMPONENT_SELECTION> m_symbolHistoryList; std::vector<PICKED_SYMBOL> m_symbolHistoryList;
std::vector<COMPONENT_SELECTION> m_powerHistoryList; std::vector<PICKED_SYMBOL> m_powerHistoryList;
PINSHEETLABEL_SHAPE m_lastSheetPinType; PINSHEETLABEL_SHAPE m_lastSheetPinType;
PINSHEETLABEL_SHAPE m_lastGlobalLabelShape; PINSHEETLABEL_SHAPE m_lastGlobalLabelShape;
LABEL_SPIN_STYLE m_lastTextOrientation; LABEL_SPIN_STYLE m_lastTextOrientation;
bool m_lastTextBold; bool m_lastTextBold;
bool m_lastTextItalic; bool m_lastTextItalic;
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup; std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
}; };

View File

@ -155,15 +155,15 @@ protected:
FOOTPRINT_LIST* m_owner; ///< provides access to FP_LIB_TABLE FOOTPRINT_LIST* m_owner; ///< provides access to FP_LIB_TABLE
bool m_loaded; bool m_loaded;
wxString m_nickname; ///< library as known in FP_LIB_TABLE wxString m_nickname; ///< library as known in FP_LIB_TABLE
wxString m_fpname; ///< Module name. wxString m_fpname; ///< Module name.
int m_num; ///< Order number in the display list. int m_num; ///< Order number in the display list.
unsigned m_pad_count; ///< Number of pads unsigned m_pad_count; ///< Number of pads
unsigned m_unique_pad_count; ///< Number of unique pads unsigned m_unique_pad_count; ///< Number of unique pads
wxString m_doc; ///< Footprint description. wxString m_doc; ///< Footprint description.
wxString m_keywords; ///< Footprint keywords. wxString m_keywords; ///< Footprint keywords.
}; };
@ -216,12 +216,13 @@ public:
/** /**
* Get info for a module by id. * Get info for a module by id.
*/ */
FOOTPRINT_INFO* GetModuleInfo( const wxString& aFootprintId ); FOOTPRINT_INFO* GetFootprintInfo( const wxString& aFootprintName );
/** /**
* Get info for a module by libNickname/footprintName * Get info for a module by libNickname/footprintName
*/ */
FOOTPRINT_INFO* GetModuleInfo( const wxString& aLibNickname, const wxString& aFootprintName ); FOOTPRINT_INFO* GetFootprintInfo( const wxString& aLibNickname,
const wxString& aFootprintName );
/** /**
* Get info for a module by index. * Get info for a module by index.
@ -333,7 +334,7 @@ public:
* @param aNThreads is the number of worker threads. * @param aNThreads is the number of worker threads.
*/ */
void Start( FP_LIB_TABLE* aTable, wxString const* aNickname = nullptr, void Start( FP_LIB_TABLE* aTable, wxString const* aNickname = nullptr,
unsigned aNThreads = DEFAULT_THREADS ); unsigned aNThreads = DEFAULT_THREADS );
/** /**
* Wait until the worker threads are finished, and then perform any required * Wait until the worker threads are finished, and then perform any required

View File

@ -43,7 +43,7 @@
DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent, DIALOG_CHOOSE_FOOTPRINT::DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent,
const wxString& aTitle, const wxString& aTitle,
FP_TREE_MODEL_ADAPTER::PTR& aAdapter ) wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter )
: DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize, : DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
m_browser_button( nullptr ), m_browser_button( nullptr ),

View File

@ -94,7 +94,7 @@ public:
* for documentation. * for documentation.
*/ */
DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent, const wxString& aTitle, DIALOG_CHOOSE_FOOTPRINT( PCB_BASE_FRAME* aParent, const wxString& aTitle,
FP_TREE_MODEL_ADAPTER::PTR& aAdapter ); wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter );
~DIALOG_CHOOSE_FOOTPRINT(); ~DIALOG_CHOOSE_FOOTPRINT();

View File

@ -41,7 +41,8 @@ class FOOTPRINT_EDIT_FRAME : public PCB_BASE_EDIT_FRAME
friend struct PCB::IFACE; friend struct PCB::IFACE;
FOOTPRINT_TREE_PANE* m_treePane; FOOTPRINT_TREE_PANE* m_treePane;
LIB_TREE_MODEL_ADAPTER::PTR m_adapter;
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
std::unique_ptr<MODULE> m_revertModule; std::unique_ptr<MODULE> m_revertModule;
wxString m_footprintNameWhenLoaded; wxString m_footprintNameWhenLoaded;
@ -169,7 +170,7 @@ public:
/** /**
* Returns the adapter object that provides the stored data. * Returns the adapter object that provides the stored data.
*/ */
LIB_TREE_MODEL_ADAPTER::PTR& GetLibTreeAdapter() { return m_adapter; } wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& GetLibTreeAdapter() { return m_adapter; }
/** /**
* Save in an existing library a given footprint. * Save in an existing library a given footprint.
@ -239,10 +240,10 @@ public:
/** /**
* Load in Modedit a footprint from the main board. * Load in Modedit a footprint from the main board.
* *
* @param Module = the module to load. If NULL, a module reference will we asked to user * @param aFootprint = the module to load. If NULL, a module reference will we asked to user
* @return true if a module isloaded, false otherwise. * @return true if a module isloaded, false otherwise.
*/ */
bool Load_Module_From_BOARD( MODULE* Module ); bool LoadFootprintFromBoard( MODULE* aFootprint );
/** /**
* Display the list of footprints currently existing on the BOARD. * Display the list of footprints currently existing on the BOARD.

View File

@ -54,7 +54,7 @@ using namespace std::placeholders;
void FOOTPRINT_EDIT_FRAME::LoadModuleFromBoard( wxCommandEvent& event ) void FOOTPRINT_EDIT_FRAME::LoadModuleFromBoard( wxCommandEvent& event )
{ {
Load_Module_From_BOARD( NULL ); LoadFootprintFromBoard( NULL );
} }

View File

@ -27,10 +27,11 @@
#include "fp_tree_model_adapter.h" #include "fp_tree_model_adapter.h"
FP_TREE_MODEL_ADAPTER::PTR FP_TREE_MODEL_ADAPTER::Create( EDA_BASE_FRAME* aParent, wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
LIB_TABLE* aLibs ) FP_TREE_MODEL_ADAPTER::Create( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs )
{ {
return PTR( new FP_TREE_MODEL_ADAPTER( aParent, aLibs ) ); auto* adapter = new FP_TREE_MODEL_ADAPTER( aParent, aLibs );
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
} }
@ -42,7 +43,7 @@ FP_TREE_MODEL_ADAPTER::FP_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent, LIB_TABLE
void FP_TREE_MODEL_ADAPTER::AddLibraries() void FP_TREE_MODEL_ADAPTER::AddLibraries()
{ {
for( const auto& libName : m_libs->GetLogicalLibs() ) for( const wxString& libName : m_libs->GetLogicalLibs() )
{ {
const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName ); const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName );
@ -63,10 +64,11 @@ std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString
// List is sorted, so use a binary search to find the range of footnotes for our library // List is sorted, so use a binary search to find the range of footnotes for our library
auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy, auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
[]( const std::unique_ptr<FOOTPRINT_INFO>& a, const std::unique_ptr<FOOTPRINT_INFO>& b ) []( const std::unique_ptr<FOOTPRINT_INFO>& a,
{ const std::unique_ptr<FOOTPRINT_INFO>& b )
return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0; {
} ); return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
} );
for( auto i = libBounds.first; i != libBounds.second; ++i ) for( auto i = libBounds.first; i != libBounds.second; ++i )
libList.push_back( i->get() ); libList.push_back( i->get() );

View File

@ -36,7 +36,8 @@ public:
* *
* @param aLibs library set from which parts will be loaded * @param aLibs library set from which parts will be loaded
*/ */
static PTR Create( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs ); static wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> Create( EDA_BASE_FRAME* aParent,
LIB_TABLE* aLibs );
void AddLibraries(); void AddLibraries();

View File

@ -34,10 +34,11 @@
#include <tools/footprint_editor_tools.h> #include <tools/footprint_editor_tools.h>
LIB_TREE_MODEL_ADAPTER::PTR FP_TREE_SYNCHRONIZING_ADAPTER::Create( FOOTPRINT_EDIT_FRAME* aFrame, wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
FP_LIB_TABLE* aLibs ) FP_TREE_SYNCHRONIZING_ADAPTER::Create( FOOTPRINT_EDIT_FRAME* aFrame, FP_LIB_TABLE* aLibs )
{ {
return PTR( new FP_TREE_SYNCHRONIZING_ADAPTER( aFrame, aLibs ) ); auto* adapter = new FP_TREE_SYNCHRONIZING_ADAPTER( aFrame, aLibs );
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
} }

View File

@ -33,7 +33,8 @@ class FOOTPRINT_EDIT_FRAME;
class FP_TREE_SYNCHRONIZING_ADAPTER : public FP_TREE_MODEL_ADAPTER class FP_TREE_SYNCHRONIZING_ADAPTER : public FP_TREE_MODEL_ADAPTER
{ {
public: public:
static PTR Create( FOOTPRINT_EDIT_FRAME* aFrame, FP_LIB_TABLE* aLibs ); static wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> Create( FOOTPRINT_EDIT_FRAME* aFrame,
FP_LIB_TABLE* aLibs );
bool IsContainer( const wxDataViewItem& aItem ) const override; bool IsContainer( const wxDataViewItem& aItem ) const override;

View File

@ -55,89 +55,87 @@ using namespace std::placeholders;
#include "fp_tree_model_adapter.h" #include "fp_tree_model_adapter.h"
static wxArrayString s_ModuleHistoryList; static wxArrayString s_FootprintHistoryList;
static unsigned s_ModuleHistoryMaxCount = 8; static unsigned s_FootprintHistoryMaxCount = 8;
static void AddModuleToHistory( const wxString& aName ) static void AddFootprintToHistory( const wxString& aName )
{ {
// Remove duplicates // Remove duplicates
for( int ii = s_ModuleHistoryList.GetCount() - 1; ii >= 0; --ii ) for( int ii = s_FootprintHistoryList.GetCount() - 1; ii >= 0; --ii )
{ {
if( s_ModuleHistoryList[ ii ] == aName ) if( s_FootprintHistoryList[ ii ] == aName )
s_ModuleHistoryList.RemoveAt( (size_t) ii ); s_FootprintHistoryList.RemoveAt((size_t) ii );
} }
// Add the new name at the beginning of the history list // Add the new name at the beginning of the history list
s_ModuleHistoryList.Insert( aName, 0 ); s_FootprintHistoryList.Insert( aName, 0 );
// Remove extra names // Remove extra names
while( s_ModuleHistoryList.GetCount() >= s_ModuleHistoryMaxCount ) while( s_FootprintHistoryList.GetCount() >= s_FootprintHistoryMaxCount )
s_ModuleHistoryList.RemoveAt( s_ModuleHistoryList.GetCount() - 1 ); s_FootprintHistoryList.RemoveAt( s_FootprintHistoryList.GetCount() - 1 );
} }
static void clearModuleItemFlags( BOARD_ITEM* aItem )
{
aItem->ClearFlags();
}
#include <bitmaps.h> #include <bitmaps.h>
bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule ) bool FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( MODULE* aFootprint )
{ {
bool is_last_fp_from_brd = IsCurrentFPFromBoard(); bool is_last_fp_from_brd = IsCurrentFPFromBoard();
MODULE* newModule; MODULE* newFootprint = nullptr;
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false ); PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
if( frame == NULL ) // happens if no board editor opened if( frame == NULL ) // happens if no board editor opened
return false; return false;
if( aModule == NULL ) if( aFootprint == NULL )
{ {
if( !frame->GetBoard() || !frame->GetBoard()->GetFirstModule() ) if( !frame->GetBoard() || !frame->GetBoard()->GetFirstModule() )
return false; return false;
aModule = SelectFootprintFromBoard( frame->GetBoard() ); aFootprint = SelectFootprintFromBoard( frame->GetBoard() );
} }
if( aModule == NULL ) if( aFootprint == NULL )
return false; return false;
if( !Clear_Pcb( true ) ) if( !Clear_Pcb( true ) )
return false; return false;
newModule = (MODULE*) aModule->Duplicate(); newFootprint = (MODULE*) aFootprint->Duplicate();
newModule->SetParent( GetBoard() ); newFootprint->SetParent( GetBoard() );
newModule->SetLink( aModule->m_Uuid ); newFootprint->SetLink( aFootprint->m_Uuid );
newModule->ClearFlags(); newFootprint->ClearFlags();
newModule->RunOnChildren( std::bind( &clearModuleItemFlags, _1 ) ); newFootprint->RunOnChildren( []( BOARD_ITEM* aItem )
{
aItem->ClearFlags();
} );
AddModuleToBoard( newModule ); AddModuleToBoard( newFootprint );
// Clear references to any net info, because the footprint editor // Clear references to any net info, because the footprint editor
// does know any thing about nets handled by the current edited board. // does know any thing about nets handled by the current edited board.
// Morever we do not want to save any reference to an unknown net when // Morever we do not want to save any reference to an unknown net when
// saving the footprint in lib cache // saving the footprint in lib cache
// so we force the ORPHANED dummy net info for all pads // so we force the ORPHANED dummy net info for all pads
newModule->ClearAllNets(); newFootprint->ClearAllNets();
GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false ); GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
PlaceModule( newModule ); PlaceModule( newFootprint );
newModule->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized at the moment newFootprint->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized at the moment
// Put it on FRONT layer, // Put it on FRONT layer,
// because this is the default in ModEdit, and in libs // because this is the default in ModEdit, and in libs
if( newModule->GetLayer() != F_Cu ) if( newFootprint->GetLayer() != F_Cu )
newModule->Flip( newModule->GetPosition(), frame->Settings().m_FlipLeftRight ); newFootprint->Flip( newFootprint->GetPosition(), frame->Settings().m_FlipLeftRight );
// Put it in orientation 0, // Put it in orientation 0,
// because this is the default orientation in ModEdit, and in libs // because this is the default orientation in ModEdit, and in libs
newModule->SetOrientation( 0 ); newFootprint->SetOrientation( 0 );
Zoom_Automatique( false ); Zoom_Automatique( false );
m_adapter->SetPreselectNode( newModule->GetFPID(), 0 ); m_adapter->SetPreselectNode( newFootprint->GetFPID(), 0 );
ClearUndoRedoList(); ClearUndoRedoList();
GetScreen()->ClrModify(); GetScreen()->ClrModify();
@ -196,9 +194,9 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser()
MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect ) MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect )
{ {
FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs(); FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
wxString moduleName; wxString footprintName;
LIB_ID fpid; LIB_ID fpid;
MODULE* module = NULL; MODULE* footprint = nullptr;
static wxString lastComponentName; static wxString lastComponentName;
@ -215,14 +213,14 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect )
if( GFootprintList.GetErrorCount() ) if( GFootprintList.GetErrorCount() )
GFootprintList.DisplayErrors( this ); GFootprintList.DisplayErrors( this );
auto adapterPtr( FP_TREE_MODEL_ADAPTER::Create( this, fpTable ) ); wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> ptr = FP_TREE_MODEL_ADAPTER::Create( this, fpTable );
auto adapter = static_cast<FP_TREE_MODEL_ADAPTER*>( adapterPtr.get() ); FP_TREE_MODEL_ADAPTER* adapter = static_cast<FP_TREE_MODEL_ADAPTER*>( ptr.get() );
std::vector<LIB_TREE_ITEM*> historyInfos; std::vector<LIB_TREE_ITEM*> historyInfos;
for( auto const& item : s_ModuleHistoryList ) for( const wxString& item : s_FootprintHistoryList )
{ {
LIB_TREE_ITEM* fp_info = GFootprintList.GetModuleInfo( item ); LIB_TREE_ITEM* fp_info = GFootprintList.GetFootprintInfo( item );
// this can be null, for example, if the footprint has been deleted from a library. // this can be null, for example, if the footprint has been deleted from a library.
if( fp_info != nullptr ) if( fp_info != nullptr )
@ -241,7 +239,7 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect )
wxString title; wxString title;
title.Printf( _( "Choose Footprint (%d items loaded)" ), adapter->GetItemCount() ); title.Printf( _( "Choose Footprint (%d items loaded)" ), adapter->GetItemCount() );
DIALOG_CHOOSE_FOOTPRINT dialog( this, title, adapterPtr ); DIALOG_CHOOSE_FOOTPRINT dialog( this, title, ptr );
if( dialog.ShowQuasiModal() == wxID_CANCEL ) if( dialog.ShowQuasiModal() == wxID_CANCEL )
return NULL; return NULL;
@ -250,12 +248,12 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect )
{ {
// SelectFootprintFromLibBrowser() returns the "full" footprint name, i.e. // SelectFootprintFromLibBrowser() returns the "full" footprint name, i.e.
// <lib_name>/<footprint name> or LIB_ID format "lib_name:fp_name:rev#" // <lib_name>/<footprint name> or LIB_ID format "lib_name:fp_name:rev#"
moduleName = SelectFootprintFromLibBrowser(); footprintName = SelectFootprintFromLibBrowser();
if( moduleName.IsEmpty() ) // Cancel command if( footprintName.IsEmpty() ) // Cancel command
return NULL; return NULL;
else else
fpid.Parse( moduleName, LIB_ID::ID_PCB ); fpid.Parse( footprintName, LIB_ID::ID_PCB );
} }
else else
{ {
@ -264,24 +262,24 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect )
if( !fpid.IsValid() ) if( !fpid.IsValid() )
return NULL; return NULL;
else else
moduleName = fpid.Format(); footprintName = fpid.Format();
} }
try try
{ {
module = loadFootprint( fpid ); footprint = loadFootprint( fpid );
} }
catch( const IO_ERROR& ) catch( const IO_ERROR& )
{ {
} }
if( module ) if( footprint )
{ {
lastComponentName = moduleName; lastComponentName = footprintName;
AddModuleToHistory( moduleName ); AddFootprintToHistory( footprintName );
} }
return module; return footprint;
} }

View File

@ -1532,7 +1532,7 @@ void PCB_EDIT_FRAME::ShowFootprintPropertiesDialog( MODULE* aFootprint )
{ {
auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ); auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
editor->Load_Module_From_BOARD( aFootprint ); editor->LoadFootprintFromBoard( aFootprint );
editor->Show( true ); editor->Show( true );
editor->Raise(); // Iconize( false ); editor->Raise(); // Iconize( false );

View File

@ -1264,7 +1264,7 @@ int PCB_EDITOR_CONTROL::EditFpInFpEditor( const TOOL_EVENT& aEvent )
auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ); auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
editor->Load_Module_From_BOARD( fp ); editor->LoadFootprintFromBoard( fp );
editor->Show( true ); editor->Show( true );
editor->Raise(); // Iconize( false ); editor->Raise(); // Iconize( false );