PerObjectSettingsTool.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Uranium is released under the terms of the AGPLv3 or higher.
  3. from UM.Tool import Tool
  4. from UM.Scene.Selection import Selection
  5. from UM.Application import Application
  6. from UM.Preferences import Preferences
  7. class PerObjectSettingsTool(Tool):
  8. def __init__(self):
  9. super().__init__()
  10. self._model = None
  11. self.setExposedProperties("SelectedObjectId","ContainerID")
  12. Preferences.getInstance().preferenceChanged.connect(self._onPreferenceChanged)
  13. Selection.selectionChanged.connect(self.propertyChanged)
  14. self._onPreferenceChanged("cura/active_mode")
  15. def event(self, event):
  16. return False
  17. def getSelectedObjectId(self):
  18. try:
  19. selected_object = Selection.getSelectedObject(0)
  20. if selected_object.getParent().callDecoration("isGroup"):
  21. selected_object = selected_object.getParent()
  22. except:
  23. selected_object = None
  24. selected_object_id = id(selected_object)
  25. return selected_object_id
  26. def getContainerID(self):
  27. try:
  28. selected_object = Selection.getSelectedObject(0)
  29. if selected_object.getParent().callDecoration("isGroup"):
  30. selected_object = selected_object.getParent()
  31. try:
  32. return selected_object.callDecoration("getStack").getId()
  33. except:
  34. print(":(")
  35. return
  36. except:
  37. print(":((")
  38. return
  39. def setContainerID(self, value):
  40. pass
  41. def _onPreferenceChanged(self, preference):
  42. if preference == "cura/active_mode":
  43. enabled = Preferences.getInstance().getValue(preference)==1
  44. Application.getInstance().getController().toolEnabledChanged.emit(self._plugin_id, enabled)