ExtruderConfigurationModel.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
  4. class ExtruderConfigurationModel(QObject):
  5. extruderConfigurationChanged = pyqtSignal()
  6. def __init__(self):
  7. super().__init__()
  8. self._position = -1
  9. self._material = None
  10. self._hotend_id = None
  11. def setPosition(self, position):
  12. self._position = position
  13. @pyqtProperty(int, fset = setPosition, notify = extruderConfigurationChanged)
  14. def position(self):
  15. return self._position
  16. def setMaterial(self, material):
  17. self._material = material
  18. @pyqtProperty(QObject, fset = setMaterial, notify = extruderConfigurationChanged)
  19. def material(self):
  20. return self._material
  21. def setHotendID(self, hotend_id):
  22. self._hotend_id = hotend_id
  23. @pyqtProperty(str, fset = setHotendID, notify = extruderConfigurationChanged)
  24. def hotendID(self):
  25. return self._hotend_id
  26. ## This method is intended to indicate whether the configuration is valid or not.
  27. # The method checks if the mandatory fields are or not set
  28. # At this moment is always valid since we allow to have empty material and variants.
  29. def isValid(self):
  30. return True
  31. def __str__(self):
  32. message_chunks = []
  33. message_chunks.append("Position: " + str(self._position))
  34. message_chunks.append("-")
  35. message_chunks.append("Material: " + self.material.type if self.material else "empty")
  36. message_chunks.append("-")
  37. message_chunks.append("HotendID: " + self.hotendID if self.hotendID else "empty")
  38. return " ".join(message_chunks)
  39. def __eq__(self, other):
  40. return hash(self) == hash(other)
  41. # Calculating a hash function using the position of the extruder, the material GUID and the hotend id to check if is
  42. # unique within a set
  43. def __hash__(self):
  44. return hash(self._position) ^ (hash(self._material.guid) if self._material is not None else hash(0)) ^ hash(self._hotend_id)