mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56:22 -06:00
Add a notice to linked materials and allow "unlinking" a material.
This commit is contained in:
parent
23cd6b1c2c
commit
67b8302d40
2 changed files with 62 additions and 1 deletions
|
@ -695,6 +695,7 @@ class ContainerManager(QObject):
|
|||
duplicated_container.setDirty(True)
|
||||
self._container_registry.addContainer(duplicated_container)
|
||||
|
||||
# Create a new material by cloning Generic PLA and setting the GUID to something unqiue
|
||||
@pyqtSlot(result = str)
|
||||
def createMaterial(self) -> str:
|
||||
# Ensure all settings are saved.
|
||||
|
@ -702,7 +703,7 @@ class ContainerManager(QObject):
|
|||
|
||||
containers = self._container_registry.findInstanceContainers(id="generic_pla")
|
||||
if not containers:
|
||||
Logger.log("d", "Unable to creata a new material by cloning generic_pla, because it doesn't exist.")
|
||||
Logger.log("d", "Unable to create a new material by cloning generic_pla, because it doesn't exist.")
|
||||
return ""
|
||||
|
||||
# Create a new ID & container to hold the data.
|
||||
|
@ -722,6 +723,39 @@ class ContainerManager(QObject):
|
|||
|
||||
self._container_registry.addContainer(duplicated_container)
|
||||
|
||||
@pyqtSlot(str, result = "QStringList")
|
||||
def getLinkedMaterials(self, material_id: str):
|
||||
containers = self._container_registry.findInstanceContainers(id=material_id)
|
||||
if not containers:
|
||||
Logger.log("d", "Unable to find materials linked to material with id %s, because it doesn't exist.", material_id)
|
||||
return []
|
||||
|
||||
material_container = containers[0]
|
||||
material_guid = material_container.getMetaDataEntry("GUID", "")
|
||||
if not material_guid:
|
||||
Logger.log("d", "Unable to find materials linked to material with id %s, because it doesn't have a GUID.", material_id)
|
||||
return []
|
||||
|
||||
containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_guid)
|
||||
linked_material_names = []
|
||||
for container in containers:
|
||||
if container.getId() == material_id or container.getMetaDataEntry("base_file") != container.getId():
|
||||
continue
|
||||
|
||||
linked_material_names.append(container.getName())
|
||||
return linked_material_names
|
||||
|
||||
@pyqtSlot(str)
|
||||
def unlinkMaterial(self, material_id: str):
|
||||
containers = self._container_registry.findInstanceContainers(id=material_id)
|
||||
if not containers:
|
||||
Logger.log("d", "Unable to make the material with id %s unique, because it doesn't exist.", material_id)
|
||||
return ""
|
||||
|
||||
containers[0].setMetaDataEntry("base_file", material_id)
|
||||
containers[0].setMetaDataEntry("GUID", str(uuid.uuid4()))
|
||||
|
||||
|
||||
## Get the singleton instance for this class.
|
||||
@classmethod
|
||||
def getInstance(cls) -> "ContainerManager":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue