From 2ae998737f7acb2acd1f05eeae1493aedc575927 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 25 Aug 2016 09:54:22 +0200 Subject: [PATCH 1/3] Added materialspage Display Name field and made it work. CURA-1969 --- cura/Settings/ContainerManager.py | 20 +++++++++++++++++- .../XmlMaterialProfile/XmlMaterialProfile.py | 21 +++++++++++++++++++ resources/qml/Preferences/MaterialView.qml | 20 +++++++++++++++++- .../qml/Preferences/ReadOnlyTextField.qml | 1 + 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/cura/Settings/ContainerManager.py b/cura/Settings/ContainerManager.py index 6efcd029c6..8957f386fc 100644 --- a/cura/Settings/ContainerManager.py +++ b/cura/Settings/ContainerManager.py @@ -181,7 +181,7 @@ class ContainerManager(QObject): def setContainerMetaDataEntry(self, container_id, entry_name, entry_value): containers = UM.Settings.ContainerRegistry.getInstance().findContainers(None, id = container_id) if not containers: - UM.Logger.log("w", "Could set metadata of container %s because it was not found.", container_id) + UM.Logger.log("w", "Could not set metadata of container %s because it was not found.", container_id) return False container = containers[0] @@ -210,6 +210,24 @@ class ContainerManager(QObject): return True + ## Set the name of the specified container. + @pyqtSlot(str, str, result = bool) + def setContainerName(self, container_id, new_name): + containers = UM.Settings.ContainerRegistry.getInstance().findContainers(None, id = container_id) + if not containers: + UM.Logger.log("w", "Could not set name of container %s because it was not found.", container_id) + return False + + container = containers[0] + + if container.isReadOnly(): + UM.Logger.log("w", "Cannot set name of read-only container %s.", container_id) + return False + + container.setName(new_name) + + return True + ## Find instance containers matching certain criteria. # # This effectively forwards to ContainerRegistry::findInstanceContainers. diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index 61ecce10a9..6f683a458d 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -61,6 +61,27 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer): for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(GUID = self.getMetaDataEntry("GUID"), base_file = basefile): container.setMetaData(copy.deepcopy(self._metadata)) + ## Overridden from InstanceContainer, similar to setMetaDataEntry. + # without this function the setName would only set the name of the specific nozzle / material / machine combination container + # The function is a bit tricky. It will not set the name of all containers if it has the correct name itself. + def setName(self, new_name): + if self.isReadOnly(): + return + + # Not only is this faster, it also prevents a major loop that causes a stack overflow. + if self.getName() == new_name: + return + + super().setName(new_name) + + basefile = self.getMetaDataEntry("base_file", self._id) # if basefile is none, this is a basefile. + # Update the basefile as well, this is actually what we're trying to do + # Update all containers that share GUID and basefile + containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=basefile) + UM.Settings.ContainerRegistry.getInstance().findInstanceContainers( + GUID=self.getMetaDataEntry("GUID"), base_file=basefile) + for container in containers: + container.setName(new_name) + ## Overridden from InstanceContainer def setProperty(self, key, property_name, property_value, container = None): if self.isReadOnly(): diff --git a/resources/qml/Preferences/MaterialView.qml b/resources/qml/Preferences/MaterialView.qml index 9dbb5c6d15..da3399eb4d 100644 --- a/resources/qml/Preferences/MaterialView.qml +++ b/resources/qml/Preferences/MaterialView.qml @@ -44,6 +44,16 @@ TabView property real rowHeight: textField.height; + Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Display Name") } + ReadOnlyTextField + { + id: displayNameTextField; + width: base.secondColumnWidth; + text: properties.name; + readOnly: !base.editingEnabled; + onEditingFinished: base.setName(properties.name, text) + } + Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Brand") } ReadOnlyTextField { @@ -254,7 +264,15 @@ TabView { if(old_value != new_value) { - Cura.ContainerManager.setContainerMetaDataEntry(base.containerId, entry_name, new_value) + Cura.ContainerManager.setContainerMetaDataEntry(base.containerId, entry_name, new_value); + } + } + + function setName(old_value, new_value) + { + if(old_value != new_value) + { + Cura.ContainerManager.setContainerName(base.containerId, new_value); } } } diff --git a/resources/qml/Preferences/ReadOnlyTextField.qml b/resources/qml/Preferences/ReadOnlyTextField.qml index 28c714259b..2ff0357020 100644 --- a/resources/qml/Preferences/ReadOnlyTextField.qml +++ b/resources/qml/Preferences/ReadOnlyTextField.qml @@ -1,5 +1,6 @@ // Copyright (c) 2016 Ultimaker B.V. // Uranium is released under the terms of the AGPLv3 or higher. +// Different than the name suggests, it is not always read-only. import QtQuick 2.1 import QtQuick.Controls 1.1 From 77b58d82311c648c89840aff26b5d433de3b0b96 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 25 Aug 2016 10:37:11 +0200 Subject: [PATCH 2/3] MaterialsPage material label is now also updated after rename. CURA-1969 --- resources/qml/Preferences/MaterialView.qml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/qml/Preferences/MaterialView.qml b/resources/qml/Preferences/MaterialView.qml index da3399eb4d..3041115ad2 100644 --- a/resources/qml/Preferences/MaterialView.qml +++ b/resources/qml/Preferences/MaterialView.qml @@ -273,6 +273,8 @@ TabView if(old_value != new_value) { Cura.ContainerManager.setContainerName(base.containerId, new_value); + // update material name label. not so pretty, but it works + materialProperties.name = new_value; } } } From 043343d536a829526221c8b470355cc79ac49fc4 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Thu, 25 Aug 2016 10:46:19 +0200 Subject: [PATCH 3/3] Select correctly "inherited" profile when switching to a material that has no qualities of its own CURA-2095 --- cura/Settings/MachineManager.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index b40b412956..22a7bb3a10 100644 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -809,10 +809,13 @@ class MachineManager(QObject): # If a quality for this specific material cannot be found, try finding qualities for a generic version of the material material_search_criteria = { "type": "material", "material": material_container.getMetaDataEntry("material"), "color_name": "Generic" } if definition.getMetaDataEntry("has_machine_quality"): - material_search_criteria["definition"] = definition.id + if material_container: + material_search_criteria["definition"] = material_container.getDefinition().id + else: + material_search_criteria["definition"] = definition.id - if definition.getMetaDataEntry("has_variants") and variant_container: - material_search_criteria["variant"] = variant_container.id + if definition.getMetaDataEntry("has_variants") and variant_container: + material_search_criteria["variant"] = variant_container.id else: material_search_criteria["definition"] = "fdmprinter"