From 02c1e017887f32d90b456748e34ecadddfe8f6e0 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 30 Nov 2021 17:42:29 +0100 Subject: [PATCH] Parse list of compatible support materials This one is quite complex because the support material names are in their profiles, so we need to consult the profiles, if present. Contributes to issue CURA-8585. --- plugins/Marketplace/PackageModel.py | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plugins/Marketplace/PackageModel.py b/plugins/Marketplace/PackageModel.py index 578b73a82e..605674ca16 100644 --- a/plugins/Marketplace/PackageModel.py +++ b/plugins/Marketplace/PackageModel.py @@ -5,7 +5,9 @@ from PyQt5.QtCore import pyqtProperty, QObject import re from typing import Any, Dict, List, Optional +from cura.Settings.CuraContainerRegistry import CuraContainerRegistry # To get names of materials we're compatible with. from UM.i18n import i18nCatalog # To translate placeholder names if data is not present. + catalog = i18nCatalog("cura") @@ -46,6 +48,7 @@ class PackageModel(QObject): self._safety_data_sheet = self._findLink(subdata, "safety_data_sheet") self._where_to_buy = self._findLink(subdata, "where_to_buy") self._compatible_printers = self._getCompatiblePrinters(subdata) + self._compatible_support_materials = self._getCompatibleSupportMaterials(subdata) author_data = package_data.get("author", {}) self._author_name = author_data.get("display_name", catalog.i18nc("@label:property", "Unknown Author")) @@ -109,6 +112,35 @@ class PackageModel(QObject): return list(sorted(result)) + def _getCompatibleSupportMaterials(self, subdata: Dict[str, Any]) -> List[str]: + """ + Gets the list of support materials that the materials in this package are compatible with. + + Since the materials are individually encoded as keys in the API response, only PVA and Breakaway are currently + supported. + :param subdata: The "data" element in the package data, which should contain this compatibility information. + :return: A list of support materials that the materials in this package are compatible with. + """ + result = set() + + container_registry = CuraContainerRegistry.getInstance() + try: + pva_name = container_registry.findContainersMetadata(id = "ultimaker_pva")[0].get("name", "Ultimaker PVA") + except IndexError: + pva_name = "Ultimaker PVA" + try: + breakaway_name = container_registry.findContainersMetadata(id = "ultimaker_bam")[0].get("name", "Ultimaker Breakaway") + except IndexError: + breakaway_name = "Ultimaker Breakaway" + + for material in subdata.get("materials", []): + if material.get("pva_compatible", False): + result.add(pva_name) + if material.get("breakaway_compatible", False): + result.add(breakaway_name) + + return list(sorted(result)) + @pyqtProperty(str, constant = True) def packageId(self) -> str: return self._package_id @@ -180,3 +212,7 @@ class PackageModel(QObject): @pyqtProperty("QVariantList", constant = True) def compatiblePrinters(self) -> List[str]: return self._compatible_printers + + @pyqtProperty("QVariantList", constant = True) + def compatibleSupportMaterials(self) -> List[str]: + return self._compatible_support_materials