45 result.Trim(
true ).Trim(
false );
50 for(
size_t i = 0; i <
result.length(); ++i )
52 const wxUniChar ch =
result[i];
54 if( !( wxIsalnum( ch ) || ch ==
'_' || ch ==
'-' || ch ==
'.' ) )
67 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,
154 std::optional<LIBRARY_TABLE*> tableOpt = manager.
Table(
161 aError =
_(
"Unable to access the library table." );
167 const wxString fullPath = aLibraryPath.GetFullPath();
169 if(
table->HasRow( aNickname ) )
171 if( std::optional<LIBRARY_TABLE_ROW*> rowOpt =
table->Row( aNickname ); rowOpt )
175 if( row->
URI() != fullPath )
181 aError =
_(
"Failed to update the library table." );
200 aError =
_(
"Failed to save the library table." );
209 const wxString& aLibItemName, wxString& aError )
213 aError =
_(
"No schematic editor is available for placement." );
225 aError =
_(
"Unable to load the downloaded symbol for placement." );
240 aError =
_(
"Unable to access the schematic placement tools." );
252 const wxString& aLibItemName,
255 if( aPayload.empty() )
257 aError =
_(
"Symbol payload was empty." );
261 wxString tempPath = wxFileName::CreateTempFileName( wxS(
"remote_symbol" ) );
263 if( tempPath.IsEmpty() )
265 aError =
_(
"Unable to create a temporary file for the symbol payload." );
269 wxFileName tempFile( tempPath );
270 wxFFile file( tempFile.GetFullPath(), wxS(
"wb" ) );
272 if( !file.IsOpened() )
274 aError =
_(
"Unable to create a temporary file for the symbol payload." );
275 wxRemoveFile( tempFile.GetFullPath() );
279 if( file.Write( aPayload.data(), aPayload.size() ) != aPayload.size() )
281 aError =
_(
"Failed to write the temporary symbol payload." );
283 wxRemoveFile( tempFile.GetFullPath() );
293 aError =
_(
"Unable to access the KiCad symbol plugin." );
294 wxRemoveFile( tempFile.GetFullPath() );
298 std::unique_ptr<LIB_SYMBOL> symbol;
302 LIB_SYMBOL* loaded = plugin->LoadSymbol( tempFile.GetFullPath(), aLibItemName );
305 symbol = std::make_unique<LIB_SYMBOL>( *loaded );
307 aError =
_(
"Symbol payload did not include the expected symbol." );
311 aError = wxString::Format(
_(
"Unable to decode the symbol payload: %s" ), e.
What() );
314 wxRemoveFile( tempFile.GetFullPath() );
321 const wxString nickname =
329 id.SetLibItemName( itemName );
341 if( aLinks.size() == 1 )
346 for(
size_t i = 1; i < aLinks.size(); ++i )
347 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()
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.
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 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()
std::vector< std::vector< std::string > > table
wxString result
Test unit parsing edge cases and error handling.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().