ConvexHullDecorator.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
  2. from UM.Application import Application
  3. class ConvexHullDecorator(SceneNodeDecorator):
  4. def __init__(self):
  5. super().__init__()
  6. self._convex_hull = None
  7. # In case of printing all at once this is the same as the convex hull. For one at the time this is the area without the head.
  8. self._convex_hull_boundary = None
  9. # In case of printing all at once this is the same as the convex hull. For one at the time this is area with full head
  10. self._convex_hull_head = None
  11. self._convex_hull_node = None
  12. self._convex_hull_job = None
  13. settings = Application.getInstance().getActiveMachine()
  14. print_sequence_setting = settings.getSettingByKey("print_sequence")
  15. if print_sequence_setting:
  16. print_sequence_setting.valueChanged.connect(self._onPrintSequenceSettingChanged)
  17. def _onPrintSequenceSettingChanged(self, setting):
  18. if self._convex_hull_job:
  19. self._convex_hull_job.cancel()
  20. self.setConvexHull(None)
  21. if self._convex_hull_node:
  22. self._convex_hull_node.setParent(None)
  23. self._convex_hull_node = None
  24. def getConvexHull(self):
  25. return self._convex_hull
  26. def getConvexHullHead(self):
  27. if not self._convex_hull_head:
  28. return self.getConvexHull()
  29. return self._convex_hull_head
  30. def getConvexHullBoundary(self):
  31. if not self._convex_hull_boundary:
  32. return self.getConvexHull()
  33. return self._convex_hull_boundary
  34. def setConvexHullBoundary(self, hull):
  35. self._convex_hull_boundary = hull
  36. def setConvexHullHead(self, hull):
  37. self._convex_hull_head = hull
  38. def setConvexHull(self, hull):
  39. self._convex_hull = hull
  40. def getConvexHullJob(self):
  41. return self._convex_hull_job
  42. def setConvexHullJob(self, job):
  43. self._convex_hull_job = job
  44. def getConvexHullNode(self):
  45. return self._convex_hull_node
  46. def setConvexHullNode(self, node):
  47. self._convex_hull_node = node