mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Add missing changes
CURA-3710
This commit is contained in:
parent
8fe6e82459
commit
54dc63a596
@ -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())
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user