mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 23:46:22 -06:00
Moved compressing of GCode to one class higher
CL-541
This commit is contained in:
parent
c6f2e167e2
commit
83b13546fb
4 changed files with 82 additions and 35 deletions
|
@ -45,6 +45,10 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
|||
|
||||
self._cached_multiparts = {}
|
||||
|
||||
self._sending_gcode = False
|
||||
self._compressing_gcode = False
|
||||
self._gcode = []
|
||||
|
||||
def requestWrite(self, nodes, file_name=None, filter_by_machine=False, file_handler=None, **kwargs):
|
||||
raise NotImplementedError("requestWrite needs to be implemented")
|
||||
|
||||
|
@ -57,6 +61,34 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
|||
def authenticationState(self):
|
||||
return self._authentication_state
|
||||
|
||||
def _compressGCode(self):
|
||||
self._compressing_gcode = True
|
||||
|
||||
## Mash the data into single string
|
||||
max_chars_per_line = int(1024 * 1024 / 4) # 1/4 MB per line.
|
||||
byte_array_file_data = b""
|
||||
batched_line = ""
|
||||
|
||||
for line in self._gcode:
|
||||
if not self._compressing_gcode:
|
||||
self._progress_message.hide()
|
||||
# Stop trying to zip / send as abort was called.
|
||||
return
|
||||
batched_line += 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:
|
||||
continue
|
||||
byte_array_file_data += self.__compressDataAndNotifyQt(batched_line)
|
||||
batched_line = ""
|
||||
|
||||
# Don't miss the last batch (If any)
|
||||
if batched_line:
|
||||
byte_array_file_data += self.__compressDataAndNotifyQt(batched_line)
|
||||
|
||||
self._compressing_gcode = False
|
||||
return byte_array_file_data
|
||||
|
||||
def _update(self):
|
||||
if self._last_response_time:
|
||||
time_since_last_response = time() - self._last_response_time
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue