mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-05 09:07:39 +00:00
Merge branch 'main' into feature/cache_profiles_and_optimize_loading_speed
This commit is contained in:
@@ -39,6 +39,8 @@
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include <boost/property_tree/ini_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
@@ -534,6 +536,39 @@ std::string Preset::get_type_string(Preset::Type type)
|
||||
}
|
||||
}
|
||||
|
||||
std::string generate_preset_setting_id(const std::string& vendor, const std::string& type, const std::string& name)
|
||||
{
|
||||
if (vendor.empty() || name.empty())
|
||||
return "";
|
||||
|
||||
// Dedicated namespace for preset setting_ids, distinct from the cloud per-user
|
||||
// namespace (OrcaCloudServiceAgent). Keep in sync with scripts/assign_vendor_setting_ids.py;
|
||||
// never change this constant.
|
||||
static const boost::uuids::uuid vendor_namespace =
|
||||
boost::uuids::string_generator()("c1f4d9e2-7a3b-5c8d-9e0f-1a2b3c4d5e6f");
|
||||
|
||||
boost::uuids::name_generator_sha1 gen(vendor_namespace);
|
||||
boost::uuids::uuid id = gen(vendor + "/" + type + "/" + name);
|
||||
|
||||
// Render the low 16 base62 digits of the 128-bit id, most-significant first.
|
||||
// Implemented as long-division over the 16 raw (big-endian) bytes so it stays
|
||||
// portable (no __int128, which MSVC lacks) and matches the Python reference.
|
||||
static const char ALPHABET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
unsigned char bytes[16];
|
||||
std::copy(id.begin(), id.end(), bytes);
|
||||
char out[16];
|
||||
for (int pos = 15; pos >= 0; --pos) {
|
||||
unsigned int rem = 0;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
unsigned int cur = (rem << 8) | bytes[i];
|
||||
bytes[i] = static_cast<unsigned char>(cur / 62);
|
||||
rem = cur % 62;
|
||||
}
|
||||
out[pos] = ALPHABET[rem];
|
||||
}
|
||||
return std::string(out, 16);
|
||||
}
|
||||
|
||||
std::string Preset::get_iot_type_string(Preset::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
@@ -1319,7 +1354,7 @@ static std::vector<std::string> s_Preset_filament_options {/*"filament_colour",
|
||||
"filament_loading_speed", "filament_loading_speed_start",
|
||||
"filament_unloading_speed", "filament_unloading_speed_start", "filament_toolchange_delay", "filament_cooling_moves", "filament_stamping_loading_speed", "filament_stamping_distance",
|
||||
"filament_cooling_initial_speed", "filament_cooling_final_speed", "filament_ramming_parameters",
|
||||
"filament_multitool_ramming", "filament_multitool_ramming_volume", "filament_multitool_ramming_flow", "activate_chamber_temp_control",
|
||||
"filament_multitool_ramming", "filament_multitool_ramming_volume", "filament_multitool_ramming_flow", "activate_chamber_temp_control", "chamber_minimal_temperature",
|
||||
"filament_long_retractions_when_cut","filament_retraction_distances_when_cut", "idle_temperature",
|
||||
//BBS filament change length while the extruder color
|
||||
"filament_change_length","filament_flush_volumetric_speed","filament_flush_temp", "filament_cooling_before_tower",
|
||||
@@ -1652,6 +1687,7 @@ void PresetCollection::load_presets(
|
||||
std::string inherits_value = option_str->value;
|
||||
// Orca: try to find if the parent preset has been renamed
|
||||
inherit_preset = this->find_preset2(inherits_value);
|
||||
Preset::normalize_inherits(config, inherit_preset);
|
||||
} else {
|
||||
;
|
||||
}
|
||||
@@ -1904,6 +1940,7 @@ void PresetCollection::load_project_embedded_presets(std::vector<Preset*>& proje
|
||||
option_str->value = inherits_value;
|
||||
}*/
|
||||
inherit_preset = this->find_preset2(inherits_value, true);
|
||||
Preset::normalize_inherits(config, inherit_preset);
|
||||
}
|
||||
const Preset& default_preset = this->default_preset_for(config);
|
||||
if (inherit_preset) {
|
||||
@@ -2211,11 +2248,12 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
|
||||
const auto inherits_iter = preset_values.find(BBL_JSON_KEY_INHERITS);
|
||||
const bool preset_inherits_from_parent = inherits_iter != preset_values.end() && !inherits_iter->second.empty();
|
||||
if (preset_inherits_from_parent) {
|
||||
// This indicates that there is inherits exists but there is no base_id
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__
|
||||
<< boost::format("can not find base_id, not loading for user preset %1%") % canonical_name;
|
||||
unlock();
|
||||
return false;
|
||||
// No base_id stored although the preset inherits from a parent. Rather than
|
||||
// dropping the preset, derive base_id on the fly from the resolved parent's
|
||||
// setting_id below (the parent is found by its "inherits" name). Only the
|
||||
// genuinely unresolvable-parent case is skipped, further down.
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__
|
||||
<< boost::format("no base_id for user preset %1%, will derive it from the parent") % canonical_name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2239,10 +2277,16 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
|
||||
ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
|
||||
std::string inherits_value = option_str->value;
|
||||
inherit_preset = this->find_preset2(inherits_value, true);
|
||||
Preset::normalize_inherits(cloud_config, inherit_preset);
|
||||
}
|
||||
const Preset& default_preset = this->default_preset_for(cloud_config);
|
||||
if (inherit_preset) {
|
||||
new_config = inherit_preset->config;
|
||||
// Derive base_id from the resolved parent when it was not supplied. The
|
||||
// parent's setting_id is itself computed deterministically at load time, so
|
||||
// this stays stable. Does not affect the preset's own (cloud) setting_id.
|
||||
if (based_id.empty())
|
||||
based_id = inherit_preset->setting_id;
|
||||
if (cloud_filament_id == "null") {
|
||||
cloud_filament_id = inherit_preset->filament_id;
|
||||
}
|
||||
@@ -2648,7 +2692,10 @@ std::pair<Preset*, bool> PresetCollection::load_external_preset(
|
||||
preset.filament_id = filament_id;
|
||||
else {
|
||||
if (!inherits.empty()) {
|
||||
Preset *parent = this->find_preset(inherits, false, true);
|
||||
// Orca: resolve via find_preset2 so a renamed/removed-and-matched parent still
|
||||
// yields its filament_id (external presets store a full config, so the dangling
|
||||
// "inherits" itself is normalized on the next load_presets pass).
|
||||
Preset *parent = this->find_preset2(inherits, true);
|
||||
if (parent)
|
||||
preset.filament_id = parent->filament_id;
|
||||
}
|
||||
@@ -2912,10 +2959,14 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det
|
||||
//BBS: only save difference for user preset
|
||||
Preset* parent_preset = nullptr;
|
||||
if (!final_inherits.empty()) {
|
||||
parent_preset = this->find_preset(final_inherits, false, true);
|
||||
if (parent_preset && this->get_selected_preset().base_id.empty()) {
|
||||
this->get_selected_preset().base_id = parent_preset->setting_id;
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " base_id: " << parent_preset->setting_id;
|
||||
parent_preset = this->find_preset2(final_inherits, true);
|
||||
if (parent_preset) {
|
||||
// Orca: take the saved diff against the resolved parent (renamed / library-matched).
|
||||
Preset::normalize_inherits(this->get_selected_preset().config, parent_preset);
|
||||
if (this->get_selected_preset().base_id.empty()) {
|
||||
this->get_selected_preset().base_id = parent_preset->setting_id;
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " base_id: " << parent_preset->setting_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parent_preset)
|
||||
@@ -3006,6 +3057,25 @@ void PresetCollection::check_and_fix_syncinfo(Preset& preset, const std::string&
|
||||
preset.updated_time = 0;
|
||||
preset.sync_info = "create";
|
||||
preset.save_info();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto inherits = Preset::inherits(preset.config);
|
||||
Preset* parent = find_preset2(inherits, true);
|
||||
if (!inherits.empty() && parent) {
|
||||
const std::string expected = parent->setting_id;
|
||||
if (expected.empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Direct parent of " << preset.name << " does not have a setting_id";
|
||||
return;
|
||||
}
|
||||
// Reconcile a missing or stale base_id against the direct parent's setting_id.
|
||||
if (preset.base_id != expected) {
|
||||
preset.base_id = expected;
|
||||
// Already-synced preset whose base changed -> re-push it.
|
||||
if (!preset.setting_id.empty() && preset.sync_info.empty())
|
||||
preset.sync_info = "update";
|
||||
preset.save_info();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3027,14 +3097,8 @@ const Preset* PresetCollection::get_selected_preset_parent() const
|
||||
return nullptr;
|
||||
preset = &this->default_preset(m_type == Preset::Type::TYPE_PRINTER && edited_preset.printer_technology() == ptSLA ? 1 : 0);
|
||||
} else
|
||||
// find_preset() already resolves "renamed_from" internally.
|
||||
preset = this->find_preset(inherits, false);
|
||||
if (preset == nullptr) {
|
||||
// Resolve the "renamed_from" field.
|
||||
assert(! inherits.empty());
|
||||
auto it = this->find_preset_renamed(inherits);
|
||||
if (it != m_presets.end())
|
||||
preset = &(*it);
|
||||
}
|
||||
//BBS: add project embedded preset logic and refine is_external
|
||||
return (preset == nullptr/* || preset->is_default || preset->is_external*/) ? nullptr : preset;
|
||||
//return (preset == nullptr/* || preset->is_default*/ || preset->is_external) ? nullptr : preset;
|
||||
@@ -3046,12 +3110,8 @@ const Preset* PresetCollection::get_preset_parent(const Preset& child) const
|
||||
if (inherits.empty())
|
||||
// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
|
||||
return nullptr;
|
||||
// find_preset() already resolves "renamed_from" internally.
|
||||
const Preset* preset = this->find_preset(inherits, false);
|
||||
if (preset == nullptr) {
|
||||
auto it = this->find_preset_renamed(inherits);
|
||||
if (it != m_presets.end())
|
||||
preset = &(*it);
|
||||
}
|
||||
return
|
||||
// not found
|
||||
(preset == nullptr/* || preset->is_default */||
|
||||
@@ -3150,6 +3210,14 @@ Preset* PresetCollection::find_preset(const std::string &name, bool first_visibl
|
||||
auto it = this->find_preset_internal(canonical, only_from_library);
|
||||
if (it != m_presets.end() && it->name == canonical)
|
||||
return &this->preset(it - m_presets.begin(), real);
|
||||
// Resolve the "renamed_from" field: a system preset may have been renamed (e.g. by a
|
||||
// vendor profile sync), which records its old name in "renamed_from". Try the rename
|
||||
// map before the first-visible fallback so every caller - including those passing
|
||||
// real/only_from_library or first_visible_if_not_found - resolves to the renamed preset
|
||||
// rather than a mismatched one. Recursion follows multi-step renames (A->B->C) and
|
||||
// terminates as soon as a name resolves or has no further rename entry.
|
||||
if (const std::string* renamed = get_preset_name_renamed(name))
|
||||
return find_preset(*renamed, first_visible_if_not_found, real, only_from_library);
|
||||
return first_visible_if_not_found ? &this->first_visible() : nullptr;
|
||||
}
|
||||
|
||||
@@ -3157,14 +3225,11 @@ Preset* PresetCollection::find_preset2(const std::string& name, bool auto_match/
|
||||
{
|
||||
auto preset = find_preset(name, false, true);
|
||||
if (preset == nullptr) {
|
||||
auto _name = get_preset_name_renamed(name);
|
||||
if (_name != nullptr)
|
||||
preset = find_preset(*_name, false, true);
|
||||
if (auto_match && preset == nullptr) {
|
||||
if (auto_match) {
|
||||
//Orca: one more try, find the most likely preset in OrcaFilamentLibrary
|
||||
if (name.find("Generic") != std::string::npos) {
|
||||
// The regex pattern matches an optional prefix ending in '_' then "Generic" followed by the material name.
|
||||
std::regex re(R"(^(?:.*?\b(?:\w+_)?)(Generic)\b\s+([^@]+?)\s*(?:@.*)?$)");
|
||||
static const std::regex re(R"(^(?:.*?\b(?:\w+_)?)(Generic)\b\s+([^@]+?)\s*(?:@.*)?$)");
|
||||
auto alter_name = std::regex_replace(name, re, "Generic $2 @System");
|
||||
preset = find_preset2(alter_name, false);
|
||||
// print preset file name
|
||||
|
||||
Reference in New Issue
Block a user