|
@@ -21,27 +21,56 @@ class MachineSettingsAction(MachineAction):
|
|
|
|
|
|
self._container_index = 0
|
|
|
|
|
|
- cura.Settings.CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
|
|
|
+ self._container_registry = UM.Settings.ContainerRegistry.getInstance()
|
|
|
+ self._container_registry.containerAdded.connect(self._onContainerAdded)
|
|
|
|
|
|
def _reset(self):
|
|
|
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
|
|
- if global_container_stack:
|
|
|
+ if not global_container_stack:
|
|
|
+ return
|
|
|
+
|
|
|
+ # First check if there is a variant previously generated by this machine
|
|
|
+ machine_settings_variant = global_container_stack.findContainer({"type": "variant", "subtype": "machine_settings"})
|
|
|
+ if not machine_settings_variant:
|
|
|
+ # There may be a variant created by the UMOUpgradeSelection machine action
|
|
|
+ machine_settings_variant = global_container_stack.findContainer({"type": "variant", "id": global_container_stack.getName() + "_variant"})
|
|
|
+
|
|
|
+ if not machine_settings_variant:
|
|
|
variant = global_container_stack.findContainer({"type": "variant"})
|
|
|
- if variant:
|
|
|
- variant_index = global_container_stack.getContainerIndex(variant)
|
|
|
- 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):
|
|
|
- # Create and switch to a variant to store the settings in
|
|
|
- new_variant = UM.Settings.InstanceContainer(global_container_stack.getName() + "_variant")
|
|
|
- new_variant.addMetaDataEntry("type", "variant")
|
|
|
- new_variant.setDefinition(global_container_stack.getBottom())
|
|
|
- UM.Settings.ContainerRegistry.getInstance().addContainer(new_variant)
|
|
|
- global_container_stack.replaceContainer(self._container_index, new_variant)
|
|
|
+ if variant and variant.getId() == "empty_variant":
|
|
|
+ # There is an empty variant that we can use to store the machine settings
|
|
|
+ container_index = global_container_stack.getContainerIndex(variant)
|
|
|
+ machine_settings_variant = self._createMachineVariant(global_container_stack, container_index)
|
|
|
+ else:
|
|
|
+ # Add a second variant before the current variant to store the machine settings
|
|
|
+ machine_settings_variant = self._createMachineVariant(global_container_stack)
|
|
|
+
|
|
|
+ # Notify the UI in which container to store the machine settings data
|
|
|
+ container_index = global_container_stack.getContainerIndex(machine_settings_variant)
|
|
|
+ if container_index != self._container_index:
|
|
|
+ self._container_index = container_index
|
|
|
+ self.containerIndexChanged.emit()
|
|
|
+
|
|
|
+ def _createMachineSettingsVariant(self, global_container_stack, container_index = None):
|
|
|
+ machine_settings_variant = UM.Settings.InstanceContainer(global_container_stack.getName() + "_variant")
|
|
|
+ if global_container_stack.getMetaDataEntry("has_variants", False):
|
|
|
+ # If the current machine uses visible variants (eg for nozzle selection), make sure
|
|
|
+ # not to add this variant to the list.
|
|
|
+ definition = self._container_registry.findDefinitionContainers(id="fdmprinter")[0]
|
|
|
+ else:
|
|
|
+ definition = global_container_stack.getBottom()
|
|
|
+ machine_settings_variant.setDefinition(definition)
|
|
|
+ machine_settings_variant.addMetaDataEntry("type", "variant")
|
|
|
+ machine_settings_variant.addMetaDataEntry("subtype", "machine_settings")
|
|
|
+
|
|
|
+ self._container_registry.addContainer(machine_settings_variant)
|
|
|
+
|
|
|
+ if container_index:
|
|
|
+ global_container_stack.replaceContainer(container_index, machine_settings_variant)
|
|
|
+ else:
|
|
|
+ index = len(global_container_stack.getContainers()) - 1
|
|
|
+ global_container_stack.addContainer(machine_settings_variant, index)
|
|
|
+ return machine_settings_variant
|
|
|
|
|
|
containerIndexChanged = pyqtSignal()
|
|
|
|
|
@@ -56,10 +85,6 @@ class MachineSettingsAction(MachineAction):
|
|
|
# Multiextruder printers are not currently supported
|
|
|
UM.Logger.log("d", "Not attaching MachineSettingsAction to %s; Multi-extrusion printers are not supported", container.getId())
|
|
|
return
|
|
|
- if container.getMetaDataEntry("has_variants", False):
|
|
|
- # Machines that use variants are not currently supported
|
|
|
- UM.Logger.log("d", "Not attaching MachineSettingsAction to %s; Machines that use variants are not supported", container.getId())
|
|
|
- return
|
|
|
|
|
|
UM.Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
|
|
|
|
@@ -90,7 +115,7 @@ class MachineSettingsAction(MachineAction):
|
|
|
# Set the material container to a sane default
|
|
|
if material_container.getId() == "empty_material":
|
|
|
search_criteria = { "type": "material", "definition": "fdmprinter", "id": "*pla*" }
|
|
|
- containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
|
|
+ containers = self._container_registry.findInstanceContainers(**search_criteria)
|
|
|
if containers:
|
|
|
global_container_stack.replaceContainer(material_index, containers[0])
|
|
|
else:
|
|
@@ -99,7 +124,7 @@ class MachineSettingsAction(MachineAction):
|
|
|
if "has_materials" in global_container_stack.getMetaData():
|
|
|
global_container_stack.removeMetaDataEntry("has_materials")
|
|
|
|
|
|
- empty_material = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = "empty_material")[0]
|
|
|
+ empty_material = self._container_registry.findInstanceContainers(id = "empty_material")[0]
|
|
|
global_container_stack.replaceContainer(material_index, empty_material)
|
|
|
|
|
|
UM.Application.getInstance().globalContainerStackChanged.emit()
|