MaterialOutputModel.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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-cf10" :{"name": "ABS-CF" ,"guid": "495a0ce5-9daf-4a16-b7b2-06856d82394d"},
  20. "abs-wss1" :{"name" :"ABS-R" ,"guid": "88c8919c-6a09-471a-b7b6-e801263d862d"},
  21. "asa" :{"name" :"ASA" ,"guid": "f79bc612-21eb-482e-ad6c-87d75bdde066"},
  22. "nylon12-cf":{"name": "Nylon 12 CF" ,"guid": "3c6f2877-71cc-4760-84e6-4b89ab243e3b"},
  23. "wss1" :{"name" :"RapidRinse" ,"guid": "a140ef8f-4f26-4e73-abe0-cfc29d6d1024"},
  24. "sr30" :{"name" :"SR-30" ,"guid": "77873465-83a9-4283-bc44-4e542b8eb3eb"}
  25. }
  26. if guid is None and brand != "empty" and type in _MATERIAL_MAP:
  27. name = _MATERIAL_MAP[type]["name"]
  28. guid = _MATERIAL_MAP[type]["guid"]
  29. return name, guid
  30. @pyqtProperty(str, constant = True)
  31. def type(self) -> str:
  32. return self._type
  33. @pyqtProperty(str, constant = True)
  34. def brand(self) -> str:
  35. return self._brand
  36. @pyqtProperty(str, constant = True)
  37. def color(self) -> str:
  38. return self._color
  39. @pyqtProperty(str, constant = True)
  40. def name(self) -> str:
  41. return self._name
  42. def __eq__(self, other):
  43. if self is other:
  44. return True
  45. if type(other) is not MaterialOutputModel:
  46. return False
  47. 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