diff --git a/plugins/3MFReader/ThreeMFWorkspaceReader.py b/plugins/3MFReader/ThreeMFWorkspaceReader.py index 4cf0306026..6b6f28a46b 100644 --- a/plugins/3MFReader/ThreeMFWorkspaceReader.py +++ b/plugins/3MFReader/ThreeMFWorkspaceReader.py @@ -12,6 +12,8 @@ from UM.Job import Job from UM.Preferences import Preferences from .WorkspaceDialog import WorkspaceDialog +import xml.etree.ElementTree as ET + from cura.Settings.ExtruderManager import ExtruderManager import zipfile @@ -74,6 +76,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader): machine_conflict = True Job.yieldThread() + material_labels = [] material_conflict = False xml_material_profile = self._getXmlProfileClass() if self._material_container_suffix is None: @@ -83,10 +86,10 @@ class ThreeMFWorkspaceReader(WorkspaceReader): for material_container_file in material_container_files: container_id = self._stripFileToId(material_container_file) materials = self._container_registry.findInstanceContainers(id=container_id) + material_labels.append(self._getMaterialLabelFromSerialized(archive.open(material_container_file).read().decode("utf-8"))) if materials and not materials[0].isReadOnly(): # Only non readonly materials can be in conflict material_conflict = True Job.yieldThread() - # Check if any quality_changes instance container is in conflict. instance_container_files = [name for name in cura_file_names if name.endswith(self._instance_container_suffix)] quality_name = "" @@ -141,6 +144,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader): self._dialog.setNumSettingsOverridenByQualityChanges(num_settings_overriden_by_quality_changes) self._dialog.setActiveMode(active_mode) self._dialog.setMachineName(machine_name) + self._dialog.setMaterialLabels(material_labels) self._dialog.show() # Block until the dialog is closed. @@ -445,3 +449,10 @@ class ThreeMFWorkspaceReader(WorkspaceReader): parser = configparser.ConfigParser(interpolation=None, empty_lines_in_values=False) parser.read_string(serialized) return parser["general"].get("name", "") + + def _getMaterialLabelFromSerialized(self, serialized): + data = ET.fromstring(serialized) + metadata = data.iterfind("./um:metadata/um:name/um:label", {"um": "http://www.ultimaker.com/material"}) + for entry in metadata: + return entry.text + pass \ No newline at end of file diff --git a/plugins/3MFReader/WorkspaceDialog.py b/plugins/3MFReader/WorkspaceDialog.py index 9ae1c29c52..0055b209ff 100644 --- a/plugins/3MFReader/WorkspaceDialog.py +++ b/plugins/3MFReader/WorkspaceDialog.py @@ -37,6 +37,7 @@ class WorkspaceDialog(QObject): self._num_settings_overriden_by_quality_changes = 0 self._quality_type = "" self._machine_name = "" + self._material_labels = [] machineConflictChanged = pyqtSignal() qualityChangesConflictChanged = pyqtSignal() @@ -47,6 +48,15 @@ class WorkspaceDialog(QObject): numSettingsOverridenByQualityChangesChanged = pyqtSignal() qualityTypeChanged = pyqtSignal() machineNameChanged = pyqtSignal() + materialLabelsChanged = pyqtSignal() + + @pyqtProperty("QVariantList", notify = materialLabelsChanged) + def materialLabels(self): + return self._material_labels + + def setMaterialLabels(self, material_labels): + self._material_labels = material_labels + self.materialLabelsChanged.emit() @pyqtProperty(str, notify = machineNameChanged) def machineName(self): diff --git a/plugins/3MFReader/WorkspaceDialog.qml b/plugins/3MFReader/WorkspaceDialog.qml index 21fc4db69e..5b5de4c84d 100644 --- a/plugins/3MFReader/WorkspaceDialog.qml +++ b/plugins/3MFReader/WorkspaceDialog.qml @@ -192,19 +192,35 @@ UM.Dialog text: catalog.i18nc("@action:label", "Material settings") font.bold: true } + + Repeater + { + model: manager.materialLabels + delegate: Row + { + width: parent.width + height: childrenRect.height + Label + { + text: catalog.i18nc("@action:label", "Name") + width: parent.width / 3 + } + Label + { + text: modelData + width: parent.width / 3 + } + } + } + Row { width: parent.width height: childrenRect.height - Label + Item { - text: catalog.i18nc("@action:label", "Type") - width: parent.width / 3 - } - Label - { - text: catalog.i18nc("@action:label", "TOCHANGE") - width: parent.width / 3 + width: parent.width / 3 * 2 + height: comboboxHeight } UM.TooltipArea @@ -213,7 +229,7 @@ UM.Dialog width: parent.width / 3 height: visible ? comboboxHeight : 0 visible: manager.materialConflict - text: catalog.i18nc("@info:tooltip", "How should the conflict in the profile be resolved?") + text: catalog.i18nc("@info:tooltip", "How should the conflict in the material be resolved?") ComboBox { model: resolveStrategiesModel