WIP Detaching of system profiles and user profiles derived from system profiles.

This commit is contained in:
bubnikv 2020-03-06 17:41:00 +01:00
parent da9412705e
commit 2816b5a9fb
4 changed files with 53 additions and 30 deletions

View File

@ -851,7 +851,7 @@ Preset& PresetCollection::load_preset(const std::string &path, const std::string
return preset;
}
void PresetCollection::save_current_preset(const std::string &new_name)
void PresetCollection::save_current_preset(const std::string &new_name, bool detach)
{
// 1) Find the preset with a new_name or create a new one,
// initialize it with the edited config.
@ -866,6 +866,13 @@ void PresetCollection::save_current_preset(const std::string &new_name)
preset.config = std::move(m_edited_preset.config);
// The newly saved preset will be activated -> make it visible.
preset.is_visible = true;
if (detach) {
// Clear the link to the parent profile.
preset.vendor = nullptr;
preset.inherits().clear();
preset.alias.clear();
preset.renamed_from.clear();
}
} else {
// Creating a new preset.
Preset &preset = *m_presets.insert(it, m_edited_preset);
@ -874,7 +881,12 @@ void PresetCollection::save_current_preset(const std::string &new_name)
preset.name = new_name;
preset.file = this->path_from_name(new_name);
preset.vendor = nullptr;
if (preset.is_system) {
preset.alias.clear();
preset.renamed_from.clear();
if (detach) {
// Clear the link to the parent profile.
inherits.clear();
} else if (preset.is_system) {
// Inheriting from a system preset.
inherits = /* preset.vendor->name + "/" + */ old_name;
} else if (inherits.empty()) {
@ -1061,6 +1073,7 @@ size_t PresetCollection::update_compatible_internal(const PresetWithVendorProfil
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()));
bool some_compatible = false;
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];
@ -1068,6 +1081,7 @@ size_t PresetCollection::update_compatible_internal(const PresetWithVendorProfil
const PresetWithVendorProfile this_preset_with_vendor_profile = this->get_preset_with_vendor_profile(preset_edited);
bool was_compatible = preset_edited.is_compatible;
preset_edited.is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config);
some_compatible |= preset_edited.is_compatible;
if (active_print != nullptr)
preset_edited.is_compatible &= is_compatible_with_print(this_preset_with_vendor_profile, *active_print, active_printer);
if (! preset_edited.is_compatible && selected &&
@ -1076,6 +1090,10 @@ size_t PresetCollection::update_compatible_internal(const PresetWithVendorProfil
if (selected)
preset_selected.is_compatible = preset_edited.is_compatible;
}
// Update visibility of the default profiles here if the defaults are suppressed, the current profile is not compatible and we don't want to select another compatible profile.
if (m_idx_selected >= m_num_default_presets && m_default_suppressed)
for (size_t i = 0; i < m_num_default_presets; ++ i)
m_presets[i].is_visible = ! some_compatible;
return m_idx_selected;
}

View File

@ -312,7 +312,7 @@ public:
// Save the preset under a new name. If the name is different from the old one,
// a new preset is stored into the list of presets.
// All presets are marked as not modified and the new preset is activated.
void save_current_preset(const std::string &new_name);
void save_current_preset(const std::string &new_name, bool detach = false);
// Delete the current preset, activate the first visible preset.
// returns true if the preset was deleted successfully.

View File

@ -953,19 +953,6 @@ void Tab::on_presets_changed()
m_dependent_tabs.clear();
}
void Tab::detach_preset(Preset& preset)
{
preset.inherits().clear();
preset.renamed_from.clear();
preset.vendor = nullptr;
update_ui_items_related_on_parent_preset(m_presets->get_selected_preset_parent());
update_dirty();
reload_config();
update();
}
void Tab::build_preset_description_line(ConfigOptionsGroup* optgroup)
{
auto description_line = [this](wxWindow* parent) {
@ -997,12 +984,7 @@ void Tab::build_preset_description_line(ConfigOptionsGroup* optgroup)
wxMessageDialog dialog(parent, msg_text, _(L("Detach preset")), wxICON_WARNING | wxYES_NO);
if (dialog.ShowModal() == wxID_YES)
{
if (m_presets->get_edited_preset().is_system)
save_preset("", _utf8(L("Detached")));
detach_preset(m_presets->get_edited_preset());
}
save_preset(m_presets->get_edited_preset().is_system ? std::string() : m_presets->get_edited_preset().name, true);
});
btn->Hide();
@ -2784,7 +2766,7 @@ void Tab::select_preset(std::string preset_name, bool delete_current)
bool printer_tab = m_presets->type() == Preset::TYPE_PRINTER;
bool canceled = false;
bool technology_changed = false;
m_dependent_tabs = {};
m_dependent_tabs.clear();
if (current_dirty && ! may_discard_current_dirty_preset()) {
canceled = true;
} else if (print_tab) {
@ -3038,15 +3020,14 @@ void Tab::OnKeyDown(wxKeyEvent& event)
// and activates the new preset.
// Wizard calls save_preset with a name "My Settings", otherwise no name is provided and this method
// opens a Slic3r::GUI::SavePresetWindow dialog.
void Tab::save_preset(std::string name /*= ""*/, std::string suffix/* = ""*/)
void Tab::save_preset(std::string name /*= ""*/, bool detach)
{
// since buttons(and choices too) don't get focus on Mac, we set focus manually
// to the treectrl so that the EVT_* events are fired for the input field having
// focus currently.is there anything better than this ?
//! m_treectrl->OnSetFocus();
if (suffix.empty())
suffix = _CTX_utf8(L_CONTEXT("Copy", "PresetName"), "PresetName");
std::string suffix = detach ? _utf8(L("Detached")) : _CTX_utf8(L_CONTEXT("Copy", "PresetName"), "PresetName");
if (name.empty()) {
const Preset &preset = m_presets->get_selected_preset();
@ -3102,8 +3083,9 @@ void Tab::save_preset(std::string name /*= ""*/, std::string suffix/* = ""*/)
}
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
m_presets->save_current_preset(name);
m_presets->save_current_preset(name, detach);
// Mark the print & filament enabled if they are compatible with the currently selected preset.
// If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible.
m_preset_bundle->update_compatible(PresetSelectCompatibleType::Never);
// Add the new item into the UI component, remove dirty flags and activate the saved item.
update_tab_ui();
@ -3121,6 +3103,30 @@ void Tab::save_preset(std::string name /*= ""*/, std::string suffix/* = ""*/)
* but in full_config a filament_colors option aren't.*/
if (m_type == Preset::TYPE_FILAMENT && wxGetApp().extruders_edited_cnt() > 1)
wxGetApp().plater()->force_filament_colors_update();
{
// Profile compatiblity is updated first when the profile is saved.
// Update profile selection combo boxes at the depending tabs to reflect modifications in profile compatibility.
std::vector<Preset::Type> dependent;
switch (m_type) {
case Preset::TYPE_PRINT:
dependent = { Preset::TYPE_FILAMENT };
break;
case Preset::TYPE_SLA_PRINT:
dependent = { Preset::TYPE_SLA_MATERIAL };
break;
case Preset::TYPE_PRINTER:
if (static_cast<const TabPrinter*>(this)->m_printer_technology == ptFFF)
dependent = { Preset::TYPE_PRINT, Preset::TYPE_FILAMENT };
else
dependent = { Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL };
break;
default:
break;
}
for (Preset::Type preset_type : dependent)
wxGetApp().get_tab(preset_type)->update_tab_ui();
}
}
// Called for a currently selected preset.

View File

@ -201,7 +201,7 @@ protected:
bool m_disable_tree_sel_changed_event;
bool m_show_incompatible_presets;
std::vector<Preset::Type> m_dependent_tabs = {};
std::vector<Preset::Type> m_dependent_tabs;
enum OptStatus { osSystemValue = 1, osInitValue = 2 };
std::map<std::string, int> m_options_list;
int m_opt_status_value = 0;
@ -270,7 +270,7 @@ public:
void OnTreeSelChange(wxTreeEvent& event);
void OnKeyDown(wxKeyEvent& event);
void save_preset(std::string name = "", std::string suffix = "");
void save_preset(std::string name = std::string(), bool detach = false);
void delete_preset();
void toggle_show_hide_incompatible();
void update_show_hide_incompatible_button();
@ -318,7 +318,6 @@ protected:
void load_key_value(const std::string& opt_key, const boost::any& value, bool saved_value = false);
void on_presets_changed();
void detach_preset(Preset& preset);
void build_preset_description_line(ConfigOptionsGroup* optgroup);
void update_preset_description_line();
void update_frequently_changed_parameters();