OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
generate_system_cache.cpp File Reference
#include "libslic3r/PresetBundle.hpp"
#include "libslic3r/Preset.hpp"
#include "libslic3r/Utils.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/directory.hpp>
#include <boost/log/trivial.hpp>
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/value_semantic.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/errors.hpp>
#include <exception>
#include <cstddef>
#include <iostream>
#include <memory>
#include "libslic3r/Config.hpp"
Include dependency graph for generate_system_cache.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )
26{
27 po::options_description desc("OrcaSlicer System Cache Generator\nUsage");
28 // clang-format off
29 desc.add_options()
30 ("help,h", "Show help")
31#ifdef __APPLE__
32 ("path,p", po::value<std::string>()->default_value("../../../../../../../resources/profiles"), "Path to profiles directory")
33#else
34 ("path,p", po::value<std::string>()->default_value("../../../resources/profiles"), "Path to profiles directory")
35#endif
36 ("log_level,l", po::value<int>()->default_value(2), "Log level (0=trace, 2=info, 4=error)")
37 ("vendor,v", po::value<std::string>()->default_value(""), "Vendor name. Optional; generate the cache for this vendor only (the Orca filament library is always included as the inheritance base). All vendors if not specified.");
38 // clang-format on
39
40 po::variables_map vm;
41 try {
42 po::store(po::parse_command_line(argc, argv, desc), vm);
43 if (vm.count("help")) { std::cout << desc << "\n"; return 0; }
44 po::notify(vm);
45 } catch (const po::error& e) {
46 std::cerr << "Error: " << e.what() << "\n" << desc << "\n";
47 return 1;
48 }
49
50 const std::string profiles_path = vm["path"].as<std::string>();
51 const int log_level = vm["log_level"].as<int>();
52 const std::string vendor = vm["vendor"].as<std::string>();
53
54 if (!fs::exists(profiles_path) || !fs::is_directory(profiles_path)) {
55 std::cerr << "Error: '" << profiles_path << "' is not a valid directory\n";
56 return 1;
57 }
58
59 set_logging_level(log_level);
60 set_data_dir(profiles_path);
61 set_resources_dir(fs::path(profiles_path).parent_path().make_preferred().string());
62
63 const fs::path user_dir = fs::path(data_dir()) / PRESET_USER_DIR;
64 if (!fs::exists(user_dir))
65 fs::create_directories(user_dir);
66
67 AppConfig app_config;
68 app_config.set("preset_folder", "default");
69
70 auto preset_bundle = std::make_unique<PresetBundle>();
71 preset_bundle->set_is_validation_mode(true);
72 preset_bundle->set_default_suppressed(true);
73 preset_bundle->set_generate_vendor_caches(true);
74 // Empty == every vendor. Otherwise only this vendor (plus the always-loaded
75 // Orca filament library) is parsed, so only its <vendor>.opc is written.
76 preset_bundle->set_vendor_to_validate(vendor);
77
78 std::cout << "Loading system presets from: " << profiles_path
79 << (vendor.empty() ? "" : " (vendor: " + vendor + ")") << "\n";
80
81 try {
82 // In validation mode data_dir() is the profiles directory set above, so the
83 // loader writes each <vendor>.opc next to its <vendor>.json as it parses it.
84 preset_bundle->load_presets(app_config, ForwardCompatibilitySubstitutionRule::EnableSilent);
85 } catch (const std::exception& ex) {
86 std::cerr << "Failed to load presets: " << ex.what() << "\n";
87 return 1;
88 }
89
90 // A specific vendor must have produced its own cache; the always-loaded
91 // filament library alone would otherwise mask a misspelt or removed name.
92 if (!vendor.empty() && !fs::exists(fs::path(profiles_path) / (vendor + ".opc"))) {
93 std::cerr << "No cache was generated for vendor '" << vendor << "' under " << profiles_path
94 << " - check the vendor name.\n";
95 return 1;
96 }
97
98 size_t cache_count = 0;
99 for (auto& entry : fs::directory_iterator(profiles_path))
100 if (boost::iends_with(entry.path().string(), ".opc"))
101 ++ cache_count;
102 if (cache_count == 0) {
103 std::cerr << "No vendor cache files were generated under " << profiles_path << "\n";
104 return 1;
105 }
106 std::cout << "Generated " << cache_count << " vendor cache file(s) under " << profiles_path << "\n";
107 return 0;
108}
#define PRESET_USER_DIR
Definition Preset.hpp:32
Definition AppConfig.hpp:100
void set(const std::string &section, const std::string &key, const std::string &value)
Definition AppConfig.hpp:167
void set_data_dir(const std::string &dir)
Definition utils.cpp:353
const std::string & data_dir()
Definition utils.cpp:365
void set_logging_level(unsigned int level)
Definition utils.cpp:171
void set_resources_dir(const std::string &dir)
Definition utils.cpp:291

References Slic3r::data_dir(), Slic3r::EnableSilent, PRESET_USER_DIR, Slic3r::AppConfig::set(), Slic3r::set_data_dir(), Slic3r::set_logging_level(), and Slic3r::set_resources_dir().

Here is the call graph for this function: