Skip to content

Commit

Permalink
QoL: Port profile value transfer on profile diff dialog from PrusaSli…
Browse files Browse the repository at this point in the history
…cer (#3737)

* DiffDialog: Implemented a transfer of options from one preset to another
Related to [Feature Request] #5384 - Copy values in Profile comparaison dialog

Cherry-picked from prusa3d/PrusaSlicer@0b8d738

Co-authored-by: YuSanka <[email protected]>

* Remove save button

* Sync with latest PS

* Use Orca button style

* Show tips about trasnfer disabled

---------

Co-authored-by: YuSanka <[email protected]>
  • Loading branch information
Noisyfox and YuSanka authored Jan 24, 2024
1 parent 48541be commit 55b6f2a
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 109 deletions.
13 changes: 13 additions & 0 deletions src/libslic3r/PresetBundle.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
///|/ Copyright (c) Prusa Research 2017 - 2023 Oleksandra Iushchenko @YuSanka, Enrico Turri @enricoturri1966, Lukáš Matěna @lukasmatena, Vojtěch Bubník @bubnikv, David Kocík @kocikdav, Vojtěch Král @vojtechkral
///|/ Copyright (c) 2019 John Drake @foxox
///|/
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
///|/
#ifndef slic3r_PresetBundle_hpp_
#define slic3r_PresetBundle_hpp_

Expand All @@ -7,6 +12,7 @@

#include <memory>
#include <unordered_map>
#include <array>
#include <boost/filesystem/path.hpp>

#define DEFAULT_USER_FOLDER_NAME "default"
Expand Down Expand Up @@ -247,6 +253,13 @@ class PresetBundle
static const char *BBL_DEFAULT_PRINTER_MODEL;
static const char *BBL_DEFAULT_PRINTER_VARIANT;
static const char *BBL_DEFAULT_FILAMENT;

static std::array<Preset::Type, 3> types_list(PrinterTechnology pt) {
if (pt == ptFFF)
return { Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT };
return { Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL };
}

private:
//std::pair<PresetsConfigSubstitutions, std::string> load_system_presets(ForwardCompatibilitySubstitutionRule compatibility_rule);
//BBS: add json related logic
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/ConfigWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2405,9 +2405,9 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
bool check_unsaved_preset_changes = false;
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
9 changes: 4 additions & 5 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3758,8 +3758,7 @@ void GUI_App::request_user_logout()
bool transfer_preset_changes = false;
wxString header = _L("Some presets are modified.") + "\n" +
_L("You can keep the modifield presets to the new project, discard or save changes as new presets.");
using ab = UnsavedChangesDialog::ActionButtons;
wxGetApp().check_and_keep_current_preset_changes(_L("User logged out"), header, ab::KEEP | ab::SAVE, &transfer_preset_changes);
wxGetApp().check_and_keep_current_preset_changes(_L("User logged out"), header, ActionButtons::KEEP | ActionButtons::SAVE, &transfer_preset_changes);

m_device_manager->clean_user_info();
GUI::wxGetApp().sidebar().load_ams_list({}, {});
Expand Down Expand Up @@ -5606,11 +5605,11 @@ std::vector<std::pair<unsigned int, std::string>> GUI_App::get_selected_presets(
bool GUI_App::check_and_save_current_preset_changes(const wxString& caption, const wxString& header, bool remember_choice/* = true*/, bool dont_save_insted_of_discard/* = false*/)
{
if (has_current_preset_changes()) {
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;
if (remember_choice)
act_buttons |= UnsavedChangesDialog::ActionButtons::REMEMBER_CHOISE;
act_buttons |= ActionButtons::REMEMBER_CHOISE;
UnsavedChangesDialog dlg(caption, header, "", act_buttons);
if (dlg.ShowModal() == wxID_CANCEL)
return false;
Expand Down
36 changes: 33 additions & 3 deletions src/slic3r/GUI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,41 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_

wxGetApp().persist_window_geometry(this, true);
wxGetApp().persist_window_geometry(&m_settings_dialog, true);
// 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),
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.types_list() )
process(type);
}
else
process(diff_dlg_type);
};

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


#ifdef __WIN32__

WXLRESULT MainFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
Expand Down Expand Up @@ -3599,9 +3632,6 @@ void MainFrame::RunScript(wxString js)

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 ? _omitL("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 @@ -131,6 +131,7 @@ class MainFrame : public DPIFrame
bool can_delete() const;
bool can_delete_all() const;
bool can_reslice() const;
void bind_diff_dialog();

// BBS
wxBoxSizer* create_side_tools();
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 @@ -8299,10 +8299,9 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_
wxString header = _L("Some presets are modified.") + "\n" +
(yes_or_no ? _L("You can keep the modified presets to the new project or discard them") :
_L("You can keep the modifield presets to the new project, discard or save changes as new presets."));
using ab = UnsavedChangesDialog::ActionButtons;
int act_buttons = ab::KEEP | ab::REMEMBER_CHOISE;
int act_buttons = ActionButtons::KEEP | ActionButtons::REMEMBER_CHOISE;
if (!yes_or_no)
act_buttons |= ab::SAVE;
act_buttons |= ActionButtons::SAVE;
return wxGetApp().check_and_keep_current_preset_changes(_L("Creating a new project"), header, act_buttons, &transfer_preset_changes);
};
int result;
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ wxBoxSizer *PreferencesDialog::create_item_language_combobox(
auto check = [this](bool yes_or_no) {
// if (yes_or_no)
// return true;
int act_btns = UnsavedChangesDialog::ActionButtons::SAVE;
int act_btns = ActionButtons::SAVE;
return wxGetApp().check_and_keep_current_preset_changes(_L("Switching application language"),
_L("Switching application language while some presets are modified."), act_btns);
};
Expand Down
1 change: 0 additions & 1 deletion src/slic3r/GUI/PresetComboBoxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "../Utils/FixModelByWin10.hpp"
#include "../Utils/UndoRedo.hpp"
#include "BitmapCache.hpp"
#include "SavePresetDialog.hpp"
#include "MsgDialog.hpp"
#include "ParamsDialog.hpp"

Expand Down
59 changes: 53 additions & 6 deletions src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
///|/ Copyright (c) Prusa Research 2017 - 2023 Oleksandra Iushchenko @YuSanka, Lukáš Matěna @lukasmatena, Lukáš Hejl @hejllukas, Vojtěch Bubník @bubnikv, Pavel Mikuš @Godrak, Tomáš Mészáros @tamasmeszaros, David Kocík @kocikdav, Enrico Turri @enricoturri1966, Vojtěch Král @vojtechkral
///|/ Copyright (c) 2021 Martin Budden
///|/ Copyright (c) 2021 Ilya @xorza
///|/ Copyright (c) 2019 John Drake @foxox
///|/ Copyright (c) 2019 Matthias Urlichs @smurfix
///|/ Copyright (c) 2019 Thomas Moore
///|/ Copyright (c) 2019 Sijmen Schoon
///|/ Copyright (c) 2018 Martin Loidl @LoidlM
///|/
///|/ ported from lib/Slic3r/GUI/Tab.pm:
///|/ Copyright (c) Prusa Research 2016 - 2018 Vojtěch Bubník @bubnikv, Lukáš Matěna @lukasmatena
///|/ Copyright (c) 2015 - 2017 Joseph Lenox @lordofhyphens
///|/ Copyright (c) Slic3r 2012 - 2016 Alessandro Ranellucci @alranel
///|/ Copyright (c) 2016 Chow Loong Jin @hyperair
///|/ Copyright (c) 2012 QuantumConcepts
///|/ Copyright (c) 2012 Henrik Brix Andersen @henrikbrixandersen
///|/
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
///|/
// #include "libslic3r/GCodeSender.hpp"
//#include "slic3r/Utils/Serial.hpp"
#include "Tab.hpp"
Expand Down Expand Up @@ -1692,9 +1711,9 @@ void Tab::apply_searcher()
wxGetApp().sidebar().get_searcher().apply(m_config, m_type, m_mode);
}

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 @@ -5076,6 +5095,32 @@ 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();
}

// 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 @@ -5513,13 +5558,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;

// BBS. Get extruder count from preset instead of m_extruders_count.
m_cache_extruder_count = dynamic_cast<ConfigOptionFloats*>((m_presets->get_edited_preset().config).option("nozzle_diameter"))->values.size();
// 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 Down
19 changes: 17 additions & 2 deletions src/slic3r/GUI/Tab.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
///|/ Copyright (c) Prusa Research 2017 - 2023 Oleksandra Iushchenko @YuSanka, Tomáš Mészáros @tamasmeszaros, Vojtěch Bubník @bubnikv, Lukáš Matěna @lukasmatena, Enrico Turri @enricoturri1966, Vojtěch Král @vojtechkral
///|/ Copyright (c) 2019 John Drake @foxox
///|/ Copyright (c) 2018 Martin Loidl @LoidlM
///|/
///|/ ported from lib/Slic3r/GUI/Tab.pm:
///|/ Copyright (c) Prusa Research 2016 - 2018 Vojtěch Bubník @bubnikv, Lukáš Matěna @lukasmatena
///|/ Copyright (c) 2015 - 2017 Joseph Lenox @lordofhyphens
///|/ Copyright (c) Slic3r 2012 - 2016 Alessandro Ranellucci @alranel
///|/ Copyright (c) 2016 Chow Loong Jin @hyperair
///|/ Copyright (c) 2012 QuantumConcepts
///|/ Copyright (c) 2012 Henrik Brix Andersen @henrikbrixandersen
///|/
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
///|/
#ifndef slic3r_Tab_hpp_
#define slic3r_Tab_hpp_

Expand Down Expand Up @@ -338,6 +352,7 @@ 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);
//BBS: add project embedded preset relate logic
void save_preset(std::string name = std::string(), bool detach = false, bool save_to_project = false, bool from_input = false, std::string input_name = "");
//void save_preset(std::string name = std::string(), bool detach = false);
Expand Down Expand Up @@ -396,7 +411,7 @@ class Tab: public wxPanel
void update_wiping_button_visibility();
void activate_option(const std::string& opt_key, const wxString& category);
void apply_searcher();
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();
void show_timelapse_warning_dialog();

Expand Down Expand Up @@ -625,7 +640,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 55b6f2a

Please sign in to comment.