diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index 4a18537a1c..1ac4d8f462 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2017 Wayne Stambaugh * Copyright (C) 2021 CERN - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -328,6 +328,23 @@ PANEL_SYM_LIB_TABLE::~PANEL_SYM_LIB_TABLE() } +bool PANEL_SYM_LIB_TABLE::allowAutomaticPluginTypeSelection( wxString& aLibraryPath ) +{ + // When the plugin type depends only of the file extension, return true. + // if it needs to read the actual file (taht can be not available), return false + + wxFileName fn( aLibraryPath ); + wxString ext = fn.GetExt().Lower(); + + // Currently, only the extension .lib is common to legacy libraries and Cadstar libraries + // so return false in this case + if( ext == LegacySymbolLibFileExtension ) + return false; + + return true; +} + + bool PANEL_SYM_LIB_TABLE::verifyTables() { wxString msg; @@ -389,7 +406,16 @@ bool PANEL_SYM_LIB_TABLE::verifyTables() { // set the trimmed values back into the table so they get saved to disk. model->SetValue( r, COL_NICKNAME, nick ); - model->SetValue( r, COL_URI, uri ); + + if( allowAutomaticPluginTypeSelection( uri ) ) + model->SetValue( r, COL_URI, uri ); + else + { + wxString ltype = model->GetValue( r, COL_TYPE ); + model->LIB_TABLE_GRID::SetValue( r, COL_URI, uri ); + model->SetValue( r, COL_TYPE, ltype ); + } + ++r; // this row was OK. } } diff --git a/eeschema/dialogs/panel_sym_lib_table.h b/eeschema/dialogs/panel_sym_lib_table.h index 6db6f0d9da..6ef25e1115 100644 --- a/eeschema/dialogs/panel_sym_lib_table.h +++ b/eeschema/dialogs/panel_sym_lib_table.h @@ -74,6 +74,14 @@ private: SYMBOL_LIB_TABLE_GRID* cur_model() const; + /** + * @return true if the plugin type can be selected from the library path only + * (i.e. only from its extension) + * if the type needs an access to the file itself, return false because + * the file can be not (at least temporary) available + */ + bool allowAutomaticPluginTypeSelection( wxString& aLibraryPath ); + private: // Caller's tables are modified only on OK button and successful verification. SYMBOL_LIB_TABLE* m_globalTable; diff --git a/eeschema/sch_io_mgr.cpp b/eeschema/sch_io_mgr.cpp index 602ce67c47..052fdfb830 100644 --- a/eeschema/sch_io_mgr.cpp +++ b/eeschema/sch_io_mgr.cpp @@ -168,6 +168,11 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& a { wxString fullName = ExpandEnvVarSubstitutions( aLibPath, nullptr ); + // Of course the file should exist to be read. If not, use the SCH_LEGACY + // format: it is more usual than SCH_CADSTAR_ARCHIVE + if( !wxFileExists( fullName ) ) + return SCH_LEGACY; + for( SCH_FILE_T pluginType : { SCH_LEGACY, SCH_CADSTAR_ARCHIVE } ) { SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) ); @@ -179,16 +184,13 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& a } } + // If not found, use the SCH_LEGACY. + return SCH_LEGACY; } for( SCH_IO_MGR::SCH_FILE_T piType : SCH_IO_MGR::SCH_FILE_T_vector ) { - - if( ext == LegacySymbolLibFileExtension ) - { - break; - } - else if( SCH_IO_MGR::GetLibraryFileExtension( piType ).Lower() == fn.GetExt().Lower() ) + if( SCH_IO_MGR::GetLibraryFileExtension( piType ).Lower() == ext ) { ret = piType; break; diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index d69a30c8a4..612163cf2d 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2016 Wayne Stambaugh * Copyright (C) 2022 CERN - * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -680,6 +680,26 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable ) } +bool SYMBOL_LIB_TABLE::operator==( const SYMBOL_LIB_TABLE& aOther ) const +{ + if( m_rows.size() != aOther.m_rows.size() ) + return false; + + unsigned i; + + for( i = 0; i < m_rows.size(); ++i ) + { + const SYMBOL_LIB_TABLE_ROW& curr = static_cast( m_rows[i] ); + const SYMBOL_LIB_TABLE_ROW& curr_other = static_cast( aOther.m_rows[i] ); + + if( curr != curr_other ) + return false; + } + + return true; +} + + wxString SYMBOL_LIB_TABLE::GetGlobalTableFileName() { wxFileName fn; diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index 499d8de501..18744a3e30 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Wayne Stambaugh - * Copyright (C) 2016-2021 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -308,6 +308,15 @@ public: static const wxString& GetSymbolLibTableFileName(); + /** + * Compares this table against another. + * This compares the row *contents* against each other. + */ + bool operator==( const SYMBOL_LIB_TABLE& aOther ) const; + + bool operator!=( const SYMBOL_LIB_TABLE& aOther ) const { return !( *this == aOther ); } + + private: friend class SYMBOL_LIB_TABLE_GRID; friend class PANEL_SYM_LIB_TABLE;