Generate cache per vendor

This commit is contained in:
ExPikaPaka
2026-06-17 08:45:24 +02:00
committed by SoftFever
parent c12e348ce3
commit 5ad7a3eb5d
5 changed files with 159 additions and 108 deletions

View File

@@ -420,8 +420,10 @@ jobs:
shell: pwsh shell: pwsh
run: | run: |
$tool = Get-ChildItem -Recurse -Path build -Filter "generate_system_cache.exe" | Select-Object -First 1 $tool = Get-ChildItem -Recurse -Path build -Filter "generate_system_cache.exe" | Select-Object -First 1
if (-not $tool) { Write-Error "generate_system_cache.exe not found in build tree"; exit 1 }
$profiles = Get-ChildItem -Recurse -Path build -Directory -Filter profiles | $profiles = Get-ChildItem -Recurse -Path build -Directory -Filter profiles |
Where-Object { $_.FullName -match 'resources' } | Select-Object -First 1 Where-Object { $_.FullName -match 'resources' } | Select-Object -First 1
if (-not $profiles) { Write-Error "profiles directory not found in build tree"; exit 1 }
& $tool.FullName --path $profiles.FullName --log_level 2 & $tool.FullName --path $profiles.FullName --log_level 2
# NSIS is x86-only; it runs (and the installer it emits runs) under ARM64's # NSIS is x86-only; it runs (and the installer it emits runs) under ARM64's
@@ -576,12 +578,13 @@ jobs:
shell: bash shell: bash
run: | run: |
tool=$(find build -name generate_system_cache -type f | head -1) tool=$(find build -name generate_system_cache -type f | head -1)
if [ -z "$tool" ]; then echo "ERROR: generate_system_cache not found in build tree" >&2; exit 1; fi
"$tool" --path build/package/resources/profiles --log_level 2 "$tool" --path build/package/resources/profiles --log_level 2
# Re-pack the AppImage so the cache is included # Re-pack the AppImage so the per-vendor caches are included
appimage=$(find build -maxdepth 1 -name "OrcaSlicer_Linux_AppImage*.AppImage" | head -1) appimage=$(find build -maxdepth 1 -name "OrcaSlicer_Linux_AppImage*.AppImage" | head -1)
chmod +x "$appimage" chmod +x "$appimage"
"$appimage" --appimage-extract "$appimage" --appimage-extract
cp build/package/resources/profiles/system_presets_cache.cache squashfs-root/resources/profiles/ cp build/package/resources/profiles/*.cache squashfs-root/resources/profiles/
appimagetool=$(find build -name "appimagetool.AppImage" | head -1) appimagetool=$(find build -name "appimagetool.AppImage" | head -1)
ARCH=$(uname -m) "$appimagetool" --appimage-extract-and-run squashfs-root "$appimage" ARCH=$(uname -m) "$appimagetool" --appimage-extract-and-run squashfs-root "$appimage"
rm -rf squashfs-root rm -rf squashfs-root

View File

@@ -23,7 +23,7 @@ endif()
if (ORCA_TOOLS) if (ORCA_TOOLS)
set(_DEV_DEFS -DBOOST_ALL_NO_LIB -DBOOST_USE_WINAPI_VERSION=0x602 -DBOOST_SYSTEM_USE_UTF8) set(_DEV_DEFS -DBOOST_ALL_NO_LIB -DBOOST_USE_WINAPI_VERSION=0x602 -DBOOST_SYSTEM_USE_UTF8)
# generate_system_cache: pre-generates resources/profiles/system_presets_cache.cache for CI bundling. # generate_system_cache: pre-generates per-vendor resources/profiles/<id>.cache files for CI bundling.
add_executable(generate_system_cache generate_system_cache.cpp) add_executable(generate_system_cache generate_system_cache.cpp)
target_link_libraries(generate_system_cache libslic3r boost_headeronly) target_link_libraries(generate_system_cache libslic3r boost_headeronly)
target_compile_definitions(generate_system_cache PRIVATE ${_DEV_DEFS}) target_compile_definitions(generate_system_cache PRIVATE ${_DEV_DEFS})

View File

@@ -1,5 +1,5 @@
#include "libslic3r/PresetBundle.hpp" #include "libslic3r/PresetBundle.hpp"
#include "libslic3r/PresetBundleCache.hpp" #include "libslic3r/Preset.hpp"
#include "libslic3r/Utils.hpp" #include "libslic3r/Utils.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@@ -70,17 +70,59 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
const std::string cache_path = // Collect all vendor names from JSON files in the profiles directory.
(fs::path(profiles_path) / "system_presets_cache.cache").make_preferred().string(); std::vector<std::string> vendor_names;
for (const auto& e : fs::directory_iterator(profiles_path)) {
if (e.path().extension() == ".json")
vendor_names.push_back(e.path().stem().string());
}
PresetBundleCache::SystemPresetsCache cache; // Sort: PresetBundle::ORCA_FILAMENT_LIBRARY first, rest alphabetical.
cache.capture(*preset_bundle, profiles_path); std::sort(vendor_names.begin(), vendor_names.end(),
cache.save(cache_path); [](const std::string& a, const std::string& b) {
if (a == PresetBundle::ORCA_FILAMENT_LIBRARY) return true;
if (b == PresetBundle::ORCA_FILAMENT_LIBRARY) return false;
return a < b;
});
std::cout << "Cache written: " << cache_path << "\n" size_t total_print = 0, total_filament = 0, total_printer = 0;
<< " Vendor profiles: " << cache.vendor_profiles.size() << "\n" int saved = 0, failed = 0;
<< " Print presets: " << cache.print_presets.size() << "\n"
<< " Filament presets: " << cache.filament_presets.size() << "\n" for (const auto& vendor_name : vendor_names) {
<< " Printer presets: " << cache.printer_presets.size() << "\n"; const std::string json_path = (fs::path(profiles_path) / (vendor_name + ".json")).string();
return 0; const Semver ver = get_version_from_json(json_path);
const std::string ver_str = ver.valid() ? ver.to_string() : "";
const bool is_orca_lib = (vendor_name == PresetBundle::ORCA_FILAMENT_LIBRARY);
Slic3r::VendorCache vc;
vc.capture(*preset_bundle, vendor_name, ver_str, is_orca_lib);
const std::string cache_path =
(fs::path(profiles_path) / (vendor_name + ".cache")).make_preferred().string();
vc.save(cache_path);
// Verify the file was written and can be reloaded.
Slic3r::VendorCache verify;
if (!verify.load(cache_path) || !verify.is_valid(ver_str)) {
std::cerr << "WARNING: verification failed for " << cache_path << "\n";
++failed;
} else {
std::cout << " [ok] " << vendor_name << ".cache"
<< " (" << vc.print_presets.size() << " print, "
<< vc.filament_presets.size() << " filament, "
<< vc.printer_presets.size() << " printer)\n";
total_print += vc.print_presets.size();
total_filament += vc.filament_presets.size();
total_printer += vc.printer_presets.size();
++saved;
}
}
std::cout << "\nDone: " << saved << " cache(s) written";
if (failed) std::cout << ", " << failed << " FAILED";
std::cout << "\n"
<< " Total print presets: " << total_print << "\n"
<< " Total filament presets: " << total_filament << "\n"
<< " Total printer presets: " << total_printer << "\n";
return failed ? 1 : 0;
} }

View File

@@ -1,22 +1,106 @@
#include "libslic3r/PresetBundleCache.hpp" #include "libslic3r/PresetBundle.hpp"
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
using namespace Slic3r; using namespace Slic3r;
namespace fs = boost::filesystem;
namespace po = boost::program_options; namespace po = boost::program_options;
static void print_bar(char c, int n) { std::cout << std::string(n, c) << "\n"; } 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;
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";
return;
}
bool show_all = !vm.count("vendors") && !vm.count("models") &&
!vm.count("presets") && !vm.count("filaments") &&
!vm.count("printers") && !vm.count("process");
// ---- Summary ----
print_bar('=', 60);
std::cout << "Cache file : " << path << "\n";
std::cout << "Vendor : " << vc.profile.id << " v" << vc.profile.config_version << "\n";
std::cout << "JSON version: " << (vc.vendor_json_version.empty() ? "(none)" : vc.vendor_json_version) << "\n";
std::cout << "Cache ver : " << vc.cache_version << "\n";
std::cout << "Config opts : " << vc.config_options_count << "\n";
print_bar('-', 60);
std::cout << "Models : " << vc.profile.models.size() << "\n";
std::cout << "Printers : " << vc.printer_presets.size() << "\n";
std::cout << "Filaments : " << vc.filament_presets.size() << "\n";
std::cout << "Print proc : " << vc.print_presets.size() << "\n";
std::cout << "SLA print : " << vc.sla_print_presets.size() << "\n";
std::cout << "SLA material: " << vc.sla_material_presets.size() << "\n";
std::cout << "config_maps : " << vc.config_maps.size() << "\n";
std::cout << "filament_id_maps: " << vc.filament_id_maps.size() << "\n";
print_bar('=', 60);
// ---- Models ----
if (show_all || vm.count("vendors") || vm.count("models")) {
std::cout << "\nVENDOR PROFILE [" << vc.profile.id << "]\n";
print_bar('-', 60);
std::cout << " Name: " << vc.profile.name << "\n";
std::cout << " Config version: " << vc.profile.config_version << "\n";
if (vm.count("models") || show_all) {
for (const auto& m : vc.profile.models) {
std::cout << " " << std::left << std::setw(40) << m.name
<< " variants:" << m.variants.size() << "\n";
}
}
}
// ---- Printer presets ----
if (vm.count("presets") || vm.count("printers")) {
std::cout << "\nPRINTER PRESETS (" << vc.printer_presets.size() << ")\n";
print_bar('-', 60);
for (const auto& cp : vc.printer_presets) {
const auto* pm = cp.config.option<ConfigOptionString>("printer_model");
const auto* pv = cp.config.option<ConfigOptionString>("printer_variant");
std::cout << " " << std::left << std::setw(50) << cp.name
<< " model=" << (pm ? pm->value : "?")
<< " nozzle=" << (pv ? pv->value : "?")
<< (cp.is_visible ? "" : " [hidden]") << "\n";
}
}
// ---- Filament presets ----
if (vm.count("presets") || vm.count("filaments")) {
std::cout << "\nFILAMENT PRESETS (" << vc.filament_presets.size() << ")\n";
print_bar('-', 60);
for (const auto& cp : vc.filament_presets) {
const auto* fv = cp.config.option<ConfigOptionStrings>("filament_vendor");
const auto* ft = cp.config.option<ConfigOptionStrings>("filament_type");
std::cout << " " << std::left << std::setw(50) << cp.name
<< " vendor=" << (fv && !fv->values.empty() ? fv->values[0] : "?")
<< " type=" << (ft && !ft->values.empty() ? ft->values[0] : "?")
<< (cp.is_visible ? "" : " [hidden]") << "\n";
}
}
// ---- Print process presets ----
if (vm.count("presets") || vm.count("process")) {
std::cout << "\nPRINT PROCESS PRESETS (" << vc.print_presets.size() << ")\n";
print_bar('-', 60);
for (const auto& cp : vc.print_presets)
std::cout << " " << cp.name << (cp.is_visible ? "" : " [hidden]") << "\n";
}
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
po::options_description desc("OrcaSlicer Cache Inspector\nUsage"); po::options_description desc("OrcaSlicer Cache Inspector\nUsage");
desc.add_options() desc.add_options()
("help,h", "Show help") ("help,h", "Show help")
("path,p", po::value<std::string>(), "Path to .cache file (required)") ("path,p", po::value<std::string>(), "Path to a .cache file or a directory of .cache files (required)")
("vendors,V", "List all vendor IDs and versions") ("vendors,V", "Show vendor profile summary")
("models,m", "List all printer models per vendor") ("models,m", "List all printer models")
("presets,P", "List all preset names") ("presets,P", "List all preset names")
("filaments,f", "List filament presets") ("filaments,f", "List filament presets")
("printers,r", "List printer presets") ("printers,r", "List printer presets")
@@ -33,93 +117,17 @@ int main(int argc, char* argv[])
const std::string path = vm["path"].as<std::string>(); const std::string path = vm["path"].as<std::string>();
PresetBundleCache::SystemPresetsCache cache; if (fs::is_directory(path)) {
if (!cache.load(path)) { // Inspect all .cache files in the directory.
std::cerr << "Failed to load cache: " << path << "\n" std::vector<fs::path> files;
<< " (wrong format version, truncated file, or not a .cache file)\n"; for (const auto& e : fs::directory_iterator(path))
return 1; if (e.path().extension() == ".cache")
} files.push_back(e.path());
std::sort(files.begin(), files.end());
// ---- Summary ---- for (const auto& f : files)
print_bar('=', 60); inspect_one(f.string(), vm);
std::cout << "Cache file : " << path << "\n"; } else {
std::cout << "Format ver : " << cache.format_version << "\n"; inspect_one(path, vm);
std::cout << "Config opts: " << cache.config_options_count << "\n";
print_bar('-', 60);
std::cout << "Vendors : " << cache.vendor_versions.size() << "\n";
std::cout << "Models : ";
size_t total_models = 0;
for (const auto& vp : cache.vendor_profiles) total_models += vp.models.size();
std::cout << total_models << "\n";
std::cout << "Printers : " << cache.printer_presets.size() << "\n";
std::cout << "Filaments : " << cache.filament_presets.size() << "\n";
std::cout << "Print proc : " << cache.print_presets.size() << "\n";
std::cout << "config_maps: " << cache.config_maps.size() << "\n";
std::cout << "filament_id_maps: " << cache.filament_id_maps.size() << "\n";
print_bar('=', 60);
bool show_all = !vm.count("vendors") && !vm.count("models") &&
!vm.count("presets") && !vm.count("filaments") &&
!vm.count("printers") && !vm.count("process");
// ---- Vendor versions ----
if (show_all || vm.count("vendors")) {
std::cout << "\nVENDOR VERSIONS (" << cache.vendor_versions.size() << ")\n";
print_bar('-', 60);
for (const auto& [id, ver] : cache.vendor_versions)
std::cout << " " << std::left << std::setw(30) << id << " " << ver << "\n";
}
// ---- Models per vendor ----
if (show_all || vm.count("models")) {
std::cout << "\nVENDOR PROFILES & MODELS\n";
print_bar('-', 60);
for (const auto& vp : cache.vendor_profiles) {
std::cout << " [" << vp.id << "] v" << vp.config_version
<< " (" << vp.models.size() << " models)\n";
if (vm.count("models")) {
for (const auto& m : vp.models) {
std::cout << " " << std::left << std::setw(40) << m.name
<< " variants:" << m.variants.size() << "\n";
}
}
}
}
// ---- Printer presets ----
if (vm.count("presets") || vm.count("printers")) {
std::cout << "\nPRINTER PRESETS (" << cache.printer_presets.size() << ")\n";
print_bar('-', 60);
for (const auto& cp : cache.printer_presets) {
const auto* pm = cp.config.option<ConfigOptionString>("printer_model");
const auto* pv = cp.config.option<ConfigOptionString>("printer_variant");
std::cout << " " << std::left << std::setw(50) << cp.name
<< " model=" << (pm ? pm->value : "?")
<< " nozzle=" << (pv ? pv->value : "?")
<< (cp.is_visible ? "" : " [hidden]") << "\n";
}
}
// ---- Filament presets ----
if (vm.count("presets") || vm.count("filaments")) {
std::cout << "\nFILAMENT PRESETS (" << cache.filament_presets.size() << ")\n";
print_bar('-', 60);
for (const auto& cp : cache.filament_presets) {
const auto* fv = cp.config.option<ConfigOptionString>("filament_vendor");
const auto* ft = cp.config.option<ConfigOptionStrings>("filament_type");
std::cout << " " << std::left << std::setw(50) << cp.name
<< " vendor=" << (fv ? fv->value : "?")
<< " type=" << (ft && !ft->values.empty() ? ft->values[0] : "?")
<< (cp.is_visible ? "" : " [hidden]") << "\n";
}
}
// ---- Print process presets ----
if (vm.count("presets") || vm.count("process")) {
std::cout << "\nPRINT PROCESS PRESETS (" << cache.print_presets.size() << ")\n";
print_bar('-', 60);
for (const auto& cp : cache.print_presets)
std::cout << " " << cp.name << (cp.is_visible ? "" : " [hidden]") << "\n";
} }
return 0; return 0;

View File

@@ -346,8 +346,6 @@ set(lisbslic3r_sources
Polyline.hpp Polyline.hpp
PresetBundle.cpp PresetBundle.cpp
PresetBundle.hpp PresetBundle.hpp
PresetBundleCache.cpp
PresetBundleCache.hpp
Preset.cpp Preset.cpp
Preset.hpp Preset.hpp
PrincipalComponents2D.cpp PrincipalComponents2D.cpp