Browse Source

User settings are now properly proposed for export

CURA-11561
Erwan MATHIEU 1 year ago
parent
commit
8ad4ab90a8

+ 7 - 1
plugins/PCBWriter/PCBDialog.py

@@ -1,7 +1,7 @@
 # Copyright (c) 2024 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
-from PyQt6.QtCore import pyqtSignal, QObject, pyqtProperty, QCoreApplication, QUrl
+from PyQt6.QtCore import pyqtSignal, QObject, pyqtProperty, QCoreApplication, QUrl, pyqtSlot
 from PyQt6.QtGui import QDesktopServices
 from typing import List, Optional, Dict, cast
 
@@ -26,6 +26,8 @@ i18n_catalog = i18nCatalog("cura")
 
 
 class PCBDialog(QObject):
+    finished = pyqtSignal()
+
     def __init__(self, parent = None) -> None:
         super().__init__(parent)
 
@@ -35,3 +37,7 @@ class PCBDialog(QObject):
 
     def show(self) -> None:
         self._view.show()
+
+    @pyqtSlot()
+    def notifyClosed(self):
+        self.finished.emit()

+ 2 - 0
plugins/PCBWriter/PCBDialog.qml

@@ -130,4 +130,6 @@ UM.Dialog
     }
 
     buttonSpacing: UM.Theme.getSize("wide_margin").width
+
+    onClosing: manager.notifyClosed()
 }

+ 4 - 0
plugins/PCBWriter/PCBWriter.py

@@ -64,4 +64,8 @@ class PCBWriter(MeshWriter):
 
     def _write(self, stream, nodes, mode):
         self._config_dialog = PCBDialog()
+        self._config_dialog.finished.connect(self._onDialogClosed)
         self._config_dialog.show()
+
+    def _onDialogClosed(self):
+        self._main_thread_lock.release()

+ 1 - 5
plugins/PCBWriter/SettingExport.py

@@ -1,11 +1,7 @@
 #  Copyright (c) 2024 Ultimaker B.V.
 #  Cura is released under the terms of the LGPLv3 or higher.
 
-from PyQt6.QtCore import Qt, QObject, pyqtProperty
-from UM.FlameProfiler import pyqtSlot
-from UM.Application import Application
-from UM.Qt.ListModel import ListModel
-from UM.Logger import Logger
+from PyQt6.QtCore import QObject, pyqtProperty
 
 
 class SettingsExport(QObject):

+ 1 - 7
plugins/PCBWriter/SettingsExportGroup.py

@@ -3,13 +3,7 @@
 
 from enum import IntEnum
 
-from PyQt6.QtCore import Qt, QObject, pyqtProperty, pyqtEnum
-from UM.FlameProfiler import pyqtSlot
-from UM.Application import Application
-from UM.Qt.ListModel import ListModel
-from UM.Logger import Logger
-
-from .SettingExport import SettingsExport
+from PyQt6.QtCore import QObject, pyqtProperty, pyqtEnum
 
 
 class SettingsExportGroup(QObject):

+ 100 - 34
plugins/PCBWriter/SettingsExportModel.py

@@ -1,49 +1,115 @@
 #  Copyright (c) 2024 Ultimaker B.V.
 #  Cura is released under the terms of the LGPLv3 or higher.
 
-from PyQt6.QtCore import QObject, Qt, pyqtProperty
-from UM.FlameProfiler import pyqtSlot
-from UM.Application import Application
-from UM.Qt.ListModel import ListModel
-from UM.Logger import Logger
+from PyQt6.QtCore import QObject, pyqtProperty
 
 from .SettingsExportGroup import SettingsExportGroup
 from .SettingExport import SettingsExport
+from cura.CuraApplication import CuraApplication
+from UM.Settings.SettingDefinition import SettingDefinition
+from cura.Settings.ExtruderManager import ExtruderManager
 
 
 class SettingsExportModel(QObject):
 
+    EXPORTABLE_SETTINGS = {'infill_sparse_density',
+                           'adhesion_type',
+                           'support_enable',
+                           'infill_pattern',
+                           'support_type',
+                           'support_structure',
+                           'support_angle',
+                           'support_infill_rate',
+                           'ironing_enabled',
+                           'fill_outline_gaps',
+                           'coasting_enable',
+                           'skin_monotonic',
+                           'z_seam_position',
+                           'infill_before_walls',
+                           'ironing_only_highest_layer',
+                           'xy_offset',
+                           'adaptive_layer_height_enabled',
+                           'brim_gap',
+                           'support_offset',
+                           'brim_outside_only',
+                           'magic_spiralize',
+                           'slicing_tolerance',
+                           'outer_inset_first',
+                           'magic_fuzzy_skin_outside_only',
+                           'conical_overhang_enabled',
+                           'min_infill_area',
+                           'small_hole_max_size',
+                           'magic_mesh_surface_mode',
+                           'carve_multiple_volumes',
+                           'meshfix_union_all_remove_holes',
+                           'support_tree_rest_preference',
+                           'small_feature_max_length',
+                           'draft_shield_enabled',
+                           'brim_smart_ordering',
+                           'ooze_shield_enabled',
+                           'bottom_skin_preshrink',
+                           'skin_edge_support_thickness',
+                           'alternate_carve_order',
+                           'top_skin_preshrink',
+                           'interlocking_enable'}
+
     def __init__(self, parent = None):
         super().__init__(parent)
-        self._settingsGroups = []
-        self._updateSettingsExportGroups()
+        self._settings_groups = []
+
+        application = CuraApplication.getInstance()
+
+        # Display global settings
+        global_stack = application.getGlobalContainerStack()
+        self._settings_groups.append(SettingsExportGroup("Global settings",
+                                                         SettingsExportGroup.Category.Global,
+                                                         self._exportSettings(global_stack)))
+
+        # Display per-extruder settings
+        extruders_stacks = ExtruderManager.getInstance().getUsedExtruderStacks()
+        for extruder_stack in extruders_stacks:
+            color = ""
+            if extruder_stack.material:
+                color = extruder_stack.material.getMetaDataEntry("color_code")
+
+            self._settings_groups.append(SettingsExportGroup("Extruder settings",
+                                                             SettingsExportGroup.Category.Extruder,
+                                                             self._exportSettings(extruder_stack),
+                                                             extruder_index=extruder_stack.position,
+                                                             extruder_color=color))
+
+        # Display per-model settings
+        scene_root = application.getController().getScene().getRoot()
+        for scene_node in scene_root.getChildren():
+            per_model_stack = scene_node.callDecoration("getStack")
+            if per_model_stack is not None:
+                self._settings_groups.append(SettingsExportGroup("Model settings",
+                                                                 SettingsExportGroup.Category.Model,
+                                                                 self._exportSettings(per_model_stack),
+                                                                 scene_node.getName()))
 
     @pyqtProperty(list, constant=True)
     def settingsGroups(self):
-        return self._settingsGroups
-
-    def _updateSettingsExportGroups(self):
-        self._settingsGroups.append(SettingsExportGroup("Global settings",
-                                                        SettingsExportGroup.Category.Global,
-                                                        [SettingsExport("Generate Support", "Enabled"),
-                                                         SettingsExport("Support Type", "Tree")]))
-        self._settingsGroups.append(SettingsExportGroup("Extruder settings",
-                                                        SettingsExportGroup.Category.Extruder,
-                                                        [SettingsExport("Brim Width", "0.7mm")],
-                                                        extruder_index=1,
-                                                        extruder_color='#ff0000'))
-        self._settingsGroups.append(SettingsExportGroup("Extruder settings",
-                                                        SettingsExportGroup.Category.Extruder,
-                                                        [],
-                                                        extruder_index=8,
-                                                        extruder_color='#008fff'))
-        self._settingsGroups.append(SettingsExportGroup("Model settings",
-                                                        SettingsExportGroup.Category.Model,
-                                                        [SettingsExport("Brim Width", "20.0 mm"),
-                                                         SettingsExport("Z Hop when retracted", "Disabled")],
-                                                        'hypercube.stl'))
-        self._settingsGroups.append(SettingsExportGroup("Model settings",
-                                                        SettingsExportGroup.Category.Model,
-                                                        [SettingsExport("Walls Thickness", "3.0 mm"),
-                                                         SettingsExport("Enable Ironing", "Enabled")],
-                                                        'homer-simpson.stl'))
+        return self._settings_groups
+
+    @staticmethod
+    def _exportSettings(settings_stack):
+        user_settings_container = settings_stack.getTop()
+        user_keys = user_settings_container.getAllKeys()
+
+        settings_export = []
+
+        for setting_to_export in user_keys.intersection(SettingsExportModel.EXPORTABLE_SETTINGS):
+            label = settings_stack.getProperty(setting_to_export, "label")
+            value = settings_stack.getProperty(setting_to_export, "value")
+
+            setting_type = settings_stack.getProperty(setting_to_export, "type")
+            if setting_type is not None:
+                # This is not very good looking, but will do for now
+                value = SettingDefinition.settingValueToString(setting_type, value)
+            else:
+                value = str(value)
+
+            settings_export.append(SettingsExport(label, value))
+
+        return settings_export