ArrangeObjectsJob.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import List
  4. from UM.Application import Application
  5. from UM.Job import Job
  6. from UM.Logger import Logger
  7. from UM.Message import Message
  8. from UM.Scene.SceneNode import SceneNode
  9. from UM.i18n import i18nCatalog
  10. from cura.Arranging.Nest2DArrange import arrange
  11. i18n_catalog = i18nCatalog("cura")
  12. class ArrangeObjectsJob(Job):
  13. def __init__(self, nodes: List[SceneNode], fixed_nodes: List[SceneNode], min_offset = 8) -> None:
  14. super().__init__()
  15. self._nodes = nodes
  16. self._fixed_nodes = fixed_nodes
  17. self._min_offset = min_offset
  18. def run(self):
  19. found_solution_for_all = False
  20. status_message = Message(i18n_catalog.i18nc("@info:status", "Finding new location for objects"),
  21. lifetime = 0,
  22. dismissable = False,
  23. progress = 0,
  24. title = i18n_catalog.i18nc("@info:title", "Finding Location"))
  25. status_message.show()
  26. try:
  27. found_solution_for_all = arrange(self._nodes, Application.getInstance().getBuildVolume(), self._fixed_nodes)
  28. except: # If the thread crashes, the message should still close
  29. Logger.logException("e", "Unable to arrange the objects on the buildplate. The arrange algorithm has crashed.")
  30. status_message.hide()
  31. if not found_solution_for_all:
  32. no_full_solution_message = Message(
  33. i18n_catalog.i18nc("@info:status",
  34. "Unable to find a location within the build volume for all objects"),
  35. title = i18n_catalog.i18nc("@info:title", "Can't Find Location"),
  36. message_type = Message.MessageType.ERROR)
  37. no_full_solution_message.show()
  38. self.finished.emit(self)