mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-11-26 20:31:35 -07:00
Load current machine's extruders upon creation, start and switch of machines
This requires some trickery of initialising the extruder manager before the machine manager is initialised, so that it properly listens to global container stack changes. Contributes to issues CURA-340 and CURA-1278.
This commit is contained in:
parent
98a0f90dae
commit
8b1c363932
3 changed files with 33 additions and 8 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) 2016 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QObject #For communicating data and events to Qt.
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QObject, QVariant #For communicating data and events to Qt.
|
||||
|
||||
import UM.Application #To get the global container stack to find the current machine.
|
||||
import UM.Logger
|
||||
|
|
@ -13,7 +13,7 @@ import UM.Settings.ContainerRegistry #Finding containers by ID.
|
|||
# This keeps a list of extruder stacks for each machine.
|
||||
class ExtruderManager(QObject):
|
||||
## Signal to notify other components when the list of extruders changes.
|
||||
extrudersChanged = pyqtSignal()
|
||||
extrudersChanged = pyqtSignal(QVariant)
|
||||
|
||||
## Notify when the user switches the currently active extruder.
|
||||
activeExtruderChanged = pyqtSignal()
|
||||
|
|
@ -21,8 +21,9 @@ class ExtruderManager(QObject):
|
|||
## Registers listeners and such to listen to changes to the extruders.
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
self._extruder_trains = { } #Extruders for the current machine.
|
||||
self._extruder_trains = { } #Per machine, a dictionary of extruder container stack IDs.
|
||||
self._active_extruder_index = 0
|
||||
UM.Application.getInstance().globalContainerStackChanged.connect(self._addCurrentMachineExtruders)
|
||||
|
||||
## Gets the unique identifier of the currently active extruder stack.
|
||||
#
|
||||
|
|
@ -79,7 +80,7 @@ class ExtruderManager(QObject):
|
|||
for extruder_definition in container_registry.findDefinitionContainers(machine = machine_definition.getId()):
|
||||
position = extruder_definition.getMetaDataEntry("position", None)
|
||||
if not position:
|
||||
UM.Logger.Log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.getId())
|
||||
UM.Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.getId())
|
||||
if not container_registry.findContainerStacks(machine = machine_id, position = position): #Doesn't exist yet.
|
||||
name = container_registry.uniqueName(extruder_definition.getId()) #Make a name based on the ID of the definition.
|
||||
self.createExtruderTrain(extruder_definition, machine_definition, name, position)
|
||||
|
|
@ -89,7 +90,7 @@ class ExtruderManager(QObject):
|
|||
for extruder_train in extruder_trains:
|
||||
self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train.getId()
|
||||
if extruder_trains:
|
||||
self.extrudersChanged.emit()
|
||||
self.extrudersChanged.emit(machine_definition)
|
||||
|
||||
def createExtruderTrain(self, extruder_definition, machine_definition, extruder_train_id, position):
|
||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
||||
|
|
@ -156,3 +157,21 @@ class ExtruderManager(QObject):
|
|||
container_stack.setNextStack(UM.Application.getInstance().getGlobalContainerStack())
|
||||
|
||||
container_registry.addContainer(container_stack)
|
||||
|
||||
## Generates extruders for a specific machine.
|
||||
def getMachineExtruders(self, machine_definition):
|
||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
||||
machine_id = machine_definition.getId()
|
||||
if not machine_id in self._extruder_trains:
|
||||
UM.Logger.log("w", "Tried to get the extruder trains for machine %s, which doesn't exist.", machine_id)
|
||||
return
|
||||
for extruder_train_id in self._extruder_trains[machine_id]:
|
||||
extruder_train = container_registry.findContainerStacks(id = extruder_train_id)
|
||||
if extruder_train:
|
||||
yield extruder_train[0]
|
||||
|
||||
## Adds the extruders of the currently active machine.
|
||||
def _addCurrentMachineExtruders(self):
|
||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
||||
if global_stack and global_stack.getBottom():
|
||||
self.addMachineExtruders(global_stack.getBottom())
|
||||
Loading…
Add table
Add a link
Reference in a new issue