mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Tightended up the signals associated with the extruders. Bug fixed.
CURA-1585 Profile dropdown options non functional.
This commit is contained in:
parent
b48db45a37
commit
f52f713694
3 changed files with 70 additions and 57 deletions
|
@ -23,7 +23,8 @@ class ExtruderManager(QObject):
|
|||
super().__init__(parent)
|
||||
self._extruder_trains = { } #Per machine, a dictionary of extruder container stack IDs.
|
||||
self._active_extruder_index = -1
|
||||
UM.Application.getInstance().globalContainerStackChanged.connect(self._addCurrentMachineExtruders)
|
||||
UM.Application.getInstance().globalContainerStackChanged.connect(self.__globalContainerStackChanged)
|
||||
self._addCurrentMachineExtruders()
|
||||
|
||||
## Gets the unique identifier of the currently active extruder stack.
|
||||
#
|
||||
|
@ -78,20 +79,21 @@ class ExtruderManager(QObject):
|
|||
if global_definition_container.getId() in self._extruder_trains:
|
||||
if str(self._active_extruder_index) in self._extruder_trains[global_definition_container.getId()]:
|
||||
return self._extruder_trains[global_definition_container.getId()][str(self._active_extruder_index)]
|
||||
|
||||
return None
|
||||
|
||||
## Adds all extruders of a specific machine definition to the extruder
|
||||
# manager.
|
||||
#
|
||||
# \param machine_definition The machine to add the extruders for.
|
||||
def addMachineExtruders(self, machine_definition):
|
||||
changed = False
|
||||
machine_id = machine_definition.getId()
|
||||
if machine_id not in self._extruder_trains:
|
||||
self._extruder_trains[machine_id] = { }
|
||||
changed = True
|
||||
|
||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
||||
if not container_registry: #Then we shouldn't have any machine definition either. In any case, there are no extruder trains then so bye bye.
|
||||
return
|
||||
if container_registry:
|
||||
|
||||
#Add the extruder trains that don't exist yet.
|
||||
for extruder_definition in container_registry.findDefinitionContainers(machine = machine_definition.getId()):
|
||||
|
@ -100,6 +102,7 @@ class ExtruderManager(QObject):
|
|||
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.
|
||||
self.createExtruderTrain(extruder_definition, machine_definition, position)
|
||||
changed = True
|
||||
|
||||
#Gets the extruder trains that we just created as well as any that still existed.
|
||||
extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = machine_definition.getId())
|
||||
|
@ -108,8 +111,9 @@ class ExtruderManager(QObject):
|
|||
|
||||
#Ensure that the extruder train stacks are linked to global stack.
|
||||
extruder_train.setNextStack(UM.Application.getInstance().getGlobalContainerStack())
|
||||
changed = True
|
||||
|
||||
if extruder_trains:
|
||||
if changed:
|
||||
self.extrudersChanged.emit(machine_definition)
|
||||
|
||||
## Creates a container stack for an extruder train.
|
||||
|
@ -227,6 +231,10 @@ class ExtruderManager(QObject):
|
|||
for name in self._extruder_trains[machine_id]:
|
||||
yield self._extruder_trains[machine_id][name]
|
||||
|
||||
def __globalContainerStackChanged(self):
|
||||
self._addCurrentMachineExtruders()
|
||||
self.activeExtruderChanged.emit()
|
||||
|
||||
## Adds the extruders of the currently active machine.
|
||||
def _addCurrentMachineExtruders(self):
|
||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
||||
|
|
|
@ -52,7 +52,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
#Listen to changes.
|
||||
manager = ExtruderManager.getInstance()
|
||||
manager.extrudersChanged.connect(self._updateExtruders) #When the list of extruders changes in general.
|
||||
UM.Application.getInstance().globalContainerStackChanged.connect(self._updateExtruders) #When the current machine changes.
|
||||
|
||||
self._updateExtruders()
|
||||
|
||||
manager.activeExtruderChanged.connect(self._onActiveExtruderChanged)
|
||||
|
@ -65,6 +65,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
self.addGlobalChanged.emit()
|
||||
|
||||
addGlobalChanged = pyqtSignal()
|
||||
|
||||
@pyqtProperty(bool, fset = setAddGlobal, notify = addGlobalChanged)
|
||||
def addGlobal(self):
|
||||
return self._add_global
|
||||
|
@ -93,12 +94,14 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
#
|
||||
# This should be called whenever the list of extruders changes.
|
||||
def _updateExtruders(self):
|
||||
self.clear()
|
||||
manager = ExtruderManager.getInstance()
|
||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
||||
if not global_container_stack:
|
||||
return #There is no machine to get the extruders of.
|
||||
changed = False
|
||||
|
||||
if self.rowCount() != 0:
|
||||
self.clear()
|
||||
changed = True
|
||||
|
||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
if self._add_global:
|
||||
material = global_container_stack.findContainer({ "type": "material" })
|
||||
colour = material.getMetaDataEntry("color_code", default = self.defaultColours[0]) if material else self.defaultColours[0]
|
||||
|
@ -109,7 +112,9 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
"index": -1
|
||||
}
|
||||
self.appendItem(item)
|
||||
changed = True
|
||||
|
||||
manager = ExtruderManager.getInstance()
|
||||
for extruder in manager.getMachineExtruders(global_container_stack.getBottom().getId()):
|
||||
extruder_name = extruder.getName()
|
||||
material = extruder.findContainer({ "type": "material" })
|
||||
|
@ -120,7 +125,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
position = int(position)
|
||||
except ValueError: #Not a proper int.
|
||||
position = -1
|
||||
default_colour = self.defaultColours[position] if position >= 0 and position < len(self.defaultColours) else defaultColours[0]
|
||||
default_colour = self.defaultColours[position] if position >= 0 and position < len(self.defaultColours) else self.defaultColours[0]
|
||||
colour = material.getMetaDataEntry("color_code", default = default_colour) if material else default_colour
|
||||
item = { #Construct an item with only the relevant information.
|
||||
"id": extruder.getId(),
|
||||
|
@ -129,6 +134,8 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
"index": position
|
||||
}
|
||||
self.appendItem(item)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
self.sort(lambda item: item["index"])
|
||||
self.modelChanged.emit()
|
||||
|
|
|
@ -11,7 +11,6 @@ from UM.Logger import Logger
|
|||
import UM.Settings
|
||||
|
||||
from cura.PrinterOutputDevice import PrinterOutputDevice
|
||||
|
||||
from . import ExtruderManager
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
|
@ -31,7 +30,6 @@ class MachineManager(QObject):
|
|||
self._onGlobalContainerChanged()
|
||||
|
||||
ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderStackChanged)
|
||||
self.globalContainerChanged.connect(self._onActiveExtruderStackChanged)
|
||||
self._onActiveExtruderStackChanged()
|
||||
|
||||
## When the global container is changed, active material probably needs to be updated.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue