Fix for #7905 - Segfault when changing printer after loading 3mf with a different printer set

Update searcher only before open one of next dialogs : SearchDialog, UnsavedChangesDialog or DiffPresetDialog.
But only Search dialog respects to the mode of PrusaSlicer
This commit is contained in:
YuSanka 2022-04-07 14:22:28 +02:00 committed by Lukas Matena
parent 169ef8bfe4
commit a248490507
8 changed files with 31 additions and 58 deletions

View File

@ -194,7 +194,8 @@ enum ConfigOptionType {
enum ConfigOptionMode {
comSimple = 0,
comAdvanced,
comExpert
comExpert,
comUndef
};
enum PrinterTechnology : unsigned char

View File

@ -1483,22 +1483,18 @@ bool Sidebar::is_multifilament()
return p->combos_filament.size() > 1;
}
static std::vector<Search::InputInfo> get_search_inputs(ConfigOptionMode mode)
void Sidebar::check_and_update_searcher(bool respect_mode /*= false*/)
{
std::vector<Search::InputInfo> ret {};
std::vector<Search::InputInfo> search_inputs{};
auto& tabs_list = wxGetApp().tabs_list;
auto print_tech = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology();
for (auto tab : tabs_list)
if (tab->supports_printer_technology(print_tech))
ret.emplace_back(Search::InputInfo {tab->get_config(), tab->type(), mode});
search_inputs.emplace_back(Search::InputInfo{ tab->get_config(), tab->type() });
return ret;
}
void Sidebar::update_searcher()
{
p->searcher.init(get_search_inputs(m_mode));
p->searcher.check_and_update(wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology(),
respect_mode ? m_mode : comExpert, search_inputs);
}
void Sidebar::update_mode()
@ -1507,7 +1503,6 @@ void Sidebar::update_mode()
update_reslice_btn_tooltip();
update_mode_sizer();
update_searcher();
wxWindowUpdateLocker noUpdates(this);
@ -1565,6 +1560,8 @@ Search::OptionsSearcher& Sidebar::get_searcher()
std::string& Sidebar::get_search_line()
{
// update searcher before show imGui search dialog on the plater, if printer technology or mode was changed
check_and_update_searcher(true);
return p->searcher.search_string();
}
@ -6290,8 +6287,6 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
p->config->set_key_value(opt_key, config.option(opt_key)->clone());
if (opt_key == "printer_technology") {
this->set_printer_technology(config.opt_enum<PrinterTechnology>(opt_key));
// print technology is changed, so we should to update a search list
p->sidebar->update_searcher();
p->sidebar->show_sliced_info_sizer(false);
p->reset_gcode_toolpaths();
p->view3D->get_canvas3d()->reset_sequential_print_clearance();
@ -6537,8 +6532,6 @@ bool Plater::set_printer_technology(PrinterTechnology printer_technology)
p->update_main_toolbar_tooltips();
p->sidebar->get_searcher().set_printer_technology(printer_technology);
p->notification_manager->set_fff(printer_technology == ptFFF);
p->notification_manager->set_slicing_progress_hidden();
@ -6703,9 +6696,11 @@ void Plater::search(bool plater_is_active)
evt.SetControlDown(true);
canvas3D()->on_char(evt);
}
else
else {
p->sidebar->check_and_update_searcher(true);
p->sidebar->get_searcher().show_dialog();
}
}
void Plater::msw_rescale()
{

View File

@ -111,7 +111,7 @@ public:
void update_mode();
bool is_collapsed();
void collapse(bool collapse);
void update_searcher();
void check_and_update_searcher(bool respect_mode = false);
void update_ui_from_settings();
#ifdef _MSW_DARK_MODE

View File

@ -76,7 +76,7 @@ static std::string get_key(const std::string& opt_key, Preset::Type type)
return std::to_string(int(type)) + ";" + opt_key;
}
void OptionsSearcher::append_options(DynamicPrintConfig* config, Preset::Type type, ConfigOptionMode mode)
void OptionsSearcher::append_options(DynamicPrintConfig* config, Preset::Type type)
{
auto emplace = [this, type](const std::string key, const wxString& label)
{
@ -297,27 +297,18 @@ OptionsSearcher::~OptionsSearcher()
{
}
void OptionsSearcher::init(std::vector<InputInfo> input_values)
void OptionsSearcher::check_and_update(PrinterTechnology pt_in, ConfigOptionMode mode_in, std::vector<InputInfo> input_values)
{
options.clear();
for (auto i : input_values)
append_options(i.config, i.type, i.mode);
sort_options();
search(search_line, true);
}
void OptionsSearcher::apply(DynamicPrintConfig* config, Preset::Type type, ConfigOptionMode mode)
{
if (options.empty())
if (printer_technology == pt_in && mode == mode_in)
return;
options.erase(std::remove_if(options.begin(), options.end(), [type](Option opt) {
return opt.type == type;
}), options.end());
options.clear();
append_options(config, type, mode);
printer_technology = pt_in;
mode = mode_in;
for (auto i : input_values)
append_options(i.config, i.type);
sort_options();
search(search_line, true);

View File

@ -32,7 +32,6 @@ struct InputInfo
{
DynamicPrintConfig* config {nullptr};
Preset::Type type {Preset::TYPE_INVALID};
ConfigOptionMode mode {comSimple};
};
struct GroupAndCategory {
@ -82,12 +81,13 @@ class OptionsSearcher
{
std::string search_line;
std::map<std::string, GroupAndCategory> groups_and_categories;
PrinterTechnology printer_technology;
PrinterTechnology printer_technology {ptAny};
ConfigOptionMode mode{ comUndef };
std::vector<Option> options {};
std::vector<FoundOption> found {};
void append_options(DynamicPrintConfig* config, Preset::Type type, ConfigOptionMode mode);
void append_options(DynamicPrintConfig* config, Preset::Type type);
void sort_options() {
std::sort(options.begin(), options.end(), [](const Option& o1, const Option& o2) {
@ -109,10 +109,9 @@ public:
OptionsSearcher();
~OptionsSearcher();
void init(std::vector<InputInfo> input_values);
void apply(DynamicPrintConfig *config,
Preset::Type type,
ConfigOptionMode mode);
void check_and_update( PrinterTechnology pt_in,
ConfigOptionMode mode_in,
std::vector<InputInfo> input_values);
bool search();
bool search(const std::string& search, bool force = false);
@ -129,8 +128,6 @@ public:
const GroupAndCategory& get_group_and_category (const std::string& opt_key) { return groups_and_categories[opt_key]; }
std::string& search_string() { return search_line; }
void set_printer_technology(PrinterTechnology pt) { printer_technology = pt; }
void sort_options_by_key() {
std::sort(options.begin(), options.end(), [](const Option& o1, const Option& o2) {
return o1.key < o2.key; });

View File

@ -1233,11 +1233,6 @@ 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::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)
{
m_cache_config.apply_only(m_presets->get_edited_preset().config, selected_options);
@ -2867,9 +2862,6 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
// Reload preset pages with current configuration values
reload_config();
// apply searcher with current configuration
apply_searcher();
}
// this gets executed after preset is loaded and before GUI fields are updated

View File

@ -392,7 +392,6 @@ public:
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 apply_config_from_cache();

View File

@ -1243,6 +1243,8 @@ void UnsavedChangesDialog::update(Preset::Type type, PresetCollection* dependent
void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* presets_)
{
// update searcher befofre update of tree
wxGetApp().sidebar().check_and_update_searcher();
Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher();
searcher.sort_options_by_key();
@ -1298,9 +1300,6 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
get_string_value(opt_key, old_config), get_string_value(opt_key, new_config), category_icon_map.at(option.category));
}
}
// Revert sort of searcher back
searcher.sort_options_by_label();
}
void UnsavedChangesDialog::on_dpi_changed(const wxRect& suggested_rect)
@ -1606,6 +1605,8 @@ void DiffPresetDialog::update_presets(Preset::Type type)
void DiffPresetDialog::update_tree()
{
// update searcher befofre update of tree
wxGetApp().sidebar().check_and_update_searcher();
Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher();
searcher.sort_options_by_key();
@ -1708,9 +1709,6 @@ void DiffPresetDialog::update_tree()
Fit();
Refresh();
}
// Revert sort of searcher back
searcher.sort_options_by_label();
}
void DiffPresetDialog::on_dpi_changed(const wxRect&)