mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 02:37:49 -06:00
Check if a material container is used by GUID
CURA-4129 isContainerUsed() is used to enable/disable the "Remove" button on the Material Manager dialog. When a custom material is created, it creates multiple containers, one for each extruder variant. In the dialog, it only checks if the material for the currently active extruder is being used or not. This causes a problem when 2 extruders are of different types and one uses a custom material. Then, the "Remove" button will not be correctly enabled/disable in the Material Manager dialog when the other extruder is activated.
This commit is contained in:
parent
ac5c0d019b
commit
4a34f141d1
1 changed files with 23 additions and 5 deletions
|
@ -333,11 +333,29 @@ class ContainerManager(QObject):
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def isContainerUsed(self, container_id):
|
def isContainerUsed(self, container_id):
|
||||||
Logger.log("d", "Checking if container %s is currently used", container_id)
|
Logger.log("d", "Checking if container %s is currently used", container_id)
|
||||||
containers = self._container_registry.findContainerStacks()
|
# check if this is a material container. If so, check if any material with the same GUID is being used by any
|
||||||
for stack in containers:
|
# stacks.
|
||||||
if container_id in [child.getId() for child in stack.getContainers()]:
|
container_ids_to_check = [container_id]
|
||||||
Logger.log("d", "The container is in use by %s", stack.getId())
|
container_results = self._container_registry.findInstanceContainers(id = container_id)
|
||||||
return True
|
if container_results:
|
||||||
|
this_container = container_results[0]
|
||||||
|
container_guid = this_container.getMetaDataEntry("GUID")
|
||||||
|
# FIXME: only material containers have GUIDs, but to make it safer, metadata/material is also checked.
|
||||||
|
# but note that this is not a proper way to check whether a container is a material container.
|
||||||
|
# there should be a better way to do this
|
||||||
|
is_material = container_guid and this_container.getMetaDataEntry("material")
|
||||||
|
if is_material:
|
||||||
|
# check all material container IDs with the same guid
|
||||||
|
material_containers = self._container_registry.findInstanceContainers(GUID = container_guid)
|
||||||
|
if material_containers:
|
||||||
|
container_ids_to_check = [container.getId() for container in material_containers]
|
||||||
|
|
||||||
|
all_stacks = self._container_registry.findContainerStacks()
|
||||||
|
for stack in all_stacks:
|
||||||
|
for container_id in container_ids_to_check:
|
||||||
|
if container_id in [child.getId() for child in stack.getContainers()]:
|
||||||
|
Logger.log("d", "The container is in use by %s", stack.getId())
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@pyqtSlot(str, result = str)
|
@pyqtSlot(str, result = str)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue