FIX:Fix the crashes when users import 3MF files that use third-party printers.

Jira:STUDIO-13586

Change-Id: I977e9e426e2f2b98da389e7bfa8fb57388c55628
(cherry picked from commit 9d170ebd52a94579a81a9e8bc8eb19ae27ba3076)
This commit is contained in:
weizhen.xie 2025-08-01 15:05:37 +08:00 committed by Noisyfox
parent 95c63e2534
commit fa832b7539
3 changed files with 16 additions and 2 deletions

View file

@ -1495,8 +1495,10 @@ bool MainFrame::can_send_gcode() const
if (m_plater && !m_plater->model().objects.empty())
{
auto cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
if (const auto *print_host_opt = cfg.option<ConfigOptionString>("print_host"); print_host_opt)
return !print_host_opt->value.empty();
const auto *print_host_opt = cfg.option<ConfigOptionString>("print_host");
if (! print_host_opt) return false;
else return !print_host_opt->value.empty();
}
return true;
}

View file

@ -94,6 +94,7 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxWindow* parent) :
m_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config;
m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config);
check_host_key_valid();
build_printhost_settings(m_optgroup);
auto dlg_btns = new DialogButtons(this, {"OK"});
@ -726,6 +727,16 @@ void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect)
Refresh();
}
void PhysicalPrinterDialog::check_host_key_valid()
{
std::vector<std::string> keys = {"print_host", "print_host_webui", "printhost_apikey", "printhost_cafile", "printhost_user", "printhost_password", "printhost_port"};
for (auto &key : keys) {
auto it = m_config->option<ConfigOptionString>(key);
if (!it) m_config->set_key_value(key, new ConfigOptionString(""));
}
return;
}
void PhysicalPrinterDialog::OnOK(wxEvent& event)
{
wxGetApp().get_tab(Preset::TYPE_PRINTER)->save_preset("", false, false, true, m_preset_name );

View file

@ -69,6 +69,7 @@ public:
protected:
void on_dpi_changed(const wxRect& suggested_rect) override;
void on_sys_color_changed() override {};
void check_host_key_valid();
};