|
KiCad PCB EDA Suite
|
#include <embedded_files.h>
Classes | |
| struct | EMBEDDED_FILE |
Public Types | |
| enum class | RETURN_CODE : int { OK , FILE_NOT_FOUND , PERMISSIONS_ERROR , FILE_ALREADY_EXISTS , OUT_OF_MEMORY , CHECKSUM_ERROR } |
| using | FILE_ADDED_CALLBACK = std::function<void( EMBEDDED_FILE* )> |
Public Member Functions | |
| EMBEDDED_FILES ()=default | |
| EMBEDDED_FILES (EMBEDDED_FILES &&other) noexcept | |
| EMBEDDED_FILES (const EMBEDDED_FILES &other) | |
| EMBEDDED_FILES (const EMBEDDED_FILES &other, bool aDeepCopy) | |
| virtual | ~EMBEDDED_FILES ()=default |
| void | SetFileAddedCallback (FILE_ADDED_CALLBACK callback) |
| FILE_ADDED_CALLBACK | GetFileAddedCallback () const |
| EMBEDDED_FILE * | AddFile (const wxFileName &aName, bool aOverwrite) |
| Load a file from disk and adds it to the collection. | |
| EMBEDDED_FILE * | AddFile (EMBEDDED_FILE *aFile) |
| Append a file to the collection. | |
| EMBEDDED_FILE * | AddFile (std::shared_ptr< EMBEDDED_FILE > aFile) |
| Append a file (already managed by a shared_ptr) to the collection. | |
| void | RemoveFile (const wxString &name, bool aErase=true) |
| Remove a file from the collection and frees the memory. | |
| void | AssignSharedFrom (const EMBEDDED_FILES &aSource, const std::set< wxString > &aExcludedNames={}) |
Replace this collection's files with references to aSource's files, skipping any whose name appears in aExcludedNames. | |
| void | WriteEmbeddedFiles (OUTPUTFORMATTER &aOut, bool aWriteData) const |
| Output formatter for the embedded files. | |
| wxString | GetEmbeddedFileLink (const EMBEDDED_FILE &aFile) const |
| Return the link for an embedded file. | |
| bool | HasFile (const wxString &name) const |
| bool | IsEmpty () const |
| virtual void | RunOnNestedEmbeddedFiles (const std::function< void(EMBEDDED_FILES *)> &aFunction) |
| Provide access to nested embedded files, such as symbols in schematics and footprints in boards. | |
| const std::vector< wxString > * | UpdateFontFiles () |
| Helper function to get a list of fonts for fontconfig to add to the library. | |
| const std::vector< wxString > * | GetFontFiles () const |
| If we just need the cached version of the font files, we can use this function which is const and will not update the font files. | |
| void | ClearEmbeddedFonts () |
| Remove all embedded fonts from the collection. | |
| EMBEDDED_FILE * | GetEmbeddedFile (const wxString &aName) const |
| Returns the embedded file with the given name or nullptr if it does not exist. | |
| const std::map< wxString, std::shared_ptr< EMBEDDED_FILE > > & | EmbeddedFileMap () const |
| Provide an iterable view of the file collection. | |
| wxFileName | GetTemporaryFileName (const wxString &aName) const |
| wxFileName | GetTemporaryFileName (EMBEDDED_FILE *aFile) const |
| void | ClearEmbeddedFiles (bool aDeleteFiles=true) |
| virtual void | EmbedFonts () |
| virtual std::set< KIFONT::OUTLINE_FONT * > | GetFonts () const |
| void | SetAreFontsEmbedded (bool aEmbedFonts) |
| bool | GetAreFontsEmbedded () const |
| EMBEDDED_FILES & | operator= (EMBEDDED_FILES &&other) noexcept |
| EMBEDDED_FILES & | operator= (const EMBEDDED_FILES &other) |
Static Public Member Functions | |
| static RETURN_CODE | CompressAndEncode (EMBEDDED_FILE &aFile) |
| Take data from the #decompressedData buffer and compresses it using ZSTD into the #compressedEncodedData buffer. | |
| static RETURN_CODE | DecompressAndDecode (EMBEDDED_FILE &aFile, bool aAllowEmptyHash=false) |
| Takes data from the #compressedEncodedData buffer and Base64 decodes it. | |
| static RETURN_CODE | ComputeFileHash (const wxFileName &aFileName, std::string &aHash) |
| Compute the hash of a file on disk without fully embedding it. | |
| static uint32_t | Seed () |
Protected Attributes | |
| bool | m_embedFonts = false |
| If set, fonts will be embedded in the element on save. | |
Private Attributes | |
| std::map< wxString, std::shared_ptr< EMBEDDED_FILE > > | m_files |
| std::vector< wxString > | m_fontFiles |
| FILE_ADDED_CALLBACK | m_fileAddedCallback |
Definition at line 41 of file embedded_files.h.
| using EMBEDDED_FILES::FILE_ADDED_CALLBACK = std::function<void( EMBEDDED_FILE* )> |
Definition at line 94 of file embedded_files.h.
|
strong |
Definition at line 76 of file embedded_files.h.
|
default |
References EMBEDDED_FILES().
Referenced by AssignSharedFrom(), EMBEDDED_FILES(), EMBEDDED_FILES(), EMBEDDED_FILES(), EMBEDDED_FILES(), BOARD::FixupEmbeddedData(), FOOTPRINT::FOOTPRINT(), BOARD::GetEmbeddedFiles(), BOARD::GetEmbeddedFiles(), FOOTPRINT::GetEmbeddedFiles(), FOOTPRINT::GetEmbeddedFiles(), LIB_SYMBOL::GetEmbeddedFiles(), LIB_SYMBOL::GetEmbeddedFiles(), SCHEMATIC::GetEmbeddedFiles(), SCHEMATIC::GetEmbeddedFiles(), LIB_SYMBOL::LIB_SYMBOL(), operator=(), operator=(), BOARD::RunOnNestedEmbeddedFiles(), RunOnNestedEmbeddedFiles(), SCHEMATIC::RunOnNestedEmbeddedFiles(), and BOARD::SetEmbeddedFilesDelegate().
|
noexcept |
Definition at line 665 of file embedded_files.cpp.
References EMBEDDED_FILES().
| EMBEDDED_FILES::EMBEDDED_FILES | ( | const EMBEDDED_FILES & | other | ) |
Definition at line 700 of file embedded_files.cpp.
References EMBEDDED_FILES(), m_embedFonts, m_fileAddedCallback, m_files, and m_fontFiles.
| EMBEDDED_FILES::EMBEDDED_FILES | ( | const EMBEDDED_FILES & | other, |
| bool | aDeepCopy ) |
Definition at line 709 of file embedded_files.cpp.
References EMBEDDED_FILES(), m_embedFonts, m_fileAddedCallback, m_files, m_fontFiles, and name.
|
virtualdefault |
| EMBEDDED_FILES::EMBEDDED_FILE * EMBEDDED_FILES::AddFile | ( | const wxFileName & | aName, |
| bool | aOverwrite ) |
Load a file from disk and adds it to the collection.
| aName | is the name of the file to load. |
| aOverwrite | is true if the file should be overwritten if it already exists. |
Definition at line 69 of file embedded_files.cpp.
References CompressAndEncode(), EMBEDDED_FILES::EMBEDDED_FILE::DATASHEET, EMBEDDED_FILES::EMBEDDED_FILE::FONT, HasFile(), m_fileAddedCallback, m_files, EMBEDDED_FILES::EMBEDDED_FILE::MODEL, OK, result, and EMBEDDED_FILES::EMBEDDED_FILE::WORKSHEET.
Referenced by AddFile(), ORCAD_CONVERTER::applyFont(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PCB_CONTROL::CollectAndEmbed3DModels(), BOARD::EmbedFonts(), FOOTPRINT::EmbedFonts(), LIB_SYMBOL::EmbedFonts(), SCHEMATIC::EmbedFonts(), BOARD::ExchangeFootprint(), PCB_IO_KICAD_SEXPR::format(), API_HANDLER_PCB::handleAddEmbeddedFiles(), ALTIUM_PCB::HelperEmbedModel(), TEXT_BUTTON_URL::OnButtonClick(), EMBEDDED_FILES_PARSER::ParseEmbedded(), LIB_BUFFER::SaveBuffer(), SYMBOL_LIBRARY_MANAGER::SaveLibrary(), and kiapi::board::UnpackEmbeddedFiles().
| EMBEDDED_FILES::EMBEDDED_FILE * EMBEDDED_FILES::AddFile | ( | EMBEDDED_FILE * | aFile | ) |
Append a file to the collection.
Ownership of aFile is transferred to the collection.
aFile itself is destroyed when a file of that name is already embedded. Definition at line 141 of file embedded_files.cpp.
References AddFile().
| EMBEDDED_FILES::EMBEDDED_FILE * EMBEDDED_FILES::AddFile | ( | std::shared_ptr< EMBEDDED_FILE > | aFile | ) |
Append a file (already managed by a shared_ptr) to the collection.
Allows multiple collections to share ownership of the same underlying file payload, avoiding deep copies of large embedded blobs such as 3D models when footprints are cloned for undo snapshots.
Definition at line 147 of file embedded_files.cpp.
References m_fileAddedCallback, m_files, and name.
| void EMBEDDED_FILES::AssignSharedFrom | ( | const EMBEDDED_FILES & | aSource, |
| const std::set< wxString > & | aExcludedNames = {} ) |
Replace this collection's files with references to aSource's files, skipping any whose name appears in aExcludedNames.
Payloads are shared, not copied.
This leaves aSource untouched, so the operation is idempotent. Editor dialogs commit their working copy on both page change and OK; a destructive commit would wipe the target on the second pass.
Definition at line 179 of file embedded_files.cpp.
References EMBEDDED_FILES(), m_files, and name.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 267 of file embedded_files.h.
References m_files.
Referenced by BOOST_AUTO_TEST_CASE(), PCB_IO_KICAD_SEXPR::format(), operator=(), LIB_BUFFER::SaveBuffer(), SYMBOL_LIBRARY_MANAGER::SaveLibrary(), and kiapi::board::UnpackEmbeddedFiles().
| void EMBEDDED_FILES::ClearEmbeddedFonts | ( | ) |
Remove all embedded fonts from the collection.
Definition at line 197 of file embedded_files.cpp.
References EMBEDDED_FILES::EMBEDDED_FILE::FONT, and m_files.
Referenced by SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol().
|
static |
Take data from the #decompressedData buffer and compresses it using ZSTD into the #compressedEncodedData buffer.
The data is then Base64 encoded. This call is used when adding a new file to the collection from disk.
Definition at line 271 of file embedded_files.cpp.
References MMH3_HASH::add(), EMBEDDED_FILES::EMBEDDED_FILE::compressedEncodedData, EMBEDDED_FILES::EMBEDDED_FILE::data_hash, EMBEDDED_FILES::EMBEDDED_FILE::decompressedData, MMH3_HASH::digest(), OK, OUT_OF_MEMORY, Seed(), and HASH_128::ToString().
Referenced by AddFile(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PADS_SCH_BINARY::PADS_SCH_BINARY_BUILDER::Build(), ALTIUM_PCB::ConvertComponentBody6ToFootprintItem(), and SYMBOL_EMBEDDED_FILES_TEST_FIXTURE::CreateTestEmbeddedFile().
|
static |
Compute the hash of a file on disk without fully embedding it.
| aFileName | is the path to the file to hash. |
| aHash | is the output string to store the computed hash. |
Definition at line 403 of file embedded_files.cpp.
References MMH3_HASH::add(), MMH3_HASH::digest(), FILE_NOT_FOUND, OK, OUT_OF_MEMORY, Seed(), and HASH_128::ToString().
Referenced by PANEL_EMBEDDED_FILES::AddEmbeddedFile(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
static |
Takes data from the #compressedEncodedData buffer and Base64 decodes it.
The data is then decompressed using ZSTD and stored in the #decompressedData buffer. This call is used when loading the embedded files using the parsers.
| aAllowEmptyHash | will let this succeed if aFile.data_hash is empty |
Definition at line 306 of file embedded_files.cpp.
References MMH3_HASH::add(), MMH3_HASH::addDataV1(), CHECKSUM_ERROR, EMBEDDED_FILES::EMBEDDED_FILE::compressedEncodedData, EMBEDDED_FILES::EMBEDDED_FILE::data_hash, EMBEDDED_FILES::EMBEDDED_FILE::decompressedData, MMH3_HASH::digest(), EMBEDDED_FILES::EMBEDDED_FILE::name, OK, OUT_OF_MEMORY, Seed(), and HASH_128::ToString().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), EMBEDDED_FILES_PARSER::ParseEmbedded(), and kiapi::board::UnpackEmbeddedFiles().
|
inline |
Provide an iterable view of the file collection.
The map stores files via shared_ptr so that the copy constructor (used by Clone()) can share ownership of payloads, keeping transient snapshots cheap. Copy assignment, in contrast, performs a deep copy so callers that mutate file fields through raw pointers after assignment cannot affect the source. Callers that need a guaranteed-unique mutable copy from a const-ref source must allocate a new EMBEDDED_FILE explicitly.
Definition at line 258 of file embedded_files.h.
References m_files.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOARD::ExchangeFootprint(), BOARD::FixupEmbeddedData(), LIB_SYMBOL::Flatten(), PCB_IO_KICAD_SEXPR::format(), API_HANDLER_PCB::handleAddEmbeddedFiles(), ALTIUM_PCB::HelperEmbedModel(), kiapi::board::PackEmbeddedFiles(), SYMBOL_LIBRARY_MANAGER::SaveLibrary(), and SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol().
|
inlinevirtual |
Reimplemented in BOARD, FOOTPRINT, LIB_SYMBOL, and SCHEMATIC.
Definition at line 276 of file embedded_files.h.
|
inline |
Definition at line 288 of file embedded_files.h.
References m_embedFonts.
Referenced by PCB_IO_KICAD_SEXPR::format(), PCB_IO_KICAD_SEXPR::format(), SCH_IO_KICAD_SEXPR_PARSER::ParseSchematic(), SYMBOL_LIBRARY_MANAGER::SaveLibrary(), SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol(), and LIB_SYMBOL::Serialize().
|
inline |
Returns the embedded file with the given name or nullptr if it does not exist.
Definition at line 242 of file embedded_files.h.
References m_files.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOARD::FixupEmbeddedData(), SCH_SCREEN::FixupEmbeddedData(), and SCH_EDIT_FRAME::importFile().
|
inline |
Return the link for an embedded file.
| aFile | is the file to get the link for. |
Definition at line 166 of file embedded_files.h.
References EMBEDDED_FILES::EMBEDDED_FILE::GetLink().
|
inline |
Definition at line 101 of file embedded_files.h.
References m_fileAddedCallback.
Referenced by PADS_SCH_BINARY::PADS_SCH_BINARY_BUILDER::Build(), and SYMBOL_LIBRARY_MANAGER::SaveLibrary().
| const std::vector< wxString > * EMBEDDED_FILES::GetFontFiles | ( | ) | const |
If we just need the cached version of the font files, we can use this function which is const and will not update the font files.
Definition at line 644 of file embedded_files.cpp.
References m_fontFiles.
Referenced by SCH_IO_KICAD_SEXPR_PARSER::ParseSchematic().
|
inlinevirtual |
Reimplemented in BOARD, FOOTPRINT, LIB_SYMBOL, and SCHEMATIC.
Definition at line 278 of file embedded_files.h.
| wxFileName EMBEDDED_FILES::GetTemporaryFileName | ( | const wxString & | aName | ) | const |
Definition at line 599 of file embedded_files.cpp.
References PATHS::EnsurePathExists(), PATHS::GetUserCachePath(), and m_files.
Referenced by UpdateFontFiles().
| wxFileName EMBEDDED_FILES::GetTemporaryFileName | ( | EMBEDDED_FILE * | aFile | ) | const |
|
inline |
Definition at line 171 of file embedded_files.h.
Referenced by AddFile(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and PANEL_EMBEDDED_FILES::TransferDataFromWindow().
|
inline |
Definition at line 178 of file embedded_files.h.
References m_files.
Referenced by BOOST_AUTO_TEST_CASE(), LIB_SYMBOL::Flatten(), FootprintChainBridgingLength(), PCB_IO_KICAD_SEXPR::format(), PCB_IO_KICAD_SEXPR::format(), LIB_SYMBOL::GetDescription(), and API_HANDLER_SCH::handleGetCurrentVariant().
| EMBEDDED_FILES & EMBEDDED_FILES::operator= | ( | const EMBEDDED_FILES & | other | ) |
Definition at line 733 of file embedded_files.cpp.
References EMBEDDED_FILES(), m_embedFonts, m_fileAddedCallback, m_files, m_fontFiles, and name.
|
noexcept |
Definition at line 676 of file embedded_files.cpp.
References ClearEmbeddedFiles(), EMBEDDED_FILES(), m_embedFonts, m_fileAddedCallback, m_files, and m_fontFiles.
Referenced by FOOTPRINT::operator=(), FOOTPRINT::operator=(), and LIB_SYMBOL::operator=().
| void EMBEDDED_FILES::RemoveFile | ( | const wxString & | name, |
| bool | aErase = true ) |
Remove a file from the collection and frees the memory.
| aName | is the name of the file to remove. |
Definition at line 166 of file embedded_files.cpp.
Referenced by BOARD::ExchangeFootprint(), and PANEL_EMBEDDED_FILES::TransferDataFromWindow().
|
inlinevirtual |
Provide access to nested embedded files, such as symbols in schematics and footprints in boards.
Reimplemented in BOARD, and SCHEMATIC.
Definition at line 187 of file embedded_files.h.
References EMBEDDED_FILES().
|
inlinestatic |
Definition at line 293 of file embedded_files.h.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), CompressAndEncode(), ComputeFileHash(), SYMBOL_EMBEDDED_FILES_TEST_FIXTURE::CreateTestEmbeddedFile(), DecompressAndDecode(), and EMBEDDED_FILES::EMBEDDED_FILE::Validate().
|
inline |
Definition at line 283 of file embedded_files.h.
References m_embedFonts.
Referenced by ORCAD_CONVERTER::applyFont(), LIB_SYMBOL::Deserialize(), SCH_IO_KICAD_SEXPR_PARSER::ParseSchematic(), LIB_BUFFER::SaveBuffer(), and SYMBOL_LIBRARY_MANAGER::SaveLibrary().
|
inline |
Definition at line 96 of file embedded_files.h.
References m_fileAddedCallback.
Referenced by LIB_BUFFER::SaveBuffer(), and SYMBOL_LIBRARY_MANAGER::SaveLibrary().
| const std::vector< wxString > * EMBEDDED_FILES::UpdateFontFiles | ( | ) |
Helper function to get a list of fonts for fontconfig to add to the library.
This is necessary because EMBEDDED_FILES lives in common at the moment and fontconfig is in libkicommon. This will create the cache files in the KiCad cache directory (if they do not already exist) and return the temp files names
Definition at line 650 of file embedded_files.cpp.
References EMBEDDED_FILES::EMBEDDED_FILE::FONT, GetTemporaryFileName(), m_files, m_fontFiles, and name.
Referenced by ORCAD_CONVERTER::applyFont(), SCH_SCREEN::FixupEmbeddedData(), PCB_IO_KICAD_SEXPR_PARSER::Parse(), and SCH_IO_KICAD_SEXPR_PARSER::ParseSymbol().
| void EMBEDDED_FILES::WriteEmbeddedFiles | ( | OUTPUTFORMATTER & | aOut, |
| bool | aWriteData ) const |
Output formatter for the embedded files.
| aOut | is the output formatter. |
| aWriteData | is true if the actual data should be written. This is false when writing an element that is already embedded in a file that itself has embedded files (boards, schematics, etc.). |
Definition at line 210 of file embedded_files.cpp.
References EMBEDDED_FILES::EMBEDDED_FILE::compressedEncodedData, EMBEDDED_FILES::EMBEDDED_FILE::data_hash, EMBEDDED_FILES::EMBEDDED_FILE::DATASHEET, EMBEDDED_FILES::EMBEDDED_FILE::FONT, m_files, MIME_BASE64_LENGTH, EMBEDDED_FILES::EMBEDDED_FILE::MODEL, EMBEDDED_FILES::EMBEDDED_FILE::name, name, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), EMBEDDED_FILES::EMBEDDED_FILE::type, and EMBEDDED_FILES::EMBEDDED_FILE::WORKSHEET.
Referenced by PCB_IO_KICAD_SEXPR::format(), PCB_IO_KICAD_SEXPR::format(), and SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol().
|
protected |
If set, fonts will be embedded in the element on save.
Otherwise, font files embedded in the element will be removed on save.
Definition at line 307 of file embedded_files.h.
Referenced by EMBEDDED_FILES(), EMBEDDED_FILES(), FOOTPRINT::FOOTPRINT(), FOOTPRINT::FOOTPRINT(), GetAreFontsEmbedded(), operator=(), operator=(), and SetAreFontsEmbedded().
|
private |
Definition at line 304 of file embedded_files.h.
Referenced by AddFile(), AddFile(), EMBEDDED_FILES(), EMBEDDED_FILES(), GetFileAddedCallback(), operator=(), operator=(), and SetFileAddedCallback().
|
private |
Definition at line 302 of file embedded_files.h.
Referenced by AddFile(), AddFile(), AssignSharedFrom(), ClearEmbeddedFiles(), ClearEmbeddedFonts(), EMBEDDED_FILES(), EMBEDDED_FILES(), EmbeddedFileMap(), GetEmbeddedFile(), GetTemporaryFileName(), HasFile(), IsEmpty(), operator=(), operator=(), RemoveFile(), UpdateFontFiles(), and WriteEmbeddedFiles().
|
private |
Definition at line 303 of file embedded_files.h.
Referenced by EMBEDDED_FILES(), EMBEDDED_FILES(), GetFontFiles(), operator=(), operator=(), and UpdateFontFiles().