KiCad PCB EDA Suite
Loading...
Searching...
No Matches
remote_symbol_import_utils.cpp File Reference
#include "remote_symbol_import_utils.h"
#include <common.h>
#include <eeschema_settings.h>
#include <io/io_mgr.h>
#include <lib_symbol.h>
#include <libraries/library_manager.h>
#include <pgm_base.h>
#include <remote_provider_settings.h>
#include <sch_edit_frame.h>
#include <sch_io/sch_io.h>
#include <sch_io/sch_io_mgr.h>
#include <sch_symbol.h>
#include <settings/settings_manager.h>
#include <tool/tool_manager.h>
#include <tools/sch_actions.h>
#include <wx/ffile.h>
#include <wx/filefn.h>
#include <wx/intl.h>

Go to the source code of this file.

Functions

wxString SanitizeRemoteFileComponent (const wxString &aValue, const wxString &aDefault, bool aLower)
 Replace non-alphanumeric characters (other than _ - .) with underscores.
 
wxString RemoteLibraryPrefix ()
 Return the configured (or default) library prefix for remote downloads, sanitized for use as a filename component.
 
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.
 
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 PlaceRemoteDownloadedSymbol (SCH_EDIT_FRAME *aFrame, const wxString &aNickname, const wxString &aLibItemName, wxString &aError)
 Place a symbol from a remote download into the schematic editor.
 
std::unique_ptr< LIB_SYMBOLLoadRemoteSymbolFromPayload (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.
 
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.
 

Function Documentation

◆ ApplyFootprintLinks()

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.

The first LIB_ID is written to the symbol's Footprint field as a fully-qualified <nickname>:<itemName> string (overwriting any previous value). Remaining LIB_IDs are appended to the symbol's footprint filter list as bare item names (filters are globs over footprint name only and would not match colon-qualified strings).

If aLinks is empty, the symbol is left untouched.

Definition at line 334 of file remote_symbol_import_utils.cpp.

References LIB_SYMBOL::GetFPFilters(), LIB_SYMBOL::SetFootprintProp(), and LIB_SYMBOL::SetFPFilters().

Referenced by REMOTE_SYMBOL_IMPORT_JOB::Import(), and PANEL_REMOTE_SYMBOL::receiveSymbol().

◆ BuildRemoteLibId()

LIB_ID BuildRemoteLibId ( const wxString & aResolvedLibrary,
const wxString & aResolvedItemName )

Build the local LIB_ID for a remote-downloaded library item.

The caller is responsible for resolving any fallbacks before calling. The library nickname is constructed as <RemoteLibraryPrefix()>_<sanitized aResolvedLibrary>; the item name is the sanitized aResolvedItemName.

Definition at line 319 of file remote_symbol_import_utils.cpp.

References RemoteLibraryPrefix(), SanitizeRemoteFileComponent(), and LIB_ID::SetLibNickname().

Referenced by REMOTE_SYMBOL_IMPORT_JOB::Import(), and PANEL_REMOTE_SYMBOL::receiveFootprint().

◆ EnsureRemoteDestinationRoot()

◆ EnsureRemoteLibraryEntry()

bool EnsureRemoteLibraryEntry ( LIBRARY_TABLE_TYPE aTableType,
const wxFileName & aLibraryPath,
const wxString & aNickname,
bool aGlobalTable,
bool aStrict,
wxString & aError )

◆ LoadRemoteSymbolFromPayload()

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.

The payload is expected to be a complete kicad_symbol_lib s-expression. The named symbol is extracted via the SCH_KICAD plugin and returned as an owned copy.

Definition at line 251 of file remote_symbol_import_utils.cpp.

References _, and IO_ERROR::What().

Referenced by REMOTE_SYMBOL_IMPORT_JOB::Import(), and PANEL_REMOTE_SYMBOL::receiveSymbol().

◆ PlaceRemoteDownloadedSymbol()

◆ RemoteLibraryPrefix()

◆ SanitizeRemoteFileComponent()

wxString SanitizeRemoteFileComponent ( const wxString & aValue,
const wxString & aDefault,
bool aLower = false )

Replace non-alphanumeric characters (other than _ - .) with underscores.

Returns aDefault when aValue is empty after trimming.

Definition at line 42 of file remote_symbol_import_utils.cpp.

References result.

Referenced by BuildRemoteLibId(), PANEL_REMOTE_SYMBOL::cookieFilePath(), REMOTE_SYMBOL_IMPORT_JOB::Import(), PANEL_REMOTE_SYMBOL::receive3DModel(), PANEL_REMOTE_SYMBOL::receiveSPICEModel(), PANEL_REMOTE_SYMBOL::receiveSymbol(), and RemoteLibraryPrefix().

◆ WriteRemoteBinaryFile()

bool WriteRemoteBinaryFile ( const wxFileName & aOutput,
const std::vector< uint8_t > & aPayload,
wxString & aError )

Write binary data to a file, creating parent directories as needed.

Definition at line 74 of file remote_symbol_import_utils.cpp.

References _.

Referenced by REMOTE_SYMBOL_IMPORT_JOB::Import(), PANEL_REMOTE_SYMBOL::receive3DModel(), PANEL_REMOTE_SYMBOL::receiveFootprint(), and PANEL_REMOTE_SYMBOL::receiveSPICEModel().