30#include <magic_enum.hpp>
54 wxCHECK( aRow->
plugin && ret,
nullptr );
67 wxFileName fileName( row->
URI() );
69 if( fileName.FileExists() )
72 msg = wxString::Format(
_(
"Nested table '%s' not found." ), row->
URI() );
79 wxString msg = wxString::Format(
_(
"Unknown library type %s " ), row->
Type() );
98 wxArrayString dummyList;
112 wxArrayString dummyList;
144 std::vector<DESIGN_BLOCK*> blocks;
146 std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname );
153 wxArrayString blockNames;
164 for(
const wxString& blockName : blockNames )
168 blocks.emplace_back(
dbplugin( lib )->DesignBlockLoad(
getUri( lib->
row ), blockName,
false, &options ) );
172 wxLogTrace(
traceLibraries,
"DB: Exception enumerating design block %s: %s", blockName, e.
What() );
183 wxArrayString namesAS;
184 std::vector<wxString> names;
186 if( std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname ) )
194 for(
const wxString&
name : namesAS )
195 names.emplace_back(
name );
202 const wxString& aDesignBlockName,
bool aKeepUUID )
204 if( std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname ) )
212 dbplugin( lib )->DesignBlockLoad(
getUri( lib->
row ), aDesignBlockName, aKeepUUID, &options ) )
214 db->GetLibId().SetLibNickname( aNickname );
220 wxLogTrace(
traceLibraries,
"LoadDesignBlock: error loading %s:%s: %s", aNickname, aDesignBlockName,
226 wxLogTrace(
traceLibraries,
"LoadDesignBlock: requested library %s not loaded", aNickname );
235 if( std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname ) )
248 const wxString& aDesignBlockName )
250 if( std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname ) )
266 if( std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname ) )
282 const wxString& aDesignBlockName )
284 if( std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname ) )
295 if( std::optional<const LIB_DATA*> maybeLib =
fetchIfLoaded( aNickname ) )
311 if( nickname.size() )
@ DESIGN_BLOCK_FILE_UNKNOWN
0 is not a legal menu id on Mac
static DESIGN_BLOCK_FILE_T EnumFromStr(const wxString &aFileType)
static DESIGN_BLOCK_IO * FindPlugin(DESIGN_BLOCK_FILE_T aFileType)
bool DesignBlockExists(const wxString &aLibraryPath, const wxString &aDesignBlockName, const std::map< std::string, UTF8 > *aProperties=nullptr)
void DesignBlockDelete(const wxString &aLibraryPath, const wxString &aDesignBlockName, const std::map< std::string, UTF8 > *aProperties=nullptr)
void DesignBlockSave(const wxString &aLibraryPath, const DESIGN_BLOCK *aDesignBlock, const std::map< std::string, UTF8 > *aProperties=nullptr)
const DESIGN_BLOCK * GetEnumeratedDesignBlock(const wxString &aLibraryPath, const wxString &aDesignBlockName, const std::map< std::string, UTF8 > *aProperties=nullptr)
void DesignBlockEnumerate(wxArrayString &aDesignBlockNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr)
std::vector< wxString > GetDesignBlockNames(const wxString &aNickname)
SAVE_T
The set of return values from DesignBlockSave() below.
std::vector< DESIGN_BLOCK * > GetDesignBlocks(const wxString &aNickname)
IO_BASE * plugin(const LIB_DATA *aRow) override
static DESIGN_BLOCK_IO * dbplugin(const LIB_DATA *aRow)
Helper to cast the ABC plugin in the LIB_DATA* to a concrete plugin.
void DeleteDesignBlock(const wxString &aNickname, const wxString &aDesignBlockName)
Delete the aDesignBlockName from the library given by aNickname.
static wxString GlobalPathEnvVariableName()
LIBRARY_RESULT< IO_BASE * > createPlugin(const LIBRARY_TABLE_ROW *row) override
Creates a concrete plugin for the given row.
static LEAK_AT_EXIT< std::map< wxString, LIB_DATA > > GlobalLibraries
void enumerateLibrary(LIB_DATA *aLib) override
Override in derived class to perform library-specific enumeration.
DESIGN_BLOCK * LoadDesignBlock(const wxString &aNickname, const wxString &aDesignBlockName, bool aKeepUUID=false)
Load a design block having aDesignBlockName from the library given by aNickname.
DESIGN_BLOCK * DesignBlockLoadWithOptionalNickname(const LIB_ID &aDesignBlockId, bool aKeepUUID=false)
Load a design block having aDesignBlockId with possibly an empty nickname.
SAVE_T SaveDesignBlock(const wxString &aNickname, const DESIGN_BLOCK *aDesignBlock, bool aOverwrite=true)
Write aDesignBlock to an existing library given by aNickname.
DESIGN_BLOCK_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
bool IsDesignBlockLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
const DESIGN_BLOCK * GetEnumeratedDesignBlock(const wxString &aNickname, const wxString &aDesignBlockName)
A version of #DesignBlockLoad() for use after #DesignBlockEnumerate() for more efficient cache manage...
bool DesignBlockExists(const wxString &aNickname, const wxString &aDesignBlockName)
Indicates whether or not the given design block already exists in the given library.
static std::shared_mutex GlobalLibraryMutex
wxString GetName() const override
virtual bool IsLibraryWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
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::vector< wxString > GetLibraryNames() const
Returns a list of library nicknames that are available (skips any that failed to load)
static wxString getUri(const LIBRARY_TABLE_ROW *aRow)
std::optional< const LIB_DATA * > fetchIfLoaded(const wxString &aNickname) 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.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
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::unique_ptr< IO_BASE > plugin
const LIBRARY_TABLE_ROW * row
The overall status of a loaded or loading library.
std::optional< LIBRARY_ERROR > error
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.