Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2019-12-05 16:48:11 +0300
committerbubnikv <bubnikv@gmail.com>2019-12-05 16:48:11 +0300
commitf80ed539a7977991f852bf263042fffda6cfd24c (patch)
treed7cd5d304485c0e74b3a4821692c30559c8de1f0 /src/slic3r/GUI/Preset.cpp
parent5e3e5492487690fb48cd7c4bb0b7e0e019e30a5c (diff)
System profiles and profiles derived from system profiles are now
compatible with the profiles of the same vendor only.
Diffstat (limited to 'src/slic3r/GUI/Preset.cpp')
-rw-r--r--src/slic3r/GUI/Preset.cpp78
1 files changed, 47 insertions, 31 deletions
diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp
index bb1e5478d..1c848b60f 100644
--- a/src/slic3r/GUI/Preset.cpp
+++ b/src/slic3r/GUI/Preset.cpp
@@ -303,60 +303,58 @@ std::string Preset::label() const
return this->name + (this->is_dirty ? g_suffix_modified : "");
}
-bool Preset::is_compatible_with_print(const Preset &active_print) const
+bool is_compatible_with_print(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print)
{
- auto &condition = this->compatible_prints_condition();
- auto *compatible_prints = dynamic_cast<const ConfigOptionStrings*>(this->config.option("compatible_prints"));
+ if (preset.vendor != nullptr && preset.vendor != active_print.vendor)
+ // The current profile has a vendor assigned and it is different from the active print's vendor.
+ return false;
+ auto &condition = preset.preset.compatible_prints_condition();
+ auto *compatible_prints = dynamic_cast<const ConfigOptionStrings*>(preset.preset.config.option("compatible_prints"));
bool has_compatible_prints = compatible_prints != nullptr && ! compatible_prints->values.empty();
if (! has_compatible_prints && ! condition.empty()) {
try {
- return PlaceholderParser::evaluate_boolean_expression(condition, active_print.config);
+ return PlaceholderParser::evaluate_boolean_expression(condition, active_print.preset.config);
} catch (const std::runtime_error &err) {
//FIXME in case of an error, return "compatible with everything".
- printf("Preset::is_compatible_with_print - parsing error of compatible_prints_condition %s:\n%s\n", active_print.name.c_str(), err.what());
+ printf("Preset::is_compatible_with_print - parsing error of compatible_prints_condition %s:\n%s\n", active_print.preset.name.c_str(), err.what());
return true;
}
}
- return this->is_default || active_print.name.empty() || ! has_compatible_prints ||
- std::find(compatible_prints->values.begin(), compatible_prints->values.end(), active_print.name) !=
+ return preset.preset.is_default || active_print.preset.name.empty() || ! has_compatible_prints ||
+ std::find(compatible_prints->values.begin(), compatible_prints->values.end(), active_print.preset.name) !=
compatible_prints->values.end();
}
-bool Preset::is_compatible_with_printer(const Preset &active_printer, const DynamicPrintConfig *extra_config) const
+bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer, const DynamicPrintConfig *extra_config)
{
- auto &condition = this->compatible_printers_condition();
- auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(this->config.option("compatible_printers"));
+ if (preset.vendor != nullptr && preset.vendor != active_printer.vendor)
+ // The current profile has a vendor assigned and it is different from the active print's vendor.
+ return false;
+ auto &condition = preset.preset.compatible_printers_condition();
+ auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(preset.preset.config.option("compatible_printers"));
bool has_compatible_printers = compatible_printers != nullptr && ! compatible_printers->values.empty();
if (! has_compatible_printers && ! condition.empty()) {
try {
- return PlaceholderParser::evaluate_boolean_expression(condition, active_printer.config, extra_config);
+ return PlaceholderParser::evaluate_boolean_expression(condition, active_printer.preset.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());
+ printf("Preset::is_compatible_with_printer - parsing error of compatible_printers_condition %s:\n%s\n", active_printer.preset.name.c_str(), err.what());
return true;
}
}
- return this->is_default || active_printer.name.empty() || ! has_compatible_printers ||
- std::find(compatible_printers->values.begin(), compatible_printers->values.end(), active_printer.name) !=
+ return preset.preset.is_default || active_printer.preset.name.empty() || ! has_compatible_printers ||
+ std::find(compatible_printers->values.begin(), compatible_printers->values.end(), active_printer.preset.name) !=
compatible_printers->values.end();
}
-bool Preset::is_compatible_with_printer(const Preset &active_printer) const
+bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer)
{
DynamicPrintConfig config;
- config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name));
- const ConfigOption *opt = active_printer.config.option("nozzle_diameter");
+ config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name));
+ const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter");
if (opt)
config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size()));
- return this->is_compatible_with_printer(active_printer, &config);
-}
-
-bool Preset::update_compatible(const Preset &active_printer, const DynamicPrintConfig *extra_config, const Preset *active_print)
-{
- this->is_compatible = is_compatible_with_printer(active_printer, extra_config);
- if (active_print != nullptr)
- this->is_compatible &= is_compatible_with_print(*active_print);
- return this->is_compatible;
+ return is_compatible_with_printer(preset, active_printer, &config);
}
void Preset::set_visible_from_appconfig(const AppConfig &app_config)
@@ -905,6 +903,21 @@ const Preset* PresetCollection::get_preset_parent(const Preset& child) const
return (preset == nullptr/* || preset->is_default */|| preset->is_external) ? nullptr : preset;
}
+// Return vendor of the first parent profile, for which the vendor is defined, or null if such profile does not exist.
+PresetWithVendorProfile PresetCollection::get_preset_with_vendor_profile(const Preset &preset) const
+{
+ const Preset *p = &preset;
+ const VendorProfile *v = nullptr;
+ do {
+ if (p->vendor != nullptr) {
+ v = p->vendor;
+ break;
+ }
+ p = this->get_preset_parent(*p);
+ } while (p != nullptr);
+ return PresetWithVendorProfile(preset, v);
+}
+
const std::string& PresetCollection::get_preset_name_by_alias(const std::string& alias) const
{
for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++i) {
@@ -956,19 +969,22 @@ void PresetCollection::set_default_suppressed(bool default_suppressed)
}
}
-size_t PresetCollection::update_compatible_internal(const Preset &active_printer, const Preset *active_print, bool unselect_if_incompatible)
+size_t PresetCollection::update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, bool unselect_if_incompatible)
{
DynamicPrintConfig config;
- config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name));
- const ConfigOption *opt = active_printer.config.option("nozzle_diameter");
+ config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name));
+ const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter");
if (opt)
config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size()));
for (size_t idx_preset = m_num_default_presets; idx_preset < m_presets.size(); ++ idx_preset) {
bool selected = idx_preset == m_idx_selected;
Preset &preset_selected = m_presets[idx_preset];
Preset &preset_edited = selected ? m_edited_preset : preset_selected;
- if (! preset_edited.update_compatible(active_printer, &config, active_print) &&
- selected && unselect_if_incompatible)
+ const PresetWithVendorProfile this_preset_with_vendor_profile = this->get_preset_with_vendor_profile(preset_edited);
+ preset_edited.is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config);
+ if (active_print != nullptr)
+ preset_edited.is_compatible &= is_compatible_with_print(this_preset_with_vendor_profile, *active_print);
+ if (! preset_edited.is_compatible && selected && unselect_if_incompatible)
m_idx_selected = -1;
if (selected)
preset_selected.is_compatible = preset_edited.is_compatible;