Remove hardcoded container index

This commit is contained in:
fieldOfView 2016-11-08 10:45:43 +01:00
parent 29e04bb825
commit 1325c31882
2 changed files with 28 additions and 16 deletions

View file

@ -1,7 +1,7 @@
# Copyright (c) 2016 Ultimaker B.V. # Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot
from cura.MachineAction import MachineAction from cura.MachineAction import MachineAction
import cura.Settings.CuraContainerRegistry import cura.Settings.CuraContainerRegistry
@ -19,23 +19,35 @@ class MachineSettingsAction(MachineAction):
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings")) super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
self._qml_url = "MachineSettingsAction.qml" self._qml_url = "MachineSettingsAction.qml"
self._container_index = 0
cura.Settings.CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded) cura.Settings.CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
def _reset(self): def _reset(self):
global_container_stack = UM.Application.getInstance().getGlobalContainerStack() global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
if global_container_stack: if global_container_stack:
variant = global_container_stack.findContainer({"type": "variant"}) variant = global_container_stack.findContainer({"type": "variant"})
if variant and variant.getId() == "empty_variant": if variant:
variant_index = global_container_stack.getContainerIndex(variant) variant_index = global_container_stack.getContainerIndex(variant)
self._createVariant(global_container_stack, variant_index) if variant_index != self._container_index:
self._container_index = variant_index
self.containerIndexChanged.emit()
if variant.getId() == "empty_variant":
self._createVariant(global_container_stack, self._container_index)
def _createVariant(self, global_container_stack, variant_index): def _createVariant(self, global_container_stack):
# Create and switch to a variant to store the settings in # Create and switch to a variant to store the settings in
new_variant = UM.Settings.InstanceContainer(global_container_stack.getName() + "_variant") new_variant = UM.Settings.InstanceContainer(global_container_stack.getName() + "_variant")
new_variant.addMetaDataEntry("type", "variant") new_variant.addMetaDataEntry("type", "variant")
new_variant.setDefinition(global_container_stack.getBottom()) new_variant.setDefinition(global_container_stack.getBottom())
UM.Settings.ContainerRegistry.getInstance().addContainer(new_variant) UM.Settings.ContainerRegistry.getInstance().addContainer(new_variant)
global_container_stack.replaceContainer(variant_index, new_variant) global_container_stack.replaceContainer(self._container_index, new_variant)
containerIndexChanged = pyqtSignal()
@pyqtProperty(int, notify = containerIndexChanged)
def containerIndex(self):
return self._container_index
def _onContainerAdded(self, container): def _onContainerAdded(self, container):
# Add this action as a supported action to all machine definitions # Add this action as a supported action to all machine definitions

View file

@ -377,7 +377,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_width" key: "machine_width"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -387,7 +387,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_depth" key: "machine_depth"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -397,7 +397,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_height" key: "machine_height"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -407,7 +407,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_heated_bed" key: "machine_heated_bed"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -417,7 +417,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_center_is_zero" key: "machine_center_is_zero"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -427,7 +427,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_gcode_flavor" key: "machine_gcode_flavor"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -437,7 +437,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_nozzle_size" key: "machine_nozzle_size"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -447,7 +447,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "gantry_height" key: "gantry_height"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -457,7 +457,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_head_with_fans_polygon" key: "machine_head_with_fans_polygon"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
@ -468,7 +468,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_start_gcode" key: "machine_start_gcode"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
UM.SettingPropertyProvider UM.SettingPropertyProvider
@ -478,7 +478,7 @@ Cura.MachineAction
containerStackId: Cura.MachineManager.activeMachineId containerStackId: Cura.MachineManager.activeMachineId
key: "machine_end_gcode" key: "machine_end_gcode"
watchedProperties: [ "value" ] watchedProperties: [ "value" ]
storeIndex: 4 storeIndex: manager.containerIndex
} }
} }