From 9e6f5a4a6898609766b138d82e87e980f0b4e5ff Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 10:04:47 +0200 Subject: [PATCH] CURA-1615 - Updating for API 3 This updates the firmware updater to use the new MachineManagerModel Additionally renamed "machine_type" to "machine_id", which makes it more selfexplaining, when reading the code. My printers firmware is not available here and has no heated bed, so please test this commit! --- cura/MachineManagerModel.py | 7 +++++++ .../USBPrinterOutputDeviceManager.py | 21 ++++++++++--------- plugins/USBPrinting/__init__.py | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index 46425ba55e..fc978916e1 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -485,6 +485,13 @@ class MachineManagerModel(QObject): return False + @pyqtProperty(bool, notify = globalContainerChanged) + def hasHeatedBed(self): + if self._active_container_stack: + return bool(self._global_container_stack.getMetaDataEntry("machine_heated_bed", False)) + + return False + @pyqtProperty(bool, notify = globalContainerChanged) def hasVariants(self): if self._active_container_stack: diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index 24e2148375..74072e324e 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -13,6 +13,7 @@ from UM.Qt.ListModel import ListModel from UM.Message import Message from cura.CuraApplication import CuraApplication +from cura.MachineManagerModel import MachineManagerModel import threading import platform @@ -128,8 +129,9 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, return USBPrinterOutputDeviceManager._instance def _getDefaultFirmwareName(self): - machine_instance = Application.getInstance().getMachineManager().getActiveMachineInstance() - machine_type = machine_instance.getMachineDefinition().getId() + machine_manager_model = MachineManagerModel() + machine_id = machine_manager_model.activeDefinitionId + if platform.system() == "Linux": baudrate = 115200 else: @@ -151,23 +153,22 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, } machine_with_heated_bed = {"ultimaker_original" : "MarlinUltimaker-HBK-{baudrate}.hex", } - ##TODO: Add check for multiple extruders hex_file = None - if machine_type in machine_without_extras.keys(): # The machine needs to be defined here! - if machine_type in machine_with_heated_bed.keys() and machine_instance.getMachineSettingValue("machine_heated_bed"): + if machine_id in machine_without_extras.keys(): # The machine needs to be defined here! + if machine_id in machine_with_heated_bed.keys() and machine_manager_model.hasHeatedBed: Logger.log("d", "Choosing firmware with heated bed enabled for machine %s.", machine_type) - hex_file = machine_with_heated_bed[machine_type] # Return firmware with heated bed enabled + hex_file = machine_with_heated_bed[machine_id] # Return firmware with heated bed enabled else: - Logger.log("d", "Choosing basic firmware for machine %s.", machine_type) - hex_file = machine_without_extras[machine_type] # Return "basic" firmware + Logger.log("d", "Choosing basic firmware for machine %s.", machine_id) + hex_file = machine_without_extras[machine_id] # Return "basic" firmware else: - Logger.log("e", "There is no firmware for machine %s.", machine_type) + Logger.log("e", "There is no firmware for machine %s.", machine_id) if hex_file: return hex_file.format(baudrate=baudrate) else: - Logger.log("e", "Could not find any firmware for machine %s.", machine_type) + Logger.log("e", "Could not find any firmware for machine %s.", machine_id) raise FileNotFoundError() ## Helper to identify serial ports (and scan for them) diff --git a/plugins/USBPrinting/__init__.py b/plugins/USBPrinting/__init__.py index 4fab439bad..b8581586d8 100644 --- a/plugins/USBPrinting/__init__.py +++ b/plugins/USBPrinting/__init__.py @@ -13,7 +13,7 @@ def getMetaData(): "name": i18n_catalog.i18nc("@label", "USB printing"), "author": "Ultimaker", "version": "1.0", - "api": 2, + "api": 3, "description": i18n_catalog.i18nc("@info:whatsthis","Accepts G-Code and sends them to a printer. Plugin can also update firmware.") } }