MaterialOutputModel.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (c) 2024 UltiMaker
  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. from cura.PrinterOutput.FormatMaps import FormatMaps
  6. class MaterialOutputModel(QObject):
  7. def __init__(self, guid: Optional[str], type: str, color: str, brand: str, name: str, parent = None) -> None:
  8. super().__init__(parent)
  9. name, guid = MaterialOutputModel.getMaterialFromDefinition(guid, type, brand, name)
  10. self._guid = guid
  11. self._type = type
  12. self._color = color
  13. self._brand = brand
  14. self._name = name
  15. @pyqtProperty(str, constant = True)
  16. def guid(self) -> str:
  17. return self._guid if self._guid else ""
  18. @staticmethod
  19. def getMaterialFromDefinition(guid, type, brand, name):
  20. if guid is None and brand != "empty" and type in FormatMaps.MATERIAL_MAP:
  21. name = FormatMaps.MATERIAL_MAP[type]["name"]
  22. guid = FormatMaps.MATERIAL_MAP[type]["guid"]
  23. return name, guid
  24. @pyqtProperty(str, constant = True)
  25. def type(self) -> str:
  26. return self._type
  27. @pyqtProperty(str, constant = True)
  28. def brand(self) -> str:
  29. return self._brand
  30. @pyqtProperty(str, constant = True)
  31. def color(self) -> str:
  32. return self._color
  33. @pyqtProperty(str, constant = True)
  34. def name(self) -> str:
  35. return self._name
  36. def __eq__(self, other):
  37. if self is other:
  38. return True
  39. if type(other) is not MaterialOutputModel:
  40. return False
  41. 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