Skip to content

Commit

Permalink
DiffPresetDialog improvements:
Browse files Browse the repository at this point in the history
* Update presets lists after save changes in edited preset or change printer_technology
* Tab.cpp: Build all unregular pages on a first build of the Printer Settings
  • Loading branch information
YuSanka committed Jan 20, 2021
1 parent 01171c8 commit 316bafb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
23 changes: 13 additions & 10 deletions src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ void TabPrinter::build_fff()

build_preset_description_line(optgroup.get());

build_unregular_pages();
build_unregular_pages(true);
}

void TabPrinter::build_sla()
Expand Down Expand Up @@ -2477,14 +2477,11 @@ PageShp TabPrinter::build_kinematics_page()
* but "Machine limits" and "Single extruder MM setup" too
* (These pages can changes according to the another values of a current preset)
* */
void TabPrinter::build_unregular_pages()
void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
{
size_t n_before_extruders = 2; // Count of pages before Extruder pages
bool is_marlin_flavor = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value == gcfMarlin;

// just for first build, if SLA printer preset is selected
bool just_initial_build = m_printer_technology == ptSLA;

/* ! Freeze/Thaw in this function is needed to avoid call OnPaint() for erased pages
* and be cause of application crash, when try to change Preset in moment,
* when one of unregular pages is selected.
Expand All @@ -2502,9 +2499,9 @@ void TabPrinter::build_unregular_pages()
break;
}

if (existed_page < n_before_extruders && (is_marlin_flavor || just_initial_build)) {
if (existed_page < n_before_extruders && (is_marlin_flavor || from_initial_build)) {
auto page = build_kinematics_page();
if (just_initial_build)
if (from_initial_build)
page->clear();
else
m_pages.insert(m_pages.begin() + n_before_extruders, page);
Expand All @@ -2525,7 +2522,7 @@ void TabPrinter::build_unregular_pages()
}
m_has_single_extruder_MM_page = false;
}
if (just_initial_build ||
if (from_initial_build ||
(m_extruders_count > 1 && m_config->opt_bool("single_extruder_multi_material") && !m_has_single_extruder_MM_page)) {
// create a page, but pretend it's an extruder page, so we can add it to m_pages ourselves
auto page = add_options_page(L("Single extruder MM setup"), "printer", true);
Expand All @@ -2535,7 +2532,7 @@ void TabPrinter::build_unregular_pages()
optgroup->append_single_option_line("parking_pos_retraction");
optgroup->append_single_option_line("extra_loading_move");
optgroup->append_single_option_line("high_current_on_filament_swap");
if (just_initial_build)
if (from_initial_build)
page->clear();
else {
m_pages.insert(m_pages.end() - n_after_single_extruder_MM, page);
Expand Down Expand Up @@ -2656,7 +2653,7 @@ void TabPrinter::build_unregular_pages()

m_extruders_count_old = m_extruders_count;

if (just_initial_build)
if (m_printer_technology == ptSLA/*from_initial_build*/)
return; // next part of code is no needed to execute at this moment

rebuild_page_tree();
Expand Down Expand Up @@ -3190,6 +3187,9 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/,

load_current_preset();
}

if (technology_changed)
wxGetApp().mainframe->diff_dialog.update_presets();
}

// If the current preset is dirty, the user is asked whether the changes may be discarded.
Expand Down Expand Up @@ -3451,6 +3451,9 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach)
for (Preset::Type preset_type : dependent)
wxGetApp().get_tab(preset_type)->update_tab_ui();
}

// update preset comboboxes in DiffPresetDlg
wxGetApp().mainframe->diff_dialog.update_presets(m_type);
}

// Called for a currently selected preset.
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Tab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class TabPrinter : public Tab
void update_pages(); // update m_pages according to printer technology
void extruders_count_changed(size_t extruders_count);
PageShp build_kinematics_page();
void build_unregular_pages();
void build_unregular_pages(bool from_initial_build = false);
void on_preset_loaded() override;
void init_options_list() override;
void msw_rescale() override;
Expand Down
38 changes: 35 additions & 3 deletions src/slic3r/GUI/UnsavedChangesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,10 +1427,8 @@ DiffPresetDialog::DiffPresetDialog()
topSizer->SetSizeHints(this);
}

void DiffPresetDialog::show(Preset::Type type /* = Preset::TYPE_INVALID*/)
void DiffPresetDialog::update_controls_visibility(Preset::Type type /* = Preset::TYPE_INVALID*/)
{
this->SetTitle(type == Preset::TYPE_INVALID ? _L("Compare Presets") : format_wxstr(_L("Compare %1% Presets"), wxGetApp().get_tab(type)->name()));

for (auto preset_combos : m_preset_combos) {
Preset::Type cb_type = preset_combos.presets_left->get_type();
bool show = type != Preset::TYPE_INVALID ? type == cb_type :
Expand All @@ -1443,13 +1441,47 @@ void DiffPresetDialog::show(Preset::Type type /* = Preset::TYPE_INVALID*/)
}

m_show_all_presets->Show(type != Preset::TYPE_PRINTER);
}

void DiffPresetDialog::show(Preset::Type type /* = Preset::TYPE_INVALID*/)
{
this->SetTitle(type == Preset::TYPE_INVALID ? _L("Compare Presets") : format_wxstr(_L("Compare %1% Presets"), wxGetApp().get_tab(type)->name()));

update_controls_visibility(type);
if (type == Preset::TYPE_INVALID)
Fit();

update_tree();
Show();
}

void DiffPresetDialog::update_presets(Preset::Type type)
{
m_pr_technology = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology();

update_controls_visibility(type);

if (type == Preset::TYPE_INVALID)
for (auto preset_combos : m_preset_combos) {
if (preset_combos.presets_left->get_type() == Preset::TYPE_PRINTER) {
const std::string& preset_name = wxGetApp().preset_bundle->printers.get_edited_preset().name;
preset_combos.presets_left->update(preset_name);
preset_combos.presets_right->update(preset_name);
break;
}
}
else
for (auto preset_combos : m_preset_combos) {
if (preset_combos.presets_left->get_type() == type) {
preset_combos.presets_left->update();
preset_combos.presets_right->update();
break;
}
}

update_tree();
}

void DiffPresetDialog::update_tree()
{
Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher();
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/GUI/UnsavedChangesDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class DiffPresetDialog : public DPIDialog
PrinterTechnology m_pr_technology;

void update_tree();
void update_controls_visibility(Preset::Type type = Preset::TYPE_INVALID);

struct DiffPresets
{
Expand All @@ -331,6 +332,7 @@ class DiffPresetDialog : public DPIDialog
~DiffPresetDialog() {}

void show(Preset::Type type = Preset::TYPE_INVALID);
void update_presets(Preset::Type type = Preset::TYPE_INVALID);

protected:
void on_dpi_changed(const wxRect& suggested_rect) override;
Expand Down

0 comments on commit 316bafb

Please sign in to comment.