mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-06-20 19:04:06 +00:00
Simplify code a bit more
This commit is contained in:
@@ -94,7 +94,7 @@ int main(int argc, char* argv[])
|
||||
const std::string ver_str = ver.valid() ? ver.to_string() : "";
|
||||
|
||||
const bool is_orca_lib = (vendor_name == PresetBundle::ORCA_FILAMENT_LIBRARY);
|
||||
Slic3r::VendorCache vc;
|
||||
Slic3r::PresetBundle::VendorCache vc;
|
||||
vc.capture(*preset_bundle, vendor_name, ver_str, is_orca_lib);
|
||||
|
||||
const std::string cache_path =
|
||||
@@ -102,7 +102,7 @@ int main(int argc, char* argv[])
|
||||
vc.save(cache_path);
|
||||
|
||||
// Verify the file was written and can be reloaded.
|
||||
Slic3r::VendorCache verify;
|
||||
Slic3r::PresetBundle::VendorCache verify;
|
||||
if (!verify.load(cache_path) || !verify.is_valid(ver_str)) {
|
||||
std::cerr << "WARNING: verification failed for " << cache_path << "\n";
|
||||
++failed;
|
||||
|
||||
@@ -13,7 +13,7 @@ static void print_bar(char c, int n) { std::cout << std::string(n, c) << "\n"; }
|
||||
|
||||
static void inspect_one(const std::string& path, const po::variables_map& vm)
|
||||
{
|
||||
Slic3r::VendorCache vc;
|
||||
Slic3r::PresetBundle::VendorCache vc;
|
||||
if (!vc.load(path)) {
|
||||
std::cerr << "Failed to load cache: " << path << "\n"
|
||||
<< " (wrong format version, truncated file, CRC mismatch, or not a .cache file)\n";
|
||||
|
||||
@@ -5716,8 +5716,8 @@ static void save_blob(const std::string& path, const T& obj)
|
||||
return;
|
||||
}
|
||||
CacheFileHeader hdr;
|
||||
hdr.magic = VendorCache::CACHE_MAGIC;
|
||||
hdr.version = VendorCache::CACHE_VERSION;
|
||||
hdr.magic = PresetBundle::VendorCache::CACHE_MAGIC;
|
||||
hdr.version = PresetBundle::VendorCache::CACHE_VERSION;
|
||||
hdr.data_size = static_cast<uint64_t>(blob.size());
|
||||
hdr.crc32 = crc.checksum();
|
||||
ofs.write(reinterpret_cast<const char*>(&hdr), sizeof(hdr));
|
||||
@@ -5737,7 +5737,7 @@ static bool load_blob(const std::string& path, T& obj)
|
||||
CacheFileHeader hdr;
|
||||
if (!ifs.read(reinterpret_cast<char*>(&hdr), sizeof(hdr)))
|
||||
return false;
|
||||
if (hdr.magic != VendorCache::CACHE_MAGIC || hdr.version != VendorCache::CACHE_VERSION)
|
||||
if (hdr.magic != PresetBundle::VendorCache::CACHE_MAGIC || hdr.version != PresetBundle::VendorCache::CACHE_VERSION)
|
||||
return false;
|
||||
if (hdr.data_size == 0 || hdr.data_size > 512u * 1024u * 1024u)
|
||||
return false;
|
||||
@@ -5762,29 +5762,29 @@ static bool load_blob(const std::string& path, T& obj)
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
std::string VendorCache::user_path(const std::string& vendor_id)
|
||||
std::string PresetBundle::VendorCache::user_path(const std::string& vendor_id)
|
||||
{
|
||||
return (boost::filesystem::path(data_dir()) / PRESET_SYSTEM_DIR / (vendor_id + ".cache"))
|
||||
.make_preferred().string();
|
||||
}
|
||||
|
||||
std::string VendorCache::bundled_path(const std::string& vendor_id)
|
||||
std::string PresetBundle::VendorCache::bundled_path(const std::string& vendor_id)
|
||||
{
|
||||
return (boost::filesystem::path(resources_dir()) / "profiles" / (vendor_id + ".cache"))
|
||||
.make_preferred().string();
|
||||
}
|
||||
|
||||
bool VendorCache::load(const std::string& path)
|
||||
bool PresetBundle::VendorCache::load(const std::string& path)
|
||||
{
|
||||
return load_blob(path, *this);
|
||||
}
|
||||
|
||||
void VendorCache::save(const std::string& path) const
|
||||
void PresetBundle::VendorCache::save(const std::string& path) const
|
||||
{
|
||||
save_blob(path, *this);
|
||||
}
|
||||
|
||||
void VendorCache::capture(const PresetBundle& bundle,
|
||||
void PresetBundle::VendorCache::capture(const PresetBundle& bundle,
|
||||
const std::string& vendor_id,
|
||||
const std::string& vendor_json_ver,
|
||||
bool capture_filament_maps)
|
||||
@@ -5819,7 +5819,7 @@ void VendorCache::capture(const PresetBundle& bundle,
|
||||
cm.family = model.family;
|
||||
cm.technology = static_cast<int>(model.technology);
|
||||
for (const auto& v : model.variants)
|
||||
cm.variants.push_back({v.name});
|
||||
cm.variants.push_back(v.name);
|
||||
cm.default_materials = model.default_materials;
|
||||
cm.not_support_bed_types = model.not_support_bed_types;
|
||||
cm.bed_model = model.bed_model;
|
||||
@@ -5875,7 +5875,7 @@ void VendorCache::capture(const PresetBundle& bundle,
|
||||
}
|
||||
}
|
||||
|
||||
void VendorCache::apply(PresetBundle& bundle) const
|
||||
void PresetBundle::VendorCache::apply(PresetBundle& bundle) const
|
||||
{
|
||||
// Restore vendor profile (additive — does not reset the bundle)
|
||||
{
|
||||
@@ -5895,7 +5895,7 @@ void VendorCache::apply(PresetBundle& bundle) const
|
||||
model.family = cm.family;
|
||||
model.technology = static_cast<PrinterTechnology>(cm.technology);
|
||||
for (const auto& v : cm.variants)
|
||||
model.variants.emplace_back(v.name);
|
||||
model.variants.emplace_back(v);
|
||||
model.default_materials = cm.default_materials;
|
||||
model.not_support_bed_types = cm.not_support_bed_types;
|
||||
model.bed_model = cm.bed_model;
|
||||
|
||||
@@ -154,130 +154,122 @@ struct PresetBundleMetadata
|
||||
}
|
||||
};
|
||||
|
||||
// ---- Per-vendor binary preset cache ----------------------------------------
|
||||
// One file per vendor:
|
||||
// Bundled (CI-generated): resources/profiles/<vendor_id>.cache
|
||||
// User (runtime): data_dir/system/<vendor_id>.cache
|
||||
|
||||
struct CachedPrinterVariant {
|
||||
std::string name;
|
||||
template<class Archive> void serialize(Archive& ar) { ar(name); }
|
||||
};
|
||||
|
||||
struct CachedPrinterModel {
|
||||
std::string id, name, model_id, family;
|
||||
int technology = 0;
|
||||
std::vector<CachedPrinterVariant> variants;
|
||||
std::vector<std::string> default_materials;
|
||||
std::vector<std::string> not_support_bed_types;
|
||||
std::string bed_model, bed_texture, image_bed_type;
|
||||
std::string bottom_texture_end_name, use_double_extruder_default_texture;
|
||||
std::string bottom_texture_rect, middle_texture_rect, hotend_model;
|
||||
|
||||
template<class Archive>
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
struct CachedVendorProfile {
|
||||
std::string id, name, config_version, config_update_url, changelog_url;
|
||||
std::vector<CachedPrinterModel> models;
|
||||
std::vector<std::string> default_filaments;
|
||||
std::vector<std::string> default_sla_materials;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar)
|
||||
{
|
||||
ar(id, name, config_version, config_update_url, changelog_url,
|
||||
models, default_filaments, default_sla_materials);
|
||||
}
|
||||
};
|
||||
|
||||
struct CachedPreset {
|
||||
int type = 0;
|
||||
std::string name, alias, file, version;
|
||||
std::string vendor_id;
|
||||
std::string filament_id, setting_id, description;
|
||||
std::string base_id, user_id, sync_info;
|
||||
long long updated_time = 0;
|
||||
std::vector<std::string> renamed_from;
|
||||
bool is_system = true;
|
||||
bool is_visible = true;
|
||||
bool m_from_orca_filament_lib = false;
|
||||
DynamicPrintConfig config;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar)
|
||||
{
|
||||
ar(type, name, alias, file, version, vendor_id, filament_id, setting_id,
|
||||
description, base_id, user_id, sync_info, updated_time, renamed_from,
|
||||
is_system, is_visible, m_from_orca_filament_lib, config);
|
||||
}
|
||||
};
|
||||
|
||||
struct VendorCache {
|
||||
static constexpr uint32_t CACHE_MAGIC = 0x4F52435A; // "ORCZ"
|
||||
static constexpr uint32_t CACHE_VERSION = 3;
|
||||
|
||||
uint32_t cache_version = CACHE_VERSION;
|
||||
size_t config_options_count = 0;
|
||||
std::string vendor_json_version; // Semver string, or "" for version-less vendors
|
||||
|
||||
CachedVendorProfile profile;
|
||||
std::vector<CachedPreset> print_presets;
|
||||
std::vector<CachedPreset> filament_presets;
|
||||
std::vector<CachedPreset> printer_presets;
|
||||
std::vector<CachedPreset> sla_print_presets;
|
||||
std::vector<CachedPreset> sla_material_presets;
|
||||
|
||||
// Only populated for the ORCA_FILAMENT_LIBRARY vendor.
|
||||
std::map<std::string, DynamicPrintConfig> config_maps;
|
||||
std::map<std::string, std::string> filament_id_maps;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar)
|
||||
{
|
||||
ar(cache_version, config_options_count, vendor_json_version,
|
||||
profile,
|
||||
print_presets, filament_presets, printer_presets,
|
||||
sla_print_presets, sla_material_presets,
|
||||
config_maps, filament_id_maps);
|
||||
}
|
||||
|
||||
// True when this cache entry is current and can be used without re-parsing JSON.
|
||||
bool is_valid(const std::string& current_vendor_json_version) const
|
||||
{
|
||||
return cache_version == CACHE_VERSION
|
||||
&& config_options_count == print_config_def.options.size()
|
||||
&& vendor_json_version == current_vendor_json_version;
|
||||
}
|
||||
|
||||
static std::string user_path(const std::string& vendor_id); // data_dir/system/<id>.cache
|
||||
static std::string bundled_path(const std::string& vendor_id); // resources/profiles/<id>.cache
|
||||
|
||||
bool load(const std::string& path);
|
||||
void save(const std::string& path) const;
|
||||
|
||||
// Capture one vendor's data from an already-loaded PresetBundle.
|
||||
// Set capture_filament_maps=true only for the ORCA_FILAMENT_LIBRARY vendor.
|
||||
void capture(const PresetBundle& bundle,
|
||||
const std::string& vendor_id,
|
||||
const std::string& vendor_json_version,
|
||||
bool capture_filament_maps);
|
||||
|
||||
// Apply this vendor's data into bundle (additive — does NOT reset the bundle).
|
||||
void apply(PresetBundle& bundle) const;
|
||||
};
|
||||
|
||||
// Bundle of Print + Filament + Printer presets.
|
||||
class PresetBundle
|
||||
{
|
||||
public:
|
||||
// ---- Per-vendor binary preset cache ------------------------------------
|
||||
// One file per vendor:
|
||||
// Bundled (CI-generated): resources/profiles/<vendor_id>.cache
|
||||
// User (runtime): data_dir/system/<vendor_id>.cache
|
||||
|
||||
struct CachedPrinterModel {
|
||||
std::string id, name, model_id, family;
|
||||
int technology = 0;
|
||||
std::vector<std::string> variants; // nozzle diameter strings
|
||||
std::vector<std::string> default_materials;
|
||||
std::vector<std::string> not_support_bed_types;
|
||||
std::string bed_model, bed_texture, image_bed_type;
|
||||
std::string bottom_texture_end_name, use_double_extruder_default_texture;
|
||||
std::string bottom_texture_rect, middle_texture_rect, hotend_model;
|
||||
|
||||
template<class Archive>
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
struct CachedVendorProfile {
|
||||
std::string id, name, config_version, config_update_url, changelog_url;
|
||||
std::vector<CachedPrinterModel> models;
|
||||
std::vector<std::string> default_filaments;
|
||||
std::vector<std::string> default_sla_materials;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar)
|
||||
{
|
||||
ar(id, name, config_version, config_update_url, changelog_url,
|
||||
models, default_filaments, default_sla_materials);
|
||||
}
|
||||
};
|
||||
|
||||
struct CachedPreset {
|
||||
int type = 0;
|
||||
std::string name, alias, file, version;
|
||||
std::string vendor_id;
|
||||
std::string filament_id, setting_id, description;
|
||||
std::string base_id, user_id, sync_info;
|
||||
long long updated_time = 0;
|
||||
std::vector<std::string> renamed_from;
|
||||
bool is_system = true;
|
||||
bool is_visible = true;
|
||||
bool m_from_orca_filament_lib = false;
|
||||
DynamicPrintConfig config;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar)
|
||||
{
|
||||
ar(type, name, alias, file, version, vendor_id, filament_id, setting_id,
|
||||
description, base_id, user_id, sync_info, updated_time, renamed_from,
|
||||
is_system, is_visible, m_from_orca_filament_lib, config);
|
||||
}
|
||||
};
|
||||
|
||||
struct VendorCache {
|
||||
static constexpr uint32_t CACHE_MAGIC = 0x4F52435A; // "ORCZ"
|
||||
static constexpr uint32_t CACHE_VERSION = 3;
|
||||
|
||||
uint32_t cache_version = CACHE_VERSION;
|
||||
size_t config_options_count = 0;
|
||||
std::string vendor_json_version; // Semver string, or "" for version-less vendors
|
||||
|
||||
CachedVendorProfile profile;
|
||||
std::vector<CachedPreset> print_presets;
|
||||
std::vector<CachedPreset> filament_presets;
|
||||
std::vector<CachedPreset> printer_presets;
|
||||
std::vector<CachedPreset> sla_print_presets;
|
||||
std::vector<CachedPreset> sla_material_presets;
|
||||
|
||||
// Only populated for the ORCA_FILAMENT_LIBRARY vendor.
|
||||
std::map<std::string, DynamicPrintConfig> config_maps;
|
||||
std::map<std::string, std::string> filament_id_maps;
|
||||
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar)
|
||||
{
|
||||
ar(cache_version, config_options_count, vendor_json_version,
|
||||
profile,
|
||||
print_presets, filament_presets, printer_presets,
|
||||
sla_print_presets, sla_material_presets,
|
||||
config_maps, filament_id_maps);
|
||||
}
|
||||
|
||||
bool is_valid(const std::string& current_vendor_json_version) const
|
||||
{
|
||||
return cache_version == CACHE_VERSION
|
||||
&& config_options_count == print_config_def.options.size()
|
||||
&& vendor_json_version == current_vendor_json_version;
|
||||
}
|
||||
|
||||
static std::string user_path(const std::string& vendor_id); // data_dir/system/<id>.cache
|
||||
static std::string bundled_path(const std::string& vendor_id); // resources/profiles/<id>.cache
|
||||
|
||||
bool load(const std::string& path);
|
||||
void save(const std::string& path) const;
|
||||
|
||||
void capture(const PresetBundle& bundle,
|
||||
const std::string& vendor_id,
|
||||
const std::string& vendor_json_version,
|
||||
bool capture_filament_maps);
|
||||
|
||||
void apply(PresetBundle& bundle) const;
|
||||
};
|
||||
|
||||
|
||||
static DynamicPrintConfig construct_full_config(Preset &in_printer_preset,
|
||||
Preset &in_print_preset,
|
||||
const DynamicPrintConfig &project_config,
|
||||
|
||||
@@ -1403,7 +1403,7 @@ bool GuideFrame::BuildProfileDataFromBundledCache()
|
||||
const Semver ver = get_version_from_json(json_path.string());
|
||||
const std::string ver_str = ver.valid() ? ver.to_string() : "";
|
||||
|
||||
VendorCache vc;
|
||||
PresetBundle::VendorCache vc;
|
||||
if (!vc.load(cache_path.string()) || !vc.is_valid(ver_str))
|
||||
continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user