MaterialOutputModel.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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": "416eead4-0d8e-4f0b-8bfc-a91a519befa5"},
  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": "0ff92885-617b-4144-a03c-9989872454bc"},
  28. "pva" :{"name" :"PVA" ,"guid": "a4255da2-cb2a-4042-be49-4a83957a2f9a"},
  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. }
  36. if guid is None and brand != "empty" and type in _MATERIAL_MAP:
  37. name = _MATERIAL_MAP[type]["name"]
  38. guid = _MATERIAL_MAP[type]["guid"]
  39. return name, guid
  40. @pyqtProperty(str, constant = True)
  41. def type(self) -> str:
  42. return self._type
  43. @pyqtProperty(str, constant = True)
  44. def brand(self) -> str:
  45. return self._brand
  46. @pyqtProperty(str, constant = True)
  47. def color(self) -> str:
  48. return self._color
  49. @pyqtProperty(str, constant = True)
  50. def name(self) -> str:
  51. return self._name
  52. def __eq__(self, other):
  53. if self is other:
  54. return True
  55. if type(other) is not MaterialOutputModel:
  56. return False
  57. 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