mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-20 21:27:52 -06:00
Storing and recovering the "compatible_printers_condition"
and "inherits" fields from / to the AMF/3MF/Config files. The "compatible_printers_condition" are collected over all active profiles (one print, possibly multiple filament, and one printer profile) into a single vector.
This commit is contained in:
parent
082ed95a94
commit
1175dc95f6
6 changed files with 128 additions and 41 deletions
|
@ -180,7 +180,7 @@ void Preset::normalize(DynamicPrintConfig &config)
|
|||
size_t n = (nozzle_diameter == nullptr) ? 1 : nozzle_diameter->values.size();
|
||||
const auto &defaults = FullPrintConfig::defaults();
|
||||
for (const std::string &key : Preset::filament_options()) {
|
||||
if (key == "compatible_printers")
|
||||
if (key == "compatible_printers" || key == "compatible_printers_condition" || key == "inherits")
|
||||
continue;
|
||||
auto *opt = config.option(key, false);
|
||||
assert(opt != nullptr);
|
||||
|
@ -234,12 +234,12 @@ std::string Preset::label() const
|
|||
|
||||
bool Preset::is_compatible_with_printer(const Preset &active_printer, const DynamicPrintConfig *extra_config) const
|
||||
{
|
||||
auto *condition = dynamic_cast<const ConfigOptionString*>(this->config.option("compatible_printers_condition"));
|
||||
auto *condition = dynamic_cast<const ConfigOptionStrings*>(this->config.option("compatible_printers_condition"));
|
||||
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(this->config.option("compatible_printers"));
|
||||
bool has_compatible_printers = compatible_printers != nullptr && ! compatible_printers->values.empty();
|
||||
if (! has_compatible_printers && condition != nullptr && ! condition->value.empty()) {
|
||||
if (! has_compatible_printers && condition != nullptr && ! condition->values.empty() && ! condition->values.front().empty()) {
|
||||
try {
|
||||
return PlaceholderParser::evaluate_boolean_expression(condition->value, active_printer.config, extra_config);
|
||||
return PlaceholderParser::evaluate_boolean_expression(condition->values.front(), active_printer.config, extra_config);
|
||||
} catch (const std::runtime_error &err) {
|
||||
//FIXME in case of an error, return "compatible with everything".
|
||||
printf("Preset::is_compatible_with_printer - parsing error of compatible_printers_condition %s:\n%s\n", active_printer.name.c_str(), err.what());
|
||||
|
@ -449,9 +449,8 @@ Preset& PresetCollection::load_external_preset(
|
|||
std::deque<Preset>::iterator it = original_name.empty() ? m_presets.end() : this->find_preset_internal(original_name);
|
||||
if (it != m_presets.end()) {
|
||||
t_config_option_keys diff = it->config.diff(cfg);
|
||||
//FIXME Following keys are either not updated in the preset (the *_settings_id),
|
||||
// or not stored into the AMF/3MF/Config file, therefore they will most likely not match.
|
||||
// Ignore these differences for now.
|
||||
// Following keys are used by the UI, not by the slicing core, therefore they are not important
|
||||
// when comparing profiles for equality. Ignore them.
|
||||
for (const char *key : { "compatible_printers", "compatible_printers_condition", "inherits",
|
||||
"print_settings_id", "filament_settings_id", "printer_settings_id",
|
||||
"printer_model", "printer_variant", "default_print_profile", "default_filament_profile" })
|
||||
|
@ -503,7 +502,10 @@ void PresetCollection::save_current_preset(const std::string &new_name)
|
|||
} else {
|
||||
// Creating a new preset.
|
||||
Preset &preset = *m_presets.insert(it, m_edited_preset);
|
||||
std::string &inherits = preset.config.opt_string("inherits", true);
|
||||
ConfigOptionStrings *opt_inherits = preset.config.option<ConfigOptionStrings>("inherits", true);
|
||||
if (opt_inherits->values.empty())
|
||||
opt_inherits->values.emplace_back(std::string());
|
||||
std::string &inherits = opt_inherits->values.front();
|
||||
std::string old_name = preset.name;
|
||||
preset.name = new_name;
|
||||
preset.file = this->path_from_name(new_name);
|
||||
|
@ -556,20 +558,20 @@ bool PresetCollection::load_bitmap_default(const std::string &file_name)
|
|||
|
||||
const Preset* PresetCollection::get_selected_preset_parent() const
|
||||
{
|
||||
auto *inherits = dynamic_cast<const ConfigOptionString*>(this->get_edited_preset().config.option("inherits"));
|
||||
if (inherits == nullptr || inherits->value.empty())
|
||||
return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr; // nullptr;
|
||||
const Preset* preset = this->find_preset(inherits->value, false);
|
||||
auto *inherits = dynamic_cast<const ConfigOptionStrings*>(this->get_edited_preset().config.option("inherits"));
|
||||
if (inherits == nullptr || inherits->values.empty() || inherits->values.front().empty())
|
||||
return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
|
||||
const Preset* preset = this->find_preset(inherits->values.front(), false);
|
||||
return (preset == nullptr || preset->is_default || preset->is_external) ? nullptr : preset;
|
||||
}
|
||||
|
||||
const Preset* PresetCollection::get_preset_parent(const Preset& child) const
|
||||
{
|
||||
auto *inherits = dynamic_cast<const ConfigOptionString*>(child.config.option("inherits"));
|
||||
if (inherits == nullptr || inherits->value.empty())
|
||||
auto *inherits = dynamic_cast<const ConfigOptionStrings*>(child.config.option("inherits"));
|
||||
if (inherits == nullptr || inherits->values.empty() || inherits->values.front().empty())
|
||||
// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
|
||||
return nullptr;
|
||||
const Preset* preset = this->find_preset(inherits->value, false);
|
||||
const Preset* preset = this->find_preset(inherits->values.front(), false);
|
||||
return (preset == nullptr/* || preset->is_default */|| preset->is_external) ? nullptr : preset;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue