From bc52830c8902f14a53bd40fa009856e545876436 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Fri, 28 Sep 2018 11:49:00 +0200 Subject: [PATCH] Move getDefaultFirmwareName() into GlobalStack --- cura/Settings/GlobalStack.py | 29 ++++++++++++++++- cura/Settings/MachineManager.py | 32 ------------------- .../UpgradeFirmwareMachineAction.qml | 2 +- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py index 517b45eb98..e3ae8c2deb 100755 --- a/cura/Settings/GlobalStack.py +++ b/cura/Settings/GlobalStack.py @@ -4,7 +4,7 @@ from collections import defaultdict import threading from typing import Any, Dict, Optional, Set, TYPE_CHECKING -from PyQt5.QtCore import pyqtProperty +from PyQt5.QtCore import pyqtProperty, pyqtSlot from UM.Decorators import override from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase @@ -13,6 +13,8 @@ from UM.Settings.SettingInstance import InstanceState from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.Interfaces import PropertyEvaluationContext from UM.Logger import Logger +from UM.Resources import Resources +from UM.Platform import Platform from UM.Util import parseBool import cura.CuraApplication @@ -200,6 +202,31 @@ class GlobalStack(CuraContainerStack): def getHasMachineQuality(self) -> bool: return parseBool(self.getMetaDataEntry("has_machine_quality", False)) + ## Get default firmware file name if one is specified in the firmware + @pyqtSlot(result = str) + def getDefaultFirmwareName(self) -> str: + machine_has_heated_bed = self.getProperty("machine_heated_bed", "value") + + baudrate = 250000 + if Platform.isLinux(): + # Linux prefers a baudrate of 115200 here because older versions of + # pySerial did not support a baudrate of 250000 + baudrate = 115200 + + # If a firmware file is available, it should be specified in the definition for the printer + hex_file = self.getMetaDataEntry("firmware_file", None) + if machine_has_heated_bed: + hex_file = self.getMetaDataEntry("firmware_hbk_file", hex_file) + + if hex_file: + try: + return Resources.getPath(cura.CuraApplication.CuraApplication.ResourceTypes.Firmware, hex_file.format(baudrate=baudrate)) + except FileNotFoundError: + Logger.log("w", "Firmware file %s not found.", hex_file) + return "" + else: + Logger.log("w", "There is no firmware for machine %s.", self.getBottom().id) + return "" ## private: global_stack_mime = MimeType( diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 911022b6ac..0abb1a5dc2 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -10,7 +10,6 @@ from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.Interfaces import ContainerInterface from UM.Signal import Signal -from UM.Platform import Platform from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QTimer from UM.FlameProfiler import pyqtSlot @@ -1540,34 +1539,3 @@ class MachineManager(QObject): with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue): self.updateMaterialWithVariant(None) self._updateQualityWithMaterial() - - ## Get default firmware file name if one is specified in the firmware - @pyqtSlot(result = str) - def getDefaultFirmwareName(self) -> str: - # Check if there is a valid global container stack - if not self._global_container_stack: - return "" - - # The bottom of the containerstack is the machine definition - machine_has_heated_bed = self._global_container_stack.getProperty("machine_heated_bed", "value") - - baudrate = 250000 - if Platform.isLinux(): - # Linux prefers a baudrate of 115200 here because older versions of - # pySerial did not support a baudrate of 250000 - baudrate = 115200 - - # If a firmware file is available, it should be specified in the definition for the printer - hex_file = self._global_container_stack.getMetaDataEntry("firmware_file", None) - if machine_has_heated_bed: - hex_file = self._global_container_stack.getMetaDataEntry("firmware_hbk_file", hex_file) - - if hex_file: - try: - return Resources.getPath(cura.CuraApplication.CuraApplication.ResourceTypes.Firmware, hex_file.format(baudrate=baudrate)) - except FileNotFoundError: - Logger.log("w", "Firmware file %s not found.", hex_file) - return "" - else: - Logger.log("w", "There is no firmware for machine %s.", self._global_container_stack.getBottom().id) - return "" diff --git a/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml b/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml index 0d12f72a0a..469ada7afb 100644 --- a/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml +++ b/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml @@ -51,7 +51,7 @@ Cura.MachineAction anchors.horizontalCenter: parent.horizontalCenter width: childrenRect.width spacing: UM.Theme.getSize("default_margin").width - property var firmwareName: Cura.MachineManager.getDefaultFirmwareName() + property var firmwareName: Cura.MachineManager.activeMachine.getDefaultFirmwareName() Button { id: autoUpgradeButton