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->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->label = L("Default SLA material 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;
config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name));
config.set_key_value("num_extruders", new ConfigOptionInt(
(int)static_cast<const ConfigOptionFloats*>(active_printer.config.option("nozzle_diameter"))->values.size()));
const ConfigOption *opt = active_printer.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);
}
@ -373,6 +374,7 @@ const std::vector<std::string>& Preset::sla_printer_options()
"bed_shape", "max_print_height",
"display_width", "display_height", "display_pixels_x", "display_pixels_y",
"printer_correction",
"printer_notes",
"inherits"
};
}
@ -387,13 +389,14 @@ const std::vector<std::string>& Preset::sla_material_options()
"layer_height", "initial_layer_height",
"exposure_time", "initial_exposure_time",
"material_correction_printing", "material_correction_curing",
"material_notes",
"compatible_printers_condition", "inherits"
};
}
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_edited_preset(type, "", false),
m_idx_selected(0),
@ -401,7 +404,7 @@ PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::str
m_bitmap_cache(new GUI::BitmapCache)
{
// 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_edited_preset.config.apply(m_presets.front().config);
}
@ -416,7 +419,7 @@ PresetCollection::~PresetCollection()
void PresetCollection::reset(bool delete_files)
{
if (m_presets.size() > 1) {
if (m_presets.size() > m_num_default_presets) {
if (delete_files) {
// Erase the preset files.
for (Preset &preset : m_presets)
@ -424,11 +427,19 @@ void PresetCollection::reset(bool delete_files)
boost::nowide::remove(preset.file.c_str());
}
// 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);
}
}
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.
// Throws an exception on error.
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";
}
}
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());
if (! errors_cummulative.empty())
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.
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)
if (m_presets[idx].is_visible)
break;
@ -689,7 +700,7 @@ void PresetCollection::set_default_suppressed(bool default_suppressed)
{
if (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;
config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name));
config.set_key_value("num_extruders", new ConfigOptionInt(
(int)static_cast<const ConfigOptionFloats*>(active_printer.config.option("nozzle_diameter"))->values.size()));
for (size_t idx_preset = 1; idx_preset < m_presets.size(); ++ idx_preset) {
const ConfigOption *opt = active_printer.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;
@ -740,7 +752,7 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
wxString selected = "";
if (!this->m_presets.front().is_visible)
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];
if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected))
continue;
@ -778,7 +790,7 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui)
if (i == m_idx_selected)
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);
}
if (!nonsys_presets.empty())
@ -808,7 +820,7 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
wxString selected = "";
if (!this->m_presets.front().is_visible)
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];
if (! preset.is_visible || (! show_incompatible && ! preset.is_compatible && i != m_idx_selected))
continue;
@ -838,7 +850,7 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati
if (i == m_idx_selected)
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);
}
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();
else {
// 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) {
idx = i;
break;
@ -972,7 +984,7 @@ std::vector<std::string> PresetCollection::merge_presets(PresetCollection &&othe
if (preset.is_default || preset.is_external)
continue;
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 (preset.vendor != nullptr) {
// Re-assign a pointer to the vendor structure in the new PresetBundle.

View File

@ -194,13 +194,13 @@ class PresetCollection
{
public:
// 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();
typedef std::deque<Preset>::iterator Iterator;
typedef std::deque<Preset>::const_iterator ConstIterator;
Iterator begin() { return m_presets.begin() + 1; }
ConstIterator begin() const { return m_presets.begin() + 1; }
Iterator begin() { return m_presets.begin() + m_num_default_presets; }
ConstIterator begin() const { return m_presets.begin() + m_num_default_presets; }
Iterator end() { return m_presets.end(); }
ConstIterator end() const { return m_presets.end(); }
@ -210,6 +210,9 @@ public:
std::string name() const;
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.
void load_presets(const std::string &dir_path, const std::string &subdir);
@ -295,7 +298,7 @@ public:
template<typename PreferedCondition>
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 i_compatible = n;
for (; i < n; ++ i)
@ -321,7 +324,8 @@ public:
const Preset& first_compatible() const { return this->preset(this->first_compatible_idx()); }
// 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.
template<typename PreferedCondition>
@ -386,8 +390,16 @@ private:
std::deque<Preset>::iterator find_preset_internal(const std::string &name)
{
Preset key(m_type, name);
auto it = std::lower_bound(m_presets.begin() + 1, m_presets.end(), key);
return ((it == m_presets.end() || it->name != name) && m_presets.front().name == name) ? m_presets.begin() : it;
auto it = std::lower_bound(m_presets.begin() + m_num_default_presets, m_presets.end(), key);
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
{ return const_cast<PresetCollection*>(this)->find_preset_internal(name); }
@ -408,6 +420,7 @@ private:
int m_idx_selected;
// Is the "- default -" preset suppressed?
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.
// These bitmaps are not owned by PresetCollection, but by a PresetBundle.
const wxBitmap *m_bitmap_compatible = nullptr;

View File

@ -43,7 +43,7 @@ PresetBundle::PresetBundle() :
prints(Preset::TYPE_PRINT, Preset::print_options()),
filaments(Preset::TYPE_FILAMENT, Preset::filament_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_bitmapIncompatible(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().inherits();
this->printers.default_preset().config.optptr("printer_settings_id", true);
this->printers.default_preset().config.optptr("printer_vendor", true);
this->printers.default_preset().config.optptr("printer_model", true);
this->printers.default_preset().config.optptr("printer_variant", true);
this->printers.default_preset().config.optptr("default_print_profile", true);
this->printers.default_preset().config.option<ConfigOptionStrings>("default_filament_profile", true)->values = { "" };
this->printers.default_preset().inherits();
this->printers.add_default_preset(Preset::sla_printer_options(), "- default SLA -");
this->printers.preset(1).printer_technology() = ptSLA;
for (size_t i = 0; i < 2; ++ i) {
Preset &preset = this->printers.preset(i);
preset.config.optptr("printer_settings_id", true);
preset.config.optptr("printer_vendor", true);
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.
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()
{
if (printers.get_edited_preset().printer_technology() != ptFFF)
return;
// Verify and select the filament presets.
auto *nozzle_diameter = static_cast<const ConfigOptionFloats*>(printers.get_edited_preset().config.option("nozzle_diameter"));
size_t num_extruders = nozzle_diameter->values.size();
@ -1158,6 +1166,10 @@ void PresetBundle::update_multi_material_filament_presets()
void PresetBundle::update_compatible_with_printer(bool select_other_if_incompatible)
{
const Preset &printer_preset = this->printers.get_edited_preset();
switch (printers.get_edited_preset().printer_technology()) {
case ptFFF:
{
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() ?
@ -1188,6 +1200,17 @@ void PresetBundle::update_compatible_with_printer(bool select_other_if_incompati
}
}
}
}
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

View File

@ -64,7 +64,7 @@ public:
ObsoletePresets obsolete_presets;
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;

View File

@ -2052,48 +2052,52 @@ void Tab::rebuild_page_tree()
// 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.
// 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 (name.empty())
name= presets->default_preset().name;
auto current_dirty = presets->current_is_dirty();
if (preset_name.empty())
preset_name = m_presets->default_preset().name;
auto current_dirty = m_presets->current_is_dirty();
auto printer_tab = m_presets->name() == "printer";
auto canceled = false;
auto printer_tab = presets->name().compare("printer")==0;
m_reload_dependent_tabs = {};
if (!force && current_dirty && !may_discard_current_dirty_preset()) {
if (!current_dirty && !may_discard_current_dirty_preset()) {
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
// are compatible with the new printer.
// 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.
auto new_printer_preset = presets->find_preset(name, true);
auto print_presets = &m_preset_bundle->prints;
bool print_preset_dirty = print_presets->current_is_dirty();
bool print_preset_compatible = print_presets->get_edited_preset().is_compatible_with_printer(*new_printer_preset);
canceled = !force && print_preset_dirty && !print_preset_compatible &&
!may_discard_current_dirty_preset(print_presets, name);
auto filament_presets = &m_preset_bundle->filaments;
bool filament_preset_dirty = filament_presets->current_is_dirty();
bool filament_preset_compatible = filament_presets->get_edited_preset().is_compatible_with_printer(*new_printer_preset);
if (!canceled && !force) {
canceled = filament_preset_dirty && !filament_preset_compatible &&
!may_discard_current_dirty_preset(filament_presets, name);
//
// With the introduction of the SLA printer types, we need to support switching between
// the FFF and SLA printers.
const Preset &new_printer_preset = *m_presets->find_preset(preset_name, true);
PrinterTechnology old_printer_technology = m_presets->get_edited_preset().printer_technology();
PrinterTechnology new_printer_technology = new_printer_preset.printer_technology();
struct PresetUpdate {
std::string name;
PresetCollection *presets;
PrinterTechnology technology;
bool old_preset_dirty;
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 (!print_preset_compatible) {
if (! canceled) {
for (PresetUpdate &pu : updates) {
// The preset will be switched to a different, compatible preset, or the '-- default --'.
m_reload_dependent_tabs.push_back("print");
if (print_preset_dirty) print_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();
m_reload_dependent_tabs.emplace_back(pu.name);
if (pu.old_preset_dirty)
pu.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,
// if this action was initiated from the platter.
on_presets_changed();
}
else {
if (current_dirty) presets->discard_current_changes() ;
presets->select_preset_by_name(name, force);
} else {
if (current_dirty)
m_presets->discard_current_changes() ;
m_presets->select_preset_by_name(preset_name, false);
// 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,
// 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.
load_current_preset();
}
}
// 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 load_current_preset();
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 = "");
wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn);

View File

@ -32,7 +32,6 @@
%name{Slic3r::GUI::PresetCollection} class PresetCollection {
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 num_visible() const;
std::string name() const;