PerObjectSettingsTool.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. selected_object = Selection.getSelectedObject(0)
  28. if selected_object.getParent().callDecoration("isGroup"):
  29. selected_object = selected_object.getParent()
  30. try:
  31. return selected_object.callDecoration("getStack").getId()
  32. except AttributeError:
  33. return ""
  34. def setContainerID(self, value):
  35. pass
  36. def _onPreferenceChanged(self, preference):
  37. if preference == "cura/active_mode":
  38. enabled = Preferences.getInstance().getValue(preference)==1
  39. Application.getInstance().getController().toolEnabledChanged.emit(self._plugin_id, enabled)