mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Move removeMaterial to MaterialManagementModel
Moving away from the MaterialManager. Contributes to issue CURA-6600.
This commit is contained in:
parent
99ccddefa4
commit
3dc7c7b61c
4 changed files with 21 additions and 4 deletions
|
@ -246,7 +246,7 @@ class MaterialManager(QObject):
|
||||||
|
|
||||||
def removeMaterialByRootId(self, root_material_id: str):
|
def removeMaterialByRootId(self, root_material_id: str):
|
||||||
container_registry = CuraContainerRegistry.getInstance()
|
container_registry = CuraContainerRegistry.getInstance()
|
||||||
results = container_registry.findContainers(id=root_material_id)
|
results = container_registry.findContainers(id = root_material_id)
|
||||||
if not results:
|
if not results:
|
||||||
container_registry.addWrongContainerId(root_material_id)
|
container_registry.addWrongContainerId(root_material_id)
|
||||||
|
|
||||||
|
|
|
@ -45,4 +45,21 @@ class MaterialManagementModel(QObject):
|
||||||
if container_registry.isReadOnly(root_material_id):
|
if container_registry.isReadOnly(root_material_id):
|
||||||
Logger.log("w", "Cannot set name of read-only container %s.", root_material_id)
|
Logger.log("w", "Cannot set name of read-only container %s.", root_material_id)
|
||||||
return
|
return
|
||||||
return container_registry.findContainers(id = root_material_id)[0].setName(name)
|
return container_registry.findContainers(id = root_material_id)[0].setName(name)
|
||||||
|
|
||||||
|
## Deletes a material from Cura.
|
||||||
|
#
|
||||||
|
# This function does not do any safety checking any more. Please call this
|
||||||
|
# function only if:
|
||||||
|
# - The material is not read-only.
|
||||||
|
# - The material is not used in any stacks.
|
||||||
|
# If the material was not lazy-loaded yet, this will fully load the
|
||||||
|
# container. When removing this material node, all other materials with
|
||||||
|
# the same base fill will also be removed.
|
||||||
|
# \param material_node The material to remove.
|
||||||
|
@pyqtSlot("QVariant")
|
||||||
|
def removeMaterial(self, material_node: "MaterialNode") -> None:
|
||||||
|
container_registry = CuraContainerRegistry.getInstance()
|
||||||
|
materials_this_base_file = container_registry.findContainersMetadata(base_file = material_node.base_file)
|
||||||
|
for material_metadata in materials_this_base_file:
|
||||||
|
container_registry.removeContainer(material_metadata["id"])
|
|
@ -302,7 +302,7 @@ Item
|
||||||
{
|
{
|
||||||
// Set the active material as the fallback. It will be selected when the current material is deleted
|
// Set the active material as the fallback. It will be selected when the current material is deleted
|
||||||
base.newRootMaterialIdToSwitchTo = base.active_root_material_id
|
base.newRootMaterialIdToSwitchTo = base.active_root_material_id
|
||||||
base.materialManager.removeMaterial(base.currentItem.container_node);
|
base.materialManagement.removeMaterial(base.currentItem.container_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -565,7 +565,7 @@ TabView
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the values
|
// update the values
|
||||||
base.materialManagement.setMaterialName(base.currentMaterialNode, new_name)
|
materialManagement.setMaterialName(base.currentMaterialNode, new_name)
|
||||||
properties.name = new_name
|
properties.name = new_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue