|
@@ -2,13 +2,15 @@
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
|
|
|
|
from PyQt6.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant # For communicating data and events to Qt.
|
|
from PyQt6.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant # For communicating data and events to Qt.
|
|
|
|
+
|
|
|
|
+from UM.Application import Application
|
|
from UM.FlameProfiler import pyqtSlot
|
|
from UM.FlameProfiler import pyqtSlot
|
|
|
|
|
|
import cura.CuraApplication # To get the global container stack to find the current machine.
|
|
import cura.CuraApplication # To get the global container stack to find the current machine.
|
|
|
|
+from UM.Util import parseBool
|
|
from cura.Settings.GlobalStack import GlobalStack
|
|
from cura.Settings.GlobalStack import GlobalStack
|
|
from UM.Logger import Logger
|
|
from UM.Logger import Logger
|
|
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
|
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
|
-from UM.Scene.SceneNode import SceneNode
|
|
|
|
from UM.Scene.Selection import Selection
|
|
from UM.Scene.Selection import Selection
|
|
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
|
|
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
|
|
from UM.Settings.ContainerRegistry import ContainerRegistry # Finding containers by ID.
|
|
from UM.Settings.ContainerRegistry import ContainerRegistry # Finding containers by ID.
|
|
@@ -45,6 +47,7 @@ class ExtruderManager(QObject):
|
|
self._selected_object_extruders = [] # type: List[Union[str, "ExtruderStack"]]
|
|
self._selected_object_extruders = [] # type: List[Union[str, "ExtruderStack"]]
|
|
|
|
|
|
Selection.selectionChanged.connect(self.resetSelectedObjectExtruders)
|
|
Selection.selectionChanged.connect(self.resetSelectedObjectExtruders)
|
|
|
|
+ Application.getInstance().globalContainerStackChanged.connect(self.emitGlobalStackExtrudersChanged) # When the machine is swapped we must update the active machine extruders
|
|
|
|
|
|
extrudersChanged = pyqtSignal(QVariant)
|
|
extrudersChanged = pyqtSignal(QVariant)
|
|
"""Signal to notify other components when the list of extruders for a machine definition changes."""
|
|
"""Signal to notify other components when the list of extruders for a machine definition changes."""
|
|
@@ -52,6 +55,21 @@ class ExtruderManager(QObject):
|
|
activeExtruderChanged = pyqtSignal()
|
|
activeExtruderChanged = pyqtSignal()
|
|
"""Notify when the user switches the currently active extruder."""
|
|
"""Notify when the user switches the currently active extruder."""
|
|
|
|
|
|
|
|
+ def emitGlobalStackExtrudersChanged(self):
|
|
|
|
+ # HACK
|
|
|
|
+ # The emit function can't be directly connected to another signal. This wrapper function is required.
|
|
|
|
+ # The extrudersChanged signal is emitted early when changing machines. This triggers it a second time
|
|
|
|
+ # after the extruder have changed properly. This is important for any QML using ExtruderManager.extruderIds
|
|
|
|
+ # This is a hack, but other behaviour relys on the updating in this order.
|
|
|
|
+ self.extrudersChanged.emit(self._application.getGlobalContainerStack().getId())
|
|
|
|
+
|
|
|
|
+ @pyqtProperty(int, notify = extrudersChanged)
|
|
|
|
+ def enabledExtruderCount(self) -> int:
|
|
|
|
+ global_container_stack = self._application.getGlobalContainerStack()
|
|
|
|
+ if global_container_stack:
|
|
|
|
+ return len([extruder for extruder in global_container_stack.extruderList if parseBool(extruder.getMetaDataEntry("enabled", "True"))])
|
|
|
|
+ return 0
|
|
|
|
+
|
|
@pyqtProperty(str, notify = activeExtruderChanged)
|
|
@pyqtProperty(str, notify = activeExtruderChanged)
|
|
def activeExtruderStackId(self) -> Optional[str]:
|
|
def activeExtruderStackId(self) -> Optional[str]:
|
|
"""Gets the unique identifier of the currently active extruder stack.
|
|
"""Gets the unique identifier of the currently active extruder stack.
|