ConvexHullDecorator.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 intersection of mirrored head
  10. self._convex_hull_head = None
  11. # In case of printing all at once this is the same as the convex hull. For one at the time this is area with intersection of full head
  12. self._convex_hull_head_full = None
  13. self._convex_hull_node = None
  14. self._convex_hull_job = None
  15. self._profile = None
  16. Application.getInstance().getMachineManager().activeProfileChanged.connect(self._onActiveProfileChanged)
  17. Application.getInstance().getMachineManager().activeMachineInstanceChanged.connect(self._onActiveMachineInstanceChanged)
  18. self._onActiveProfileChanged()
  19. ## Force that a new (empty) object is created upon copy.
  20. def __deepcopy__(self, memo):
  21. copy = ConvexHullDecorator()
  22. return copy
  23. def getConvexHull(self):
  24. return self._convex_hull
  25. def getConvexHullHeadFull(self):
  26. if not self._convex_hull_head_full:
  27. return self.getConvexHull()
  28. return self._convex_hull_head_full
  29. def getConvexHullHead(self):
  30. if not self._convex_hull_head:
  31. return self.getConvexHull()
  32. return self._convex_hull_head
  33. def getConvexHullBoundary(self):
  34. if not self._convex_hull_boundary:
  35. return self.getConvexHull()
  36. return self._convex_hull_boundary
  37. def setConvexHullBoundary(self, hull):
  38. self._convex_hull_boundary = hull
  39. def setConvexHullHeadFull(self, hull):
  40. self._convex_hull_head_full = hull
  41. def setConvexHullHead(self, hull):
  42. self._convex_hull_head = hull
  43. def setConvexHull(self, hull):
  44. self._convex_hull = hull
  45. def getConvexHullJob(self):
  46. return self._convex_hull_job
  47. def setConvexHullJob(self, job):
  48. self._convex_hull_job = job
  49. def getConvexHullNode(self):
  50. return self._convex_hull_node
  51. def setConvexHullNode(self, node):
  52. self._convex_hull_node = node
  53. def _onActiveProfileChanged(self):
  54. if self._profile:
  55. self._profile.settingValueChanged.disconnect(self._onSettingValueChanged)
  56. self._profile = Application.getInstance().getMachineManager().getWorkingProfile()
  57. if self._profile:
  58. self._profile.settingValueChanged.connect(self._onSettingValueChanged)
  59. def _onActiveMachineInstanceChanged(self):
  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
  66. def _onSettingValueChanged(self, setting):
  67. if setting in self._affected_settings:
  68. if self._convex_hull_job:
  69. self._convex_hull_job.cancel()
  70. self.setConvexHull(None)
  71. if self._convex_hull_node:
  72. self._convex_hull_node.setParent(None)
  73. self._convex_hull_node = None
  74. _affected_settings = [
  75. "print_sequence", "raft_margin", "adhesion_type", "brim_width",
  76. "skirt_gap", "skirt_line_width", "skirt_line_count"]