diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 053c99dffd..a888d4aaae 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -150,6 +150,17 @@ Semver get_version_from_json(std::string file_path) } } +std::string get_vendor_cache_key(const std::string& json_path) +{ + const Semver ver = get_version_from_json(json_path); + if (ver.valid()) + return ver.to_string(); + // No version field — use mtime as change fingerprint so edits invalidate the cache. + boost::system::error_code ec; + const std::time_t mtime = boost::filesystem::last_write_time(json_path, ec); + return ec ? std::string{} : ("mtime:" + std::to_string(mtime)); +} + //BBS: add a function to load the key-values from xxx.json int get_values_from_json(std::string file_path, std::vector& keys, std::map& key_values) { diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index e0d3a52a28..8fd582882a 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -16,6 +16,14 @@ #include "Semver.hpp" #include "ProjectTask.hpp" +#include +#include +#include +#include +#include +#include +#include + //BBS: change system directories #define PRESET_SYSTEM_DIR "system" #define PRESET_USER_DIR "user" @@ -103,6 +111,10 @@ extern Semver get_version_from_json(std::string file_path); //BBS: add a function to load the key-values from xxx.json extern int get_values_from_json(std::string file_path, std::vector& keys, std::map& key_values); +// Returns the cache key for a vendor JSON: the Semver string for versioned +// vendors, or "mtime:" for vendors without a version field. +extern std::string get_vendor_cache_key(const std::string& json_path); + extern ConfigFileType guess_config_file_type(const boost::property_tree::ptree &tree); extern void extend_default_config_length(DynamicPrintConfig& config, const bool set_nil_to_default, const DynamicPrintConfig& defaults); @@ -120,6 +132,9 @@ public: PrinterVariant() {} PrinterVariant(const std::string &name) : name(name) {} std::string name; + + template + void serialize(Archive& ar) { ar(name); } }; struct PrinterModel { @@ -150,6 +165,15 @@ public: } const PrinterVariant* variant(const std::string &name) const { return const_cast(this)->variant(name); } + + template + void serialize(Archive& ar) + { + ar(id, name, model_id, family, technology, variants, default_materials, + not_support_bed_types, bed_model, bed_texture, image_bed_type, + bottom_texture_end_name, use_double_extruder_default_texture, + bottom_texture_rect, middle_texture_rect, hotend_model); + } }; std::vector models; @@ -161,6 +185,13 @@ public: bool valid() const { return ! name.empty() && ! id.empty() && config_version.valid(); } + template + void serialize(Archive& ar) + { + ar(id, name, config_version, config_update_url, changelog_url, + models, default_filaments, default_sla_materials); + } + // Load VendorProfile from an ini file. // If `load_all` is false, only the header with basic info (name, version, URLs) is loaded. static VendorProfile from_ini(const boost::filesystem::path &path, bool load_all=true); @@ -394,12 +425,25 @@ public: // BBS: move constructor to public Preset(Type type, const std::string &name, bool is_default = false) : type(type), is_default(is_default), name(name) {} - -protected: + // Default constructor is public so cereal can default-construct elements when + // deserializing std::vector (std::allocator is not a cereal::access friend). Preset() = default; +protected: friend class PresetCollection; friend class PresetBundle; + friend class cereal::access; + + // Serializes the fields needed to reconstruct a system preset from a binary cache. + // The vendor pointer is NOT serialized — apply() reconstructs it from VendorCache::profile.id. + template + void serialize(Archive& ar) + { + ar(type, name, alias, file, version, + filament_id, setting_id, description, + renamed_from, is_system, is_visible, + m_from_orca_filament_lib, config); + } }; bool is_compatible_with_print (const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer); diff --git a/src/libslic3r/Semver.hpp b/src/libslic3r/Semver.hpp index 4d64b1c7db..a8a46a0d67 100644 --- a/src/libslic3r/Semver.hpp +++ b/src/libslic3r/Semver.hpp @@ -190,6 +190,15 @@ public: os << self.to_string(); return os; } + + // cereal: round-trip through the string representation + template + std::string save_minimal(const Archive&) const { return to_string(); } + template + void load_minimal(const Archive&, const std::string& s) { + if (auto v = Semver::parse(s)) *this = std::move(*v); + } + private: semver_t ver;