OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
anonymous_namespace{profile_include_dump.cpp} Namespace Reference

Classes

struct  Entry

Typedefs

using Sections = std::map<std::string, std::map<std::string, Entry>>

Functions

json read_json (const fs::path &path)
Sections read_vendor (const fs::path &dir, const std::string &vendor)
const PresetCollection & presets_of (const PresetBundle &bundle, const std::string &section)
size_t dump (const PresetBundle &bundle, const Sections &sections, std::ostream &out)
void load_vendor (PresetBundle &bundle, const std::string &dir, const std::string &vendor, bool from_cache)

Class Documentation

◆ anonymous_namespace{profile_include_dump.cpp}::Entry

struct anonymous_namespace{profile_include_dump.cpp}::Entry
Collaboration diagram for anonymous_namespace{profile_include_dump.cpp}::Entry:
Class Members
vector< string > includes
string inherits
vector< string > keys

Typedef Documentation

◆ Sections

using anonymous_namespace{profile_include_dump.cpp}::Sections = std::map<std::string, std::map<std::string, Entry>>

Function Documentation

◆ dump()

size_t anonymous_namespace{profile_include_dump.cpp}::dump ( const PresetBundle & bundle,
const Sections & sections,
std::ostream & out )
97{
98 size_t dumped = 0;
99 for (const auto &[section, entries] : sections) {
100 std::vector<const Preset *> presets;
101 for (const Preset &preset : presets_of(bundle, section).get_presets())
102 if (preset.is_system)
103 presets.push_back(&preset);
104 std::sort(presets.begin(), presets.end(), [](const Preset *a, const Preset *b) { return a->name < b->name; });
105 for (const Preset *preset : presets) {
106 // The preset and its ancestors, root first: the order their includes apply in.
107 std::vector<const Entry *> lineage;
108 for (auto it = entries.find(preset->name); it != entries.end() && lineage.size() <= entries.size();
109 it = entries.find(it->second.inherits))
110 lineage.insert(lineage.begin(), &it->second);
111 std::string templates;
112 std::set<std::string> keys;
113 for (const Entry *entry : lineage)
114 for (const std::string &name : entry->includes) {
115 templates += (templates.empty() ? "" : "; ") + name;
116 if (const auto it = entries.find(name); it != entries.end())
117 keys.insert(it->second.keys.begin(), it->second.keys.end());
118 }
119 if (templates.empty())
120 continue;
121 const std::string prefix = section.substr(0, section.find('_')) + " | " + preset->name + " | ";
122 out << prefix << "include = " << templates << "\n";
123 for (const std::string &key : keys)
124 out << prefix << key << " = " << (preset->config.has(key) ? preset->config.opt_serialize(key) : "<absent>") << "\n";
125 ++dumped;
126 }
127 }
128 return dumped;
129}
Definition Preset.hpp:241
const PresetCollection & presets_of(const PresetBundle &bundle, const std::string &section)
Definition profile_include_dump.cpp:87
Definition profile_include_dump.cpp:39

References dump(), and presets_of().

Referenced by dump(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_vendor()

void anonymous_namespace{profile_include_dump.cpp}::load_vendor ( PresetBundle & bundle,
const std::string & dir,
const std::string & vendor,
bool from_cache )
135{
136 const auto rule = ForwardCompatibilitySubstitutionRule::EnableSilent;
137 PresetBundle library;
138 const PresetBundle *base = nullptr;
139 if (fs::is_regular_file(fs::path(dir) / (std::string(PresetBundle::ORCA_FILAMENT_LIBRARY) + ".json"))) {
141 base = &library;
142 }
143 if (!from_cache) {
144 bundle.load_vendor_configs_from_json(dir, vendor, PresetBundle::LoadSystem, rule, base, false);
145 return;
146 }
147 // Parse once to write <vendor>.opc beside the profile, then load that
148 // cache into a clean bundle. Any cache already there goes first, so that a
149 // failed write cannot leave it to be loaded; one that was not there before
150 // goes again afterwards.
151 const fs::path cache = fs::path(dir) / (vendor + ".opc");
152 const bool had_cache = fs::exists(cache);
153 fs::remove(cache);
154 PresetBundle parsed;
155 parsed.set_is_validation_mode(true); // parse the JSON: validation never serves a cache
156 parsed.set_generate_vendor_caches(true);
157 parsed.load_vendor_configs_from_json(dir, vendor, PresetBundle::LoadSystem, rule, base);
158 const bool loaded = bundle.load_vendor_cache(cache.string(), vendor, parsed.vendors.at(vendor).config_version, base);
159 if (!had_cache)
160 fs::remove(cache);
161 if (!loaded)
162 throw std::runtime_error("The preset cache " + cache.string() + " was not written or was rejected");
163}
Definition PresetBundle.hpp:210
bool load_vendor_cache(const std::string &cache_path, const std::string &expected_vendor_name, const Semver &expected_vendor_version, const PresetBundle *base_bundle=nullptr)
Definition PresetBundle.cpp:9102
void set_generate_vendor_caches(bool enable)
Definition PresetBundle.hpp:235
std::pair< PresetsConfigSubstitutions, size_t > load_vendor_configs_from_json(const std::string &dir, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule, const PresetBundle *base_bundle=nullptr, bool allow_cache=true)
Definition PresetBundle.cpp:7925
static const char * ORCA_FILAMENT_LIBRARY
Definition PresetBundle.hpp:690
@ LoadSystem
Definition PresetBundle.hpp:605
VendorMap vendors
Definition PresetBundle.hpp:525
void set_is_validation_mode(bool mode)
Definition PresetBundle.hpp:466

References Slic3r::EnableSilent, load_vendor(), Slic3r::PresetBundle::load_vendor_cache(), Slic3r::PresetBundle::load_vendor_configs_from_json(), Slic3r::PresetBundle::LoadSystem, Slic3r::PresetBundle::ORCA_FILAMENT_LIBRARY, Slic3r::PresetBundle::set_generate_vendor_caches(), Slic3r::PresetBundle::set_is_validation_mode(), and Slic3r::PresetBundle::vendors.

Referenced by load_vendor(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ presets_of()

const PresetCollection & anonymous_namespace{profile_include_dump.cpp}::presets_of ( const PresetBundle & bundle,
const std::string & section )
88{
89 if (section == "process_list")
90 return bundle.prints;
91 if (section == "filament_list")
92 return bundle.filaments;
93 return bundle.printers;
94}
PrinterPresetCollection printers
Definition PresetBundle.hpp:503
PresetCollection prints
Definition PresetBundle.hpp:497
PresetCollection filaments
Definition PresetBundle.hpp:499

References Slic3r::PresetBundle::filaments, presets_of(), Slic3r::PresetBundle::printers, and Slic3r::PresetBundle::prints.

Referenced by dump(), and presets_of().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_json()

json anonymous_namespace{profile_include_dump.cpp}::read_json ( const fs::path & path)
50{
51 boost::nowide::ifstream in(path.string());
52 if (!in)
53 throw std::runtime_error("Cannot read " + path.string());
54 return json::parse(in);
55}

References read_json().

Referenced by read_json(), and read_vendor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_vendor()

Sections anonymous_namespace{profile_include_dump.cpp}::read_vendor ( const fs::path & dir,
const std::string & vendor )
58{
59 // Keys that name and place a sub-file rather than set a value.
60 static const std::set<std::string> metadata = {"name", "type", "from", "instantiation", "inherits", "include"};
61 Sections sections;
62 const json index = read_json(dir / (vendor + ".json"));
63 for (const char *section : {"process_list", "filament_list", "machine_list"}) {
64 const auto list = index.find(section);
65 if (list == index.end())
66 continue;
67 for (const json &item : *list) {
68 const json file = read_json(dir / vendor / item.at("sub_path").get<std::string>());
69 // A file without a name goes by its name in the index.
70 Entry &entry = sections[section][file.value("name", item.at("name").get<std::string>())];
71 entry.inherits = file.value("inherits", "");
72 if (const auto include = file.find("include"); include != file.end()) {
73 if (include->is_string())
74 entry.includes.push_back(include->get<std::string>());
75 else
76 for (const json &name : *include)
77 entry.includes.push_back(name.get<std::string>());
78 }
79 for (auto it = file.begin(); it != file.end(); ++it)
80 if (metadata.count(it.key()) == 0)
81 entry.keys.push_back(it.key());
82 }
83 }
84 return sections;
85}
nlohmann::json json
Definition AssembleList.cpp:42
std::string inherits
Definition profile_include_dump.cpp:40
json read_json(const fs::path &path)
Definition profile_include_dump.cpp:49
std::map< std::string, std::map< std::string, Entry > > Sections
Definition profile_include_dump.cpp:47

References anonymous_namespace{profile_include_dump.cpp}::Entry::includes, anonymous_namespace{profile_include_dump.cpp}::Entry::inherits, anonymous_namespace{profile_include_dump.cpp}::Entry::keys, read_json(), and read_vendor().

Referenced by main(), and read_vendor().

Here is the call graph for this function:
Here is the caller graph for this function: