From 6314d872e17ca71e0837421891bfe6dfd56b1f74 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 30 Mar 2017 16:07:26 +0200 Subject: [PATCH 1/7] If we find multiple materials for a new extruder, prefer a read only material CURA-3147 --- cura/Settings/ExtruderManager.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index f6c1759078..746c70099b 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -255,7 +255,12 @@ class ExtruderManager(QObject): preferred_materials = container_registry.findInstanceContainers(**search_criteria) if len(preferred_materials) >= 1: - material = preferred_materials[0] + # In some cases we get multiple materials. In that case, prefer materials that are marked as read only. + read_only_preferred_materials = [preferred_material for preferred_material in preferred_materials if preferred_material.isReadOnly()] + if len(read_only_preferred_materials) >= 1: + material = read_only_preferred_materials[0] + else: + material = preferred_materials[0] else: Logger.log("w", "The preferred material \"%s\" of machine %s doesn't exist or is not a material profile.", preferred_material_id, machine_id) # And leave it at the default material. From 2158826e06f7fc4ef640f98db5c75e1def673049 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 29 Mar 2017 13:46:36 +0200 Subject: [PATCH 2/7] Change backend state to disabled after reading a gcode CURA-3604 --- plugins/GCodeReader/GCodeReader.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index 1f02998cb3..8a9e506fef 100755 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -2,6 +2,7 @@ # Cura is released under the terms of the AGPLv3 or higher. from UM.Application import Application +from UM.Backend import Backend from UM.Job import Job from UM.Logger import Logger from UM.Math.AxisAlignedBox import AxisAlignedBox @@ -356,4 +357,8 @@ class GCodeReader(MeshReader): "Make sure the g-code is suitable for your printer and printer configuration before sending the file to it. The g-code representation may not be accurate."), lifetime=0) caution_message.show() + # The "save/print" button's state is bound to the backend state. + backend = Application.getInstance().getBackend() + backend.backendStateChange.emit(Backend.BackendState.Disabled) + return scene_node From ef666aac88bc8071cf7c33a3459e5a3f1f10fef7 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 30 Mar 2017 15:40:28 +0200 Subject: [PATCH 3/7] Set gcode_list for Scene after loading gcode CURA-3604 --- plugins/GCodeReader/GCodeReader.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index 8a9e506fef..5033557124 100755 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -336,6 +336,8 @@ class GCodeReader(MeshReader): gcode_list_decorator.setGCodeList(gcode_list) scene_node.addDecorator(gcode_list_decorator) + Application.getInstance().getController().getScene().gcode_list = gcode_list + Logger.log("d", "Finished parsing %s" % file_name) self._message.hide() From c785e84b86effbeec0d0f46fcb6fc3803d579e2f Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 30 Mar 2017 15:41:34 +0200 Subject: [PATCH 4/7] Check len(materialLengths) before using CURA-3604 --- plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py index 8c722b0b01..66e0652b79 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py @@ -624,7 +624,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): if print_information.materialLengths: # Check if print cores / materials are loaded at all. Any failure in these results in an Error. for index in range(0, self._num_extruders): - if print_information.materialLengths[index] != 0: + if index < len(print_information.materialLengths) and print_information.materialLengths[index] != 0: if self._json_printer_state["heads"][0]["extruders"][index]["hotend"]["id"] == "": Logger.log("e", "No cartridge loaded in slot %s, unable to start print", index + 1) self._error_message = Message( @@ -642,13 +642,13 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): for index in range(0, self._num_extruders): # Check if there is enough material. Any failure in these results in a warning. material_length = self._json_printer_state["heads"][0]["extruders"][index]["active_material"]["length_remaining"] - if material_length != -1 and print_information.materialLengths[index] > material_length: + if material_length != -1 and index < len(print_information.materialLengths) and print_information.materialLengths[index] > material_length: Logger.log("w", "Printer reports that there is not enough material left for extruder %s. We need %s and the printer has %s", index + 1, print_information.materialLengths[index], material_length) warnings.append(i18n_catalog.i18nc("@label", "Not enough material for spool {0}.").format(index+1)) # Check if the right cartridges are loaded. Any failure in these results in a warning. extruder_manager = cura.Settings.ExtruderManager.ExtruderManager.getInstance() - if print_information.materialLengths[index] != 0: + if index < len(print_information.materialLengths) and print_information.materialLengths[index] != 0: variant = extruder_manager.getExtruderStack(index).findContainer({"type": "variant"}) core_name = self._json_printer_state["heads"][0]["extruders"][index]["hotend"]["id"] if variant: From bfd77f915d7db9cc444d825da1185c846626ca3a Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 30 Mar 2017 16:07:53 +0200 Subject: [PATCH 5/7] Compress gcode lines in batch CURA-3604 --- .../NetworkPrinterOutputDevice.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py index 66e0652b79..b701cf2c0a 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py @@ -790,13 +790,25 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): Logger.log("d", "Started sending g-code to remote printer.") self._compressing_print = True ## Mash the data into single string + + max_chars_per_line = 1024*1024*2 # 2 MB + byte_array_file_data = b"" + batched_line = "" 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: - byte_array_file_data += gzip.compress(line.encode("utf-8")) + byte_array_file_data += gzip.compress(batched_line.encode("utf-8")) + 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() From 7ae8d96775b5b92c1e3cbfb0c60db23e299a9478 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 30 Mar 2017 16:47:08 +0200 Subject: [PATCH 6/7] Simply reset the authentication when requesting a new one. Only changing the state caused a whole lot of issues. --- plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py index b701cf2c0a..f81ab74141 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py @@ -864,7 +864,10 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): url = QUrl("http://" + self._address + self._api_prefix + "auth/request") request = QNetworkRequest(url) request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json") + self._authentication_key = None + self._authentication_id = None self._manager.post(request, json.dumps({"application": "Cura-" + Application.getInstance().getVersion(), "user": self._getUserName()}).encode()) + self.setAuthenticationState(AuthState.AuthenticationRequested) ## Send all material profiles to the printer. def sendMaterialProfiles(self): @@ -1044,7 +1047,6 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): if "/auth/request" in reply_url: # We got a response to requesting authentication. data = json.loads(bytes(reply.readAll()).decode("utf-8")) - self.setAuthenticationState(AuthState.AuthenticationRequested) global_container_stack = Application.getInstance().getGlobalContainerStack() if global_container_stack: # Remove any old data. Logger.log("d", "Removing old network authentication data as a new one was requested.") From 06fff748e34745d323803b3dbe574c57528d20e2 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 30 Mar 2017 16:59:35 +0200 Subject: [PATCH 7/7] Decreased the size of the batches to send, as it froze the interface too much. --- plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py index f81ab74141..c3c4ecb2e1 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py @@ -791,7 +791,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._compressing_print = True ## Mash the data into single string - max_chars_per_line = 1024*1024*2 # 2 MB + max_chars_per_line = 1024 * 1024 / 4 # 1 / 4 MB byte_array_file_data = b"" batched_line = ""