mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07: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)
|
super().__init__(parent)
|
||||||
self._extruder_trains = { } #Per machine, a dictionary of extruder container stack IDs.
|
self._extruder_trains = { } #Per machine, a dictionary of extruder container stack IDs.
|
||||||
self._active_extruder_index = -1
|
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.
|
## 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 global_definition_container.getId() in self._extruder_trains:
|
||||||
if str(self._active_extruder_index) in self._extruder_trains[global_definition_container.getId()]:
|
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 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
|
## Adds all extruders of a specific machine definition to the extruder
|
||||||
# manager.
|
# manager.
|
||||||
#
|
#
|
||||||
# \param machine_definition The machine to add the extruders for.
|
# \param machine_definition The machine to add the extruders for.
|
||||||
def addMachineExtruders(self, machine_definition):
|
def addMachineExtruders(self, machine_definition):
|
||||||
|
changed = False
|
||||||
machine_id = machine_definition.getId()
|
machine_id = machine_definition.getId()
|
||||||
if machine_id not in self._extruder_trains:
|
if machine_id not in self._extruder_trains:
|
||||||
self._extruder_trains[machine_id] = { }
|
self._extruder_trains[machine_id] = { }
|
||||||
|
changed = True
|
||||||
|
|
||||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
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.
|
if container_registry:
|
||||||
return
|
|
||||||
|
|
||||||
#Add the extruder trains that don't exist yet.
|
#Add the extruder trains that don't exist yet.
|
||||||
for extruder_definition in container_registry.findDefinitionContainers(machine = machine_definition.getId()):
|
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())
|
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.
|
if not container_registry.findContainerStacks(machine = machine_id, position = position): #Doesn't exist yet.
|
||||||
self.createExtruderTrain(extruder_definition, machine_definition, position)
|
self.createExtruderTrain(extruder_definition, machine_definition, position)
|
||||||
|
changed = True
|
||||||
|
|
||||||
#Gets the extruder trains that we just created as well as any that still existed.
|
#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())
|
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.
|
#Ensure that the extruder train stacks are linked to global stack.
|
||||||
extruder_train.setNextStack(UM.Application.getInstance().getGlobalContainerStack())
|
extruder_train.setNextStack(UM.Application.getInstance().getGlobalContainerStack())
|
||||||
|
changed = True
|
||||||
|
|
||||||
if extruder_trains:
|
if changed:
|
||||||
self.extrudersChanged.emit(machine_definition)
|
self.extrudersChanged.emit(machine_definition)
|
||||||
|
|
||||||
## Creates a container stack for an extruder train.
|
## Creates a container stack for an extruder train.
|
||||||
|
@ -227,6 +231,10 @@ class ExtruderManager(QObject):
|
||||||
for name in self._extruder_trains[machine_id]:
|
for name in self._extruder_trains[machine_id]:
|
||||||
yield self._extruder_trains[machine_id][name]
|
yield self._extruder_trains[machine_id][name]
|
||||||
|
|
||||||
|
def __globalContainerStackChanged(self):
|
||||||
|
self._addCurrentMachineExtruders()
|
||||||
|
self.activeExtruderChanged.emit()
|
||||||
|
|
||||||
## Adds the extruders of the currently active machine.
|
## Adds the extruders of the currently active machine.
|
||||||
def _addCurrentMachineExtruders(self):
|
def _addCurrentMachineExtruders(self):
|
||||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
||||||
#Listen to changes.
|
#Listen to changes.
|
||||||
manager = ExtruderManager.getInstance()
|
manager = ExtruderManager.getInstance()
|
||||||
manager.extrudersChanged.connect(self._updateExtruders) #When the list of extruders changes in general.
|
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()
|
self._updateExtruders()
|
||||||
|
|
||||||
manager.activeExtruderChanged.connect(self._onActiveExtruderChanged)
|
manager.activeExtruderChanged.connect(self._onActiveExtruderChanged)
|
||||||
|
@ -65,6 +65,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
||||||
self.addGlobalChanged.emit()
|
self.addGlobalChanged.emit()
|
||||||
|
|
||||||
addGlobalChanged = pyqtSignal()
|
addGlobalChanged = pyqtSignal()
|
||||||
|
|
||||||
@pyqtProperty(bool, fset = setAddGlobal, notify = addGlobalChanged)
|
@pyqtProperty(bool, fset = setAddGlobal, notify = addGlobalChanged)
|
||||||
def addGlobal(self):
|
def addGlobal(self):
|
||||||
return self._add_global
|
return self._add_global
|
||||||
|
@ -93,12 +94,14 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
||||||
#
|
#
|
||||||
# This should be called whenever the list of extruders changes.
|
# This should be called whenever the list of extruders changes.
|
||||||
def _updateExtruders(self):
|
def _updateExtruders(self):
|
||||||
self.clear()
|
changed = False
|
||||||
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.
|
|
||||||
|
|
||||||
|
if self.rowCount() != 0:
|
||||||
|
self.clear()
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
||||||
|
if global_container_stack:
|
||||||
if self._add_global:
|
if self._add_global:
|
||||||
material = global_container_stack.findContainer({ "type": "material" })
|
material = global_container_stack.findContainer({ "type": "material" })
|
||||||
colour = material.getMetaDataEntry("color_code", default = self.defaultColours[0]) if material else self.defaultColours[0]
|
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
|
"index": -1
|
||||||
}
|
}
|
||||||
self.appendItem(item)
|
self.appendItem(item)
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
manager = ExtruderManager.getInstance()
|
||||||
for extruder in manager.getMachineExtruders(global_container_stack.getBottom().getId()):
|
for extruder in manager.getMachineExtruders(global_container_stack.getBottom().getId()):
|
||||||
extruder_name = extruder.getName()
|
extruder_name = extruder.getName()
|
||||||
material = extruder.findContainer({ "type": "material" })
|
material = extruder.findContainer({ "type": "material" })
|
||||||
|
@ -120,7 +125,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
||||||
position = int(position)
|
position = int(position)
|
||||||
except ValueError: #Not a proper int.
|
except ValueError: #Not a proper int.
|
||||||
position = -1
|
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
|
colour = material.getMetaDataEntry("color_code", default = default_colour) if material else default_colour
|
||||||
item = { #Construct an item with only the relevant information.
|
item = { #Construct an item with only the relevant information.
|
||||||
"id": extruder.getId(),
|
"id": extruder.getId(),
|
||||||
|
@ -129,6 +134,8 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
||||||
"index": position
|
"index": position
|
||||||
}
|
}
|
||||||
self.appendItem(item)
|
self.appendItem(item)
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
if changed:
|
||||||
self.sort(lambda item: item["index"])
|
self.sort(lambda item: item["index"])
|
||||||
self.modelChanged.emit()
|
self.modelChanged.emit()
|
||||||
|
|
|
@ -11,7 +11,6 @@ from UM.Logger import Logger
|
||||||
import UM.Settings
|
import UM.Settings
|
||||||
|
|
||||||
from cura.PrinterOutputDevice import PrinterOutputDevice
|
from cura.PrinterOutputDevice import PrinterOutputDevice
|
||||||
|
|
||||||
from . import ExtruderManager
|
from . import ExtruderManager
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
|
@ -31,7 +30,6 @@ class MachineManager(QObject):
|
||||||
self._onGlobalContainerChanged()
|
self._onGlobalContainerChanged()
|
||||||
|
|
||||||
ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderStackChanged)
|
ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderStackChanged)
|
||||||
self.globalContainerChanged.connect(self._onActiveExtruderStackChanged)
|
|
||||||
self._onActiveExtruderStackChanged()
|
self._onActiveExtruderStackChanged()
|
||||||
|
|
||||||
## When the global container is changed, active material probably needs to be updated.
|
## When the global container is changed, active material probably needs to be updated.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue