From 9e6f5a4a6898609766b138d82e87e980f0b4e5ff Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 10:04:47 +0200 Subject: [PATCH 1/8] 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.") } } From 253bb5f43c039b793fbc73a3f892db780b4c8389 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 10:56:01 +0200 Subject: [PATCH 2/8] Removing hasHeatedBed from MachineManagerModel again.. --- cura/MachineManagerModel.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index fc978916e1..46425ba55e 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -485,13 +485,6 @@ 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: From 5128ea41c46b94784cf582589e27121b39d8767f Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 10:57:58 +0200 Subject: [PATCH 3/8] Getting "machine_heated_bed" (hopefully) correctly + little fix --- plugins/USBPrinting/USBPrinterOutputDeviceManager.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index 74072e324e..7c5d63c381 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -129,8 +129,13 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, return USBPrinterOutputDeviceManager._instance def _getDefaultFirmwareName(self): + # Detecting id of the current machine machine_manager_model = MachineManagerModel() machine_id = machine_manager_model.activeDefinitionId + + # Detecting whether it has a heated bed + _active_container_stack = Application.getInstance().getGlobalContainerStack() + machine_has_heated_bed = _active_container_stack.getProperty("machine_heated_bed", "value") if platform.system() == "Linux": baudrate = 115200 @@ -156,8 +161,8 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, ##TODO: Add check for multiple extruders hex_file = None 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) + if machine_id in machine_with_heated_bed.keys() and machine_has_heated_bed: + Logger.log("d", "Choosing firmware with heated bed enabled for machine %s.", machine_id) 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_id) From a7fc3258a74ef09ef2f56d75768bcdeb3850bf96 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 11:16:13 +0200 Subject: [PATCH 4/8] Only use Application.[...].getGlobalContainerStack() to get all values --- plugins/USBPrinting/USBPrinterOutputDeviceManager.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index 7c5d63c381..aa6a731c22 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -13,7 +13,6 @@ 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 @@ -130,13 +129,11 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, def _getDefaultFirmwareName(self): # Detecting id of the current machine - machine_manager_model = MachineManagerModel() - machine_id = machine_manager_model.activeDefinitionId + machine_id = Application.getInstance().getGlobalContainerStack().getBottom().id # Detecting whether it has a heated bed - _active_container_stack = Application.getInstance().getGlobalContainerStack() - machine_has_heated_bed = _active_container_stack.getProperty("machine_heated_bed", "value") - + machine_has_heated_bed = Application.getInstance().getGlobalContainerStack().getProperty("machine_heated_bed", "value") + if platform.system() == "Linux": baudrate = 115200 else: From 2e7db9b732cea603f64f8ed791e156f495830d6d Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 14:38:23 +0200 Subject: [PATCH 5/8] Adding check whether getGlobalContainerStack() returns None or not. If we get None here, the firmware-updater will be closed and detailed error returned to the logs with an explanation why. --- plugins/USBPrinting/USBPrinterOutputDeviceManager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index aa6a731c22..2adacde743 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -128,11 +128,18 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, return USBPrinterOutputDeviceManager._instance def _getDefaultFirmwareName(self): + # Check whether getGlobalContainerStack() returns None or not... + global_container_stack = Application.getInstance().getGlobalContainerStack() + if not global_container_stack: + Logger.log("c", "getGlobalContainerStack() returned None") + Logger.log("i", "Closing firmware-updater UI as a consequence") + self._firmware_view.close() + # Detecting id of the current machine - machine_id = Application.getInstance().getGlobalContainerStack().getBottom().id + machine_id = global_container_stack.getBottom().id # Detecting whether it has a heated bed - machine_has_heated_bed = Application.getInstance().getGlobalContainerStack().getProperty("machine_heated_bed", "value") + machine_has_heated_bed = global_container_stack.getProperty("machine_heated_bed", "value") if platform.system() == "Linux": baudrate = 115200 From 51222325b0685307e97fdb6901cb814ec813b7ae Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 17:29:49 +0200 Subject: [PATCH 6/8] Last cleanup Removing useless comments and replacing the log message with something more simple. --- plugins/USBPrinting/USBPrinterOutputDeviceManager.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index 2adacde743..b8286e7af5 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -131,14 +131,12 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, # Check whether getGlobalContainerStack() returns None or not... global_container_stack = Application.getInstance().getGlobalContainerStack() if not global_container_stack: - Logger.log("c", "getGlobalContainerStack() returned None") - Logger.log("i", "Closing firmware-updater UI as a consequence") + Logger.log("e", "There is no global container stack. Can not update firmware.") self._firmware_view.close() - # Detecting id of the current machine + # The bottom of the containerstack is the machine definition machine_id = global_container_stack.getBottom().id - # Detecting whether it has a heated bed machine_has_heated_bed = global_container_stack.getProperty("machine_heated_bed", "value") if platform.system() == "Linux": From 6b41608db27782a848a21ac4b8e466f5d8132e79 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 17:33:52 +0200 Subject: [PATCH 7/8] Correcting the last comment.. --- plugins/USBPrinting/USBPrinterOutputDeviceManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index b8286e7af5..3974881b0b 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -128,7 +128,7 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, return USBPrinterOutputDeviceManager._instance def _getDefaultFirmwareName(self): - # Check whether getGlobalContainerStack() returns None or not... + # Check if there is a valid global container stack global_container_stack = Application.getInstance().getGlobalContainerStack() if not global_container_stack: Logger.log("e", "There is no global container stack. Can not update firmware.") From 7ef64cd05b3ee3fb7952f19379498a1894275cb5 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Wed, 15 Jun 2016 17:43:28 +0200 Subject: [PATCH 8/8] Return an empty string just to be sure --- plugins/USBPrinting/USBPrinterOutputDeviceManager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index 3974881b0b..a66df1381a 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -133,6 +133,7 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin, if not global_container_stack: Logger.log("e", "There is no global container stack. Can not update firmware.") self._firmware_view.close() + return "" # The bottom of the containerstack is the machine definition machine_id = global_container_stack.getBottom().id