ArrangeObjectsJob.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. status_message = Message(i18n_catalog.i18nc("@info:status", "Finding new location for objects"),
  20. lifetime = 0,
  21. dismissable = False,
  22. progress = 0,
  23. title = i18n_catalog.i18nc("@info:title", "Finding Location"))
  24. status_message.show()
  25. found_solution_for_all = None
  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 found_solution_for_all is not None and 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)