mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-03 03:54:01 -06:00
Add a function to add a MachineNode to the tree.
This solves the issue that machines created by the stack builder broke the material updating CURA-6791
This commit is contained in:
parent
5b5256b9e4
commit
7e3f265068
2 changed files with 16 additions and 12 deletions
|
@ -74,6 +74,18 @@ class ContainerTree:
|
|||
extruder_enabled = [extruder.isEnabled for extruder in global_stack.extruderList]
|
||||
return self.machines[global_stack.definition.getId()].getQualityChangesGroups(variant_names, material_bases, extruder_enabled)
|
||||
|
||||
# Add a machine node by the id of it's definition.
|
||||
# This is automatically called by the _machineAdded function, but it's sometimes needed to add a machine node
|
||||
# faster than would have been done when waiting on any signals (for instance; when creating an entirely new machine)
|
||||
def addMachineNodeByDefinitionId(self, definition_id: str) -> None:
|
||||
if definition_id in self.machines:
|
||||
return # Already have this definition ID.
|
||||
|
||||
start_time = time.time()
|
||||
self.machines[definition_id] = MachineNode(definition_id)
|
||||
self.machines[definition_id].materialsChanged.connect(self.materialsChanged)
|
||||
Logger.log("d", "Adding container tree for {definition_id} took {duration} seconds.".format(definition_id = definition_id, duration = time.time() - start_time))
|
||||
|
||||
## Builds the initial container tree.
|
||||
def _loadAll(self):
|
||||
Logger.log("i", "Building container tree.")
|
||||
|
@ -92,14 +104,7 @@ class ContainerTree:
|
|||
Logger.log("d", "Building the container tree took %s seconds", time.time() - start_time)
|
||||
|
||||
## When a printer gets added, we need to build up the tree for that container.
|
||||
def _machineAdded(self, container_stack: ContainerInterface):
|
||||
def _machineAdded(self, container_stack: ContainerInterface) -> None:
|
||||
if not isinstance(container_stack, GlobalStack):
|
||||
return # Not our concern.
|
||||
definition_id = container_stack.definition.getId()
|
||||
if definition_id in self.machines:
|
||||
return # Already have this definition ID.
|
||||
|
||||
start_time = time.time()
|
||||
self.machines[definition_id] = MachineNode(definition_id)
|
||||
self.machines[definition_id].materialsChanged.connect(self.materialsChanged)
|
||||
Logger.log("d", "Adding container tree for {definition_id} took {duration} seconds.".format(definition_id = definition_id, duration = time.time() - start_time))
|
||||
self.addMachineNodeByDefinitionId(container_stack.definition.getId())
|
||||
|
|
|
@ -40,8 +40,7 @@ class CuraStackBuilder:
|
|||
# The container tree listens to the containerAdded signal to add the definition and build the tree,
|
||||
# but that signal is emitted with a delay which might not have passed yet.
|
||||
# Therefore we must make sure that it's manually added here.
|
||||
if machine_definition.getId() not in container_tree.machines:
|
||||
container_tree.machines[machine_definition.getId()] = MachineNode(machine_definition.getId())
|
||||
container_tree.addMachineNodeByDefinitionId(machine_definition.getId())
|
||||
machine_node = container_tree.machines[machine_definition.getId()]
|
||||
|
||||
generated_name = registry.createUniqueName("machine", "", name, machine_definition.getName())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue