Remove deprecated functions in MachineManager

CURA-6858
This commit is contained in:
Lipu Fei 2019-10-22 13:18:01 +02:00
parent 7544d049c5
commit 38ee4bf208
15 changed files with 27 additions and 170 deletions

View file

@ -447,27 +447,6 @@ class MachineManager(QObject):
def stacksHaveErrors(self) -> bool: def stacksHaveErrors(self) -> bool:
return bool(self._stacks_have_errors) return bool(self._stacks_have_errors)
@pyqtProperty(str, notify = globalContainerChanged)
@deprecated("use Cura.MachineManager.activeMachine.definition.name instead", "4.1")
def activeMachineDefinitionName(self) -> str:
if self._global_container_stack:
return self._global_container_stack.definition.getName()
return ""
@pyqtProperty(str, notify = globalContainerChanged)
@deprecated("use Cura.MachineManager.activeMachine.name instead", "4.1")
def activeMachineName(self) -> str:
if self._global_container_stack:
return self._global_container_stack.getMetaDataEntry("group_name", self._global_container_stack.getName())
return ""
@pyqtProperty(str, notify = globalContainerChanged)
@deprecated("use Cura.MachineManager.activeMachine.id instead", "4.1")
def activeMachineId(self) -> str:
if self._global_container_stack:
return self._global_container_stack.getId()
return ""
@pyqtProperty(str, notify = globalContainerChanged) @pyqtProperty(str, notify = globalContainerChanged)
def activeMachineFirmwareVersion(self) -> str: def activeMachineFirmwareVersion(self) -> str:
if not self._printer_output_devices: if not self._printer_output_devices:
@ -496,13 +475,6 @@ class MachineManager(QObject):
return has_remote_connection return has_remote_connection
return False return False
@pyqtProperty("QVariantList", notify=globalContainerChanged)
@deprecated("use Cura.MachineManager.activeMachine.configuredConnectionTypes instead", "4.1")
def activeMachineConfiguredConnectionTypes(self):
if self._global_container_stack:
return self._global_container_stack.configuredConnectionTypes
return []
@pyqtProperty(bool, notify = printerConnectedStatusChanged) @pyqtProperty(bool, notify = printerConnectedStatusChanged)
def activeMachineIsGroup(self) -> bool: def activeMachineIsGroup(self) -> bool:
return bool(self._printer_output_devices) and len(self._printer_output_devices[0].printers) > 1 return bool(self._printer_output_devices) and len(self._printer_output_devices[0].printers) > 1
@ -554,24 +526,6 @@ class MachineManager(QObject):
return material.getId() return material.getId()
return "" return ""
## Gets a dict with the active materials ids set in all extruder stacks and the global stack
# (when there is one extruder, the material is set in the global stack)
#
# \return The material ids in all stacks
@pyqtProperty("QVariantMap", notify = activeMaterialChanged)
@deprecated("use Cura.MachineManager.activeStack.extruders instead.", "4.3")
def allActiveMaterialIds(self) -> Dict[str, str]:
result = {}
active_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
for stack in active_stacks:
material_container = stack.material
if not material_container:
continue
result[stack.getId()] = material_container.getId()
return result
## Gets the layer height of the currently active quality profile. ## Gets the layer height of the currently active quality profile.
# #
# This is indicated together with the name of the active quality profile. # This is indicated together with the name of the active quality profile.
@ -693,44 +647,6 @@ class MachineManager(QObject):
# Check if the value has to be replaced # Check if the value has to be replaced
extruder_stack.userChanges.setProperty(key, "value", new_value) extruder_stack.userChanges.setProperty(key, "value", new_value)
@pyqtProperty(str, notify = activeVariantChanged)
@deprecated("use Cura.MachineManager.activeStack.variant.name instead", "4.1")
def activeVariantName(self) -> str:
if self._active_container_stack:
variant = self._active_container_stack.variant
if variant:
return variant.getName()
return ""
@pyqtProperty(str, notify = activeVariantChanged)
@deprecated("use Cura.MachineManager.activeStack.variant.id instead", "4.1")
def activeVariantId(self) -> str:
if self._active_container_stack:
variant = self._active_container_stack.variant
if variant:
return variant.getId()
return ""
@pyqtProperty(str, notify = activeVariantChanged)
@deprecated("use Cura.MachineManager.activeMachine.variant.name instead", "4.1")
def activeVariantBuildplateName(self) -> str:
if self._global_container_stack:
variant = self._global_container_stack.variant
if variant:
return variant.getName()
return ""
@pyqtProperty(str, notify = globalContainerChanged)
@deprecated("use Cura.MachineManager.activeMachine.definition.id instead", "4.1")
def activeDefinitionId(self) -> str:
if self._global_container_stack:
return self._global_container_stack.definition.id
return ""
## Get the Definition ID to use to select quality profiles for the currently active machine ## Get the Definition ID to use to select quality profiles for the currently active machine
# \returns DefinitionID (string) if found, empty string otherwise # \returns DefinitionID (string) if found, empty string otherwise
@pyqtProperty(str, notify = globalContainerChanged) @pyqtProperty(str, notify = globalContainerChanged)
@ -788,27 +704,6 @@ class MachineManager(QObject):
# This reuses the method and remove all printers recursively # This reuses the method and remove all printers recursively
self.removeMachine(hidden_containers[0].getId()) self.removeMachine(hidden_containers[0].getId())
@pyqtProperty(bool, notify = globalContainerChanged)
@deprecated("use Cura.MachineManager.activeMachine.hasMaterials instead", "4.2")
def hasMaterials(self) -> bool:
if self._global_container_stack:
return self._global_container_stack.hasMaterials
return False
@pyqtProperty(bool, notify = globalContainerChanged)
@deprecated("use Cura.MachineManager.activeMachine.hasVariants instead", "4.2")
def hasVariants(self) -> bool:
if self._global_container_stack:
return self._global_container_stack.hasVariants
return False
@pyqtProperty(bool, notify = globalContainerChanged)
@deprecated("use Cura.MachineManager.activeMachine.hasVariantBuildplates instead", "4.2")
def hasVariantBuildplates(self) -> bool:
if self._global_container_stack:
return self._global_container_stack.hasVariantBuildplates
return False
## The selected buildplate is compatible if it is compatible with all the materials in all the extruders ## The selected buildplate is compatible if it is compatible with all the materials in all the extruders
@pyqtProperty(bool, notify = activeMaterialChanged) @pyqtProperty(bool, notify = activeMaterialChanged)
def variantBuildplateCompatible(self) -> bool: def variantBuildplateCompatible(self) -> bool:
@ -823,7 +718,8 @@ class MachineManager(QObject):
if material_container == empty_material_container: if material_container == empty_material_container:
continue continue
if material_container.getMetaDataEntry("buildplate_compatible"): if material_container.getMetaDataEntry("buildplate_compatible"):
buildplate_compatible = buildplate_compatible and material_container.getMetaDataEntry("buildplate_compatible")[self.activeVariantBuildplateName] active_buildplate_name = self.activeMachine.variant.name
buildplate_compatible = buildplate_compatible and material_container.getMetaDataEntry("buildplate_compatible")[active_buildplate_name]
return buildplate_compatible return buildplate_compatible
@ -946,7 +842,7 @@ class MachineManager(QObject):
if settable_per_extruder: if settable_per_extruder:
limit_to_extruder = int(self._global_container_stack.getProperty(setting_key, "limit_to_extruder")) limit_to_extruder = int(self._global_container_stack.getProperty(setting_key, "limit_to_extruder"))
extruder_position = max(0, limit_to_extruder) extruder_position = max(0, limit_to_extruder)
extruder_stack = self.getExtruder(extruder_position) extruder_stack = self._global_container_stack.extruderList[extruder_position]
if extruder_stack: if extruder_stack:
extruder_stack.userChanges.setProperty(setting_key, "value", global_user_container.getProperty(setting_key, "value")) extruder_stack.userChanges.setProperty(setting_key, "value", global_user_container.getProperty(setting_key, "value"))
else: else:
@ -957,20 +853,6 @@ class MachineManager(QObject):
self._application.globalContainerStackChanged.emit() self._application.globalContainerStackChanged.emit()
self.forceUpdateAllSettings() self.forceUpdateAllSettings()
@pyqtSlot(int, result = QObject)
def getExtruder(self, position: int) -> Optional[ExtruderStack]:
return self._getExtruder(position)
# This is a workaround for the deprecated decorator and the pyqtSlot not playing well together.
@deprecated("use Cura.MachineManager.activeMachine.extruders instead", "4.2")
def _getExtruder(self, position) -> Optional[ExtruderStack]:
if self._global_container_stack:
try:
return self._global_container_stack.extruderList[int(position)]
except IndexError:
return None
return None
def updateDefaultExtruder(self) -> None: def updateDefaultExtruder(self) -> None:
if self._global_container_stack is None: if self._global_container_stack is None:
return return
@ -1021,10 +903,10 @@ class MachineManager(QObject):
@pyqtSlot(int, bool) @pyqtSlot(int, bool)
def setExtruderEnabled(self, position: int, enabled: bool) -> None: def setExtruderEnabled(self, position: int, enabled: bool) -> None:
extruder = self.getExtruder(position) if self._global_container_stack is None:
if not extruder or self._global_container_stack is None:
Logger.log("w", "Could not find extruder on position %s", position) Logger.log("w", "Could not find extruder on position %s", position)
return return
extruder = self._global_container_stack.extruderList[position]
extruder.setEnabled(enabled) extruder.setEnabled(enabled)
self.updateDefaultExtruder() self.updateDefaultExtruder()
@ -1356,7 +1238,7 @@ class MachineManager(QObject):
@pyqtSlot(str) @pyqtSlot(str)
def switchPrinterType(self, machine_name: str) -> None: def switchPrinterType(self, machine_name: str) -> None:
# Don't switch if the user tries to change to the same type of printer # Don't switch if the user tries to change to the same type of printer
if self._global_container_stack is None or self.activeMachineDefinitionName == machine_name: if self._global_container_stack is None or self._global_container_stack.definition.name == machine_name:
return return
Logger.log("i", "Attempting to switch the printer type to [%s]", machine_name) Logger.log("i", "Attempting to switch the printer type to [%s]", machine_name)
# Get the definition id corresponding to this machine name # Get the definition id corresponding to this machine name

View file

@ -68,7 +68,7 @@ Item
Cura.NumericTextFieldWithUnit // "Nozzle size" Cura.NumericTextFieldWithUnit // "Nozzle size"
{ {
id: extruderNozzleSizeField id: extruderNozzleSizeField
visible: !Cura.MachineManager.hasVariants visible: !Cura.MachineManager.activeMachine.hasVariants
containerStackId: base.extruderStackId containerStackId: base.extruderStackId
settingKey: "machine_nozzle_size" settingKey: "machine_nozzle_size"
settingStoreIndex: propertyStoreIndex settingStoreIndex: propertyStoreIndex

View file

@ -25,7 +25,7 @@ Item
property int controlWidth: (columnWidth / 3) | 0 property int controlWidth: (columnWidth / 3) | 0
property var labelFont: UM.Theme.getFont("default") property var labelFont: UM.Theme.getFont("default")
property string machineStackId: Cura.MachineManager.activeMachineId property string machineStackId: Cura.MachineManager.activeMachine.id
property var forceUpdateFunction: manager.forceUpdate property var forceUpdateFunction: manager.forceUpdate

View file

@ -25,7 +25,7 @@ Rectangle
{ {
// Readability: // Readability:
var connectedTypes = [2, 3]; var connectedTypes = [2, 3];
var types = Cura.MachineManager.activeMachineConfiguredConnectionTypes var types = Cura.MachineManager.activeMachine.configuredConnectionTypes
// Check if configured connection types includes either 2 or 3 (LAN or cloud) // Check if configured connection types includes either 2 or 3 (LAN or cloud)
for (var i = 0; i < types.length; i++) for (var i = 0; i < types.length; i++)

View file

@ -27,7 +27,7 @@ NumericTextFieldWithUnit
id: printerHeadMinMaxField id: printerHeadMinMaxField
UM.I18nCatalog { id: catalog; name: "cura" } UM.I18nCatalog { id: catalog; name: "cura" }
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachine.id
settingKey: "machine_head_with_fans_polygon" settingKey: "machine_head_with_fans_polygon"
settingStoreIndex: 1 settingStoreIndex: 1

View file

@ -32,7 +32,7 @@ Cura.ExpandablePopup
} }
contentPadding: UM.Theme.getSize("default_lining").width contentPadding: UM.Theme.getSize("default_lining").width
enabled: Cura.MachineManager.hasMaterials || Cura.MachineManager.hasVariants || Cura.MachineManager.hasVariantBuildplates; //Only let it drop down if there is any configuration that you could change. enabled: Cura.MachineManager.activeMachine.hasMaterials || Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates; //Only let it drop down if there is any configuration that you could change.
headerItem: Item headerItem: Item
{ {
@ -44,7 +44,7 @@ Cura.ExpandablePopup
orientation: ListView.Horizontal orientation: ListView.Horizontal
anchors.fill: parent anchors.fill: parent
model: extrudersModel model: extrudersModel
visible: Cura.MachineManager.hasMaterials visible: Cura.MachineManager.activeMachine.hasMaterials
delegate: Item delegate: Item
{ {
@ -86,7 +86,7 @@ Cura.ExpandablePopup
{ {
id: variantLabel id: variantLabel
visible: Cura.MachineManager.hasVariants visible: Cura.MachineManager.activeMachine.hasVariants
text: model.variant text: model.variant
elide: Text.ElideRight elide: Text.ElideRight
@ -115,7 +115,7 @@ Cura.ExpandablePopup
color: UM.Theme.getColor("text") color: UM.Theme.getColor("text")
renderType: Text.NativeRendering renderType: Text.NativeRendering
visible: !Cura.MachineManager.hasMaterials && (Cura.MachineManager.hasVariants || Cura.MachineManager.hasVariantBuildplates) visible: !Cura.MachineManager.activeMachine.hasMaterials && (Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates)
anchors anchors
{ {

View file

@ -244,7 +244,7 @@ Item
Row Row
{ {
height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0 height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0
visible: Cura.MachineManager.hasMaterials visible: Cura.MachineManager.activeMachine.hasMaterials
Label Label
{ {
@ -305,7 +305,7 @@ Item
Row Row
{ {
height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0 height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0
visible: Cura.MachineManager.hasVariants visible: Cura.MachineManager.activeMachine.hasVariants
Label Label
{ {

View file

@ -22,13 +22,13 @@ Menu
Menu Menu
{ {
title: modelData.name title: modelData.name
property var extruder: Cura.MachineManager.getExtruder(model.index) property var extruder: Cura.MachineManager.activeMachine.extruderList[model.index]
NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: Cura.MachineManager.hasVariants; extruderIndex: index } NozzleMenu { title: Cura.MachineManager.activeDefinitionVariantsName; visible: Cura.MachineManager.activeMachine.hasVariants; extruderIndex: index }
MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: Cura.MachineManager.hasMaterials; extruderIndex: index } MaterialMenu { title: catalog.i18nc("@title:menu", "&Material"); visible: Cura.MachineManager.activeMachine.hasMaterials; extruderIndex: index }
MenuSeparator MenuSeparator
{ {
visible: Cura.MachineManager.hasVariants || Cura.MachineManager.hasMaterials visible: Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasMaterials
} }
MenuItem MenuItem

View file

@ -84,7 +84,7 @@ UM.ManagementPage
Flow Flow
{ {
id: machineActions id: machineActions
visible: currentItem && currentItem.id == Cura.MachineManager.activeMachineId visible: currentItem && currentItem.id == Cura.MachineManager.activeMachine.id
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: machineName.bottom anchors.top: machineName.bottom

View file

@ -103,7 +103,7 @@ Item
id: activateMenuButton id: activateMenuButton
text: catalog.i18nc("@action:button", "Activate") text: catalog.i18nc("@action:button", "Activate")
iconName: "list-activate" iconName: "list-activate"
enabled: !isCurrentItemActivated && Cura.MachineManager.hasMaterials enabled: !isCurrentItemActivated && Cura.MachineManager.activeMachine.hasMaterials
onClicked: onClicked:
{ {
forceActiveFocus() forceActiveFocus()
@ -227,7 +227,7 @@ Item
text: text:
{ {
var caption = catalog.i18nc("@action:label", "Printer") + ": " + Cura.MachineManager.activeMachine.name; var caption = catalog.i18nc("@action:label", "Printer") + ": " + Cura.MachineManager.activeMachine.name;
if (Cura.MachineManager.hasVariants) if (Cura.MachineManager.activeMachine.hasVariants)
{ {
var activeVariantName = "" var activeVariantName = ""
if(Cura.MachineManager.activeStack != null) if(Cura.MachineManager.activeStack != null)

View file

@ -449,7 +449,7 @@ TabView
UM.ContainerPropertyProvider UM.ContainerPropertyProvider
{ {
id: variantPropertyProvider id: variantPropertyProvider
containerId: Cura.MachineManager.activeVariantId containerId: Cura.MachineManager.activeStack.variant.id
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
key: model.key key: model.key
} }

View file

@ -393,7 +393,7 @@ Item
left: parent.left left: parent.left
} }
visible: text != "" visible: text != ""
text: catalog.i18nc("@label %1 is printer name", "Printer: %1").arg(Cura.MachineManager.activeMachineName) text: catalog.i18nc("@label %1 is printer name", "Printer: %1").arg(Cura.MachineManager.activeMachine.name)
width: profileScrollView.width width: profileScrollView.width
elide: Text.ElideRight elide: Text.ElideRight
} }

View file

@ -32,7 +32,7 @@ ListView
width: listView.width width: listView.width
outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
checked: Cura.MachineManager.activeMachineId == model.id checked: Cura.MachineManager.activeMachine.id == model.id
onClicked: onClicked:
{ {

View file

@ -33,7 +33,7 @@ Item
// Create properties to put property provider stuff in (bindings break in qt 5.5.1 otherwise) // Create properties to put property provider stuff in (bindings break in qt 5.5.1 otherwise)
property var state: propertyProvider.properties.state property var state: propertyProvider.properties.state
// There is no resolve property if there is only one stack. // There is no resolve property if there is only one stack.
property var resolve: Cura.MachineManager.activeStackId !== Cura.MachineManager.activeMachineId ? propertyProvider.properties.resolve : "None" property var resolve: Cura.MachineManager.activeStackId !== Cura.MachineManager.activeMachine.id ? propertyProvider.properties.resolve : "None"
property var stackLevels: propertyProvider.stackLevels property var stackLevels: propertyProvider.stackLevels
property var stackLevel: stackLevels[0] property var stackLevel: stackLevels[0]
// A list of stack levels that will trigger to show the revert button // A list of stack levels that will trigger to show the revert button

View file

@ -90,37 +90,12 @@ def createMockedInstanceContainer(instance_id, name = ""):
return instance return instance
def test_allActiveMaterialIds(machine_manager, extruder_manager):
extruder_1 = createMockedExtruder("extruder_1")
extruder_2 = createMockedExtruder("extruder_2")
extruder_1.material = createMockedInstanceContainer("material_1")
extruder_2.material = createMockedInstanceContainer("material_2")
extruder_manager.getActiveExtruderStacks = MagicMock(return_value = [extruder_1, extruder_2])
assert machine_manager.allActiveMaterialIds == {"extruder_1": "material_1", "extruder_2": "material_2"}
def test_globalVariantName(machine_manager, application): def test_globalVariantName(machine_manager, application):
global_stack = application.getGlobalContainerStack() global_stack = application.getGlobalContainerStack()
global_stack.variant = createMockedInstanceContainer("beep", "zomg") global_stack.variant = createMockedInstanceContainer("beep", "zomg")
assert machine_manager.globalVariantName == "zomg" assert machine_manager.globalVariantName == "zomg"
def test_activeMachineDefinitionName(machine_manager):
global_stack = machine_manager.activeMachine
global_stack.definition = createMockedInstanceContainer("beep", "zomg")
assert machine_manager.activeMachineDefinitionName == "zomg"
def test_activeMachineId(machine_manager):
assert machine_manager.activeMachineId == "GlobalStack"
def test_activeVariantBuildplateName(machine_manager):
global_stack = machine_manager.activeMachine
global_stack.variant = createMockedInstanceContainer("beep", "zomg")
assert machine_manager.activeVariantBuildplateName == "zomg"
def test_resetSettingForAllExtruders(machine_manager): def test_resetSettingForAllExtruders(machine_manager):
global_stack = machine_manager.activeMachine global_stack = machine_manager.activeMachine
extruder_1 = createMockedExtruder("extruder_1") extruder_1 = createMockedExtruder("extruder_1")