46 result.Trim(
true ).Trim(
false );
51 for(
size_t i = 0; i <
result.length(); ++i )
53 const wxUniChar ch =
result[i];
55 if( !( wxIsalnum( ch ) || ch ==
'_' || ch ==
'-' || ch ==
'.' ) )
68 if( prefix.IsEmpty() )
78 if( aPayload.empty() )
80 aError =
_(
"Payload was empty." );
84 wxFileName targetDir = aOutput;
85 targetDir.SetFullName( wxEmptyString );
87 if( !targetDir.DirExists() && !targetDir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
89 aError = wxString::Format(
_(
"Unable to create '%s'." ), targetDir.GetFullPath() );
93 wxFFile file( aOutput.GetFullPath(), wxS(
"wb" ) );
95 if( !file.IsOpened() )
97 aError = wxString::Format(
_(
"Unable to open '%s' for writing." ), aOutput.GetFullPath() );
101 if( file.Write( aPayload.data(), aPayload.size() ) != aPayload.size() )
103 aError = wxString::Format(
_(
"Failed to write '%s'." ), aOutput.GetFullPath() );
118 aError =
_(
"Unable to load schematic settings." );
124 if( destination.IsEmpty() )
128 destination.Trim(
true ).Trim(
false );
130 if( destination.IsEmpty() )
132 aError =
_(
"Destination directory is not configured." );
136 wxFileName dir = wxFileName::DirName( destination );
139 if( !dir.DirExists() && !dir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
141 aError = wxString::Format(
_(
"Unable to create directory '%s'." ), dir.GetFullPath() );
151 const wxString& aNickname,
bool aGlobalTable,
bool aStrict,
155 std::optional<LIBRARY_TABLE*> tableOpt = manager.
Table(
162 aError =
_(
"Unable to access the library table." );
168 const wxString fullPath = aLibraryPath.GetFullPath();
170 if(
table->HasRow( aNickname ) )
172 if( std::optional<LIBRARY_TABLE_ROW*> rowOpt =
table->Row( aNickname ); rowOpt )
176 if( row->
URI() != fullPath )
182 aError =
_(
"Failed to update the library table." );
201 aError =
_(
"Failed to save the library table." );
210 const wxString& aNickname,
bool aGlobalTable,
211 std::unique_ptr<LIB_SYMBOL> aSymbol, wxString& aError )
220 if( !aLibraryFile.FileExists() && !aAdapter.
CreateLibrary( aNickname ) )
222 aError = wxString::Format(
_(
"Unable to create '%s'." ), aLibraryFile.GetFullPath() );
228 aError =
_(
"Unable to save the downloaded symbol." );
243 const wxString& aLibItemName, wxString& aError )
247 aError =
_(
"No schematic editor is available for placement." );
259 aError =
_(
"Unable to load the downloaded symbol for placement." );
274 aError =
_(
"Unable to access the schematic placement tools." );
286 const wxString& aLibItemName,
289 if( aPayload.empty() )
291 aError =
_(
"Symbol payload was empty." );
295 wxString tempPath = wxFileName::CreateTempFileName( wxS(
"remote_symbol" ) );
297 if( tempPath.IsEmpty() )
299 aError =
_(
"Unable to create a temporary file for the symbol payload." );
303 wxFileName tempFile( tempPath );
304 wxFFile file( tempFile.GetFullPath(), wxS(
"wb" ) );
306 if( !file.IsOpened() )
308 aError =
_(
"Unable to create a temporary file for the symbol payload." );
309 wxRemoveFile( tempFile.GetFullPath() );
313 if( file.Write( aPayload.data(), aPayload.size() ) != aPayload.size() )
315 aError =
_(
"Failed to write the temporary symbol payload." );
317 wxRemoveFile( tempFile.GetFullPath() );
327 aError =
_(
"Unable to access the KiCad symbol plugin." );
328 wxRemoveFile( tempFile.GetFullPath() );
332 std::unique_ptr<LIB_SYMBOL> symbol;
336 LIB_SYMBOL* loaded = plugin->LoadSymbol( tempFile.GetFullPath(), aLibItemName );
339 symbol = std::make_unique<LIB_SYMBOL>( *loaded );
341 aError =
_(
"Symbol payload did not include the expected symbol." );
345 aError = wxString::Format(
_(
"Unable to decode the symbol payload: %s" ), e.
What() );
348 wxRemoveFile( tempFile.GetFullPath() );
355 const wxString nickname =
363 id.SetLibItemName( itemName );
375 if( aLinks.size() == 1 )
380 for(
size_t i = 1; i < aLinks.size(); ++i )
381 filters.Add( aLinks[i].GetUniStringLibItemName() );
virtual void SetParent(EDA_ITEM *aParent)
REMOTE_PROVIDER_SETTINGS m_RemoteSymbol
AUTOPLACE_FIELDS m_AutoplaceFields
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()
bool CreateLibrary(const wxString &aNickname)
Creates the library (i.e. saves to disk) for the given row if it exists.
void ReloadLibraryEntry(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
std::optional< LIBRARY_TABLE * > Table(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope)
Retrieves a given table; creating a new empty project table if a valid project is loaded and the give...
void SetOptions(const wxString &aOptions)
void SetNickname(const wxString &aNickname)
void SetOk(bool aOk=true)
void SetType(const wxString &aType)
void SetDescription(const wxString &aDescription)
void SetURI(const wxString &aUri)
const wxString & URI() const
A logical library item identifier and consists of various portions much like a URI.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Define a library symbol object.
wxArrayString GetFPFilters() const
void SetFootprintProp(const wxString &aFootprint)
void SetFPFilters(const wxArrayString &aFilters)
virtual LIBRARY_MANAGER & GetLibraryManager() const
static TOOL_ACTION placeSymbol
EESCHEMA_SETTINGS * eeconfig() const
LIB_SYMBOL * GetLibSymbol(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
Load symbol from symbol library table.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Automatically orient all the fields in the symbol.
bool IsMultiUnit() const override
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
SAVE_T SaveSymbol(const wxString &aNickname, std::unique_ptr< LIB_SYMBOL > aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
PGM_BASE & Pgm()
The global program "get" accessor.
void ApplyFootprintLinks(LIB_SYMBOL &aSymbol, const std::vector< LIB_ID > &aLinks)
Apply a list of footprint LIB_IDs to a symbol about to be saved.
std::unique_ptr< LIB_SYMBOL > LoadRemoteSymbolFromPayload(const std::vector< uint8_t > &aPayload, const wxString &aLibItemName, wxString &aError)
Deserialize a remote-downloaded symbol payload into a LIB_SYMBOL.
LIB_ID BuildRemoteLibId(const wxString &aResolvedLibrary, const wxString &aResolvedItemName)
Build the local LIB_ID for a remote-downloaded library item.
bool PlaceRemoteDownloadedSymbol(SCH_EDIT_FRAME *aFrame, const wxString &aNickname, const wxString &aLibItemName, wxString &aError)
Place a symbol from a remote download into the schematic editor.
bool EnsureRemoteLibraryEntry(LIBRARY_TABLE_TYPE aTableType, const wxFileName &aLibraryPath, const wxString &aNickname, bool aGlobalTable, bool aStrict, wxString &aError)
Add or update a library table entry for a remote download library.
bool WriteRemoteBinaryFile(const wxFileName &aOutput, const std::vector< uint8_t > &aPayload, wxString &aError)
Write binary data to a file, creating parent directories as needed.
bool SaveRemoteSymbolToLibrary(SYMBOL_LIBRARY_ADAPTER &aAdapter, const wxFileName &aLibraryFile, const wxString &aNickname, bool aGlobalTable, std::unique_ptr< LIB_SYMBOL > aSymbol, wxString &aError)
Save a downloaded symbol into the remote symbol library aNickname backed by aLibraryFile.
bool EnsureRemoteDestinationRoot(wxFileName &aOutDir, wxString &aError)
Resolve and create the configured destination root directory for remote symbol downloads.
wxString RemoteLibraryPrefix()
Return the configured (or default) library prefix for remote downloads, sanitized for use as a filena...
wxString SanitizeRemoteFileComponent(const wxString &aValue, const wxString &aDefault, bool aLower)
Replace non-alphanumeric characters (other than _ - .) with underscores.
T * GetAppSettings(const char *aFilename)
static wxString DefaultLibraryPrefix()
static wxString DefaultDestinationDir()
wxString result
Test unit parsing edge cases and error handling.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().