FIX: fix crash when cancel a print job
Change-Id: Ib82d3be93ba7eefeb3a340a060021af323005ba9 Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
parent
7fb886a03c
commit
64fb6e7a24
|
@ -4461,12 +4461,16 @@ const Plater* GUI_App::plater() const
|
|||
|
||||
ParamsPanel* GUI_App::params_panel()
|
||||
{
|
||||
return mainframe->m_param_panel;
|
||||
if (mainframe)
|
||||
return mainframe->m_param_panel;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ParamsDialog* GUI_App::params_dialog()
|
||||
{
|
||||
return mainframe->m_param_dialog;
|
||||
if (mainframe)
|
||||
return mainframe->m_param_dialog;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Model& GUI_App::model()
|
||||
|
@ -4476,22 +4480,28 @@ Model& GUI_App::model()
|
|||
|
||||
void GUI_App::load_url(wxString url)
|
||||
{
|
||||
return mainframe->load_url(url);
|
||||
if (mainframe)
|
||||
return mainframe->load_url(url);
|
||||
}
|
||||
|
||||
void GUI_App::run_script(wxString js)
|
||||
{
|
||||
return mainframe->RunScript(js);
|
||||
if (mainframe)
|
||||
return mainframe->RunScript(js);
|
||||
}
|
||||
|
||||
Notebook* GUI_App::tab_panel() const
|
||||
{
|
||||
return mainframe->m_tabpanel;
|
||||
if (mainframe)
|
||||
return mainframe->m_tabpanel;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NotificationManager * GUI_App::notification_manager()
|
||||
{
|
||||
return plater_->get_notification_manager();
|
||||
if (plater_)
|
||||
return plater_->get_notification_manager();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// extruders count from selected printer preset
|
||||
|
|
|
@ -1035,6 +1035,7 @@ void SelectMachineDialog::update_select_layout(PRINTER_TYPE type)
|
|||
|
||||
void SelectMachineDialog::prepare_mode()
|
||||
{
|
||||
m_is_in_sending_mode = false;
|
||||
if (m_print_job) {
|
||||
m_print_job->join();
|
||||
}
|
||||
|
@ -1051,6 +1052,7 @@ void SelectMachineDialog::prepare_mode()
|
|||
|
||||
void SelectMachineDialog::sending_mode()
|
||||
{
|
||||
m_is_in_sending_mode = true;
|
||||
if (m_simplebook->GetSelection() != 1){
|
||||
m_simplebook->SetSelection(1);
|
||||
Layout();
|
||||
|
@ -1060,6 +1062,7 @@ void SelectMachineDialog::sending_mode()
|
|||
|
||||
void SelectMachineDialog::finish_mode()
|
||||
{
|
||||
m_is_in_sending_mode = false;
|
||||
m_simplebook->SetSelection(2);
|
||||
Layout();
|
||||
Fit();
|
||||
|
@ -1436,7 +1439,11 @@ void SelectMachineDialog::on_cancel(wxCloseEvent &event)
|
|||
|
||||
void SelectMachineDialog::on_ok(wxCommandEvent &event)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << "print_job: on_ok to send";
|
||||
m_is_canceled = false;
|
||||
Enable_Send_Button(false);
|
||||
if (m_is_in_sending_mode)
|
||||
return;
|
||||
|
||||
int result = 0;
|
||||
if (m_printer_last_select.empty()) {
|
||||
|
@ -1466,10 +1473,17 @@ void SelectMachineDialog::on_ok(wxCommandEvent &event)
|
|||
}
|
||||
m_print_job->join();
|
||||
}
|
||||
m_is_canceled = true;
|
||||
wxCommandEvent* event = new wxCommandEvent(EVT_PRINT_JOB_CANCEL);
|
||||
wxQueueEvent(this, event);
|
||||
});
|
||||
|
||||
if (m_is_canceled) {
|
||||
BOOST_LOG_TRIVIAL(info) << "print_job: m_is_canceled";
|
||||
m_status_bar->set_status_text(task_canceled_text);
|
||||
return;
|
||||
}
|
||||
|
||||
// enter sending mode
|
||||
sending_mode();
|
||||
|
||||
|
@ -1478,13 +1492,15 @@ void SelectMachineDialog::on_ok(wxCommandEvent &event)
|
|||
get_ams_mapping_result(ams_mapping_array);
|
||||
|
||||
result = m_plater->send_gcode(m_print_plate_idx, [this](int export_stage, int current, int total, bool &cancel) {
|
||||
if (this->m_is_canceled) return;
|
||||
bool cancelled = false;
|
||||
wxString msg = _L("Preparing print job");
|
||||
m_status_bar->update_status(msg, cancelled, 10, true);
|
||||
m_export_3mf_cancel = cancel = cancelled;
|
||||
});
|
||||
|
||||
if (m_export_3mf_cancel) {
|
||||
if (m_is_canceled || m_export_3mf_cancel) {
|
||||
BOOST_LOG_TRIVIAL(info) << "print_job: m_export_3mf_cancel or m_is_canceled";
|
||||
m_status_bar->set_status_text(task_canceled_text);
|
||||
return;
|
||||
}
|
||||
|
@ -1503,6 +1519,11 @@ void SelectMachineDialog::on_ok(wxCommandEvent &event)
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (m_is_canceled || m_export_3mf_cancel) {
|
||||
BOOST_LOG_TRIVIAL(info) << "print_job: m_export_3mf_cancel or m_is_canceled";
|
||||
m_status_bar->set_status_text(task_canceled_text);
|
||||
return;
|
||||
}
|
||||
|
||||
m_print_job = std::make_shared<PrintJob>(m_status_bar, m_plater, m_printer_last_select);
|
||||
m_print_job->m_dev_ip = obj_->dev_ip;
|
||||
|
@ -1531,6 +1552,7 @@ void SelectMachineDialog::on_ok(wxCommandEvent &event)
|
|||
|
||||
wxCommandEvent evt(m_plater->get_print_finished_event());
|
||||
m_print_job->start();
|
||||
BOOST_LOG_TRIVIAL(info) << "print_job: start print job";
|
||||
}
|
||||
|
||||
void SelectMachineDialog::update_user_machine_list()
|
||||
|
@ -1597,6 +1619,7 @@ void SelectMachineDialog::on_set_finish_mapping(wxCommandEvent &evt)
|
|||
|
||||
void SelectMachineDialog::on_print_job_cancel(wxCommandEvent &evt)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << "print_job: canceled";
|
||||
show_status(PrintDialogStatus::PrintStatusSendingCanceled);
|
||||
// enter prepare mode
|
||||
prepare_mode();
|
||||
|
|
|
@ -298,6 +298,7 @@ protected:
|
|||
|
||||
StateColor btn_bg_enable;
|
||||
int m_current_filament_id;
|
||||
bool m_is_in_sending_mode { false };
|
||||
|
||||
wxGridSizer *m_sizer_select;
|
||||
wxBoxSizer * sizer_thumbnail;
|
||||
|
@ -338,6 +339,7 @@ public:
|
|||
wxObjectDataPtr<MachineListModel> machine_model;
|
||||
std::shared_ptr<BBLStatusBarSend> m_status_bar;
|
||||
bool m_export_3mf_cancel{false};
|
||||
bool m_is_canceled { false };
|
||||
|
||||
protected:
|
||||
std::vector<MachineObject *> m_list;
|
||||
|
|
Loading…
Reference in New Issue