From 8f9d8b55eb01cc4ec59df39147ca6117215266ef Mon Sep 17 00:00:00 2001 From: Stone Li Date: Thu, 17 Nov 2022 16:48:59 +0800 Subject: [PATCH] ENH: refine print progress display when sending a print Change-Id: Ie31cc0c1f71f251b79cf5ac2da64cc61c77a4858 Signed-off-by: Stone Li --- src/slic3r/GUI/Jobs/PrintJob.cpp | 33 ++++++++++++++++------ src/slic3r/GUI/Jobs/SendJob.cpp | 48 +++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/slic3r/GUI/Jobs/PrintJob.cpp b/src/slic3r/GUI/Jobs/PrintJob.cpp index e9c90bc8b1..846134c6e6 100644 --- a/src/slic3r/GUI/Jobs/PrintJob.cpp +++ b/src/slic3r/GUI/Jobs/PrintJob.cpp @@ -168,18 +168,26 @@ void PrintJob::process() wxString error_text; wxString msg_text; - auto update_fn = [this, &msg, &curr_percent, &error_text](int stage, int code, std::string info) { + + const int StagePercentPoint[(int)PrintingStageFinished + 1] = { + 20, // PrintingStageCreate + 30, // PrintingStageUpload + 70, // PrintingStageWaiting + 75, // PrintingStageRecord + 99, // PrintingStageSending + 100 // PrintingStageFinished + }; + + auto update_fn = [this, &msg, &curr_percent, &error_text, StagePercentPoint](int stage, int code, std::string info) { if (stage == BBL::SendingPrintJobStage::PrintingStageCreate) { if (this->connection_type == "lan") { msg = _L("Sending print job over LAN"); } else { msg = _L("Sending print job through cloud service"); } - curr_percent = 25; } else if (stage == BBL::SendingPrintJobStage::PrintingStageUpload) { - curr_percent = 30; - if (code == 0 && !info.empty()) { + if (code >= 0 && code <= 100 && !info.empty()) { if (this->connection_type == "lan") { msg = _L("Sending print job over LAN"); } else { @@ -194,10 +202,8 @@ void PrintJob::process() } else { msg = _L("Sending print job through cloud service"); } - curr_percent = 50; } else if (stage == BBL::SendingPrintJobStage::PrintingStageRecord) { - curr_percent = 70; msg = _L("Sending print configuration"); } else if (stage == BBL::SendingPrintJobStage::PrintingStageSending) { @@ -206,10 +212,8 @@ void PrintJob::process() } else { msg = _L("Sending print job through cloud service"); } - curr_percent = 90; } else if (stage == BBL::SendingPrintJobStage::PrintingStageFinished) { - curr_percent = 100; msg = wxString::Format(_L("Successfully sent. Will automatically jump to the device page in %s s"), info); } else { if (this->connection_type == "lan") { @@ -218,7 +222,18 @@ void PrintJob::process() msg = _L("Sending print job through cloud service"); } } - if (code != 0) { + + // update current percnet + if (stage >= 0 && stage <= (int) PrintingStageFinished) { + curr_percent = StagePercentPoint[stage]; + if ((stage == BBL::SendingPrintJobStage::PrintingStageUpload + || stage == BBL::SendingPrintJobStage::PrintingStageRecord) + && (code > 0 && code <= 100)) { + curr_percent = (StagePercentPoint[stage + 1] - StagePercentPoint[stage]) * code / 100 + StagePercentPoint[stage]; + } + } + + if (code > 100 || code < 0) { error_text = this->get_http_error_msg(code, info); msg += wxString::Format("[%s]", error_text); } diff --git a/src/slic3r/GUI/Jobs/SendJob.cpp b/src/slic3r/GUI/Jobs/SendJob.cpp index 40c5fe9a3b..3c04c9cb15 100644 --- a/src/slic3r/GUI/Jobs/SendJob.cpp +++ b/src/slic3r/GUI/Jobs/SendJob.cpp @@ -168,30 +168,37 @@ void SendJob::process() wxString error_text; wxString msg_text; - auto update_fn = [this, &msg, &curr_percent, &error_text](int stage, int code, std::string info) { + const int StagePercentPoint[(int)PrintingStageFinished + 1] = { + 20, // PrintingStageCreate + 30, // PrintingStageUpload + 99, // PrintingStageWaiting + 99, // PrintingStageRecord + 99, // PrintingStageSending + 100 // PrintingStageFinished + }; + + auto update_fn = [this, &msg, &curr_percent, &error_text, StagePercentPoint](int stage, int code, std::string info) { if (stage == SendingPrintJobStage::PrintingStageCreate) { if (this->connection_type == "lan") { msg = _L("Sending gcode file over LAN"); } else { msg = _L("Sending gcode file to sdcard"); } - curr_percent = 25; } else if (stage == SendingPrintJobStage::PrintingStageUpload) { - if (code == 0 && !info.empty()) { - if (this->connection_type == "lan") { - msg = _L("Sending gcode file over LAN"); - } - else { - msg = _L("Sending gcode file to sdcard"); - } - msg += wxString::Format("(%s)", info); - curr_percent = 40; - this->update_status(curr_percent, msg); - } + if (code >= 0 && code <= 100 && !info.empty()) { + if (this->connection_type == "lan") { + msg = _L("Sending gcode file over LAN"); + } + else { + msg = _L("Sending gcode file to sdcard"); + } + if (!info.empty()) { + msg += wxString::Format("(%s)", info); + } + } } else if (stage == SendingPrintJobStage::PrintingStageFinished) { - curr_percent = 100; msg = wxString::Format(_L("Successfully sent. Close current page in %s s"), info); } else { @@ -200,10 +207,19 @@ void SendJob::process() } else { msg = _L("Sending gcode file over LAN"); - //msg = _L("Sending gcode file through cloud service"); } } - if (code != 0) { + + // update current percnet + if (stage >= 0 && stage <= (int) PrintingStageFinished) { + curr_percent = StagePercentPoint[stage]; + if ((stage == BBL::SendingPrintJobStage::PrintingStageUpload) && + (code > 0 && code <= 100)) { + curr_percent = (StagePercentPoint[stage + 1] - StagePercentPoint[stage]) * code / 100 + StagePercentPoint[stage]; + } + } + + if (code < 0 || code > 100) { error_text = this->get_http_error_msg(code, info); msg += wxString::Format("[%s]", error_text); }