From 54dc63a596d99cd9dd292a69856a6f11bdd3612a Mon Sep 17 00:00:00 2001 From: Aleksei S Date: Tue, 23 Jan 2018 11:24:27 +0100 Subject: [PATCH] Add missing changes CURA-3710 --- cura/CuraApplication.py | 151 ++++++++++++------ plugins/3MFReader/ThreeMFWorkspaceReader.py | 1 + .../qml/Preferences/SettingVisibilityPage.qml | 108 ++++++++++++- 3 files changed, 206 insertions(+), 54 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 9261f0df1a..0df64dbacb 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -87,6 +87,7 @@ from PyQt5.QtGui import QColor, QIcon from PyQt5.QtWidgets import QMessageBox from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType +from configparser import ConfigParser import sys import os.path import numpy @@ -348,57 +349,19 @@ class CuraApplication(QtApplication): preferences.setDefault("local_file/last_used_type", "text/x-gcode") - preferences.setDefault("general/visible_settings", """ - machine_settings - resolution - layer_height - shell - wall_thickness - top_bottom_thickness - z_seam_x - z_seam_y - infill - infill_sparse_density - gradual_infill_steps - material - material_print_temperature - material_bed_temperature - material_diameter - material_flow - retraction_enable - speed - speed_print - speed_travel - acceleration_print - acceleration_travel - jerk_print - jerk_travel - travel - cooling - cool_fan_enabled - support - support_enable - support_extruder_nr - support_type - platform_adhesion - adhesion_type - adhesion_extruder_nr - brim_width - raft_airgap - layer_0_z_overlap - raft_surface_layers - dual - prime_tower_enable - prime_tower_size - prime_tower_position_x - prime_tower_position_y - meshfix - blackmagic - print_sequence - infill_mesh - cutting_mesh - experimental - """.replace("\n", ";").replace(" ", "")) + setting_visibily_preset_names = self.getVisibilitySettingsPresetTypes() + preferences.setDefault("general/visible_settings_preset", setting_visibily_preset_names) + + visible_settings_preset_choice = Preferences.getInstance().getValue("general/visible_settings_preset_choice") + + default_visibility_preset = "Basic" + if visible_settings_preset_choice == "" or visible_settings_preset_choice is None: + if not visible_settings_preset_choice in setting_visibily_preset_names: + visible_settings_preset_choice = default_visibility_preset + + visible_settings = self.getVisibilitySettingPreset(settings_preset_name = visible_settings_preset_choice) + preferences.setDefault("general/visible_settings", visible_settings) + preferences.setDefault("general/visible_settings_preset_choice", visible_settings_preset_choice) self.applicationShuttingDown.connect(self.saveSettings) self.engineCreatedSignal.connect(self._onEngineCreated) @@ -410,6 +373,92 @@ class CuraApplication(QtApplication): self.getCuraSceneController().setActiveBuildPlate(0) # Initialize + @pyqtSlot(str, result=str) + def getVisibilitySettingPreset(self, settings_preset_name): + + result = self._load_visibilyty_setting_preset(settings_preset_name) + + formatted_preset_settings = self.format_visibility_setting_preset(result) + + return formatted_preset_settings + + def format_visibility_setting_preset(self, settings_data): + + result_string = "" + + for key in settings_data: + result_string += key + ";" + + for value in settings_data[key]: + result_string += value + ";" + + return result_string + + + def _load_visibilyty_setting_preset(self, visibility_preset_name): + preset_dir = Resources.getPath(Resources.VisibilitySettingsPreset) + + result = {} + right_preset_found = False + + for item in os.listdir(preset_dir): + file_path = os.path.join(preset_dir, item) + if not os.path.isfile(file_path): + continue + + parser = ConfigParser(allow_no_value=True) # accept options without any value, + + try: + parser.read([file_path]) + + if not parser.has_option("general", "name"): + continue + + if parser["general"]["name"] == visibility_preset_name: + right_preset_found = True + for section in parser.sections(): + if section == 'general': + continue + else: + section_settings = [] + for option in parser[section]._options(): + section_settings.append(option) + + result[section] = section_settings + + if right_preset_found: + break + + except Exception as e: + Logger.log("e", "Failed to load setting visibility preset %s: %s", file_path, str(e)) + + return result + + def getVisibilitySettingsPresetTypes(self): + preset_dir = Resources.getPath(Resources.VisibilitySettingsPreset) + result = {} + + for item in os.listdir(preset_dir): + file_path = os.path.join(preset_dir, item) + if not os.path.isfile(file_path): + continue + + parser = ConfigParser(allow_no_value=True) # accept options without any value, + + try: + parser.read([file_path]) + + if not parser.has_option("general", "name") and not parser.has_option("general", "weight"): + continue + + result[parser["general"]["weight"]] = parser["general"]["name"] + + except Exception as e: + Logger.log("e", "Failed to load setting preset %s: %s", file_path, str(e)) + + return result + + def _onEngineCreated(self): self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider()) diff --git a/plugins/3MFReader/ThreeMFWorkspaceReader.py b/plugins/3MFReader/ThreeMFWorkspaceReader.py index 913cea4f26..1c6cef2b7e 100755 --- a/plugins/3MFReader/ThreeMFWorkspaceReader.py +++ b/plugins/3MFReader/ThreeMFWorkspaceReader.py @@ -420,6 +420,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader): Logger.log("w", "Workspace did not contain visible settings. Leaving visibility unchanged") else: global_preferences.setValue("general/visible_settings", visible_settings) + global_preferences.setValue("general/visible_settings_preset_choice", "Custom") categories_expanded = temp_preferences.getValue("cura/categories_expanded") if categories_expanded is None: diff --git a/resources/qml/Preferences/SettingVisibilityPage.qml b/resources/qml/Preferences/SettingVisibilityPage.qml index 5198ab1030..e1707fa196 100644 --- a/resources/qml/Preferences/SettingVisibilityPage.qml +++ b/resources/qml/Preferences/SettingVisibilityPage.qml @@ -24,6 +24,11 @@ UM.PreferencesPage function reset() { UM.Preferences.resetPreference("general/visible_settings") + + // After calling this function update Setting visibility preset combobox. + // Reset should set "Basic" setting preset + visibilityPreset.setBasicPreset() + } resetEnabled: true; @@ -72,6 +77,9 @@ UM.PreferencesPage { definitionsModel.setAllVisible(false) } + + // After change set "Custom" option + visibilityPreset.currentIndex = visibilityPreset.model.count - 1 } } } @@ -85,7 +93,8 @@ UM.PreferencesPage top: parent.top left: toggleVisibleSettings.right leftMargin: UM.Theme.getSize("default_margin").width - right: parent.right + right: visibilityPreset.left + rightMargin: UM.Theme.getSize("default_margin").width } placeholderText: catalog.i18nc("@label:textbox", "Filter...") @@ -93,6 +102,88 @@ UM.PreferencesPage onTextChanged: definitionsModel.filter = {"i18n_label": "*" + text} } + ComboBox + { + property int customOptionValue: 100 + + function setBasicPreset() + { + var index = 0 + for(var i = 0; i < presetNamesList.count; ++i) + { + if(model.get(i).text == "Basic") + { + index = i; + break; + } + } + + visibilityPreset.currentIndex = index + } + + id: visibilityPreset + width: 150 + anchors + { + top: parent.top + right: parent.right + } + + model: ListModel + { + id: presetNamesList + Component.onCompleted: + { + // returned value is Dictionary (Ex: {1:"Basic"}, The number 1 is the weight and sort by weight) + var itemsDict = UM.Preferences.getValue("general/visible_settings_preset") + var sorted = []; + for(var key in itemsDict) { + sorted[sorted.length] = key; + } + + sorted.sort(); + for(var i = 0; i < sorted.length; i++) { + presetNamesList.append({text: itemsDict[sorted[i]], value: i}); + } + + // By agreement lets "Custom" option will have value 100 + presetNamesList.append({text: "Custom", value: visibilityPreset.customOptionValue}); + } + } + + currentIndex: + { + // Load previously selected preset. + var text = UM.Preferences.getValue("general/visible_settings_preset_choice"); + + + + var index = 0; + for(var i = 0; i < presetNamesList.count; ++i) + { + if(model.get(i).text == text) + { + index = i; + break; + } + } + return index; + } + + onActivated: + { + // TODO What to do if user is selected "Custom from Combobox" ? + if (model.get(index).text == "Custom") + return + + console.log("SETTING VALUE : " + model.get(index).text) + + var newVisibleSettings = CuraApplication.getVisibilitySettingPreset(model.get(index).text) + UM.Preferences.setValue("general/visible_settings", newVisibleSettings) + UM.Preferences.setValue("general/visible_settings_preset_choice", model.get(index).text) + } + } + ScrollView { id: scrollView @@ -162,7 +253,18 @@ UM.PreferencesPage { id: settingVisibilityItem; - UM.SettingVisibilityItem { } + UM.SettingVisibilityItem { + + // after changing any visibility of settings, set the preset to the "Custom" option + visibilityChangeCallback : function() + { + // If already "Custom" then don't do nothing + if (visibilityPreset.currentIndex != visibilityPreset.model.count - 1) + { + visibilityPreset.currentIndex = visibilityPreset.model.count - 1 + } + } + } } } -} +} \ No newline at end of file