From 74e9ee0ab7a4770eaf4a06b6737b2199227e8398 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 30 Mar 2017 19:00:41 +0200 Subject: [PATCH 1/2] Fix batched gcode compression for "print over network" CURA-3604 --- .../NetworkPrinterOutputDevice.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py index c3c4ecb2e1..12804ac2ca 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py @@ -795,6 +795,13 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): byte_array_file_data = b"" batched_line = "" + + def _compress_data_and_notify_qt(file_data, data_to_append): + file_data += gzip.compress(data_to_append.encode("utf-8")) + QCoreApplication.processEvents() # Ensure that the GUI does not freeze. + # Pretend that this is a response, as zipping might take a bit of time. + self._last_response_time = time() + for line in self._gcode: if not self._compressing_print: self._progress_message.hide() @@ -807,14 +814,16 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): continue if self._use_gzip: - byte_array_file_data += gzip.compress(batched_line.encode("utf-8")) + _compress_data_and_notify_qt(byte_array_file_data, batched_line) batched_line = "" - QCoreApplication.processEvents() # Ensure that the GUI does not freeze. - # Pretend that this is a response, as zipping might take a bit of time. - self._last_response_time = time() else: byte_array_file_data += line.encode("utf-8") + # don't miss the last batch if it's there + if self._use_gzip: + if batched_line: + _compress_data_and_notify_qt(byte_array_file_data, batched_line) + if self._use_gzip: file_name = "%s.gcode.gz" % Application.getInstance().getPrintInformation().jobName else: From 08071c3aa5f23160efd365036191b392bde24063 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Fri, 31 Mar 2017 12:11:11 +0200 Subject: [PATCH 2/2] Fix batched GCode compression CURA-3604 --- .../NetworkPrinterOutputDevice.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py index 12804ac2ca..61bc3ea89f 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py @@ -796,25 +796,26 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): byte_array_file_data = b"" batched_line = "" - def _compress_data_and_notify_qt(file_data, data_to_append): - file_data += gzip.compress(data_to_append.encode("utf-8")) + def _compress_data_and_notify_qt(data_to_append): + compressed_data = gzip.compress(data_to_append.encode("utf-8")) QCoreApplication.processEvents() # Ensure that the GUI does not freeze. # Pretend that this is a response, as zipping might take a bit of time. self._last_response_time = time() + return compressed_data for line in self._gcode: if not self._compressing_print: self._progress_message.hide() return # Stop trying to zip, abort was called. - # if the gcode was read from a gcode file, self._gcode will be a list of all lines in that file. - # Compressing line by line in this case is extremely slow, so we need to batch them. - if len(batched_line) < max_chars_per_line: - batched_line += line - continue - if self._use_gzip: - _compress_data_and_notify_qt(byte_array_file_data, batched_line) + # if the gcode was read from a gcode file, self._gcode will be a list of all lines in that file. + # Compressing line by line in this case is extremely slow, so we need to batch them. + if len(batched_line) < max_chars_per_line: + batched_line += line + continue + + byte_array_file_data += _compress_data_and_notify_qt(batched_line) batched_line = "" else: byte_array_file_data += line.encode("utf-8") @@ -822,7 +823,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): # don't miss the last batch if it's there if self._use_gzip: if batched_line: - _compress_data_and_notify_qt(byte_array_file_data, batched_line) + byte_array_file_data += _compress_data_and_notify_qt(batched_line) if self._use_gzip: file_name = "%s.gcode.gz" % Application.getInstance().getPrintInformation().jobName