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.
This commit is contained in:
Lipu Fei 2018-01-08 16:18:41 +01:00
parent d05f4a493b
commit c8cef9583e
7 changed files with 37 additions and 23 deletions

View File

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

View File

@ -12,4 +12,6 @@ class ProcessGCodeLayerJob(Job):
self._message = message self._message = message
def run(self): 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"))

View File

@ -430,7 +430,10 @@ class FlavorParser:
gcode_list_decorator.setGCodeList(gcode_list) gcode_list_decorator.setGCodeList(gcode_list)
scene_node.addDecorator(gcode_list_decorator) 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) Logger.log("d", "Finished parsing %s" % file_name)
self._message.hide() self._message.hide()

View File

@ -61,7 +61,10 @@ class GCodeWriter(MeshWriter):
active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate
scene = Application.getInstance().getController().getScene() 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: if gcode_list:
for gcode in gcode_list: for gcode in gcode_list:
stream.write(gcode) stream.write(gcode)

View File

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

View File

@ -676,7 +676,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
self._print_finished = True self._print_finished = True
self.writeStarted.emit(self) self.writeStarted.emit(self)
active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate 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() print_information = Application.getInstance().getPrintInformation()
warnings = [] # There might be multiple things wrong. Keep a list of all the stuff we need to warn about. warnings = [] # There might be multiple things wrong. Keep a list of all the stuff we need to warn about.

View File

@ -163,7 +163,10 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
def startPrint(self): def startPrint(self):
self.writeStarted.emit(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._updateJobState("printing")
self.printGCode(gcode_list) self.printGCode(gcode_list)