SettingsExportModel.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Copyright (c) 2024 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from dataclasses import asdict
  4. from typing import Optional, cast, List, Dict, Pattern, Set
  5. from PyQt6.QtCore import QObject, pyqtProperty
  6. from UM.Settings.SettingDefinition import SettingDefinition
  7. from UM.Settings.InstanceContainer import InstanceContainer
  8. from UM.Settings.SettingFunction import SettingFunction
  9. from cura.CuraApplication import CuraApplication
  10. from cura.Settings.ExtruderManager import ExtruderManager
  11. from cura.Settings.GlobalStack import GlobalStack
  12. from .SettingsExportGroup import SettingsExportGroup
  13. from .SettingExport import SettingExport
  14. class SettingsExportModel(QObject):
  15. EXPORTABLE_SETTINGS = {'infill_sparse_density',
  16. 'adhesion_type',
  17. 'support_enable',
  18. 'infill_pattern',
  19. 'support_type',
  20. 'support_structure',
  21. 'support_angle',
  22. 'support_infill_rate',
  23. 'ironing_enabled',
  24. 'fill_outline_gaps',
  25. 'coasting_enable',
  26. 'skin_monotonic',
  27. 'z_seam_position',
  28. 'infill_before_walls',
  29. 'ironing_only_highest_layer',
  30. 'xy_offset',
  31. 'adaptive_layer_height_enabled',
  32. 'brim_gap',
  33. 'support_offset',
  34. 'brim_outside_only',
  35. 'magic_spiralize',
  36. 'slicing_tolerance',
  37. 'outer_inset_first',
  38. 'magic_fuzzy_skin_outside_only',
  39. 'conical_overhang_enabled',
  40. 'min_infill_area',
  41. 'small_hole_max_size',
  42. 'magic_mesh_surface_mode',
  43. 'carve_multiple_volumes',
  44. 'meshfix_union_all_remove_holes',
  45. 'support_tree_rest_preference',
  46. 'small_feature_max_length',
  47. 'draft_shield_enabled',
  48. 'brim_smart_ordering',
  49. 'ooze_shield_enabled',
  50. 'bottom_skin_preshrink',
  51. 'skin_edge_support_thickness',
  52. 'alternate_carve_order',
  53. 'top_skin_preshrink',
  54. 'interlocking_enable'}
  55. def __init__(self, parent = None):
  56. super().__init__(parent)
  57. self._settings_groups = []
  58. application = CuraApplication.getInstance()
  59. # Display global settings
  60. global_stack = application.getGlobalContainerStack()
  61. self._settings_groups.append(SettingsExportGroup(global_stack,
  62. "Global settings",
  63. SettingsExportGroup.Category.Global,
  64. self._exportSettings(global_stack)))
  65. # Display per-extruder settings
  66. extruders_stacks = ExtruderManager.getInstance().getUsedExtruderStacks()
  67. for extruder_stack in extruders_stacks:
  68. color = ""
  69. if extruder_stack.material:
  70. color = extruder_stack.material.getMetaDataEntry("color_code")
  71. self._settings_groups.append(SettingsExportGroup(extruder_stack,
  72. "Extruder settings",
  73. SettingsExportGroup.Category.Extruder,
  74. self._exportSettings(extruder_stack),
  75. extruder_index=extruder_stack.position,
  76. extruder_color=color))
  77. # Display per-model settings
  78. scene_root = application.getController().getScene().getRoot()
  79. for scene_node in scene_root.getChildren():
  80. per_model_stack = scene_node.callDecoration("getStack")
  81. if per_model_stack is not None:
  82. self._settings_groups.append(SettingsExportGroup(per_model_stack,
  83. "Model settings",
  84. SettingsExportGroup.Category.Model,
  85. self._exportSettings(per_model_stack),
  86. scene_node.getName()))
  87. @pyqtProperty(list, constant=True)
  88. def settingsGroups(self) -> List[SettingsExportGroup]:
  89. return self._settings_groups
  90. @staticmethod
  91. def _exportSettings(settings_stack):
  92. user_settings_container = settings_stack.userChanges
  93. user_keys = user_settings_container.getAllKeys()
  94. settings_export = []
  95. for setting_to_export in user_keys:
  96. label = settings_stack.getProperty(setting_to_export, "label")
  97. value = settings_stack.getProperty(setting_to_export, "value")
  98. unit = settings_stack.getProperty(setting_to_export, "unit")
  99. setting_type = settings_stack.getProperty(setting_to_export, "type")
  100. if setting_type is not None:
  101. # This is not very good looking, but will do for now
  102. value = SettingDefinition.settingValueToString(setting_type, value) + " " + unit
  103. else:
  104. value = str(value)
  105. settings_export.append(SettingExport(setting_to_export,
  106. label,
  107. value,
  108. setting_to_export in SettingsExportModel.EXPORTABLE_SETTINGS))
  109. return settings_export