MaterialOutputModel.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional
  4. from PyQt6.QtCore import pyqtProperty, QObject
  5. class MaterialOutputModel(QObject):
  6. def __init__(self, guid: Optional[str], type: str, color: str, brand: str, name: str, parent = None) -> None:
  7. super().__init__(parent)
  8. name, guid = MaterialOutputModel.getMaterialFromDefinition(guid, type, brand, name)
  9. self._guid = guid
  10. self._type = type
  11. self._color = color
  12. self._brand = brand
  13. self._name = name
  14. @pyqtProperty(str, constant = True)
  15. def guid(self) -> str:
  16. return self._guid if self._guid else ""
  17. @staticmethod
  18. def getMaterialFromDefinition(guid, type, brand, name):
  19. _MATERIAL_MAP = { "abs" :{"name" :"ABS" ,"guid": "2780b345-577b-4a24-a2c5-12e6aad3e690"},
  20. "abs-cf10" :{"name": "ABS-CF" ,"guid": "495a0ce5-9daf-4a16-b7b2-06856d82394d"},
  21. "abs-wss1" :{"name" :"ABS-R" ,"guid": "88c8919c-6a09-471a-b7b6-e801263d862d"},
  22. "asa" :{"name" :"ASA" ,"guid": "f79bc612-21eb-482e-ad6c-87d75bdde066"},
  23. "nylon12-cf":{"name": "Nylon 12 CF" ,"guid": "3c6f2877-71cc-4760-84e6-4b89ab243e3b"},
  24. "nylon" :{"name" :"Nylon" ,"guid": "283d439a-3490-4481-920c-c51d8cdecf9c"},
  25. "pc" :{"name" :"PC" ,"guid": "62414577-94d1-490d-b1e4-7ef3ec40db02"},
  26. "petg" :{"name" :"PETG" ,"guid": "69386c85-5b6c-421a-bec5-aeb1fb33f060"},
  27. "pla" :{"name" :"PLA" ,"guid": "abb9c58e-1f56-48d1-bd8f-055fde3a5b56"},
  28. "pva" :{"name" :"PVA" ,"guid": "add51ef2-86eb-4c39-afd5-5586564f0715"},
  29. "wss1" :{"name" :"RapidRinse" ,"guid": "a140ef8f-4f26-4e73-abe0-cfc29d6d1024"},
  30. "sr30" :{"name" :"SR-30" ,"guid": "77873465-83a9-4283-bc44-4e542b8eb3eb"},
  31. "bvoh" :{"name" :"BVOH" ,"guid": "923e604c-8432-4b09-96aa-9bbbd42207f4"},
  32. "cpe" :{"name" :"CPE" ,"guid": "da1872c1-b991-4795-80ad-bdac0f131726"},
  33. "hips" :{"name" :"HIPS" ,"guid": "a468d86a-220c-47eb-99a5-bbb47e514eb0"},
  34. "tpu" :{"name" :"TPU 95A" ,"guid": "19baa6a9-94ff-478b-b4a1-8157b74358d2"},
  35. "im-pla" :{"name": "Tough" ,"guid": "de031137-a8ca-4a72-bd1b-17bb964033ad"}
  36. }
  37. if guid is None and brand != "empty" and type in _MATERIAL_MAP:
  38. name = _MATERIAL_MAP[type]["name"]
  39. guid = _MATERIAL_MAP[type]["guid"]
  40. return name, guid
  41. @pyqtProperty(str, constant = True)
  42. def type(self) -> str:
  43. return self._type
  44. @pyqtProperty(str, constant = True)
  45. def brand(self) -> str:
  46. return self._brand
  47. @pyqtProperty(str, constant = True)
  48. def color(self) -> str:
  49. return self._color
  50. @pyqtProperty(str, constant = True)
  51. def name(self) -> str:
  52. return self._name
  53. def __eq__(self, other):
  54. if self is other:
  55. return True
  56. if type(other) is not MaterialOutputModel:
  57. return False
  58. return self.guid == other.guid and self.type == other.type and self.brand == other.brand and self.color == other.color and self.name == other.name