Browse Source

rename scene.gcode_list to gcode_dict

CURA-4741

With the multi build plate feature, scene.gcode_list is now a dict which
stores a list of gcode for a build plate, so it makes more sense to have
it renamed to "gcode_dict" because it's not a list.
Lipu Fei 7 years ago
parent
commit
c8cef9583e

+ 8 - 8
plugins/CuraEngineBackend/CuraEngineBackend.py

@@ -205,8 +205,8 @@ class CuraEngineBackend(QObject, Backend):
             Logger.log("d", "  ## Process layers job still busy, trying later")
             return
 
-        if not hasattr(self._scene, "gcode_list"):
-            self._scene.gcode_list = {}
+        if not hasattr(self._scene, "gcode_dict"):
+            self._scene.gcode_dict = {}
 
         # see if we really have to slice
         active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate
@@ -214,7 +214,7 @@ class CuraEngineBackend(QObject, Backend):
         Logger.log("d", "Going to slice build plate [%s]!" % build_plate_to_be_sliced)
         num_objects = self._numObjects()
         if build_plate_to_be_sliced not in num_objects or num_objects[build_plate_to_be_sliced] == 0:
-            self._scene.gcode_list[build_plate_to_be_sliced] = []
+            self._scene.gcode_dict[build_plate_to_be_sliced] = []
             Logger.log("d", "Build plate %s has no objects to be sliced, skipping", build_plate_to_be_sliced)
             if self._build_plates_to_be_sliced:
                 self.slice()
@@ -234,7 +234,7 @@ class CuraEngineBackend(QObject, Backend):
         self.processingProgress.emit(0.0)
         self.backendStateChange.emit(BackendState.NotStarted)
 
-        self._scene.gcode_list[build_plate_to_be_sliced] = []  #[] indexed by build plate number
+        self._scene.gcode_dict[build_plate_to_be_sliced] = []  #[] indexed by build plate number
         self._slicing = True
         self.slicingStarted.emit()
 
@@ -393,7 +393,7 @@ class CuraEngineBackend(QObject, Backend):
                 self.backendStateChange.emit(BackendState.Disabled)
             gcode_list = node.callDecoration("getGCodeList")
             if gcode_list is not None:
-                self._scene.gcode_list[node.callDecoration("getBuildPlateNumber")] = gcode_list
+                self._scene.gcode_dict[node.callDecoration("getBuildPlateNumber")] = gcode_list
 
         if self._use_timer == enable_timer:
             return self._use_timer
@@ -560,7 +560,7 @@ class CuraEngineBackend(QObject, Backend):
         self.backendStateChange.emit(BackendState.Done)
         self.processingProgress.emit(1.0)
 
-        gcode_list = self._scene.gcode_list[self._start_slice_job_build_plate]
+        gcode_list = self._scene.gcode_dict[self._start_slice_job_build_plate]
         for index, line in enumerate(gcode_list):
             replaced = line.replace("{print_time}", str(Application.getInstance().getPrintInformation().currentPrintTime.getDisplayString(DurationFormat.Format.ISO8601)))
             replaced = replaced.replace("{filament_amount}", str(Application.getInstance().getPrintInformation().materialLengths))
@@ -590,14 +590,14 @@ class CuraEngineBackend(QObject, Backend):
     #
     #   \param message The protobuf message containing g-code, encoded as UTF-8.
     def _onGCodeLayerMessage(self, message):
-        self._scene.gcode_list[self._start_slice_job_build_plate].append(message.data.decode("utf-8", "replace"))
+        self._scene.gcode_dict[self._start_slice_job_build_plate].append(message.data.decode("utf-8", "replace"))
 
     ##  Called when a g-code prefix message is received from the engine.
     #
     #   \param message The protobuf message containing the g-code prefix,
     #   encoded as UTF-8.
     def _onGCodePrefixMessage(self, message):
-        self._scene.gcode_list[self._start_slice_job_build_plate].insert(0, message.data.decode("utf-8", "replace"))
+        self._scene.gcode_dict[self._start_slice_job_build_plate].insert(0, message.data.decode("utf-8", "replace"))
 
     ##  Creates a new socket connection.
     def _createSocket(self):

+ 3 - 1
plugins/CuraEngineBackend/ProcessGCodeJob.py

@@ -12,4 +12,6 @@ class ProcessGCodeLayerJob(Job):
         self._message = message
 
     def run(self):
-        self._scene.gcode_list.append(self._message.data.decode("utf-8", "replace"))
+        active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate
+        gcode_list = self._scene.gcode_dict[active_build_plate_id]
+        gcode_list.append(self._message.data.decode("utf-8", "replace"))

+ 4 - 1
plugins/GCodeReader/FlavorParser.py

@@ -430,7 +430,10 @@ class FlavorParser:
         gcode_list_decorator.setGCodeList(gcode_list)
         scene_node.addDecorator(gcode_list_decorator)
 
-        Application.getInstance().getController().getScene().gcode_list = gcode_list
+        # gcode_dict stores gcode_lists for a number of build plates.
+        active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate
+        gcode_dict = {active_build_plate_id: gcode_list}
+        Application.getInstance().getController().getScene().gcode_dict = gcode_dict
 
         Logger.log("d", "Finished parsing %s" % file_name)
         self._message.hide()

+ 4 - 1
plugins/GCodeWriter/GCodeWriter.py

@@ -61,7 +61,10 @@ class GCodeWriter(MeshWriter):
 
         active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate
         scene = Application.getInstance().getController().getScene()
-        gcode_list = getattr(scene, "gcode_list")[active_build_plate]
+        gcode_dict = getattr(scene, "gcode_dict")
+        if not gcode_dict:
+            return False
+        gcode_list = gcode_dict.get(active_build_plate)
         if gcode_list:
             for gcode in gcode_list:
                 stream.write(gcode)

+ 13 - 10
plugins/UM3NetworkPrinting/NetworkClusterPrinterOutputDevice.py

@@ -244,8 +244,8 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte
         self._request_job = [nodes, file_name, filter_by_machine, file_handler, kwargs]
 
         # the build plates to be sent
-        gcodes = getattr(Application.getInstance().getController().getScene(), "gcode_list")
-        self._job_list = list(gcodes.keys())
+        gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict")
+        self._job_list = list(gcode_dict.keys())
         Logger.log("d", "build plates to be sent to printer: %s", (self._job_list))
 
         if self._stage != OutputStage.ready:
@@ -281,11 +281,14 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte
     def sendPrintJob(self):
         nodes, file_name, filter_by_machine, file_handler, kwargs = self._request_job
         output_build_plate_number = self._job_list.pop(0)
-        gcode = getattr(Application.getInstance().getController().getScene(), "gcode_list")[output_build_plate_number]
-        if not gcode:  # Empty build plate
+        gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict")[output_build_plate_number]
+        if not gcode_dict:  # Empty build plate
             Logger.log("d", "Skipping empty job (build plate number %d).", output_build_plate_number)
             return self.sendPrintJob()
 
+        active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate
+        gcode_list = gcode_dict[active_build_plate_id]
+
         self._send_gcode_start = time.time()
         Logger.log("d", "Sending print job [%s] to host, build plate [%s]..." % (file_name, output_build_plate_number))
 
@@ -302,7 +305,7 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte
 
         require_printer_name = self._selected_printer["unique_name"]
 
-        new_request = self._buildSendPrintJobHttpRequest(require_printer_name, gcode)
+        new_request = self._buildSendPrintJobHttpRequest(require_printer_name, gcode_list)
         if new_request is None or self._stage != OutputStage.uploading:
             return
         self._request = new_request
@@ -310,7 +313,7 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte
         self._reply.uploadProgress.connect(self._onUploadProgress)
         # See _finishedPrintJobPostRequest()
 
-    def _buildSendPrintJobHttpRequest(self, require_printer_name, gcode):
+    def _buildSendPrintJobHttpRequest(self, require_printer_name, gcode_list):
         api_url = QUrl(self._api_base_uri + "print_jobs/")
         request = QNetworkRequest(api_url)
         # Create multipart request and add the g-code.
@@ -321,7 +324,7 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte
         part.setHeader(QNetworkRequest.ContentDispositionHeader,
                        'form-data; name="file"; filename="%s"' % (self._file_name))
 
-        compressed_gcode = self._compressGcode(gcode)
+        compressed_gcode = self._compressGcode(gcode_list)
         if compressed_gcode is None:
             return None     # User aborted print, so stop trying.
 
@@ -339,7 +342,7 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte
         self._addUserAgentHeader(request)
         return request
 
-    def _compressGcode(self, gcode):
+    def _compressGcode(self, gcode_list):
         self._compressing_print = True
         batched_line = ""
         max_chars_per_line = int(1024 * 1024 / 4)  # 1 / 4  MB
@@ -354,11 +357,11 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte
             self._last_response_time = time.time()
             return compressed_data
 
-        if gcode is None:
+        if gcode_list is None:
             Logger.log("e", "Unable to find sliced gcode, returning empty.")
             return byte_array_file_data
 
-        for line in gcode:
+        for line in gcode_list:
             if not self._compressing_print:
                 self._progress_message.hide()
                 return None     # Stop trying to zip, abort was called.

+ 1 - 1
plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py

@@ -676,7 +676,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
         self._print_finished = True
         self.writeStarted.emit(self)
         active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate
-        self._gcode = getattr(Application.getInstance().getController().getScene(), "gcode_list")[active_build_plate]
+        self._gcode = getattr(Application.getInstance().getController().getScene(), "gcode_dict")[active_build_plate]
 
         print_information = Application.getInstance().getPrintInformation()
         warnings = []  # There might be multiple things wrong. Keep a list of all the stuff we need to warn about.

+ 4 - 1
plugins/USBPrinting/USBPrinterOutputDevice.py

@@ -163,7 +163,10 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
 
     def startPrint(self):
         self.writeStarted.emit(self)
-        gcode_list = getattr( Application.getInstance().getController().getScene(), "gcode_list")
+        active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate
+        gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict")
+        gcode_list = gcode_dict[active_build_plate_id]
+
         self._updateJobState("printing")
         self.printGCode(gcode_list)