From 4152963cebfe74d0b7146c91f59591c9f6aa40e4 Mon Sep 17 00:00:00 2001 From: supermerill Date: Wed, 15 May 2024 14:23:58 +0200 Subject: [PATCH] Fix gcodeviewer by fixing frequent settings construction supermerill/SuperSlicer#4248 --- src/slic3r/GUI/Plater.cpp | 222 ++++++++++++++++++++------------------ 1 file changed, 118 insertions(+), 104 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 6f486af2bba..ee30a76694a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -373,9 +373,6 @@ void FreqChangedParams::init() { DynamicPrintConfig* config = &wxGetApp().preset_bundle->fff_prints.get_edited_preset().config; Tab* tab_freq_fff = wxGetApp().get_tab(Preset::TYPE_FREQUENT_FFF, false); - assert(dynamic_cast(tab_freq_fff)); - if (!dynamic_cast(tab_freq_fff)) - return; /* Not a best solution, but * Temporary workaround for right border alignment @@ -388,122 +385,136 @@ void FreqChangedParams::init() m_empty_buttons.push_back(btn); return sizer; }; - - //std::vector pages; - tab_freq_fff->build(); - //if(tab_freq_fff != nullptr) pages = tab_freq_fff->create_pages(Preset::type_name(tab_freq_fff->type())+".ui", -1, tab_freq_fff->type()); - if (tab_freq_fff->get_page_count() > 0) { - m_og->set_config(config); - m_og->hide_labels(); - m_og->m_on_change = Tab::set_or_add(m_og->m_on_change, [tab_freq_fff, this](t_config_option_key opt_key, boost::any value) - //m_og->m_on_change = [tab_print, this](t_config_option_key opt_key, boost::any value) - { - const Option *opt_def = this->m_og->get_option_def(opt_key); - if (opt_def && !opt_def->opt.is_script) { - tab_freq_fff->update_dirty(); - tab_freq_fff->reload_config(); - static_cast(tab_freq_fff)->update_changed_setting(opt_key); + + assert(tab_freq_fff == nullptr || dynamic_cast(tab_freq_fff)); + if (tab_freq_fff && dynamic_cast(tab_freq_fff)) { + // std::vector pages; + tab_freq_fff->build(); + // if(tab_freq_fff != nullptr) pages = + // tab_freq_fff->create_pages(Preset::type_name(tab_freq_fff->type())+".ui", -1, tab_freq_fff->type()); + if (tab_freq_fff->get_page_count() > 0) { + m_og->set_config(config); + m_og->hide_labels(); + m_og->m_on_change = + Tab::set_or_add(m_og->m_on_change, [tab_freq_fff, this](t_config_option_key opt_key, boost::any value) + // m_og->m_on_change = [tab_print, this](t_config_option_key opt_key, boost::any value) + { + const Option *opt_def = this->m_og->get_option_def(opt_key); + if (opt_def && !opt_def->opt.is_script) { + tab_freq_fff->update_dirty(); + tab_freq_fff->reload_config(); + static_cast(tab_freq_fff)->update_changed_setting(opt_key); + } + }); + assert(tab_freq_fff->get_page_count() == 1); + assert(tab_freq_fff->get_page(0)->m_optgroups.size() == 1); + PageShp page = tab_freq_fff->get_page(0); + m_og->copy_for_freq_settings(*(page->m_optgroups[0].get())); + + // hacks + Line *line_for_purge = nullptr; + for (Line &l : page->m_optgroups[0]->set_lines()) { + if (l.label_tooltip == "freq_purging_volumes") { + l.label_tooltip = ""; + line_for_purge = &l; + } + if (l.get_options().size() == 1 && l.get_options().front().opt.full_width) { + l.append_widget(empty_widget); } - }); - assert(tab_freq_fff->get_page_count() == 1); - assert(tab_freq_fff->get_page(0)->m_optgroups.size() == 1); - PageShp page = tab_freq_fff->get_page(0); - m_og->copy_for_freq_settings(*(page->m_optgroups[0].get())); - - // hacks - Line* line_for_purge = nullptr; - for (Line& l : page->m_optgroups[0]->set_lines()) { - if (l.label_tooltip == "freq_purging_volumes") { - l.label_tooltip = ""; - line_for_purge = &l; } - if (l.get_options().size() == 1 && l.get_options().front().opt.full_width) { - l.append_widget(empty_widget); + // Purging volumesbutton + if (line_for_purge) { + auto wiping_dialog_btn = [this](wxWindow *parent) { + m_wiping_dialog_button = new wxButton(parent, wxID_ANY, _L("Purging volumes") + dots, + wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); + m_wiping_dialog_button->SetFont(wxGetApp().normal_font()); + wxGetApp().UpdateDarkUI(m_wiping_dialog_button, true); + + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(m_wiping_dialog_button, 0, wxALIGN_CENTER_VERTICAL); + m_wiping_dialog_button + ->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent &e) { + auto &project_config = wxGetApp().preset_bundle->project_config; + const std::vector &init_matrix = + (project_config.option("wiping_volumes_matrix"))->values; + const std::vector &init_extruders = + (project_config.option("wiping_volumes_extruders"))->values; + + const std::vector extruder_colours = + wxGetApp().plater()->get_extruder_colors_from_plater_config(); + + WipingDialog dlg(parent, cast(init_matrix), cast(init_extruders), + extruder_colours); + + if (dlg.ShowModal() == wxID_OK) { + std::vector matrix = dlg.get_matrix(); + std::vector extruders = dlg.get_extruders(); + (project_config.option("wiping_volumes_matrix"))->values = + std::vector(matrix.begin(), matrix.end()); + (project_config.option("wiping_volumes_extruders")) + ->values = std::vector(extruders.begin(), extruders.end()); + wxGetApp().plater()->update_project_dirty_from_presets(); + wxPostEvent(parent, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, parent)); + } + })); + + auto btn = new ScalableButton(parent, wxID_ANY, "mirroring_transparent.png", wxEmptyString, + wxDefaultSize, wxDefaultPosition, + wxBU_EXACTFIT | wxNO_BORDER | wxTRANSPARENT_WINDOW); + sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, int(0.3 * wxGetApp().em_unit())); + m_empty_buttons.push_back(btn); + + return sizer; + }; + line_for_purge->append_widget(wiping_dialog_btn); } - } - //Purging volumesbutton - if (line_for_purge) { - auto wiping_dialog_btn = [this](wxWindow* parent) { - m_wiping_dialog_button = new wxButton(parent, wxID_ANY, _L("Purging volumes") + dots, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); - m_wiping_dialog_button->SetFont(wxGetApp().normal_font()); - wxGetApp().UpdateDarkUI(m_wiping_dialog_button, true); - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(m_wiping_dialog_button, 0, wxALIGN_CENTER_VERTICAL); - m_wiping_dialog_button->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent& e) - { - auto& project_config = wxGetApp().preset_bundle->project_config; - const std::vector& init_matrix = (project_config.option("wiping_volumes_matrix"))->values; - const std::vector& init_extruders = (project_config.option("wiping_volumes_extruders"))->values; + for (const Line &l : page->m_optgroups[0]->get_lines()) { m_og->append_line(l); } - const std::vector extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config(); - - WipingDialog dlg(parent, cast(init_matrix), cast(init_extruders), extruder_colours); - - if (dlg.ShowModal() == wxID_OK) { - std::vector matrix = dlg.get_matrix(); - std::vector extruders = dlg.get_extruders(); - (project_config.option("wiping_volumes_matrix"))->values = std::vector(matrix.begin(), matrix.end()); - (project_config.option("wiping_volumes_extruders"))->values = std::vector(extruders.begin(), extruders.end()); - wxGetApp().plater()->update_project_dirty_from_presets(); - wxPostEvent(parent, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, parent)); - } - })); - - auto btn = new ScalableButton(parent, wxID_ANY, "mirroring_transparent.png", wxEmptyString, - wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER | wxTRANSPARENT_WINDOW); - sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, - int(0.3 * wxGetApp().em_unit())); - m_empty_buttons.push_back(btn); - - return sizer; - }; - line_for_purge->append_widget(wiping_dialog_btn); - } - - for (const Line& l : page->m_optgroups[0]->get_lines()) { - m_og->append_line(l); + // current_group->m_on_change = on_change; + m_og->activate(); + m_sizer->Add(m_og->sizer, 0, wxEXPAND); } - - //current_group->m_on_change = on_change; - m_og->activate(); - m_sizer->Add(m_og->sizer, 0, wxEXPAND); } // Frequently changed parameters for SLA_technology Tab* tab_freq_sla = wxGetApp().get_tab(Preset::TYPE_FREQUENT_SLA, false); - tab_freq_sla->build(); - //if (tab_freq_sla != nullptr) pages = tab_freq_sla->create_pages(Preset::type_name(tab_freq_sla->type())+".ui", -1, tab_freq_sla->type()); - if (tab_freq_sla->get_page_count() > 0) { - std::shared_ptr m_og_sla = m_og_other[ptSLA] = std::make_shared(m_parent, ""); - m_og_sla->set_config(config); - m_og_sla->hide_labels(); - m_og_sla->m_on_change = Tab::set_or_add(m_og_sla->m_on_change, [tab_freq_sla, this](t_config_option_key opt_key, boost::any value) - { + assert(tab_freq_sla == nullptr || dynamic_cast(tab_freq_sla)); + if (tab_freq_sla && dynamic_cast(tab_freq_sla)) { + tab_freq_sla->build(); + // if (tab_freq_sla != nullptr) pages = + // tab_freq_sla->create_pages(Preset::type_name(tab_freq_sla->type())+".ui", -1, tab_freq_sla->type()); + if (tab_freq_sla->get_page_count() > 0) { + std::shared_ptr m_og_sla = m_og_other[ptSLA] = + std::make_shared(m_parent, ""); + m_og_sla->set_config(config); + m_og_sla->hide_labels(); + m_og_sla->m_on_change = Tab::set_or_add(m_og_sla->m_on_change, [tab_freq_sla, + this](t_config_option_key opt_key, + boost::any value) { Option opt = this->m_og_other[ptSLA]->create_option_from_def(opt_key); if (!opt.opt.is_script) { tab_freq_sla->update_dirty(); tab_freq_sla->reload_config(); - tab_freq_sla->update(); + static_cast(tab_freq_sla)->update_changed_setting(opt_key); } }); - assert(tab_freq_sla->get_page_count() == 1); - assert(tab_freq_sla->get_page(0)->m_optgroups.size() == 1); - PageShp page = tab_freq_sla->get_page(0); - m_og_sla->copy_for_freq_settings(*(page->m_optgroups[0].get())); - // hacks - Line* line_for_purge = nullptr; - for (Line& l : page->m_optgroups[0]->set_lines()) { - if (l.get_options().size() == 1 && l.get_options().front().opt.full_width) { - l.append_widget(empty_widget); + assert(tab_freq_sla->get_page_count() == 1); + assert(tab_freq_sla->get_page(0)->m_optgroups.size() == 1); + PageShp page = tab_freq_sla->get_page(0); + m_og_sla->copy_for_freq_settings(*(page->m_optgroups[0].get())); + // hacks + Line *line_for_purge = nullptr; + for (Line &l : page->m_optgroups[0]->set_lines()) { + if (l.get_options().size() == 1 && l.get_options().front().opt.full_width) { + l.append_widget(empty_widget); + } } + for (const Line &l : page->m_optgroups[0]->get_lines()) { m_og_sla->append_line(l); } + m_og_sla->activate(); + m_sizer->Add(m_og_sla->sizer, 0, wxEXPAND); } - for (const Line& l : page->m_optgroups[0]->get_lines()) { - m_og_sla->append_line(l); - } - m_og_sla->activate(); - m_sizer->Add(m_og_sla->sizer, 0, wxEXPAND); } } @@ -521,14 +532,17 @@ void FreqChangedParams::Show(bool visible) { void FreqChangedParams::Show(PrinterTechnology tech) { - const bool is_wdb_shown = m_wiping_dialog_button->IsShown(); m_og->Show( (tech & PrinterTechnology::ptFFF) != 0); for (auto& entry : m_og_other) entry.second->Show( (entry.first & tech) != 0); - // correct showing of the FreqChangedParams sizer when m_wiping_dialog_button is hidden - if ((tech & PrinterTechnology::ptFFF) != 0 && !is_wdb_shown) - m_wiping_dialog_button->Hide(); + // correct showing of the FreqChangedParams sizer when m_wiping_dialog_button is hidden + assert(m_wiping_dialog_button); + if (m_wiping_dialog_button) { + const bool is_wdb_shown = m_wiping_dialog_button->IsShown(); + if ((tech & PrinterTechnology::ptFFF) != 0 && !is_wdb_shown) + m_wiping_dialog_button->Hide(); + } } ConfigOptionsGroup* FreqChangedParams::get_og(PrinterTechnology tech)