mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-31 12:42:03 +08:00
DiffPresetDialog: Refactoring.
Move logic of a processing of selected options to owned dialog instead of MainFrame.
This commit is contained in:
parent
e9fb61b8aa
commit
bbbeedf1ce
@ -288,49 +288,8 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
|
|||||||
|
|
||||||
preferences_dialog = new PreferencesDialog(this);
|
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),
|
|
||||||
diff_dialog.get_selected_options(type));
|
|
||||||
};
|
|
||||||
|
|
||||||
auto update_presets = [this, get_tab](Preset::Type type) {
|
|
||||||
get_tab(type)->update_preset_choice();
|
|
||||||
m_plater->sidebar().update_presets(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); });
|
|
||||||
|
|
||||||
diff_dialog.Bind(EVT_DIFF_DIALOG_UPDATE_PRESETS,[process_options, update_presets](SimpleEvent&) { process_options(update_presets); });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSW_DARK_MODE
|
#ifdef _MSW_DARK_MODE
|
||||||
static wxString pref() { return " [ "; }
|
static wxString pref() { return " [ "; }
|
||||||
static wxString suff() { return " ] "; }
|
static wxString suff() { return " ] "; }
|
||||||
|
@ -117,7 +117,6 @@ class MainFrame : public DPIFrame
|
|||||||
bool can_delete() const;
|
bool can_delete() const;
|
||||||
bool can_delete_all() const;
|
bool can_delete_all() const;
|
||||||
bool can_reslice() const;
|
bool can_reslice() const;
|
||||||
void bind_diff_dialog();
|
|
||||||
|
|
||||||
// MenuBar items changeable in respect to printer technology
|
// MenuBar items changeable in respect to printer technology
|
||||||
enum MenuItems
|
enum MenuItems
|
||||||
|
@ -41,10 +41,6 @@ namespace Slic3r {
|
|||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
wxDEFINE_EVENT(EVT_DIFF_DIALOG_TRANSFER, SimpleEvent);
|
|
||||||
wxDEFINE_EVENT(EVT_DIFF_DIALOG_UPDATE_PRESETS, SimpleEvent);
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// ModelNode: a node inside DiffModel
|
// ModelNode: a node inside DiffModel
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -2062,13 +2058,34 @@ void DiffPresetDialog::button_event(Action act)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Hide();
|
Hide();
|
||||||
|
|
||||||
if (act == Action::Transfer)
|
if (act == Action::Transfer)
|
||||||
wxPostEvent(this, SimpleEvent(EVT_DIFF_DIALOG_TRANSFER));
|
process_options([this](Preset::Type type) {
|
||||||
|
if (Tab* tab = wxGetApp().get_tab(type))
|
||||||
|
tab->transfer_options(get_left_preset_name(type),
|
||||||
|
get_right_preset_name(type),
|
||||||
|
get_selected_options(type));
|
||||||
|
});
|
||||||
else if (!presets_to_save.empty())
|
else if (!presets_to_save.empty())
|
||||||
wxPostEvent(this, SimpleEvent(EVT_DIFF_DIALOG_UPDATE_PRESETS));
|
process_options([this](Preset::Type type) {
|
||||||
|
if (Tab* tab = wxGetApp().get_tab(type)) {
|
||||||
|
tab->update_preset_choice();
|
||||||
|
wxGetApp().sidebar().update_presets(type);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiffPresetDialog::process_options(std::function<void(Preset::Type)> process)
|
||||||
|
{
|
||||||
|
if (m_view_type == Preset::TYPE_INVALID) {
|
||||||
|
for (const Preset::Type& type : types_list())
|
||||||
|
process(type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
process(m_view_type);
|
||||||
|
};
|
||||||
|
|
||||||
std::string DiffPresetDialog::get_left_preset_name(Preset::Type type)
|
std::string DiffPresetDialog::get_left_preset_name(Preset::Type type)
|
||||||
{
|
{
|
||||||
PresetComboBox* cb = m_preset_combos[int(type - Preset::TYPE_PRINT)].presets_left;
|
PresetComboBox* cb = m_preset_combos[int(type - Preset::TYPE_PRINT)].presets_left;
|
||||||
|
@ -17,10 +17,7 @@ class ScalableButton;
|
|||||||
class wxStaticText;
|
class wxStaticText;
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI{
|
namespace GUI {
|
||||||
|
|
||||||
wxDECLARE_EVENT(EVT_DIFF_DIALOG_TRANSFER, SimpleEvent);
|
|
||||||
wxDECLARE_EVENT(EVT_DIFF_DIALOG_UPDATE_PRESETS, SimpleEvent);
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// ModelNode: a node inside DiffModel
|
// ModelNode: a node inside DiffModel
|
||||||
@ -412,8 +409,7 @@ public:
|
|||||||
void show(Preset::Type type = Preset::TYPE_INVALID);
|
void show(Preset::Type type = Preset::TYPE_INVALID);
|
||||||
void update_presets(Preset::Type type = Preset::TYPE_INVALID, bool update_preset_bundles_from_app = true);
|
void update_presets(Preset::Type type = Preset::TYPE_INVALID, bool update_preset_bundles_from_app = true);
|
||||||
|
|
||||||
Preset::Type view_type() const { return m_view_type; }
|
void process_options(std::function<void(Preset::Type)> process);
|
||||||
PrinterTechnology printer_technology() const { return m_pr_technology; }
|
|
||||||
|
|
||||||
std::string get_left_preset_name(Preset::Type type);
|
std::string get_left_preset_name(Preset::Type type);
|
||||||
std::string get_right_preset_name(Preset::Type type);
|
std::string get_right_preset_name(Preset::Type type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user