123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- from typing import Optional
- from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
- from .MaterialOutputModel import MaterialOutputModel
- class ExtruderConfigurationModel(QObject):
- extruderConfigurationChanged = pyqtSignal()
- def __init__(self, position: int = -1) -> None:
- super().__init__()
- self._position = position
- self._material = None
- self._hotend_id = None
- def setPosition(self, position: int) -> None:
- self._position = position
- @pyqtProperty(int, fset = setPosition, notify = extruderConfigurationChanged)
- def position(self) -> int:
- return self._position
- def setMaterial(self, material: Optional[MaterialOutputModel]) -> None:
- if self._hotend_id != material:
- self._material = material
- self.extruderConfigurationChanged.emit()
- @pyqtProperty(QObject, fset = setMaterial, notify = extruderConfigurationChanged)
- def activeMaterial(self) -> Optional[MaterialOutputModel]:
- return self._material
- @pyqtProperty(QObject, fset=setMaterial, notify=extruderConfigurationChanged)
- def material(self) -> Optional[MaterialOutputModel]:
- return self._material
- def setHotendID(self, hotend_id: Optional[str]) -> None:
- if self._hotend_id != hotend_id:
- self._hotend_id = hotend_id
- self.extruderConfigurationChanged.emit()
- @pyqtProperty(str, fset = setHotendID, notify = extruderConfigurationChanged)
- def hotendID(self) -> Optional[str]:
- return self._hotend_id
-
-
-
- def isValid(self) -> bool:
- return True
- def __str__(self) -> str:
- message_chunks = []
- message_chunks.append("Position: " + str(self._position))
- message_chunks.append("-")
- message_chunks.append("Material: " + self.activeMaterial.type if self.activeMaterial else "empty")
- message_chunks.append("-")
- message_chunks.append("HotendID: " + self.hotendID if self.hotendID else "empty")
- return " ".join(message_chunks)
- def __eq__(self, other) -> bool:
- if not isinstance(other, ExtruderConfigurationModel):
- return False
- if self._position != other.position:
- return False
-
- if self.activeMaterial is not None and other.activeMaterial is not None:
- if self.activeMaterial.guid != other.activeMaterial.guid:
- if self.activeMaterial.guid != "" and other.activeMaterial.guid != "":
- return False
- else:
-
- return True
- if self.hotendID != other.hotendID:
- return False
- return True
-
-
- def __hash__(self):
- return hash(self._position) ^ (hash(self._material.guid) if self._material is not None else hash(0)) ^ hash(self._hotend_id)
|