ConvexHullDecorator.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. self._profile = None
  14. Application.getInstance().getMachineManager().activeProfileChanged.connect(self._onActiveProfileChanged)
  15. self._onActiveProfileChanged()
  16. def getConvexHull(self):
  17. return self._convex_hull
  18. def getConvexHullHead(self):
  19. if not self._convex_hull_head:
  20. return self.getConvexHull()
  21. return self._convex_hull_head
  22. def getConvexHullBoundary(self):
  23. if not self._convex_hull_boundary:
  24. return self.getConvexHull()
  25. return self._convex_hull_boundary
  26. def setConvexHullBoundary(self, hull):
  27. self._convex_hull_boundary = hull
  28. def setConvexHullHead(self, hull):
  29. self._convex_hull_head = hull
  30. def setConvexHull(self, hull):
  31. self._convex_hull = hull
  32. def getConvexHullJob(self):
  33. return self._convex_hull_job
  34. def setConvexHullJob(self, job):
  35. self._convex_hull_job = job
  36. def getConvexHullNode(self):
  37. return self._convex_hull_node
  38. def setConvexHullNode(self, node):
  39. self._convex_hull_node = node
  40. def _onActiveProfileChanged(self):
  41. if self._profile:
  42. self._profile.settingValueChanged.disconnect(self._onSettingValueChanged)
  43. self._profile = Application.getInstance().getMachineManager().getActiveProfile()
  44. if self._profile:
  45. self._profile.settingValueChanged.connect(self._onSettingValueChanged)
  46. def _onSettingValueChanged(self, setting):
  47. if setting == "print_sequence":
  48. if self._convex_hull_job:
  49. self._convex_hull_job.cancel()
  50. self.setConvexHull(None)
  51. if self._convex_hull_node:
  52. self._convex_hull_node.setParent(None)
  53. self._convex_hull_node = None