mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
start
This commit is contained in:
parent
ff732720ca
commit
c132300fd5
2 changed files with 33 additions and 33 deletions
|
@ -28,6 +28,20 @@ if TYPE_CHECKING:
|
||||||
#
|
#
|
||||||
# This keeps a list of extruder stacks for each machine.
|
# This keeps a list of extruder stacks for each machine.
|
||||||
class ExtruderManager(QObject):
|
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 = {} # Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders.
|
||||||
|
self._active_extruder_index = -1 # Indicates the index of the active extruder stack. -1 means no active extruder stack
|
||||||
|
self._selected_object_extruders = []
|
||||||
|
self._global_container_stack_definition_id = None
|
||||||
|
self._addCurrentMachineExtruders()
|
||||||
|
|
||||||
|
Application.getInstance().globalContainerStackChanged.connect(self.__globalContainerStackChanged)
|
||||||
|
Selection.selectionChanged.connect(self.resetSelectedObjectExtruders)
|
||||||
|
|
||||||
## 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.
|
||||||
extrudersChanged = pyqtSignal(QVariant)
|
extrudersChanged = pyqtSignal(QVariant)
|
||||||
|
|
||||||
|
@ -38,18 +52,6 @@ class ExtruderManager(QObject):
|
||||||
## Notify when the user switches the currently active extruder.
|
## Notify when the user switches the currently active extruder.
|
||||||
activeExtruderChanged = pyqtSignal()
|
activeExtruderChanged = pyqtSignal()
|
||||||
|
|
||||||
## Registers listeners and such to listen to changes to the extruders.
|
|
||||||
def __init__(self, parent = None):
|
|
||||||
super().__init__(parent)
|
|
||||||
self._extruder_trains = { } #Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders.
|
|
||||||
self._active_extruder_index = -1 # Indicates the index of the active extruder stack. -1 means no active extruder stack
|
|
||||||
self._selected_object_extruders = []
|
|
||||||
Application.getInstance().globalContainerStackChanged.connect(self.__globalContainerStackChanged)
|
|
||||||
self._global_container_stack_definition_id = None
|
|
||||||
self._addCurrentMachineExtruders()
|
|
||||||
|
|
||||||
Selection.selectionChanged.connect(self.resetSelectedObjectExtruders)
|
|
||||||
|
|
||||||
## Gets the unique identifier of the currently active extruder stack.
|
## Gets the unique identifier of the currently active extruder stack.
|
||||||
#
|
#
|
||||||
# The currently active extruder stack is the stack that is currently being
|
# The currently active extruder stack is the stack that is currently being
|
||||||
|
@ -59,10 +61,10 @@ class ExtruderManager(QObject):
|
||||||
@pyqtProperty(str, notify = activeExtruderChanged)
|
@pyqtProperty(str, notify = activeExtruderChanged)
|
||||||
def activeExtruderStackId(self) -> Optional[str]:
|
def activeExtruderStackId(self) -> Optional[str]:
|
||||||
if not Application.getInstance().getGlobalContainerStack():
|
if not Application.getInstance().getGlobalContainerStack():
|
||||||
return None # No active machine, so no active extruder.
|
return None # No active machine, so no active extruder.
|
||||||
try:
|
try:
|
||||||
return self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][str(self._active_extruder_index)].getId()
|
return self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][str(self._active_extruder_index)].getId()
|
||||||
except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong.
|
except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong.
|
||||||
return None
|
return None
|
||||||
|
|
||||||
## Return extruder count according to extruder trains.
|
## Return extruder count according to extruder trains.
|
||||||
|
@ -521,8 +523,8 @@ class ExtruderManager(QObject):
|
||||||
machine_extruder_count = global_stack.getProperty("machine_extruder_count", "value")
|
machine_extruder_count = global_stack.getProperty("machine_extruder_count", "value")
|
||||||
|
|
||||||
# In case the printer is using one extruder, shouldn't exist active extruder stacks
|
# In case the printer is using one extruder, shouldn't exist active extruder stacks
|
||||||
if machine_extruder_count == 1:
|
# if machine_extruder_count == 1:
|
||||||
return result
|
# return result
|
||||||
|
|
||||||
if global_stack and global_stack.getId() in self._extruder_trains:
|
if global_stack and global_stack.getId() in self._extruder_trains:
|
||||||
for extruder in sorted(self._extruder_trains[global_stack.getId()]):
|
for extruder in sorted(self._extruder_trains[global_stack.getId()]):
|
||||||
|
@ -537,16 +539,10 @@ class ExtruderManager(QObject):
|
||||||
self.globalContainerStackDefinitionChanged.emit()
|
self.globalContainerStackDefinitionChanged.emit()
|
||||||
|
|
||||||
# If the global container changed, the number of extruders could be changed and so the active_extruder_index is updated
|
# If the global container changed, the number of extruders could be changed and so the active_extruder_index is updated
|
||||||
extruder_count = global_container_stack.getProperty("machine_extruder_count", "value")
|
if self._active_extruder_index == -1:
|
||||||
if extruder_count > 1:
|
self.setActiveExtruderIndex(0)
|
||||||
if self._active_extruder_index == -1:
|
|
||||||
self.setActiveExtruderIndex(0)
|
|
||||||
else:
|
|
||||||
if self._active_extruder_index != -1:
|
|
||||||
self.setActiveExtruderIndex(-1)
|
|
||||||
|
|
||||||
self.activeExtruderChanged.emit()
|
self.activeExtruderChanged.emit()
|
||||||
|
|
||||||
self.resetSelectedObjectExtruders()
|
self.resetSelectedObjectExtruders()
|
||||||
|
|
||||||
## Adds the extruders of the currently active machine.
|
## Adds the extruders of the currently active machine.
|
||||||
|
|
|
@ -171,17 +171,21 @@ class MachineSettingsAction(MachineAction):
|
||||||
|
|
||||||
definition_changes_container.setProperty("machine_extruder_count", "value", extruder_count)
|
definition_changes_container.setProperty("machine_extruder_count", "value", extruder_count)
|
||||||
|
|
||||||
if extruder_count > 1:
|
# Make sure one of the extruder stacks is active
|
||||||
# Multiextrusion
|
if extruder_manager.activeExtruderIndex == -1:
|
||||||
|
extruder_manager.setActiveExtruderIndex(0)
|
||||||
|
|
||||||
|
# Move settable_per_extruder values out of the global container
|
||||||
|
extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStack()
|
||||||
|
global_user_container = self._global_container_stack.getTop()
|
||||||
|
|
||||||
|
for setting_instance in global_user_container.findInstances():
|
||||||
|
setting_key = setting_instance.definition.key
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Make sure one of the extruder stacks is active
|
|
||||||
if extruder_manager.activeExtruderIndex == -1:
|
|
||||||
extruder_manager.setActiveExtruderIndex(0)
|
|
||||||
|
|
||||||
# Move settable_per_extruder values out of the global container
|
|
||||||
if previous_extruder_count == 1:
|
|
||||||
extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
|
|
||||||
global_user_container = self._global_container_stack.getTop()
|
|
||||||
|
|
||||||
for setting_instance in global_user_container.findInstances():
|
for setting_instance in global_user_container.findInstances():
|
||||||
setting_key = setting_instance.definition.key
|
setting_key = setting_instance.definition.key
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue