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() )
77 if( aPayload.empty() )
79 aError =
_(
"Payload was empty." );
83 wxFileName targetDir = aOutput;
84 targetDir.SetFullName( wxEmptyString );
86 if( !targetDir.DirExists() && !targetDir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
88 aError = wxString::Format(
_(
"Unable to create '%s'." ), targetDir.GetFullPath() );
92 wxFFile file( aOutput.GetFullPath(), wxS(
"wb" ) );
94 if( !file.IsOpened() )
96 aError = wxString::Format(
_(
"Unable to open '%s' for writing." ), aOutput.GetFullPath() );
100 if( file.Write( aPayload.data(), aPayload.size() ) != aPayload.size() )
102 aError = wxString::Format(
_(
"Failed to write '%s'." ), aOutput.GetFullPath() );
117 aError =
_(
"Unable to load schematic settings." );
123 if( destination.IsEmpty() )
127 destination.Trim(
true ).Trim(
false );
129 if( destination.IsEmpty() )
131 aError =
_(
"Destination directory is not configured." );
135 wxFileName dir = wxFileName::DirName( destination );
138 if( !dir.DirExists() && !dir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
140 aError = wxString::Format(
_(
"Unable to create directory '%s'." ), dir.GetFullPath() );
150 const wxString& aNickname,
bool aGlobalTable,
bool aStrict, wxString& aError )
159 aError =
_(
"Unable to access the library table." );
165 const wxString fullPath = aLibraryPath.GetFullPath();
167 if(
table->HasRow( aNickname ) )
169 if( std::optional<LIBRARY_TABLE_ROW*> rowOpt =
table->Row( aNickname ); rowOpt )
173 if( row->
URI() != fullPath )
179 aError =
_(
"Failed to update the library table." );
198 aError =
_(
"Failed to save the library table." );
207 const wxString& aNickname,
bool aGlobalTable,
208 std::unique_ptr<LIB_SYMBOL> aSymbol, wxString& aError )
217 if( !aLibraryFile.FileExists() && !aAdapter.
CreateLibrary( aNickname ) )
219 aError = wxString::Format(
_(
"Unable to create '%s'." ), aLibraryFile.GetFullPath() );
225 aError =
_(
"Unable to save the downloaded symbol." );
242 aError =
_(
"No schematic editor is available for placement." );
254 aError =
_(
"Unable to load the downloaded symbol for placement." );
269 aError =
_(
"Unable to access the schematic placement tools." );
282 const wxString& aLibItemName, wxString& aError )
284 if( aPayload.empty() )
286 aError =
_(
"Symbol payload was empty." );
290 wxString tempPath = wxFileName::CreateTempFileName( wxS(
"remote_symbol" ) );
292 if( tempPath.IsEmpty() )
294 aError =
_(
"Unable to create a temporary file for the symbol payload." );
298 wxFileName tempFile( tempPath );
299 wxFFile file( tempFile.GetFullPath(), wxS(
"wb" ) );
301 if( !file.IsOpened() )
303 aError =
_(
"Unable to create a temporary file for the symbol payload." );
304 wxRemoveFile( tempFile.GetFullPath() );
308 if( file.Write( aPayload.data(), aPayload.size() ) != aPayload.size() )
310 aError =
_(
"Failed to write the temporary symbol payload." );
312 wxRemoveFile( tempFile.GetFullPath() );
322 aError =
_(
"Unable to access the KiCad symbol plugin." );
323 wxRemoveFile( tempFile.GetFullPath() );
327 std::unique_ptr<LIB_SYMBOL> symbol;
331 LIB_SYMBOL* loaded = plugin->LoadSymbol( tempFile.GetFullPath(), aLibItemName );
334 symbol = std::make_unique<LIB_SYMBOL>( *loaded );
336 aError =
_(
"Symbol payload did not include the expected symbol." );
340 aError = wxString::Format(
_(
"Unable to decode the symbol payload: %s" ), e.
What() );
343 wxRemoveFile( tempFile.GetFullPath() );
354 if( nickname.EndsWith( wxT(
".pretty" ) ) )
355 nickname = nickname.BeforeLast(
'.' );
359 if( itemName.EndsWith( wxT(
".kicad_mod" ) ) )
360 itemName = itemName.BeforeLast(
'.' );
364 id.SetLibItemName( itemName );
376 if( aLinks.size() == 1 )
381 for(
size_t i = 1; i < aLinks.size(); ++i )
382 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)
Synchronously recreates the plugin for and reloads the given library.
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...
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, bool aAllowEscapes)
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.
static const std::vector< std::string > filters
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().