21#include <magic_enum.hpp>
40using namespace std::chrono_literals;
66 wxCHECK( aRow->
plugin && ret,
nullptr );
73 wxArrayString dummyList;
87 wxArrayString dummyList;
119 if( type == SCH_IO_MGR::SCH_NESTED_TABLE )
122 wxFileName fileName( row->
URI() );
124 if( fileName.FileExists() )
127 msg = wxString::Format(
_(
"Nested table '%s' not found." ), row->
URI() );
131 else if( type == SCH_IO_MGR::SCH_FILE_UNKNOWN )
134 wxString msg = wxString::Format(
_(
"Unknown library type %s " ), row->
Type() );
141 plugin->SetLibraryManagerAdapter(
this );
144 magic_enum::enum_name( row->
Scope() ) );
152 std::vector<LIB_SYMBOL*> symbols;
154 std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname );
176 LIB_ID id = symbol->GetLibId();
178 symbol->SetLibId(
id );
187 wxArrayString namesAS;
188 std::vector<wxString> names;
190 if( std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname ) )
201 for(
const wxString&
name : namesAS )
202 names.emplace_back(
name );
210 if( std::optional<const LIB_DATA*> lib =
fetchIfLoaded( aNickname ) )
214 LIB_ID id = symbol->GetLibId();
216 symbol->SetLibId(
id );
222 wxLogTrace(
traceLibraries,
"LoadSymbol: requested library %s not loaded", aNickname );
236 if( !libResult.has_value() )
238 wxLogTrace(
traceLibraries,
"SaveSymbol: unable to load library %s: %s", aNickname,
239 libResult.error().message );
247 wxLogTrace(
traceLibraries,
"SaveSymbol: library %s not found", aNickname );
268 wxLogTrace(
traceLibraries,
"SaveSymbol: error checking for existing symbol %s:%s: %s", aNickname,
290 wxCHECK_MSG(
false, ,
"Unimplemented!" );
300 return it->second.plugin->IsLibraryWritable(
getUri( it->second.row ) );
307 return it->second.plugin->IsLibraryWritable(
getUri( it->second.row ) );
316 std::vector<wxString> fields;
351 std::vector<SUB_LIBRARY> ret;
357 std::vector<wxString> names;
360 for(
const wxString&
name : names )
374 return ( *result )->plugin->SupportsConfigurationDialog();
382 std::optional<const LIB_DATA*> optRow =
fetchIfLoaded( aNickname );
387 if( !( *optRow )->plugin->SupportsConfigurationDialog() )
390 DIALOG_SHIM* dialog = ( *optRow )->plugin->CreateConfigurationDialog( aParent );
404 wxCHECK2( rowData->
row,
continue );
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A wrapper for static data that should not be destroyed at program exit.
LIBRARY_MANAGER_ADAPTER(LIBRARY_MANAGER &aManager)
Constructs a type-specific adapter into the library manager.
LIBRARY_RESULT< LIB_DATA * > loadIfNeeded(const wxString &aNickname)
Fetches a loaded library, triggering a load of that library if it isn't loaded yet.
std::shared_mutex m_librariesMutex
std::map< wxString, LIB_DATA > m_libraries
static wxString getUri(const LIBRARY_TABLE_ROW *aRow)
LIBRARY_MANAGER & m_manager
std::optional< const LIB_DATA * > fetchIfLoaded(const wxString &aNickname) const
LIBRARY_TABLE_SCOPE Scope() const
std::map< std::string, UTF8 > GetOptionsMap() const
const wxString & Type() const
const wxString & URI() const
const wxString & Nickname() const
A logical library item identifier and consists of various portions much like a URI.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Define a library symbol object.
wxString GetName() const override
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
Base class that schematic file and library loading and saving plugins should derive from.
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
virtual bool SupportsSubLibraries() const
virtual int GetModifyHash() const =0
Return the modification hash from the library cache.
virtual void GetAvailableSymbolFields(std::vector< wxString > &aNames)
Retrieves a list of (custom) field names that are present on symbols in this library.
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
virtual wxString GetSubLibraryDescription(const wxString &aName)
Gets a description of a sublibrary.
virtual void GetSubLibraryNames(std::vector< wxString > &aNames)
Retrieves a list of sub-libraries in this library.
bool SupportsConfigurationDialog(const wxString &aNickname) const override
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
static SCH_IO * schplugin(const LIB_DATA *aRow)
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
std::vector< wxString > GetSymbolNames(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
bool SupportsSubLibraries(const wxString &aNickname) const
static std::shared_mutex GlobalLibraryMutex
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_SYMBOL *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
LIBRARY_RESULT< IO_BASE * > createPlugin(const LIBRARY_TABLE_ROW *row) override
Creates a concrete plugin for the given row.
std::vector< SUB_LIBRARY > GetSubLibraries(const wxString &aNickname) const
SYMBOL_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
static wxString GlobalPathEnvVariableName()
int GetModifyHash() const
static const char * PropPowerSymsOnly
LIBRARY_TABLE_TYPE Type() const override
The type of library table this adapter works with.
void enumerateLibrary(LIB_DATA *aLib) override
Override in derived class to perform library-specific enumeration.
IO_BASE * plugin(const LIB_DATA *aRow) override
std::vector< LIB_SYMBOL * > GetSymbols(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
static LEAK_AT_EXIT< std::map< wxString, LIB_DATA > > GlobalLibraries
std::vector< wxString > GetAvailableExtraFields(const wxString &aNickname)
Returns a list of additional (non-mandatory) symbol fields present in the given library.
void ShowConfigurationDialog(const wxString &aNickname, wxWindow *aParent) const override
SAVE_T
The set of return values from SaveSymbol() below.
static const char * PropNonPowerSymsOnly
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
Functions related to environment variables, including help functions.
const wxChar *const traceLibraries
Flag to enable library table and library manager tracing.
tl::expected< ResultType, LIBRARY_ERROR > LIBRARY_RESULT
KICOMMON_API wxString GetVersionedEnvVarName(const wxString &aBaseName)
Construct a versioned environment variable based on this KiCad major version.
Storage for an actual loaded library (including library content owned by the plugin)
std::vector< wxString > available_fields_cache
std::unique_ptr< IO_BASE > plugin
const LIBRARY_TABLE_ROW * row
The overall status of a loaded or loading library.
std::optional< LIBRARY_ERROR > error
A descriptor for a sub-library (supported by database and http libraries)
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.