mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 05:39:02 +08: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
@ -74,6 +74,18 @@ class ContainerTree:
|
|||||||
extruder_enabled = [extruder.isEnabled for extruder in global_stack.extruderList]
|
extruder_enabled = [extruder.isEnabled for extruder in global_stack.extruderList]
|
||||||
return self.machines[global_stack.definition.getId()].getQualityChangesGroups(variant_names, material_bases, extruder_enabled)
|
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.
|
## Builds the initial container tree.
|
||||||
def _loadAll(self):
|
def _loadAll(self):
|
||||||
Logger.log("i", "Building container tree.")
|
Logger.log("i", "Building container tree.")
|
||||||
@ -90,16 +102,9 @@ class ContainerTree:
|
|||||||
Logger.log("d", "Adding container tree for {definition_id} took {duration} seconds.".format(definition_id = definition_id, duration = time.time() - definition_start_time))
|
Logger.log("d", "Adding container tree for {definition_id} took {duration} seconds.".format(definition_id = definition_id, duration = time.time() - definition_start_time))
|
||||||
|
|
||||||
Logger.log("d", "Building the container tree took %s seconds", time.time() - start_time)
|
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.
|
## 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):
|
if not isinstance(container_stack, GlobalStack):
|
||||||
return # Not our concern.
|
return # Not our concern.
|
||||||
definition_id = container_stack.definition.getId()
|
self.addMachineNodeByDefinitionId(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))
|
|
||||||
|
@ -40,8 +40,7 @@ class CuraStackBuilder:
|
|||||||
# The container tree listens to the containerAdded signal to add the definition and build the tree,
|
# 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.
|
# 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.
|
# Therefore we must make sure that it's manually added here.
|
||||||
if machine_definition.getId() not in container_tree.machines:
|
container_tree.addMachineNodeByDefinitionId(machine_definition.getId())
|
||||||
container_tree.machines[machine_definition.getId()] = MachineNode(machine_definition.getId())
|
|
||||||
machine_node = container_tree.machines[machine_definition.getId()]
|
machine_node = container_tree.machines[machine_definition.getId()]
|
||||||
|
|
||||||
generated_name = registry.createUniqueName("machine", "", name, machine_definition.getName())
|
generated_name = registry.createUniqueName("machine", "", name, machine_definition.getName())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user