Skip to content

Commit

Permalink
DiffDialog: Implemented a transfer of options from one preset to another
Browse files Browse the repository at this point in the history
Related to [Feature Request] #5384 - Copy values in Profile comparaison dialog
  • Loading branch information
YuSanka committed Sep 13, 2022
1 parent 0559332 commit 0b8d738
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 105 deletions.
4 changes: 2 additions & 2 deletions src/slic3r/GUI/ConfigWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2564,9 +2564,9 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
bool check_unsaved_preset_changes = page_welcome->reset_user_profile();
if (check_unsaved_preset_changes)
header = _L("All user presets will be deleted.");
int act_btns = UnsavedChangesDialog::ActionButtons::KEEP;
int act_btns = ActionButtons::KEEP;
if (!check_unsaved_preset_changes)
act_btns |= UnsavedChangesDialog::ActionButtons::SAVE;
act_btns |= ActionButtons::SAVE;

// Install bundles from resources if needed:
std::vector<std::string> install_bundles;
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2521,9 +2521,9 @@ bool GUI_App::check_and_save_current_preset_changes(const wxString& caption, con
{
if (has_current_preset_changes()) {
const std::string app_config_key = remember_choice ? "default_action_on_close_application" : "";
int act_buttons = UnsavedChangesDialog::ActionButtons::SAVE;
int act_buttons = ActionButtons::SAVE;
if (dont_save_insted_of_discard)
act_buttons |= UnsavedChangesDialog::ActionButtons::DONT_SAVE;
act_buttons |= ActionButtons::DONT_SAVE;
UnsavedChangesDialog dlg(caption, header, app_config_key, act_buttons);
std::string act = app_config_key.empty() ? "none" : wxGetApp().app_config->get(app_config_key);
if (act == "none" && dlg.ShowModal() == wxID_CANCEL)
Expand Down
47 changes: 44 additions & 3 deletions src/slic3r/GUI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,52 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S

preferences_dialog = new PreferencesDialog(this);
}

// bind events from DiffDlg

bind_diff_dialog();
}

void MainFrame::bind_diff_dialog()
{
auto get_tab = [](Preset::Type type) {
Tab* null_tab = nullptr;
for (Tab* tab : wxGetApp().tabs_list)
if (tab->type() == type)
return tab;
return null_tab;
};

auto transfer = [this, get_tab](Preset::Type type) {
get_tab(type)->transfer_options(diff_dialog.get_left_preset_name(type),
diff_dialog.get_right_preset_name(type),
std::move(diff_dialog.get_selected_options(type)));
};

auto save = [this, get_tab](Preset::Type type) {
get_tab(type)->save_options(diff_dialog.get_left_preset_name(type),
diff_dialog.get_right_preset_name(type),
std::move(diff_dialog.get_selected_options(type)));
};

auto process_options = [this](std::function<void(Preset::Type)> process) {
const Preset::Type diff_dlg_type = diff_dialog.view_type();
if (diff_dlg_type == Preset::TYPE_INVALID) {
for (const Preset::Type& type : diff_dialog.printer_technology() == ptFFF ?
std::initializer_list<Preset::Type>{Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT} :
std::initializer_list<Preset::Type>{ Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL } )
process(type);
}
else
process(diff_dlg_type);
};

diff_dialog.Bind(EVT_DIFF_DIALOG_TRANSFER, [this, process_options, transfer](SimpleEvent&) { process_options(transfer); });

diff_dialog.Bind(EVT_DIFF_DIALOG_SAVE, [this, process_options, save](SimpleEvent&) { process_options(save); });
}


#ifdef _MSW_DARK_MODE
static wxString pref() { return " [ "; }
static wxString suff() { return " ] "; }
Expand Down Expand Up @@ -2130,9 +2174,6 @@ void MainFrame::add_to_recent_projects(const wxString& filename)

void MainFrame::technology_changed()
{
// upadte DiffDlg
diff_dialog.update_presets();

// update menu titles
PrinterTechnology pt = plater()->printer_technology();
if (int id = m_menubar->FindMenu(pt == ptFFF ? _L("Material Settings") : _L("Filament Settings")); id != wxNOT_FOUND)
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/MainFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class MainFrame : public DPIFrame
bool can_delete() const;
bool can_delete_all() const;
bool can_reslice() const;
void bind_diff_dialog();

// MenuBar items changeable in respect to printer technology
enum MenuItems
Expand Down
5 changes: 2 additions & 3 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5328,10 +5328,9 @@ void Plater::new_project()
(saved_project == wxID_YES ? _L("You can keep presets modifications to the new project or discard them") :
_L("You can keep presets modifications to the new project, discard them or save changes as new presets.\n"
"Note, if changes will be saved then new project wouldn't keep them"));
using ab = UnsavedChangesDialog::ActionButtons;
int act_buttons = ab::KEEP;
int act_buttons = ActionButtons::KEEP;
if (saved_project == wxID_NO)
act_buttons |= ab::SAVE;
act_buttons |= ActionButtons::SAVE;
if (!wxGetApp().check_and_keep_current_preset_changes(_L("Creating a new project"), header, act_buttons))
return;
}
Expand Down
50 changes: 45 additions & 5 deletions src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,9 +1183,9 @@ void Tab::activate_option(const std::string& opt_key, const wxString& category)
m_highlighter.init(get_custom_ctrl_with_blinking_ptr(opt_key));
}

void Tab::cache_config_diff(const std::vector<std::string>& selected_options)
void Tab::cache_config_diff(const std::vector<std::string>& selected_options, const DynamicPrintConfig* config/* = nullptr*/)
{
m_cache_config.apply_only(m_presets->get_edited_preset().config, selected_options);
m_cache_config.apply_only(config ? *config : m_presets->get_edited_preset().config, selected_options);
}

void Tab::apply_config_from_cache()
Expand Down Expand Up @@ -3583,6 +3583,42 @@ void Tab::compare_preset()
wxGetApp().mainframe->diff_dialog.show(m_type);
}

void Tab::transfer_options(const std::string &name_from, const std::string &name_to, std::vector<std::string> options)
{
if (options.empty())
return;

Preset* preset_from = m_presets->find_preset(name_from);
Preset* preset_to = m_presets->find_preset(name_to);

if (m_type == Preset::TYPE_PRINTER) {
auto it = std::find(options.begin(), options.end(), "extruders_count");
if (it != options.end()) {
// erase "extruders_count" option from the list
options.erase(it);
// cache the extruders count
static_cast<TabPrinter*>(this)->cache_extruder_cnt(&preset_from->config);
}
}
cache_config_diff(options, &preset_from->config);

if (name_to != m_presets->get_edited_preset().name )
select_preset(preset_to->name);

apply_config_from_cache();
load_current_preset();
}

void Tab::save_options(const std::string &name_from, const std::string &name_to, std::vector<std::string> options)
{
if (options.empty())
return;

Preset* preset_from = m_presets->find_preset(name_from);
Preset* preset_to = m_presets->find_preset(name_to);

}

// Save the current preset into file.
// This removes the "dirty" flag of the preset, possibly creates a new preset under a new name,
// and activates the new preset.
Expand Down Expand Up @@ -4267,12 +4303,15 @@ wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent)
return sizer;
}

void TabPrinter::cache_extruder_cnt()
void TabPrinter::cache_extruder_cnt(const DynamicPrintConfig* config/* = nullptr*/)
{
if (m_presets->get_edited_preset().printer_technology() == ptSLA)
const DynamicPrintConfig& cached_config = config ? *config : m_presets->get_edited_preset().config;
if (Preset::printer_technology(cached_config) == ptSLA)
return;

m_cache_extruder_count = m_extruders_count;
// get extruders count
auto* nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(cached_config.option("nozzle_diameter"));
m_cache_extruder_count = nozzle_diameter->values.size(); //m_extruders_count;
}

bool TabPrinter::apply_extruder_cnt_from_cache()
Expand All @@ -4282,6 +4321,7 @@ bool TabPrinter::apply_extruder_cnt_from_cache()

if (m_cache_extruder_count > 0) {
m_presets->get_edited_preset().set_num_extruders(m_cache_extruder_count);
// extruders_count_changed(m_cache_extruder_count);
m_cache_extruder_count = 0;
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/slic3r/GUI/Tab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ class Tab: public wxPanel
void OnKeyDown(wxKeyEvent& event);

void compare_preset();
void transfer_options(const std::string&name_from, const std::string&name_to, std::vector<std::string> options);
void save_options(const std::string &name_from, const std::string &name_to, std::vector<std::string> options);
void save_preset(std::string name = std::string(), bool detach = false);
void rename_preset();
void delete_preset();
Expand Down Expand Up @@ -374,7 +376,7 @@ class Tab: public wxPanel

void update_wiping_button_visibility();
void activate_option(const std::string& opt_key, const wxString& category);
void cache_config_diff(const std::vector<std::string>& selected_options);
void cache_config_diff(const std::vector<std::string>& selected_options, const DynamicPrintConfig* config = nullptr);
void apply_config_from_cache();

const std::map<wxString, std::string>& get_category_icon_map() { return m_category_icon; }
Expand Down Expand Up @@ -503,7 +505,7 @@ class TabPrinter : public Tab
bool supports_printer_technology(const PrinterTechnology /* tech */) const override { return true; }

wxSizer* create_bed_shape_widget(wxWindow* parent);
void cache_extruder_cnt();
void cache_extruder_cnt(const DynamicPrintConfig* config = nullptr);
bool apply_extruder_cnt_from_cache();
};

Expand Down
Loading

0 comments on commit 0b8d738

Please sign in to comment.