diff --git a/common/dialogs/panel_design_block_lib_table.cpp b/common/dialogs/panel_design_block_lib_table.cpp index 0b6fb7b717..f20e775c29 100644 --- a/common/dialogs/panel_design_block_lib_table.cpp +++ b/common/dialogs/panel_design_block_lib_table.cpp @@ -245,10 +245,10 @@ protected: void openTable( const LIBRARY_TABLE_ROW& aRow ) override { - wxString uri = LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ); - auto nestedTable = std::make_unique( uri, LIBRARY_TABLE_SCOPE::GLOBAL ); + wxFileName fn( LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ) ); + std::shared_ptr child = std::make_shared( fn, LIBRARY_TABLE_SCOPE::GLOBAL ); - m_panel->AddTable( nestedTable.get(), aRow.Nickname(), true ); + m_panel->OpenTable( child, aRow.Nickname() ); } wxString getTablePreamble() override @@ -261,7 +261,7 @@ protected: }; -void PANEL_DESIGN_BLOCK_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTitle ) +void PANEL_DESIGN_BLOCK_LIB_TABLE::OpenTable( const std::shared_ptr& aTable, const wxString& aTitle ) { for( int ii = 2; ii < (int) m_notebook->GetPageCount(); ++ii ) { @@ -276,7 +276,8 @@ void PANEL_DESIGN_BLOCK_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxStr } } - AddTable( aTable, aTitle, true ); + m_nestedTables.push_back( aTable ); + AddTable( aTable.get(), aTitle, true ); // Something is pretty fishy with wxAuiNotebook::ChangeSelection(); on Mac at least it // results in a re-entrant call where the second call is one page behind. diff --git a/common/dialogs/panel_design_block_lib_table.h b/common/dialogs/panel_design_block_lib_table.h index 36ff2054eb..e151c3e48e 100644 --- a/common/dialogs/panel_design_block_lib_table.h +++ b/common/dialogs/panel_design_block_lib_table.h @@ -43,7 +43,7 @@ public: bool TransferDataFromWindow() override; void AddTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aClosable ); - void OpenTable( LIBRARY_TABLE* table, const wxString& aTitle ); + void OpenTable( const std::shared_ptr& table, const wxString& aTitle ); private: /** @@ -84,6 +84,8 @@ private: wxString m_lastProjectLibDir; //< Transient (unsaved) last browsed folder when adding a // project level library. + std::vector> m_nestedTables; + std::map m_supportedDesignBlockFiles; }; diff --git a/common/lib_table_grid_tricks.cpp b/common/lib_table_grid_tricks.cpp index 3078334d57..04026fb2bc 100644 --- a/common/lib_table_grid_tricks.cpp +++ b/common/lib_table_grid_tricks.cpp @@ -284,7 +284,7 @@ void LIB_TABLE_GRID_TRICKS::paste_text( const wxString& cb_text ) { // paste the LIB_TABLE_ROWs of s-expr, starting at column 0 regardless of current cursor column. - if( LIBRARY_TABLE tempTable( cb_text, tbl->Table().Scope() ); tempTable.IsOk() ) + if( LIBRARY_TABLE tempTable( true, cb_text, tbl->Table().Scope() ); tempTable.IsOk() ) { std::ranges::copy( tempTable.Rows(), std::inserter( tbl->Table().Rows(), tbl->Table().Rows().begin() ) ); diff --git a/common/lib_table_notebook_panel.cpp b/common/lib_table_notebook_panel.cpp index 256acf723f..0eda185647 100644 --- a/common/lib_table_notebook_panel.cpp +++ b/common/lib_table_notebook_panel.cpp @@ -83,8 +83,8 @@ void LIB_TABLE_NOTEBOOK_PANEL::AddTable( wxAuiNotebook* aNotebook, const wxStrin bool LIB_TABLE_NOTEBOOK_PANEL::TableModified() { - wxFileName uri = GetModel()->Table().Path(); - std::unique_ptr sourceTable = std::make_unique( uri, LIBRARY_TABLE_SCOPE::GLOBAL ); + wxFileName file( GetModel()->Table().Path() ); + std::unique_ptr sourceTable = std::make_unique( file, LIBRARY_TABLE_SCOPE::GLOBAL ); return GetModel()->Table() != *sourceTable; } diff --git a/common/libraries/library_manager.cpp b/common/libraries/library_manager.cpp index 5a00763a38..b918a9b209 100644 --- a/common/libraries/library_manager.cpp +++ b/common/libraries/library_manager.cpp @@ -82,7 +82,7 @@ void LIBRARY_MANAGER::loadTables( const wxString& aTablePath, LIBRARY_TABLE_SCOP if( fn.IsFileReadable() ) { - auto table = std::make_unique( fn, aScope ); + std::unique_ptr table = std::make_unique( fn, aScope ); wxCHECK2( table->Type() == type, continue ); aTarget[type] = std::move( table ); loadNestedTables( *aTarget[type] ); @@ -99,7 +99,7 @@ void LIBRARY_MANAGER::loadNestedTables( LIBRARY_TABLE& aRootTable ) { std::unordered_set seenTables; - std::function processOneTable = + std::function processOneTable = [&]( LIBRARY_TABLE& aTable ) { seenTables.insert( aTable.Path() ); diff --git a/common/libraries/library_table.cpp b/common/libraries/library_table.cpp index b7387f6a8f..34b4cdd3cd 100644 --- a/common/libraries/library_table.cpp +++ b/common/libraries/library_table.cpp @@ -57,15 +57,15 @@ LIBRARY_TABLE::LIBRARY_TABLE( const wxFileName &aPath, LIBRARY_TABLE_SCOPE aScop { LIBRARY_TABLE_PARSER parser; - wxFileName file( aPath ); - WX_FILENAME::ResolvePossibleSymlinks( file ); - m_path = file.GetAbsolutePath(); + wxFileName fn( aPath ); + WX_FILENAME::ResolvePossibleSymlinks( fn ); + m_path = fn.GetAbsolutePath(); - if( !file.FileExists() ) + if( !fn.FileExists() ) { m_ok = false; m_errorDescription = wxString::Format( _( "The library table path '%s' does not exist" ), - file.GetFullPath() ); + fn.GetFullPath() ); return; } @@ -83,14 +83,17 @@ LIBRARY_TABLE::LIBRARY_TABLE( const wxFileName &aPath, LIBRARY_TABLE_SCOPE aScop } -LIBRARY_TABLE::LIBRARY_TABLE( const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope ) : +/** + * Note: @param aFromClipboard isn't actually used, but might keep people from calling this with a string + * filepath, which isn't going to do what they expected. + */ +LIBRARY_TABLE::LIBRARY_TABLE( bool aFromClipboard, const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope ) : m_path( wxEmptyString ), m_scope( aScope ) { LIBRARY_TABLE_PARSER parser; - tl::expected ir = - parser.ParseBuffer( aBuffer.ToStdString() ); + tl::expected ir = parser.ParseBuffer( aBuffer.ToStdString() ); if( ir.has_value() ) { diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index 36bcc63b6a..58faa27fbe 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -189,10 +189,10 @@ protected: void openTable( const LIBRARY_TABLE_ROW& aRow ) override { - wxFileName file( LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ) ); - auto nestedTable = std::make_unique( file, LIBRARY_TABLE_SCOPE::GLOBAL ); + wxFileName fn( LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ) ); + std::shared_ptr child = std::make_shared( fn, LIBRARY_TABLE_SCOPE::GLOBAL ); - m_panel->OpenTable( nestedTable.get(), aRow.Nickname() ); + m_panel->OpenTable( child, aRow.Nickname() ); } wxString getTablePreamble() override @@ -210,7 +210,7 @@ protected: }; -void PANEL_SYM_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTitle ) +void PANEL_SYM_LIB_TABLE::OpenTable( const std::shared_ptr& aTable, const wxString& aTitle ) { for( int ii = 2; ii < (int) m_notebook->GetPageCount(); ++ii ) { @@ -225,7 +225,8 @@ void PANEL_SYM_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTit } } - AddTable( aTable, aTitle, true ); + m_nestedTables.push_back( aTable ); + AddTable( aTable.get(), aTitle, true ); // Something is pretty fishy with wxAuiNotebook::ChangeSelection(); on Mac at least it // results in a re-entrant call where the second call is one page behind. diff --git a/eeschema/dialogs/panel_sym_lib_table.h b/eeschema/dialogs/panel_sym_lib_table.h index dc27a3a497..0614263385 100644 --- a/eeschema/dialogs/panel_sym_lib_table.h +++ b/eeschema/dialogs/panel_sym_lib_table.h @@ -45,7 +45,7 @@ public: bool TransferDataFromWindow() override; void AddTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aClosable ); - void OpenTable( LIBRARY_TABLE* table, const wxString& aTitle ); + void OpenTable( const std::shared_ptr& table, const wxString& aTitle ); private: /** @@ -89,6 +89,8 @@ private: wxString m_lastProjectLibDir; //< Transient (unsaved) last browsed folder when adding a // project level library. + std::vector> m_nestedTables; + std::map m_supportedSymFiles; }; diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 0cedb1a30e..52a98d9b6f 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -380,7 +380,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aCurr } wxFileName symLibTableFn( fileName.GetPath(), FILEEXT::SymbolLibraryTableFileName ); - LIBRARY_TABLE table( symLibTableFn.GetFullPath(), LIBRARY_TABLE_SCOPE::PROJECT ); + LIBRARY_TABLE table( symLibTableFn, LIBRARY_TABLE_SCOPE::PROJECT ); // If there are any new or duplicate libraries, check to see if it's possible that // there could be any missing libraries that would cause broken symbol library links. diff --git a/include/libraries/library_table.h b/include/libraries/library_table.h index 3b942ce4f9..16e3340ace 100644 --- a/include/libraries/library_table.h +++ b/include/libraries/library_table.h @@ -140,10 +140,12 @@ public: /** * Creates a library table from parsed text + * @param aFromClipboard isn't actually used, but might keep people from calling this with a string + * filepath, which isn't going to do what they expected. * @param aBuffer is a string containing data to parse * @param aScope is the scope of this table (is it global or part of a project) */ - LIBRARY_TABLE( const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope ); + LIBRARY_TABLE( bool aFromClipboard, const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope ); ~LIBRARY_TABLE() = default; diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index f37e6eed24..b845074297 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -179,10 +179,10 @@ protected: void openTable( const LIBRARY_TABLE_ROW& aRow ) override { - wxFileName uri = LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ); - auto nestedTable = std::make_unique( uri, LIBRARY_TABLE_SCOPE::GLOBAL ); + wxFileName fn( LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ) ); + std::shared_ptr child = std::make_shared( fn, LIBRARY_TABLE_SCOPE::GLOBAL ); - m_panel->OpenTable( nestedTable.get(), aRow.Nickname() ); + m_panel->OpenTable( child, aRow.Nickname() ); } wxString getTablePreamble() override @@ -195,7 +195,7 @@ protected: }; -void PANEL_FP_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTitle ) +void PANEL_FP_LIB_TABLE::OpenTable( const std::shared_ptr& aTable, const wxString& aTitle ) { for( int ii = 2; ii < (int) m_notebook->GetPageCount(); ++ii ) { @@ -210,7 +210,8 @@ void PANEL_FP_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTitl } } - AddTable( aTable, aTitle, true ); + m_nestedTables.push_back( aTable ); + AddTable( aTable.get(), aTitle, true ); // Something is pretty fishy with wxAuiNotebook::ChangeSelection(); on Mac at least it // results in a re-entrant call where the second call is one page behind. diff --git a/pcbnew/dialogs/panel_fp_lib_table.h b/pcbnew/dialogs/panel_fp_lib_table.h index fc2dd895b9..844456632a 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.h +++ b/pcbnew/dialogs/panel_fp_lib_table.h @@ -43,7 +43,7 @@ public: bool TransferDataFromWindow() override; void AddTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aClosable ); - void OpenTable( LIBRARY_TABLE* table, const wxString& aTitle ); + void OpenTable( const std::shared_ptr& table, const wxString& aTitle ); private: /** @@ -87,5 +87,7 @@ private: wxString m_lastProjectLibDir; //< Transient (unsaved) last browsed folder when adding a // project level library. + std::vector> m_nestedTables; + std::map m_supportedFpFiles; };