mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 04:26:05 +08:00
Update the removing & duplicating of material
CURA-6600
This commit is contained in:
parent
8d05ebef9d
commit
97e77994a1
@ -254,25 +254,13 @@ class MaterialManager(QObject):
|
|||||||
return node
|
return node
|
||||||
|
|
||||||
def removeMaterialByRootId(self, root_material_id: str):
|
def removeMaterialByRootId(self, root_material_id: str):
|
||||||
material_group = self.getMaterialGroup(root_material_id)
|
|
||||||
if not material_group:
|
|
||||||
Logger.log("i", "Unable to remove the material with id %s, because it doesn't exist.", root_material_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
container_registry = CuraContainerRegistry.getInstance()
|
container_registry = CuraContainerRegistry.getInstance()
|
||||||
nodes_to_remove = [material_group.root_material_node] + material_group.derived_material_node_list
|
results = container_registry.findContainers(id=root_material_id)
|
||||||
# Sort all nodes with respect to the container ID lengths in the ascending order so the base material container
|
if not results:
|
||||||
# will be the first one to be removed. We need to do this to ensure that all containers get loaded & deleted.
|
container_registry.addWrongContainerId(root_material_id)
|
||||||
nodes_to_remove = sorted(nodes_to_remove, key = lambda x: len(x.getMetaDataEntry("id", "")))
|
|
||||||
# Try to load all containers first. If there is any faulty ones, they will be put into the faulty container
|
for result in results:
|
||||||
# list, so removeContainer() can ignore those ones.
|
container_registry.removeContainer(result.getMetaDataEntry("id", ""))
|
||||||
for node in nodes_to_remove:
|
|
||||||
container_id = node.getMetaDataEntry("id", "")
|
|
||||||
results = container_registry.findContainers(id = container_id)
|
|
||||||
if not results:
|
|
||||||
container_registry.addWrongContainerId(container_id)
|
|
||||||
for node in nodes_to_remove:
|
|
||||||
container_registry.removeContainer(node.getMetaDataEntry("id", ""))
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Methods for GUI
|
# Methods for GUI
|
||||||
@ -327,14 +315,14 @@ class MaterialManager(QObject):
|
|||||||
def duplicateMaterial(self, material_node: MaterialNode, new_base_id: Optional[str] = None, new_metadata: Dict[str, Any] = None) -> Optional[str]:
|
def duplicateMaterial(self, material_node: MaterialNode, new_base_id: Optional[str] = None, new_metadata: Dict[str, Any] = None) -> Optional[str]:
|
||||||
root_material_id = cast(str, material_node.getMetaDataEntry("base_file", ""))
|
root_material_id = cast(str, material_node.getMetaDataEntry("base_file", ""))
|
||||||
|
|
||||||
material_group = self.getMaterialGroup(root_material_id)
|
container_registry = CuraContainerRegistry.getInstance()
|
||||||
if not material_group:
|
results = container_registry.findContainers(id=root_material_id)
|
||||||
|
|
||||||
|
if not results:
|
||||||
Logger.log("i", "Unable to duplicate the material with id %s, because it doesn't exist.", root_material_id)
|
Logger.log("i", "Unable to duplicate the material with id %s, because it doesn't exist.", root_material_id)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
base_container = material_group.root_material_node.container
|
base_container = results[0]
|
||||||
if not base_container:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# Ensure all settings are saved.
|
# Ensure all settings are saved.
|
||||||
cura.CuraApplication.CuraApplication.getInstance().saveSettings()
|
cura.CuraApplication.CuraApplication.getInstance().saveSettings()
|
||||||
@ -353,11 +341,9 @@ class MaterialManager(QObject):
|
|||||||
new_containers.append(new_base_container)
|
new_containers.append(new_base_container)
|
||||||
|
|
||||||
# Clone all of them.
|
# Clone all of them.
|
||||||
for node in material_group.derived_material_node_list:
|
for container_to_copy in container_registry.findContainers(base_file= root_material_id):
|
||||||
container_to_copy = node.container
|
if container_to_copy.getId() == root_material_id:
|
||||||
if not container_to_copy:
|
continue # We already have that one, skip it
|
||||||
continue
|
|
||||||
# Create unique IDs for every clone.
|
|
||||||
new_id = new_base_id
|
new_id = new_base_id
|
||||||
if container_to_copy.getMetaDataEntry("definition") != "fdmprinter":
|
if container_to_copy.getMetaDataEntry("definition") != "fdmprinter":
|
||||||
new_id += "_" + container_to_copy.getMetaDataEntry("definition")
|
new_id += "_" + container_to_copy.getMetaDataEntry("definition")
|
||||||
@ -371,7 +357,6 @@ class MaterialManager(QObject):
|
|||||||
if new_metadata is not None:
|
if new_metadata is not None:
|
||||||
for key, value in new_metadata.items():
|
for key, value in new_metadata.items():
|
||||||
new_container.getMetaData()[key] = value
|
new_container.getMetaData()[key] = value
|
||||||
|
|
||||||
new_containers.append(new_container)
|
new_containers.append(new_container)
|
||||||
|
|
||||||
for container_to_add in new_containers:
|
for container_to_add in new_containers:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user