ConvexHullDecorator.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. Application.getInstance().getMachineManager().activeMachineInstanceChanged.connect(self._onActiveMachineInstanceChanged)
  16. self._onActiveProfileChanged()
  17. ## Force that a new (empty) object is created upon copy.
  18. def __deepcopy__(self, memo):
  19. copy = ConvexHullDecorator()
  20. return copy
  21. def getConvexHull(self):
  22. return self._convex_hull
  23. def getConvexHullHead(self):
  24. if not self._convex_hull_head:
  25. return self.getConvexHull()
  26. return self._convex_hull_head
  27. def getConvexHullBoundary(self):
  28. if not self._convex_hull_boundary:
  29. return self.getConvexHull()
  30. return self._convex_hull_boundary
  31. def setConvexHullBoundary(self, hull):
  32. self._convex_hull_boundary = hull
  33. def setConvexHullHead(self, hull):
  34. self._convex_hull_head = hull
  35. def setConvexHull(self, hull):
  36. self._convex_hull = hull
  37. def getConvexHullJob(self):
  38. return self._convex_hull_job
  39. def setConvexHullJob(self, job):
  40. self._convex_hull_job = job
  41. def getConvexHullNode(self):
  42. return self._convex_hull_node
  43. def setConvexHullNode(self, node):
  44. self._convex_hull_node = node
  45. def _onActiveProfileChanged(self):
  46. if self._profile:
  47. self._profile.settingValueChanged.disconnect(self._onSettingValueChanged)
  48. self._profile = Application.getInstance().getMachineManager().getWorkingProfile()
  49. if self._profile:
  50. self._profile.settingValueChanged.connect(self._onSettingValueChanged)
  51. def _onActiveMachineInstanceChanged(self):
  52. if self._convex_hull_job:
  53. self._convex_hull_job.cancel()
  54. self.setConvexHull(None)
  55. if self._convex_hull_node:
  56. self._convex_hull_node.setParent(None)
  57. self._convex_hull_node = None
  58. def _onSettingValueChanged(self, setting):
  59. if setting == "print_sequence":
  60. if self._convex_hull_job:
  61. self._convex_hull_job.cancel()
  62. self.setConvexHull(None)
  63. if self._convex_hull_node:
  64. self._convex_hull_node.setParent(None)
  65. self._convex_hull_node = None