Adding the SLA printer profiles, WIP

This commit is contained in:
bubnikv 2018-08-01 11:09:51 +02:00
parent f0c1c15b62
commit 4e193555ae
8 changed files with 161 additions and 102 deletions

View File

@ -2135,6 +2135,15 @@ void PrintConfigDef::init_sla_params()
def->min = 0; def->min = 0;
def->default_value = new ConfigOptionFloats( { 1. , 1., 1. } ); def->default_value = new ConfigOptionFloats( { 1. , 1., 1. } );
def = this->add("material_notes", coString);
def->label = L("SLA print material notes");
def->tooltip = L("You can put your notes regarding the SLA print material here.");
def->cli = "material-notes=s";
def->multiline = true;
def->full_width = true;
def->height = 130;
def->default_value = new ConfigOptionString("");
def = this->add("default_sla_material_profile", coString); def = this->add("default_sla_material_profile", coString);
def->label = L("Default SLA material profile"); def->label = L("Default SLA material profile");
def->tooltip = L("Default print profile associated with the current printer profile. " def->tooltip = L("Default print profile associated with the current printer profile. "

View File

@ -265,8 +265,9 @@ bool Preset::is_compatible_with_printer(const Preset &active_printer) const
{ {
DynamicPrintConfig config; DynamicPrintConfig config;
config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name)); config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name));
config.set_key_value("num_extruders", new ConfigOptionInt( const ConfigOption *opt = active_printer.config.option("nozzle_diameter");
(int)static_cast<const ConfigOptionFloats*>(active_printer.config.option("nozzle_diameter"))->values.size())); 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); return this->is_compatible_with_printer(active_printer, &config);
} }
@ -373,6 +374,7 @@ const std::vector<std::string>& Preset::sla_printer_options()
"bed_shape", "max_print_height", "bed_shape", "max_print_height",
"display_width", "display_height", "display_pixels_x", "display_pixels_y", "display_width", "display_height", "display_pixels_x", "display_pixels_y",
"printer_correction", "printer_correction",
"printer_notes",
"inherits" "inherits"
}; };
} }
@ -387,13 +389,14 @@ const std::vector<std::string>& Preset::sla_material_options()
"layer_height", "initial_layer_height", "layer_height", "initial_layer_height",
"exposure_time", "initial_exposure_time", "exposure_time", "initial_exposure_time",
"material_correction_printing", "material_correction_curing", "material_correction_printing", "material_correction_curing",
"material_notes",
"compatible_printers_condition", "inherits" "compatible_printers_condition", "inherits"
}; };
} }
return s_opts; return s_opts;
} }
PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::string> &keys) : PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const std::string &default_name) :
m_type(type), m_type(type),
m_edited_preset(type, "", false), m_edited_preset(type, "", false),
m_idx_selected(0), m_idx_selected(0),
@ -401,7 +404,7 @@ PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::str
m_bitmap_cache(new GUI::BitmapCache) m_bitmap_cache(new GUI::BitmapCache)
{ {
// Insert just the default preset. // Insert just the default preset.
m_presets.emplace_back(Preset(type, "- default -", true)); this->add_default_preset(keys, default_name);
m_presets.front().load(keys); m_presets.front().load(keys);
m_edited_preset.config.apply(m_presets.front().config); m_edited_preset.config.apply(m_presets.front().config);
} }
@ -416,7 +419,7 @@ PresetCollection::~PresetCollection()
void PresetCollection::reset(bool delete_files) void PresetCollection::reset(bool delete_files)
{ {
if (m_presets.size() > 1) { if (m_presets.size() > m_num_default_presets) {
if (delete_files) { if (delete_files) {
// Erase the preset files. // Erase the preset files.
for (Preset &preset : m_presets) for (Preset &preset : m_presets)
@ -424,11 +427,19 @@ void PresetCollection::reset(bool delete_files)
boost::nowide::remove(preset.file.c_str()); boost::nowide::remove(preset.file.c_str());
} }
// Don't use m_presets.resize() here as it requires a default constructor for Preset. // Don't use m_presets.resize() here as it requires a default constructor for Preset.
m_presets.erase(m_presets.begin() + 1, m_presets.end()); m_presets.erase(m_presets.begin() + m_num_default_presets, m_presets.end());
this->select_preset(0); this->select_preset(0);
} }
} }
void PresetCollection::add_default_preset(const std::vector<std::string> &keys, const std::string &preset_name)
{
// Insert just the default preset.
m_presets.emplace_back(Preset(this->type(), preset_name, true));
m_presets.back().load(keys);
++ m_num_default_presets;
}
// Load all presets found in dir_path. // Load all presets found in dir_path.
// Throws an exception on error. // Throws an exception on error.
void PresetCollection::load_presets(const std::string &dir_path, const std::string &subdir) void PresetCollection::load_presets(const std::string &dir_path, const std::string &subdir)
@ -458,7 +469,7 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri
errors_cummulative += "\n"; errors_cummulative += "\n";
} }
} }
std::sort(m_presets.begin() + 1, m_presets.end()); std::sort(m_presets.begin() + m_num_default_presets, m_presets.end());
this->select_preset(first_visible_idx()); this->select_preset(first_visible_idx());
if (! errors_cummulative.empty()) if (! errors_cummulative.empty())
throw std::runtime_error(errors_cummulative); throw std::runtime_error(errors_cummulative);
@ -676,7 +687,7 @@ Preset* PresetCollection::find_preset(const std::string &name, bool first_visibl
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible. // Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
size_t PresetCollection::first_visible_idx() const size_t PresetCollection::first_visible_idx() const
{ {
size_t idx = m_default_suppressed ? 1 : 0; size_t idx = m_default_suppressed ? m_num_default_presets : 0;
for (; idx < this->m_presets.size(); ++ idx) for (; idx < this->m_presets.size(); ++ idx)
if (m_presets[idx].is_visible) if (m_presets[idx].is_visible)
break; break;
@ -689,7 +700,7 @@ void PresetCollection::set_default_suppressed(bool default_suppressed)
{ {
if (m_default_suppressed != default_suppressed) { if (m_default_suppressed != default_suppressed) {
m_default_suppressed = default_suppressed; m_default_suppressed = default_suppressed;
m_presets.front().is_visible = ! default_suppressed || (m_presets.size() > 1 && m_idx_selected > 0); m_presets.front().is_visible = ! default_suppressed || (m_presets.size() > m_num_default_presets && m_idx_selected > 0);
} }
} }
@ -697,9 +708,10 @@ size_t PresetCollection::update_compatible_with_printer_internal(const Preset &a
{ {
DynamicPrintConfig config; DynamicPrintConfig config;
config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name)); config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name));
config.set_key_value("num_extruders", new ConfigOptionInt( const ConfigOption *opt = active_printer.config.option("nozzle_diameter");
(int)static_cast<const ConfigOptionFloats*>(active_printer.config.option("nozzle_diameter"))->values.size())); if (opt)
for (size_t idx_preset = 1; idx_preset < m_presets.size(); ++ idx_preset) { 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; bool selected = idx_preset == m_idx_selected;
Preset &preset_selected = m_presets[idx_preset]; Preset &preset_selected = m_presets[idx_preset];
Preset &preset_edited = selected ? m_edited_preset : preset_selected; Preset &preset_edited = selected ? m_edited_preset : preset_selected;
@ -740,7 +752,7 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
wxString selected = ""; wxString selected = "";
if (!this->m_presets.front().is_visible) if (!this->m_presets.front().is_visible)
ui->Append("------- " +_(L("System presets")) + " -------", wxNullBitmap); ui->Append("------- " +_(L("System presets")) + " -------", wxNullBitmap);
for (size_t i = this->m_presets.front().is_visible ? 0 : 1; i < this->m_presets.size(); ++i) { for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++i) {
const Preset &preset = this->m_presets[i]; const Preset &preset = this->m_presets[i];
if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected)) if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected))
continue; continue;
@ -778,7 +790,7 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
if (i == m_idx_selected) if (i == m_idx_selected)
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str());
} }
if (preset.is_default) if (i + 1 == m_num_default_presets)
ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap); ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap);
} }
if (!nonsys_presets.empty()) if (!nonsys_presets.empty())
@ -808,7 +820,7 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
wxString selected = ""; wxString selected = "";
if (!this->m_presets.front().is_visible) if (!this->m_presets.front().is_visible)
ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap); ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap);
for (size_t i = this->m_presets.front().is_visible ? 0 : 1; i < this->m_presets.size(); ++i) { for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++i) {
const Preset &preset = this->m_presets[i]; const Preset &preset = this->m_presets[i];
if (! preset.is_visible || (! show_incompatible && ! preset.is_compatible && i != m_idx_selected)) if (! preset.is_visible || (! show_incompatible && ! preset.is_compatible && i != m_idx_selected))
continue; continue;
@ -838,7 +850,7 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
if (i == m_idx_selected) if (i == m_idx_selected)
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str());
} }
if (preset.is_default) if (i + 1 == m_num_default_presets)
ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap); ui->Append("------- " + _(L("System presets")) + " -------", wxNullBitmap);
} }
if (!nonsys_presets.empty()) if (!nonsys_presets.empty())
@ -930,7 +942,7 @@ bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, b
idx = it - m_presets.begin(); idx = it - m_presets.begin();
else { else {
// Find the first visible preset. // Find the first visible preset.
for (size_t i = m_default_suppressed ? 1 : 0; i < m_presets.size(); ++ i) for (size_t i = m_default_suppressed ? m_num_default_presets : 0; i < m_presets.size(); ++ i)
if (m_presets[i].is_visible) { if (m_presets[i].is_visible) {
idx = i; idx = i;
break; break;
@ -972,7 +984,7 @@ std::vector<std::string> PresetCollection::merge_presets(PresetCollection &&othe
if (preset.is_default || preset.is_external) if (preset.is_default || preset.is_external)
continue; continue;
Preset key(m_type, preset.name); Preset key(m_type, preset.name);
auto it = std::lower_bound(m_presets.begin() + 1, m_presets.end(), key); auto it = std::lower_bound(m_presets.begin() + m_num_default_presets, m_presets.end(), key);
if (it == m_presets.end() || it->name != preset.name) { if (it == m_presets.end() || it->name != preset.name) {
if (preset.vendor != nullptr) { if (preset.vendor != nullptr) {
// Re-assign a pointer to the vendor structure in the new PresetBundle. // Re-assign a pointer to the vendor structure in the new PresetBundle.

View File

@ -194,15 +194,15 @@ class PresetCollection
{ {
public: public:
// Initialize the PresetCollection with the "- default -" preset. // Initialize the PresetCollection with the "- default -" preset.
PresetCollection(Preset::Type type, const std::vector<std::string> &keys); PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const std::string &default_name = "- default -");
~PresetCollection(); ~PresetCollection();
typedef std::deque<Preset>::iterator Iterator; typedef std::deque<Preset>::iterator Iterator;
typedef std::deque<Preset>::const_iterator ConstIterator; typedef std::deque<Preset>::const_iterator ConstIterator;
Iterator begin() { return m_presets.begin() + 1; } Iterator begin() { return m_presets.begin() + m_num_default_presets; }
ConstIterator begin() const { return m_presets.begin() + 1; } ConstIterator begin() const { return m_presets.begin() + m_num_default_presets; }
Iterator end() { return m_presets.end(); } Iterator end() { return m_presets.end(); }
ConstIterator end() const { return m_presets.end(); } ConstIterator end() const { return m_presets.end(); }
void reset(bool delete_files); void reset(bool delete_files);
@ -210,6 +210,9 @@ public:
std::string name() const; std::string name() const;
const std::deque<Preset>& operator()() const { return m_presets; } const std::deque<Preset>& operator()() const { return m_presets; }
// Add default preset at the start of the collection, increment the m_default_preset counter.
void add_default_preset(const std::vector<std::string> &keys, const std::string &preset_name);
// Load ini files of the particular type from the provided directory path. // Load ini files of the particular type from the provided directory path.
void load_presets(const std::string &dir_path, const std::string &subdir); void load_presets(const std::string &dir_path, const std::string &subdir);
@ -295,7 +298,7 @@ public:
template<typename PreferedCondition> template<typename PreferedCondition>
size_t first_compatible_idx(PreferedCondition prefered_condition) const size_t first_compatible_idx(PreferedCondition prefered_condition) const
{ {
size_t i = m_default_suppressed ? 1 : 0; size_t i = m_default_suppressed ? m_num_default_presets : 0;
size_t n = this->m_presets.size(); size_t n = this->m_presets.size();
size_t i_compatible = n; size_t i_compatible = n;
for (; i < n; ++ i) for (; i < n; ++ i)
@ -321,7 +324,8 @@ public:
const Preset& first_compatible() const { return this->preset(this->first_compatible_idx()); } const Preset& first_compatible() const { return this->preset(this->first_compatible_idx()); }
// Return number of presets including the "- default -" preset. // Return number of presets including the "- default -" preset.
size_t size() const { return this->m_presets.size(); } size_t size() const { return m_presets.size(); }
bool has_defaults_only() const { return m_presets.size() <= m_num_default_presets; }
// For Print / Filament presets, disable those, which are not compatible with the printer. // For Print / Filament presets, disable those, which are not compatible with the printer.
template<typename PreferedCondition> template<typename PreferedCondition>
@ -386,8 +390,16 @@ private:
std::deque<Preset>::iterator find_preset_internal(const std::string &name) std::deque<Preset>::iterator find_preset_internal(const std::string &name)
{ {
Preset key(m_type, name); Preset key(m_type, name);
auto it = std::lower_bound(m_presets.begin() + 1, m_presets.end(), key); auto it = std::lower_bound(m_presets.begin() + m_num_default_presets, m_presets.end(), key);
return ((it == m_presets.end() || it->name != name) && m_presets.front().name == name) ? m_presets.begin() : it; if (it == m_presets.end() || it->name != name) {
// Preset has not been not found in the sorted list of non-default presets. Try the defaults.
for (size_t i = 0; i < m_num_default_presets; ++ i)
if (m_presets[i].name == name) {
it = m_presets.begin() + i;
break;
}
}
return it;
} }
std::deque<Preset>::const_iterator find_preset_internal(const std::string &name) const std::deque<Preset>::const_iterator find_preset_internal(const std::string &name) const
{ return const_cast<PresetCollection*>(this)->find_preset_internal(name); } { return const_cast<PresetCollection*>(this)->find_preset_internal(name); }
@ -407,7 +419,8 @@ private:
// Selected preset. // Selected preset.
int m_idx_selected; int m_idx_selected;
// Is the "- default -" preset suppressed? // Is the "- default -" preset suppressed?
bool m_default_suppressed = true; bool m_default_suppressed = true;
size_t m_num_default_presets = 0;
// Compatible & incompatible marks, to be placed at the wxBitmapComboBox items of a Platter. // Compatible & incompatible marks, to be placed at the wxBitmapComboBox items of a Platter.
// These bitmaps are not owned by PresetCollection, but by a PresetBundle. // These bitmaps are not owned by PresetCollection, but by a PresetBundle.
const wxBitmap *m_bitmap_compatible = nullptr; const wxBitmap *m_bitmap_compatible = nullptr;

View File

@ -43,7 +43,7 @@ PresetBundle::PresetBundle() :
prints(Preset::TYPE_PRINT, Preset::print_options()), prints(Preset::TYPE_PRINT, Preset::print_options()),
filaments(Preset::TYPE_FILAMENT, Preset::filament_options()), filaments(Preset::TYPE_FILAMENT, Preset::filament_options()),
sla_materials(Preset::TYPE_SLA_MATERIAL, Preset::sla_material_options()), sla_materials(Preset::TYPE_SLA_MATERIAL, Preset::sla_material_options()),
printers(Preset::TYPE_PRINTER, Preset::printer_options()), printers(Preset::TYPE_PRINTER, Preset::printer_options(), "- default FFF -"),
m_bitmapCompatible(new wxBitmap), m_bitmapCompatible(new wxBitmap),
m_bitmapIncompatible(new wxBitmap), m_bitmapIncompatible(new wxBitmap),
m_bitmapLock(new wxBitmap), m_bitmapLock(new wxBitmap),
@ -74,13 +74,18 @@ PresetBundle::PresetBundle() :
this->sla_materials.default_preset().compatible_printers_condition(); this->sla_materials.default_preset().compatible_printers_condition();
this->sla_materials.default_preset().inherits(); this->sla_materials.default_preset().inherits();
this->printers.default_preset().config.optptr("printer_settings_id", true); this->printers.add_default_preset(Preset::sla_printer_options(), "- default SLA -");
this->printers.default_preset().config.optptr("printer_vendor", true); this->printers.preset(1).printer_technology() = ptSLA;
this->printers.default_preset().config.optptr("printer_model", true); for (size_t i = 0; i < 2; ++ i) {
this->printers.default_preset().config.optptr("printer_variant", true); Preset &preset = this->printers.preset(i);
this->printers.default_preset().config.optptr("default_print_profile", true); preset.config.optptr("printer_settings_id", true);
this->printers.default_preset().config.option<ConfigOptionStrings>("default_filament_profile", true)->values = { "" }; preset.config.optptr("printer_vendor", true);
this->printers.default_preset().inherits(); preset.config.optptr("printer_model", true);
preset.config.optptr("printer_variant", true);
preset.config.optptr("default_print_profile", true);
preset.config.option<ConfigOptionStrings>("default_filament_profile", true)->values = { "" };
preset.inherits();
}
// Load the default preset bitmaps. // Load the default preset bitmaps.
this->prints .load_bitmap_default("cog.png"); this->prints .load_bitmap_default("cog.png");
@ -1118,6 +1123,9 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
void PresetBundle::update_multi_material_filament_presets() void PresetBundle::update_multi_material_filament_presets()
{ {
if (printers.get_edited_preset().printer_technology() != ptFFF)
return;
// Verify and select the filament presets. // Verify and select the filament presets.
auto *nozzle_diameter = static_cast<const ConfigOptionFloats*>(printers.get_edited_preset().config.option("nozzle_diameter")); auto *nozzle_diameter = static_cast<const ConfigOptionFloats*>(printers.get_edited_preset().config.option("nozzle_diameter"));
size_t num_extruders = nozzle_diameter->values.size(); size_t num_extruders = nozzle_diameter->values.size();
@ -1158,36 +1166,51 @@ void PresetBundle::update_multi_material_filament_presets()
void PresetBundle::update_compatible_with_printer(bool select_other_if_incompatible) void PresetBundle::update_compatible_with_printer(bool select_other_if_incompatible)
{ {
const Preset &printer_preset = this->printers.get_edited_preset(); const Preset &printer_preset = this->printers.get_edited_preset();
const std::string &prefered_print_profile = printer_preset.config.opt_string("default_print_profile");
const std::vector<std::string> &prefered_filament_profiles = printer_preset.config.option<ConfigOptionStrings>("default_filament_profile")->values; switch (printers.get_edited_preset().printer_technology()) {
prefered_print_profile.empty() ? case ptFFF:
this->prints.update_compatible_with_printer(printer_preset, select_other_if_incompatible) : {
this->prints.update_compatible_with_printer(printer_preset, select_other_if_incompatible, const std::string &prefered_print_profile = printer_preset.config.opt_string("default_print_profile");
[&prefered_print_profile](const std::string& profile_name){ return profile_name == prefered_print_profile; }); const std::vector<std::string> &prefered_filament_profiles = printer_preset.config.option<ConfigOptionStrings>("default_filament_profile")->values;
prefered_filament_profiles.empty() ? prefered_print_profile.empty() ?
this->filaments.update_compatible_with_printer(printer_preset, select_other_if_incompatible) : this->prints.update_compatible_with_printer(printer_preset, select_other_if_incompatible) :
this->filaments.update_compatible_with_printer(printer_preset, select_other_if_incompatible, this->prints.update_compatible_with_printer(printer_preset, select_other_if_incompatible,
[&prefered_filament_profiles](const std::string& profile_name) [&prefered_print_profile](const std::string& profile_name){ return profile_name == prefered_print_profile; });
{ return std::find(prefered_filament_profiles.begin(), prefered_filament_profiles.end(), profile_name) != prefered_filament_profiles.end(); }); prefered_filament_profiles.empty() ?
if (select_other_if_incompatible) { this->filaments.update_compatible_with_printer(printer_preset, select_other_if_incompatible) :
// Verify validity of the current filament presets. this->filaments.update_compatible_with_printer(printer_preset, select_other_if_incompatible,
this->filament_presets.front() = this->filaments.get_edited_preset().name; [&prefered_filament_profiles](const std::string& profile_name)
for (size_t idx = 1; idx < this->filament_presets.size(); ++ idx) { { return std::find(prefered_filament_profiles.begin(), prefered_filament_profiles.end(), profile_name) != prefered_filament_profiles.end(); });
std::string &filament_name = this->filament_presets[idx]; if (select_other_if_incompatible) {
Preset *preset = this->filaments.find_preset(filament_name, false); // Verify validity of the current filament presets.
if (preset == nullptr || ! preset->is_compatible) { this->filament_presets.front() = this->filaments.get_edited_preset().name;
// Pick a compatible profile. If there are prefered_filament_profiles, use them. for (size_t idx = 1; idx < this->filament_presets.size(); ++ idx) {
if (prefered_filament_profiles.empty()) std::string &filament_name = this->filament_presets[idx];
filament_name = this->filaments.first_compatible().name; Preset *preset = this->filaments.find_preset(filament_name, false);
else { if (preset == nullptr || ! preset->is_compatible) {
const std::string &preferred = (idx < prefered_filament_profiles.size()) ? // Pick a compatible profile. If there are prefered_filament_profiles, use them.
prefered_filament_profiles[idx] : prefered_filament_profiles.front(); if (prefered_filament_profiles.empty())
filament_name = this->filaments.first_compatible( filament_name = this->filaments.first_compatible().name;
[&preferred](const std::string& profile_name){ return profile_name == preferred; }).name; else {
const std::string &preferred = (idx < prefered_filament_profiles.size()) ?
prefered_filament_profiles[idx] : prefered_filament_profiles.front();
filament_name = this->filaments.first_compatible(
[&preferred](const std::string& profile_name){ return profile_name == preferred; }).name;
}
} }
} }
} }
} }
case ptSLA:
{
const std::string &prefered_print_profile = printer_preset.config.opt_string("default_print_profile");
const std::vector<std::string> &prefered_filament_profiles = printer_preset.config.option<ConfigOptionStrings>("default_filament_profile")->values;
prefered_print_profile.empty() ?
this->sla_materials.update_compatible_with_printer(printer_preset, select_other_if_incompatible) :
this->sla_materials.update_compatible_with_printer(printer_preset, select_other_if_incompatible,
[&prefered_print_profile](const std::string& profile_name){ return profile_name == prefered_print_profile; });
}
}
} }
void PresetBundle::export_configbundle(const std::string &path) //, const DynamicPrintConfig &settings void PresetBundle::export_configbundle(const std::string &path) //, const DynamicPrintConfig &settings

View File

@ -64,7 +64,7 @@ public:
ObsoletePresets obsolete_presets; ObsoletePresets obsolete_presets;
bool has_defauls_only() const bool has_defauls_only() const
{ return prints.size() <= 1 && filaments.size() <= 1 && printers.size() <= 1; } { return prints.has_defaults_only() && filaments.has_defaults_only() && printers.has_defaults_only(); }
DynamicPrintConfig full_config() const; DynamicPrintConfig full_config() const;

View File

@ -2052,48 +2052,52 @@ void Tab::rebuild_page_tree()
// Called by the UI combo box when the user switches profiles. // Called by the UI combo box when the user switches profiles.
// Select a preset by a name.If !defined(name), then the default preset is selected. // Select a preset by a name.If !defined(name), then the default preset is selected.
// If the current profile is modified, user is asked to save the changes. // If the current profile is modified, user is asked to save the changes.
void Tab::select_preset(const std::string& preset_name /*= ""*/) void Tab::select_preset(std::string preset_name /*= ""*/)
{ {
std::string name = preset_name;
auto force = false;
auto presets = m_presets;
// If no name is provided, select the "-- default --" preset. // If no name is provided, select the "-- default --" preset.
if (name.empty()) if (preset_name.empty())
name= presets->default_preset().name; preset_name = m_presets->default_preset().name;
auto current_dirty = presets->current_is_dirty(); auto current_dirty = m_presets->current_is_dirty();
auto canceled = false; auto printer_tab = m_presets->name() == "printer";
auto printer_tab = presets->name().compare("printer")==0; auto canceled = false;
m_reload_dependent_tabs = {}; m_reload_dependent_tabs = {};
if (!force && current_dirty && !may_discard_current_dirty_preset()) { if (!current_dirty && !may_discard_current_dirty_preset()) {
canceled = true; canceled = true;
} else if(printer_tab) { } else if (printer_tab) {
// Before switching the printer to a new one, verify, whether the currently active print and filament // Before switching the printer to a new one, verify, whether the currently active print and filament
// are compatible with the new printer. // are compatible with the new printer.
// If they are not compatible and the current print or filament are dirty, let user decide // If they are not compatible and the current print or filament are dirty, let user decide
// whether to discard the changes or keep the current printer selection. // whether to discard the changes or keep the current printer selection.
auto new_printer_preset = presets->find_preset(name, true); //
auto print_presets = &m_preset_bundle->prints; // With the introduction of the SLA printer types, we need to support switching between
bool print_preset_dirty = print_presets->current_is_dirty(); // the FFF and SLA printers.
bool print_preset_compatible = print_presets->get_edited_preset().is_compatible_with_printer(*new_printer_preset); const Preset &new_printer_preset = *m_presets->find_preset(preset_name, true);
canceled = !force && print_preset_dirty && !print_preset_compatible && PrinterTechnology old_printer_technology = m_presets->get_edited_preset().printer_technology();
!may_discard_current_dirty_preset(print_presets, name); PrinterTechnology new_printer_technology = new_printer_preset.printer_technology();
auto filament_presets = &m_preset_bundle->filaments; struct PresetUpdate {
bool filament_preset_dirty = filament_presets->current_is_dirty(); std::string name;
bool filament_preset_compatible = filament_presets->get_edited_preset().is_compatible_with_printer(*new_printer_preset); PresetCollection *presets;
if (!canceled && !force) { PrinterTechnology technology;
canceled = filament_preset_dirty && !filament_preset_compatible && bool old_preset_dirty;
!may_discard_current_dirty_preset(filament_presets, name); bool new_preset_compatible;
};
std::vector<PresetUpdate> updates = {
{ "print", &m_preset_bundle->prints, ptFFF },
{ "filament", &m_preset_bundle->filaments, ptFFF },
{ "sla_materials", &m_preset_bundle->sla_materials, ptSLA }
};
for (PresetUpdate &pu : updates) {
pu.old_preset_dirty = (old_printer_technology == pu.technology) && pu.presets->current_is_dirty();
pu.new_preset_compatible = (new_printer_technology == pu.technology) && pu.presets->get_edited_preset().is_compatible_with_printer(new_printer_preset);
if (! canceled)
canceled = pu.old_preset_dirty && ! pu.new_preset_compatible && ! may_discard_current_dirty_preset(pu.presets, preset_name);
} }
if (!canceled) { if (! canceled) {
if (!print_preset_compatible) { for (PresetUpdate &pu : updates) {
// The preset will be switched to a different, compatible preset, or the '-- default --'. // The preset will be switched to a different, compatible preset, or the '-- default --'.
m_reload_dependent_tabs.push_back("print"); m_reload_dependent_tabs.emplace_back(pu.name);
if (print_preset_dirty) print_presets->discard_current_changes(); if (pu.old_preset_dirty)
} pu.presets->discard_current_changes();
if (!filament_preset_compatible) {
// The preset will be switched to a different, compatible preset, or the '-- default --'.
m_reload_dependent_tabs.push_back("filament");
if (filament_preset_dirty) filament_presets->discard_current_changes();
} }
} }
} }
@ -2102,10 +2106,10 @@ void Tab::select_preset(const std::string& preset_name /*= ""*/)
// Trigger the on_presets_changed event so that we also restore the previous value in the plater selector, // Trigger the on_presets_changed event so that we also restore the previous value in the plater selector,
// if this action was initiated from the platter. // if this action was initiated from the platter.
on_presets_changed(); on_presets_changed();
} } else {
else { if (current_dirty)
if (current_dirty) presets->discard_current_changes() ; m_presets->discard_current_changes() ;
presets->select_preset_by_name(name, force); m_presets->select_preset_by_name(preset_name, false);
// Mark the print & filament enabled if they are compatible with the currently selected preset. // Mark the print & filament enabled if they are compatible with the currently selected preset.
// The following method should not discard changes of current print or filament presets on change of a printer profile, // The following method should not discard changes of current print or filament presets on change of a printer profile,
// if they are compatible with the current printer. // if they are compatible with the current printer.
@ -2114,7 +2118,6 @@ void Tab::select_preset(const std::string& preset_name /*= ""*/)
// Initialize the UI from the current preset. // Initialize the UI from the current preset.
load_current_preset(); load_current_preset();
} }
} }
// If the current preset is dirty, the user is asked whether the changes may be discarded. // If the current preset is dirty, the user is asked whether the changes may be discarded.

View File

@ -219,7 +219,7 @@ public:
void create_preset_tab(PresetBundle *preset_bundle); void create_preset_tab(PresetBundle *preset_bundle);
void load_current_preset(); void load_current_preset();
void rebuild_page_tree(); void rebuild_page_tree();
void select_preset(const std::string& preset_name = ""); void select_preset(std::string preset_name = "");
bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = ""); bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = "");
wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn); wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn);

View File

@ -32,7 +32,6 @@
%name{Slic3r::GUI::PresetCollection} class PresetCollection { %name{Slic3r::GUI::PresetCollection} class PresetCollection {
Ref<Preset> preset(size_t idx) %code%{ RETVAL = &THIS->preset(idx); %}; Ref<Preset> preset(size_t idx) %code%{ RETVAL = &THIS->preset(idx); %};
Ref<Preset> default_preset() %code%{ RETVAL = &THIS->default_preset(); %};
size_t size() const; size_t size() const;
size_t num_visible() const; size_t num_visible() const;
std::string name() const; std::string name() const;