Add a notice to linked materials and allow "unlinking" a material.

This commit is contained in:
fieldOfView 2017-04-29 19:49:12 +02:00
parent 23cd6b1c2c
commit 67b8302d40
2 changed files with 62 additions and 1 deletions

View file

@ -695,6 +695,7 @@ class ContainerManager(QObject):
duplicated_container.setDirty(True) duplicated_container.setDirty(True)
self._container_registry.addContainer(duplicated_container) self._container_registry.addContainer(duplicated_container)
# Create a new material by cloning Generic PLA and setting the GUID to something unqiue
@pyqtSlot(result = str) @pyqtSlot(result = str)
def createMaterial(self) -> str: def createMaterial(self) -> str:
# Ensure all settings are saved. # Ensure all settings are saved.
@ -702,7 +703,7 @@ class ContainerManager(QObject):
containers = self._container_registry.findInstanceContainers(id="generic_pla") containers = self._container_registry.findInstanceContainers(id="generic_pla")
if not containers: 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 "" return ""
# Create a new ID & container to hold the data. # Create a new ID & container to hold the data.
@ -722,6 +723,39 @@ class ContainerManager(QObject):
self._container_registry.addContainer(duplicated_container) 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. ## Get the singleton instance for this class.
@classmethod @classmethod
def getInstance(cls) -> "ContainerManager": def getInstance(cls) -> "ContainerManager":

View file

@ -24,6 +24,16 @@ TabView
property double spoolLength: calculateSpoolLength() property double spoolLength: calculateSpoolLength()
property real costPerMeter: calculateCostPerMeter() property real costPerMeter: calculateCostPerMeter()
property string linkedMaterialNames:
{
if(!base.containerId || !base.editingEnabled)
{
return ""
}
var linkedMaterials = Cura.ContainerManager.getLinkedMaterials(base.containerId);
return linkedMaterials.join(", ");
}
Tab Tab
{ {
title: catalog.i18nc("@title","Information") title: catalog.i18nc("@title","Information")
@ -196,6 +206,23 @@ TabView
height: parent.rowHeight height: parent.rowHeight
} }
Item { width: parent.width; height: UM.Theme.getSize("default_margin").height; visible: unlinkMaterialButton.visible }
Label
{
width: parent.width
verticalAlignment: Qt.AlignVCenter
text: catalog.i18nc("@label", "This material is linked to %1 and shares some of its properties.").arg(base.linkedMaterialNames)
wrapMode: Text.WordWrap
visible: unlinkMaterialButton.visible
}
Button
{
id: unlinkMaterialButton
text: catalog.i18nc("@label", "Unlink Material")
visible: base.linkedMaterialNames != ""
onClicked: Cura.ContainerManager.unlinkMaterial(base.containerId)
}
Item { width: parent.width; height: UM.Theme.getSize("default_margin").height } Item { width: parent.width; height: UM.Theme.getSize("default_margin").height }
Label { width: parent.width; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Description") } Label { width: parent.width; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Description") }