2022-05-29 19:29:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Jon Evans <jon@craftyjon.com>
|
2023-08-26 19:28:53 +00:00
|
|
|
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2022-05-29 19:29:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
#ifndef SCH_IO_DATABASE_H_
|
|
|
|
#define SCH_IO_DATABASE_H_
|
2022-05-29 19:29:32 +00:00
|
|
|
|
|
|
|
#include <database/database_connection.h>
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <sch_io/sch_io.h>
|
|
|
|
#include <sch_io/sch_io_mgr.h>
|
2022-05-29 19:29:32 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2024-04-27 19:57:24 +00:00
|
|
|
#include <optional>
|
2022-05-29 19:29:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DATABASE_LIB_SETTINGS;
|
|
|
|
struct DATABASE_LIB_TABLE;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A KiCad database library provides both symbol and footprint metadata, so there are "shim" plugins
|
|
|
|
* on both the symbol and footprint side of things that expose the database contents to the
|
|
|
|
* schematic and board editors. The architecture of these is slightly different from the other
|
|
|
|
* plugins because the backing file is just a configuration file rather than something that
|
|
|
|
* contains symbol or footprint data.
|
|
|
|
*/
|
2023-12-24 00:31:24 +00:00
|
|
|
class SCH_IO_DATABASE : public SCH_IO
|
2022-05-29 19:29:32 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_DATABASE();
|
|
|
|
virtual ~SCH_IO_DATABASE();
|
2022-05-29 19:29:32 +00:00
|
|
|
|
2023-12-27 16:34:59 +00:00
|
|
|
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
|
2022-05-29 19:29:32 +00:00
|
|
|
{
|
2023-12-27 16:34:59 +00:00
|
|
|
return IO_BASE::IO_FILE_DESC( _HKI( "KiCad database library files" ),
|
2023-12-28 02:10:01 +00:00
|
|
|
{ FILEEXT::DatabaseLibraryFileExtension } );
|
2022-05-29 19:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GetModifyHash() const override { return 0; }
|
|
|
|
|
|
|
|
void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
|
|
|
|
const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2022-05-29 19:29:32 +00:00
|
|
|
|
|
|
|
void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
|
|
|
|
const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2022-05-29 19:29:32 +00:00
|
|
|
|
|
|
|
LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2022-05-29 19:29:32 +00:00
|
|
|
|
2022-08-27 03:52:56 +00:00
|
|
|
bool SupportsSubLibraries() const override { return true; }
|
|
|
|
|
|
|
|
void GetSubLibraryNames( std::vector<wxString>& aNames ) override;
|
|
|
|
|
2022-08-28 23:02:12 +00:00
|
|
|
void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
|
|
|
|
|
|
|
|
void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
|
|
|
|
|
2022-05-29 19:29:32 +00:00
|
|
|
// Database libraries can never be written using the symbol editing API
|
2023-12-27 00:25:41 +00:00
|
|
|
bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
|
2022-05-29 19:29:32 +00:00
|
|
|
|
|
|
|
void SetLibTable( SYMBOL_LIB_TABLE* aTable ) override
|
|
|
|
{
|
|
|
|
m_libTable = aTable;
|
|
|
|
}
|
|
|
|
|
2023-02-26 23:39:31 +00:00
|
|
|
DATABASE_LIB_SETTINGS* Settings() const { return m_settings.get(); }
|
|
|
|
|
|
|
|
bool TestConnection( wxString* aErrorMsg = nullptr );
|
|
|
|
|
2022-05-29 19:29:32 +00:00
|
|
|
private:
|
2024-02-18 23:34:55 +00:00
|
|
|
void cacheLib();
|
|
|
|
|
2022-05-29 19:29:32 +00:00
|
|
|
void ensureSettings( const wxString& aSettingsPath );
|
|
|
|
|
|
|
|
void ensureConnection();
|
|
|
|
|
2023-02-26 23:39:31 +00:00
|
|
|
void connect();
|
|
|
|
|
2024-03-02 20:37:26 +00:00
|
|
|
std::unique_ptr<LIB_SYMBOL> loadSymbolFromRow( const wxString& aSymbolName,
|
|
|
|
const DATABASE_LIB_TABLE& aTable,
|
|
|
|
const DATABASE_CONNECTION::ROW& aRow );
|
2022-05-29 19:29:32 +00:00
|
|
|
|
2023-03-23 01:24:24 +00:00
|
|
|
static std::optional<bool> boolFromAny( const std::any& aVal );
|
|
|
|
|
2022-05-29 19:29:32 +00:00
|
|
|
SYMBOL_LIB_TABLE* m_libTable;
|
|
|
|
|
|
|
|
std::unique_ptr<DATABASE_LIB_SETTINGS> m_settings;
|
|
|
|
|
2023-05-07 13:06:23 +00:00
|
|
|
/// Generally will be null if no valid connection is established
|
2022-05-29 19:29:32 +00:00
|
|
|
std::unique_ptr<DATABASE_CONNECTION> m_conn;
|
|
|
|
|
2022-08-28 23:02:12 +00:00
|
|
|
std::set<wxString> m_customFields;
|
|
|
|
|
|
|
|
std::set<wxString> m_defaultShownFields;
|
|
|
|
|
2024-03-02 20:37:26 +00:00
|
|
|
std::map<wxString, std::unique_ptr<LIB_SYMBOL>> m_nameToSymbolcache;
|
2024-02-18 23:34:55 +00:00
|
|
|
|
|
|
|
long long m_cacheTimestamp;
|
|
|
|
|
|
|
|
int m_cacheModifyHash;
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-05-07 13:06:23 +00:00
|
|
|
wxString m_lastError;
|
2022-05-29 19:29:32 +00:00
|
|
|
};
|
|
|
|
|
2023-12-24 00:31:24 +00:00
|
|
|
#endif //SCH_IO_DATABASE_H_
|