mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 17:39:03 +08:00
Merge branch 'master' of github.com:Ultimaker/Cura
This commit is contained in:
commit
1dba5629f7
@ -1,9 +1,6 @@
|
|||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
#Type hinting.
|
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, QTimer
|
from PyQt5.QtCore import QObject, QTimer
|
||||||
from PyQt5.QtNetwork import QLocalServer
|
from PyQt5.QtNetwork import QLocalServer
|
||||||
from PyQt5.QtNetwork import QLocalSocket
|
from PyQt5.QtNetwork import QLocalSocket
|
||||||
@ -68,6 +65,8 @@ from cura.Machines.Models.QualityManagementModel import QualityManagementModel
|
|||||||
from cura.Machines.Models.QualitySettingsModel import QualitySettingsModel
|
from cura.Machines.Models.QualitySettingsModel import QualitySettingsModel
|
||||||
from cura.Machines.Models.MachineManagementModel import MachineManagementModel
|
from cura.Machines.Models.MachineManagementModel import MachineManagementModel
|
||||||
|
|
||||||
|
from cura.Machines.Models.SettingVisibilityPresetsModel import SettingVisibilityPresetsModel
|
||||||
|
|
||||||
from cura.Machines.MachineErrorChecker import MachineErrorChecker
|
from cura.Machines.MachineErrorChecker import MachineErrorChecker
|
||||||
|
|
||||||
from cura.Settings.SettingInheritanceManager import SettingInheritanceManager
|
from cura.Settings.SettingInheritanceManager import SettingInheritanceManager
|
||||||
@ -91,7 +90,6 @@ from cura.Settings.UserChangesModel import UserChangesModel
|
|||||||
from cura.Settings.ExtrudersModel import ExtrudersModel
|
from cura.Settings.ExtrudersModel import ExtrudersModel
|
||||||
from cura.Settings.MaterialSettingsVisibilityHandler import MaterialSettingsVisibilityHandler
|
from cura.Settings.MaterialSettingsVisibilityHandler import MaterialSettingsVisibilityHandler
|
||||||
from cura.Settings.ContainerManager import ContainerManager
|
from cura.Settings.ContainerManager import ContainerManager
|
||||||
from cura.Settings.SettingVisibilityPresetsModel import SettingVisibilityPresetsModel
|
|
||||||
|
|
||||||
from cura.ObjectsModel import ObjectsModel
|
from cura.ObjectsModel import ObjectsModel
|
||||||
|
|
||||||
@ -101,7 +99,6 @@ from PyQt5.QtGui import QColor, QIcon
|
|||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType
|
from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType
|
||||||
|
|
||||||
from configparser import ConfigParser
|
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os.path
|
||||||
import numpy
|
import numpy
|
||||||
@ -226,6 +223,7 @@ class CuraApplication(QtApplication):
|
|||||||
self._object_manager = None
|
self._object_manager = None
|
||||||
self._build_plate_model = None
|
self._build_plate_model = None
|
||||||
self._multi_build_plate_model = None
|
self._multi_build_plate_model = None
|
||||||
|
self._setting_visibility_presets_model = None
|
||||||
self._setting_inheritance_manager = None
|
self._setting_inheritance_manager = None
|
||||||
self._simple_mode_settings_manager = None
|
self._simple_mode_settings_manager = None
|
||||||
self._cura_scene_controller = None
|
self._cura_scene_controller = None
|
||||||
@ -381,10 +379,6 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
preferences.setDefault("local_file/last_used_type", "text/x-gcode")
|
preferences.setDefault("local_file/last_used_type", "text/x-gcode")
|
||||||
|
|
||||||
default_visibility_profile = SettingVisibilityPresetsModel.getInstance().getItem(0)
|
|
||||||
|
|
||||||
preferences.setDefault("general/visible_settings", ";".join(default_visibility_profile["settings"]))
|
|
||||||
|
|
||||||
self.applicationShuttingDown.connect(self.saveSettings)
|
self.applicationShuttingDown.connect(self.saveSettings)
|
||||||
self.engineCreatedSignal.connect(self._onEngineCreated)
|
self.engineCreatedSignal.connect(self._onEngineCreated)
|
||||||
|
|
||||||
@ -687,6 +681,11 @@ class CuraApplication(QtApplication):
|
|||||||
self._print_information = PrintInformation.PrintInformation()
|
self._print_information = PrintInformation.PrintInformation()
|
||||||
self._cura_actions = CuraActions.CuraActions(self)
|
self._cura_actions = CuraActions.CuraActions(self)
|
||||||
|
|
||||||
|
# Initialize setting visibility presets model
|
||||||
|
self._setting_visibility_presets_model = SettingVisibilityPresetsModel(self)
|
||||||
|
default_visibility_profile = self._setting_visibility_presets_model.getItem(0)
|
||||||
|
Preferences.getInstance().setDefault("general/visible_settings", ";".join(default_visibility_profile["settings"]))
|
||||||
|
|
||||||
# Detect in which mode to run and execute that mode
|
# Detect in which mode to run and execute that mode
|
||||||
if self.getCommandLineOption("headless", False):
|
if self.getCommandLineOption("headless", False):
|
||||||
self.runWithoutGUI()
|
self.runWithoutGUI()
|
||||||
@ -769,6 +768,10 @@ class CuraApplication(QtApplication):
|
|||||||
def hasGui(self):
|
def hasGui(self):
|
||||||
return self._use_gui
|
return self._use_gui
|
||||||
|
|
||||||
|
@pyqtSlot(result = QObject)
|
||||||
|
def getSettingVisibilityPresetsModel(self, *args) -> SettingVisibilityPresetsModel:
|
||||||
|
return self._setting_visibility_presets_model
|
||||||
|
|
||||||
def getMachineErrorChecker(self, *args) -> MachineErrorChecker:
|
def getMachineErrorChecker(self, *args) -> MachineErrorChecker:
|
||||||
return self._machine_error_checker
|
return self._machine_error_checker
|
||||||
|
|
||||||
@ -895,11 +898,11 @@ class CuraApplication(QtApplication):
|
|||||||
qmlRegisterType(NozzleModel, "Cura", 1, 0, "NozzleModel")
|
qmlRegisterType(NozzleModel, "Cura", 1, 0, "NozzleModel")
|
||||||
|
|
||||||
qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
|
qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
|
||||||
|
qmlRegisterType(SettingVisibilityPresetsModel, "Cura", 1, 0, "SettingVisibilityPresetsModel")
|
||||||
qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
|
qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
|
||||||
qmlRegisterType(MachineNameValidator, "Cura", 1, 0, "MachineNameValidator")
|
qmlRegisterType(MachineNameValidator, "Cura", 1, 0, "MachineNameValidator")
|
||||||
qmlRegisterType(UserChangesModel, "Cura", 1, 0, "UserChangesModel")
|
qmlRegisterType(UserChangesModel, "Cura", 1, 0, "UserChangesModel")
|
||||||
qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager)
|
qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager)
|
||||||
qmlRegisterSingletonType(SettingVisibilityPresetsModel, "Cura", 1, 0, "SettingVisibilityPresetsModel", SettingVisibilityPresetsModel.createSettingVisibilityPresetsModel)
|
|
||||||
|
|
||||||
# As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work.
|
# As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work.
|
||||||
actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))
|
actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))
|
||||||
|
176
cura/Machines/Models/SettingVisibilityPresetsModel.py
Normal file
176
cura/Machines/Models/SettingVisibilityPresetsModel.py
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
import os
|
||||||
|
import urllib.parse
|
||||||
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
from PyQt5.QtCore import pyqtProperty, Qt, pyqtSignal, pyqtSlot
|
||||||
|
|
||||||
|
from UM.Logger import Logger
|
||||||
|
from UM.Qt.ListModel import ListModel
|
||||||
|
from UM.Preferences import Preferences
|
||||||
|
from UM.Resources import Resources
|
||||||
|
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeTypeNotFoundError
|
||||||
|
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
|
class SettingVisibilityPresetsModel(ListModel):
|
||||||
|
IdRole = Qt.UserRole + 1
|
||||||
|
NameRole = Qt.UserRole + 2
|
||||||
|
SettingsRole = Qt.UserRole + 3
|
||||||
|
|
||||||
|
def __init__(self, parent = None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.addRoleName(self.IdRole, "id")
|
||||||
|
self.addRoleName(self.NameRole, "name")
|
||||||
|
self.addRoleName(self.SettingsRole, "settings")
|
||||||
|
|
||||||
|
self._populate()
|
||||||
|
basic_item = self.items[1]
|
||||||
|
basic_visibile_settings = ";".join(basic_item["settings"])
|
||||||
|
|
||||||
|
self._preferences = Preferences.getInstance()
|
||||||
|
# Preference to store which preset is currently selected
|
||||||
|
self._preferences.addPreference("cura/active_setting_visibility_preset", "basic")
|
||||||
|
# Preference that stores the "custom" set so it can always be restored (even after a restart)
|
||||||
|
self._preferences.addPreference("cura/custom_visible_settings", basic_visibile_settings)
|
||||||
|
self._preferences.preferenceChanged.connect(self._onPreferencesChanged)
|
||||||
|
|
||||||
|
self._active_preset_item = self._getItem(self._preferences.getValue("cura/active_setting_visibility_preset"))
|
||||||
|
# Initialize visible settings if it is not done yet
|
||||||
|
visible_settings = self._preferences.getValue("general/visible_settings")
|
||||||
|
if not visible_settings:
|
||||||
|
self._preferences.setValue("general/visible_settings", ";".join(self._active_preset_item["settings"]))
|
||||||
|
|
||||||
|
self.activePresetChanged.emit()
|
||||||
|
|
||||||
|
def _getItem(self, item_id: str) -> Optional[dict]:
|
||||||
|
result = None
|
||||||
|
for item in self.items:
|
||||||
|
if item["id"] == item_id:
|
||||||
|
result = item
|
||||||
|
break
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _populate(self):
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
items = []
|
||||||
|
for file_path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.SettingVisibilityPreset):
|
||||||
|
try:
|
||||||
|
mime_type = MimeTypeDatabase.getMimeTypeForFile(file_path)
|
||||||
|
except MimeTypeNotFoundError:
|
||||||
|
Logger.log("e", "Could not determine mime type of file %s", file_path)
|
||||||
|
continue
|
||||||
|
|
||||||
|
item_id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(file_path)))
|
||||||
|
if not os.path.isfile(file_path):
|
||||||
|
Logger.log("e", "[%s] is not a file", 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") or not parser.has_option("general", "weight"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
settings = []
|
||||||
|
for section in parser.sections():
|
||||||
|
if section == 'general':
|
||||||
|
continue
|
||||||
|
|
||||||
|
settings.append(section)
|
||||||
|
for option in parser[section].keys():
|
||||||
|
settings.append(option)
|
||||||
|
|
||||||
|
items.append({
|
||||||
|
"id": item_id,
|
||||||
|
"name": catalog.i18nc("@action:inmenu", parser["general"]["name"]),
|
||||||
|
"weight": parser["general"]["weight"],
|
||||||
|
"settings": settings,
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
Logger.logException("e", "Failed to load setting preset %s", file_path)
|
||||||
|
|
||||||
|
items.sort(key = lambda k: (int(k["weight"]), k["id"]))
|
||||||
|
# Put "custom" at the top
|
||||||
|
items.insert(0, {"id": "custom",
|
||||||
|
"name": "Custom selection",
|
||||||
|
"weight": -100,
|
||||||
|
"settings": []})
|
||||||
|
|
||||||
|
self.setItems(items)
|
||||||
|
|
||||||
|
@pyqtSlot(str)
|
||||||
|
def setActivePreset(self, preset_id: str):
|
||||||
|
if preset_id == self._active_preset_item["id"]:
|
||||||
|
Logger.log("d", "Same setting visibility preset [%s] selected, do nothing.", preset_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
preset_item = None
|
||||||
|
for item in self.items:
|
||||||
|
if item["id"] == preset_id:
|
||||||
|
preset_item = item
|
||||||
|
break
|
||||||
|
if preset_item is None:
|
||||||
|
Logger.log("w", "Tried to set active preset to unknown id [%s]", preset_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
need_to_save_to_custom = self._active_preset_item["id"] == "custom" and preset_id != "custom"
|
||||||
|
if need_to_save_to_custom:
|
||||||
|
# Save the current visibility settings to custom
|
||||||
|
current_visibility_string = self._preferences.getValue("general/visible_settings")
|
||||||
|
if current_visibility_string:
|
||||||
|
self._preferences.setValue("cura/custom_visible_settings", current_visibility_string)
|
||||||
|
|
||||||
|
new_visibility_string = ";".join(preset_item["settings"])
|
||||||
|
if preset_id == "custom":
|
||||||
|
# Get settings from the stored custom data
|
||||||
|
new_visibility_string = self._preferences.getValue("cura/custom_visible_settings")
|
||||||
|
if new_visibility_string is None:
|
||||||
|
new_visibility_string = self._preferences.getValue("general/visible_settings")
|
||||||
|
self._preferences.setValue("general/visible_settings", new_visibility_string)
|
||||||
|
|
||||||
|
self._preferences.setValue("cura/active_setting_visibility_preset", preset_id)
|
||||||
|
self._active_preset_item = preset_item
|
||||||
|
self.activePresetChanged.emit()
|
||||||
|
|
||||||
|
activePresetChanged = pyqtSignal()
|
||||||
|
|
||||||
|
@pyqtProperty(str, notify = activePresetChanged)
|
||||||
|
def activePreset(self) -> str:
|
||||||
|
return self._active_preset_item["id"]
|
||||||
|
|
||||||
|
def _onPreferencesChanged(self, name: str):
|
||||||
|
if name != "general/visible_settings":
|
||||||
|
return
|
||||||
|
|
||||||
|
# Find the preset that matches with the current visible settings setup
|
||||||
|
visibility_string = self._preferences.getValue("general/visible_settings")
|
||||||
|
if not visibility_string:
|
||||||
|
return
|
||||||
|
|
||||||
|
visibility_set = set(visibility_string.split(";"))
|
||||||
|
matching_preset_item = None
|
||||||
|
for item in self.items:
|
||||||
|
if item["id"] == "custom":
|
||||||
|
continue
|
||||||
|
if set(item["settings"]) == visibility_set:
|
||||||
|
matching_preset_item = item
|
||||||
|
break
|
||||||
|
|
||||||
|
if matching_preset_item is None:
|
||||||
|
# The new visibility setup is "custom" should be custom
|
||||||
|
if self._active_preset_item["id"] == "custom":
|
||||||
|
# We are already in custom, just save the settings
|
||||||
|
self._preferences.setValue("cura/custom_visible_settings", visibility_string)
|
||||||
|
else:
|
||||||
|
self._active_preset_item = self.items[0] # 0 is custom
|
||||||
|
self.activePresetChanged.emit()
|
||||||
|
else:
|
||||||
|
self._active_preset_item = matching_preset_item
|
||||||
|
self.activePresetChanged.emit()
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
|
||||||
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
|
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
|
||||||
|
|
||||||
@ -254,6 +255,21 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
|||||||
self._last_manager_create_time = time()
|
self._last_manager_create_time = time()
|
||||||
self._manager.authenticationRequired.connect(self._onAuthenticationRequired)
|
self._manager.authenticationRequired.connect(self._onAuthenticationRequired)
|
||||||
|
|
||||||
|
self._checkCorrectGroupName()
|
||||||
|
|
||||||
|
## This method checks if the name of the group stored in the definition container is correct.
|
||||||
|
# After updating from 3.2 to 3.3 some group names may be temporary. If there is a mismatch in the name of the group
|
||||||
|
# then all the container stacks are updated, both the current and the hidden ones.
|
||||||
|
def _checkCorrectGroupName(self):
|
||||||
|
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
|
if global_container_stack and self.getId() == global_container_stack.getMetaDataEntry("um_network_key"):
|
||||||
|
# Check if the connect_group_name is correct. If not, update all the containers connected to the same printer
|
||||||
|
if global_container_stack.getMetaDataEntry("connect_group_name") != self.name:
|
||||||
|
metadata_filter = {"um_network_key": global_container_stack.getMetaDataEntry("um_network_key")}
|
||||||
|
hidden_containers = ContainerRegistry.getInstance().findContainerStacks(type = "machine", **metadata_filter)
|
||||||
|
for container in hidden_containers:
|
||||||
|
container.setMetaDataEntry("connect_group_name", self.name)
|
||||||
|
|
||||||
def _registerOnFinishedCallback(self, reply: QNetworkReply, onFinished: Optional[Callable[[Any, QNetworkReply], None]]) -> None:
|
def _registerOnFinishedCallback(self, reply: QNetworkReply, onFinished: Optional[Callable[[Any, QNetworkReply], None]]) -> None:
|
||||||
if onFinished is not None:
|
if onFinished is not None:
|
||||||
self._onFinishedCallbacks[reply.url().toString() + str(reply.operation())] = onFinished
|
self._onFinishedCallbacks[reply.url().toString() + str(reply.operation())] = onFinished
|
||||||
|
@ -10,7 +10,6 @@ from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
|||||||
from UM.Signal import Signal
|
from UM.Signal import Signal
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QTimer
|
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QTimer
|
||||||
import UM.FlameProfiler
|
|
||||||
from UM.FlameProfiler import pyqtSlot
|
from UM.FlameProfiler import pyqtSlot
|
||||||
from UM import Util
|
from UM import Util
|
||||||
|
|
||||||
@ -24,7 +23,6 @@ from UM.Settings.SettingFunction import SettingFunction
|
|||||||
from UM.Signal import postponeSignals, CompressTechnique
|
from UM.Signal import postponeSignals, CompressTechnique
|
||||||
|
|
||||||
from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch
|
from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch
|
||||||
from cura.Machines.VariantManager import VariantType
|
|
||||||
from cura.PrinterOutputDevice import PrinterOutputDevice
|
from cura.PrinterOutputDevice import PrinterOutputDevice
|
||||||
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
||||||
from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel
|
from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel
|
||||||
|
@ -1,136 +0,0 @@
|
|||||||
# Copyright (c) 2018 Ultimaker B.V.
|
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
|
||||||
|
|
||||||
import os
|
|
||||||
import urllib
|
|
||||||
from configparser import ConfigParser
|
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtProperty, Qt, pyqtSignal, pyqtSlot, QUrl
|
|
||||||
|
|
||||||
from UM.Logger import Logger
|
|
||||||
from UM.Qt.ListModel import ListModel
|
|
||||||
from UM.Preferences import Preferences
|
|
||||||
from UM.Resources import Resources
|
|
||||||
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeTypeNotFoundError
|
|
||||||
|
|
||||||
import cura.CuraApplication
|
|
||||||
|
|
||||||
|
|
||||||
class SettingVisibilityPresetsModel(ListModel):
|
|
||||||
IdRole = Qt.UserRole + 1
|
|
||||||
NameRole = Qt.UserRole + 2
|
|
||||||
SettingsRole = Qt.UserRole + 4
|
|
||||||
|
|
||||||
def __init__(self, parent = None):
|
|
||||||
super().__init__(parent)
|
|
||||||
self.addRoleName(self.IdRole, "id")
|
|
||||||
self.addRoleName(self.NameRole, "name")
|
|
||||||
self.addRoleName(self.SettingsRole, "settings")
|
|
||||||
|
|
||||||
self._populate()
|
|
||||||
|
|
||||||
self._preferences = Preferences.getInstance()
|
|
||||||
self._preferences.addPreference("cura/active_setting_visibility_preset", "custom") # Preference to store which preset is currently selected
|
|
||||||
self._preferences.addPreference("cura/custom_visible_settings", "") # Preference that stores the "custom" set so it can always be restored (even after a restart)
|
|
||||||
self._preferences.preferenceChanged.connect(self._onPreferencesChanged)
|
|
||||||
|
|
||||||
self._active_preset = self._preferences.getValue("cura/active_setting_visibility_preset")
|
|
||||||
if self.find("id", self._active_preset) < 0:
|
|
||||||
self._active_preset = "custom"
|
|
||||||
|
|
||||||
self.activePresetChanged.emit()
|
|
||||||
|
|
||||||
|
|
||||||
def _populate(self):
|
|
||||||
items = []
|
|
||||||
for item in Resources.getAllResourcesOfType(cura.CuraApplication.CuraApplication.ResourceTypes.SettingVisibilityPreset):
|
|
||||||
try:
|
|
||||||
mime_type = MimeTypeDatabase.getMimeTypeForFile(item)
|
|
||||||
except MimeTypeNotFoundError:
|
|
||||||
Logger.log("e", "Could not determine mime type of file %s", item)
|
|
||||||
continue
|
|
||||||
|
|
||||||
id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(item)))
|
|
||||||
|
|
||||||
if not os.path.isfile(item):
|
|
||||||
continue
|
|
||||||
|
|
||||||
parser = ConfigParser(allow_no_value=True) # accept options without any value,
|
|
||||||
|
|
||||||
try:
|
|
||||||
parser.read([item])
|
|
||||||
|
|
||||||
if not parser.has_option("general", "name") and not parser.has_option("general", "weight"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
settings = []
|
|
||||||
for section in parser.sections():
|
|
||||||
if section == 'general':
|
|
||||||
continue
|
|
||||||
|
|
||||||
settings.append(section)
|
|
||||||
for option in parser[section].keys():
|
|
||||||
settings.append(option)
|
|
||||||
|
|
||||||
items.append({
|
|
||||||
"id": id,
|
|
||||||
"name": parser["general"]["name"],
|
|
||||||
"weight": parser["general"]["weight"],
|
|
||||||
"settings": settings
|
|
||||||
})
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
Logger.log("e", "Failed to load setting preset %s: %s", file_path, str(e))
|
|
||||||
|
|
||||||
|
|
||||||
items.sort(key = lambda k: (k["weight"], k["id"]))
|
|
||||||
self.setItems(items)
|
|
||||||
|
|
||||||
@pyqtSlot(str)
|
|
||||||
def setActivePreset(self, preset_id):
|
|
||||||
if preset_id != "custom" and self.find("id", preset_id) == -1:
|
|
||||||
Logger.log("w", "Tried to set active preset to unknown id %s", preset_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
if preset_id == "custom" and self._active_preset == "custom":
|
|
||||||
# Copy current visibility set to custom visibility set preference so it can be restored later
|
|
||||||
visibility_string = self._preferences.getValue("general/visible_settings")
|
|
||||||
self._preferences.setValue("cura/custom_visible_settings", visibility_string)
|
|
||||||
|
|
||||||
self._preferences.setValue("cura/active_setting_visibility_preset", preset_id)
|
|
||||||
|
|
||||||
self._active_preset = preset_id
|
|
||||||
self.activePresetChanged.emit()
|
|
||||||
|
|
||||||
activePresetChanged = pyqtSignal()
|
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activePresetChanged)
|
|
||||||
def activePreset(self):
|
|
||||||
return self._active_preset
|
|
||||||
|
|
||||||
def _onPreferencesChanged(self, name):
|
|
||||||
if name != "general/visible_settings":
|
|
||||||
return
|
|
||||||
|
|
||||||
if self._active_preset != "custom":
|
|
||||||
return
|
|
||||||
|
|
||||||
# Copy current visibility set to custom visibility set preference so it can be restored later
|
|
||||||
visibility_string = self._preferences.getValue("general/visible_settings")
|
|
||||||
self._preferences.setValue("cura/custom_visible_settings", visibility_string)
|
|
||||||
|
|
||||||
|
|
||||||
# Factory function, used by QML
|
|
||||||
@staticmethod
|
|
||||||
def createSettingVisibilityPresetsModel(engine, js_engine):
|
|
||||||
return SettingVisibilityPresetsModel.getInstance()
|
|
||||||
|
|
||||||
## Get the singleton instance for this class.
|
|
||||||
@classmethod
|
|
||||||
def getInstance(cls) -> "SettingVisibilityPresetsModel":
|
|
||||||
# Note: Explicit use of class name to prevent issues with inheritance.
|
|
||||||
if not SettingVisibilityPresetsModel.__instance:
|
|
||||||
SettingVisibilityPresetsModel.__instance = cls()
|
|
||||||
return SettingVisibilityPresetsModel.__instance
|
|
||||||
|
|
||||||
__instance = None # type: "SettingVisibilityPresetsModel"
|
|
@ -82,6 +82,9 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||||||
self._zero_conf_browser.cancel()
|
self._zero_conf_browser.cancel()
|
||||||
self._zero_conf_browser = None # Force the old ServiceBrowser to be destroyed.
|
self._zero_conf_browser = None # Force the old ServiceBrowser to be destroyed.
|
||||||
|
|
||||||
|
for instance_name in list(self._discovered_devices):
|
||||||
|
self._onRemoveDevice(instance_name)
|
||||||
|
|
||||||
self._zero_conf = Zeroconf()
|
self._zero_conf = Zeroconf()
|
||||||
self._zero_conf_browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.',
|
self._zero_conf_browser = ServiceBrowser(self._zero_conf, u'_ultimaker._tcp.local.',
|
||||||
[self._appendServiceChangedRequest])
|
[self._appendServiceChangedRequest])
|
||||||
|
@ -208,14 +208,9 @@ class XmlMaterialProfile(InstanceContainer):
|
|||||||
machine_variant_map = {}
|
machine_variant_map = {}
|
||||||
|
|
||||||
variant_manager = CuraApplication.getInstance().getVariantManager()
|
variant_manager = CuraApplication.getInstance().getVariantManager()
|
||||||
material_manager = CuraApplication.getInstance().getMaterialManager()
|
|
||||||
|
|
||||||
root_material_id = self.getMetaDataEntry("base_file") # if basefile is self.getId, this is a basefile.
|
root_material_id = self.getMetaDataEntry("base_file") # if basefile is self.getId, this is a basefile.
|
||||||
material_group = material_manager.getMaterialGroup(root_material_id)
|
all_containers = registry.findInstanceContainers(base_file = root_material_id)
|
||||||
|
|
||||||
all_containers = []
|
|
||||||
for node in [material_group.root_material_node] + material_group.derived_material_node_list:
|
|
||||||
all_containers.append(node.getContainer())
|
|
||||||
|
|
||||||
for container in all_containers:
|
for container in all_containers:
|
||||||
definition_id = container.getMetaDataEntry("definition")
|
definition_id = container.getMetaDataEntry("definition")
|
||||||
@ -242,7 +237,7 @@ class XmlMaterialProfile(InstanceContainer):
|
|||||||
|
|
||||||
for definition_id, container in machine_container_map.items():
|
for definition_id, container in machine_container_map.items():
|
||||||
definition_id = container.getMetaDataEntry("definition")
|
definition_id = container.getMetaDataEntry("definition")
|
||||||
definition_metadata = ContainerRegistry.getInstance().findDefinitionContainersMetadata(id = definition_id)[0]
|
definition_metadata = registry.findDefinitionContainersMetadata(id = definition_id)[0]
|
||||||
|
|
||||||
product = definition_id
|
product = definition_id
|
||||||
for product_name, product_id_list in product_id_map.items():
|
for product_name, product_id_list in product_id_map.items():
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// Copyright (c) 2018 Ultimaker B.V.
|
// Copyright (c) 2018 Ultimaker B.V.
|
||||||
// Cura is released under the terms of the LGPLv3 or higher.
|
// Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
import QtQuick 2.2
|
import QtQuick 2.7
|
||||||
import QtQuick.Controls 1.1
|
import QtQuick.Controls 1.4
|
||||||
|
|
||||||
import UM 1.2 as UM
|
import UM 1.2 as UM
|
||||||
import Cura 1.0 as Cura
|
import Cura 1.0 as Cura
|
||||||
@ -12,44 +12,26 @@ Menu
|
|||||||
id: menu
|
id: menu
|
||||||
title: catalog.i18nc("@action:inmenu", "Visible Settings")
|
title: catalog.i18nc("@action:inmenu", "Visible Settings")
|
||||||
|
|
||||||
|
property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
|
||||||
property bool showingSearchResults
|
property bool showingSearchResults
|
||||||
property bool showingAllSettings
|
property bool showingAllSettings
|
||||||
|
|
||||||
signal showAllSettings()
|
signal showAllSettings()
|
||||||
signal showSettingVisibilityProfile()
|
signal showSettingVisibilityProfile()
|
||||||
|
|
||||||
MenuItem
|
|
||||||
{
|
|
||||||
text: catalog.i18nc("@action:inmenu", "Custom selection")
|
|
||||||
checkable: true
|
|
||||||
checked: !showingSearchResults && !showingAllSettings && Cura.SettingVisibilityPresetsModel.activePreset == "custom"
|
|
||||||
exclusiveGroup: group
|
|
||||||
onTriggered:
|
|
||||||
{
|
|
||||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
|
||||||
// Restore custom set from preference
|
|
||||||
UM.Preferences.setValue("general/visible_settings", UM.Preferences.getValue("cura/custom_visible_settings"));
|
|
||||||
showSettingVisibilityProfile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MenuSeparator { }
|
|
||||||
|
|
||||||
Instantiator
|
Instantiator
|
||||||
{
|
{
|
||||||
model: Cura.SettingVisibilityPresetsModel
|
model: settingVisibilityPresetsModel
|
||||||
|
|
||||||
MenuItem
|
MenuItem
|
||||||
{
|
{
|
||||||
text: model.name
|
text: model.name
|
||||||
checkable: true
|
checkable: true
|
||||||
checked: model.id == Cura.SettingVisibilityPresetsModel.activePreset
|
checked: model.id == settingVisibilityPresetsModel.activePreset
|
||||||
exclusiveGroup: group
|
exclusiveGroup: group
|
||||||
onTriggered:
|
onTriggered:
|
||||||
{
|
{
|
||||||
Cura.SettingVisibilityPresetsModel.setActivePreset(model.id);
|
settingVisibilityPresetsModel.setActivePreset(model.id);
|
||||||
|
|
||||||
UM.Preferences.setValue("general/visible_settings", model.settings.join(";"));
|
|
||||||
|
|
||||||
showSettingVisibilityProfile();
|
showSettingVisibilityProfile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ UM.PreferencesPage
|
|||||||
{
|
{
|
||||||
title: catalog.i18nc("@title:tab", "Setting Visibility");
|
title: catalog.i18nc("@title:tab", "Setting Visibility");
|
||||||
|
|
||||||
|
property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
|
||||||
|
|
||||||
property int scrollToIndex: 0
|
property int scrollToIndex: 0
|
||||||
|
|
||||||
signal scrollToSection( string key )
|
signal scrollToSection( string key )
|
||||||
@ -27,8 +29,7 @@ UM.PreferencesPage
|
|||||||
|
|
||||||
// After calling this function update Setting visibility preset combobox.
|
// After calling this function update Setting visibility preset combobox.
|
||||||
// Reset should set default setting preset ("Basic")
|
// Reset should set default setting preset ("Basic")
|
||||||
visibilityPreset.setDefaultPreset()
|
visibilityPreset.currentIndex = 1
|
||||||
|
|
||||||
}
|
}
|
||||||
resetEnabled: true;
|
resetEnabled: true;
|
||||||
|
|
||||||
@ -37,8 +38,6 @@ UM.PreferencesPage
|
|||||||
id: base;
|
id: base;
|
||||||
anchors.fill: parent;
|
anchors.fill: parent;
|
||||||
|
|
||||||
property bool inhibitSwitchToCustom: false
|
|
||||||
|
|
||||||
CheckBox
|
CheckBox
|
||||||
{
|
{
|
||||||
id: toggleVisibleSettings
|
id: toggleVisibleSettings
|
||||||
@ -112,11 +111,6 @@ UM.PreferencesPage
|
|||||||
|
|
||||||
ComboBox
|
ComboBox
|
||||||
{
|
{
|
||||||
function setDefaultPreset()
|
|
||||||
{
|
|
||||||
visibilityPreset.currentIndex = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
id: visibilityPreset
|
id: visibilityPreset
|
||||||
width: 150 * screenScaleFactor
|
width: 150 * screenScaleFactor
|
||||||
anchors
|
anchors
|
||||||
@ -125,51 +119,25 @@ UM.PreferencesPage
|
|||||||
right: parent.right
|
right: parent.right
|
||||||
}
|
}
|
||||||
|
|
||||||
model: ListModel
|
model: settingVisibilityPresetsModel
|
||||||
{
|
textRole: "name"
|
||||||
id: visibilityPresetsModel
|
|
||||||
Component.onCompleted:
|
|
||||||
{
|
|
||||||
visibilityPresetsModel.append({text: catalog.i18nc("@action:inmenu", "Custom selection"), id: "custom"});
|
|
||||||
|
|
||||||
var presets = Cura.SettingVisibilityPresetsModel;
|
|
||||||
for(var i = 0; i < presets.rowCount(); i++)
|
|
||||||
{
|
|
||||||
visibilityPresetsModel.append({text: presets.getItem(i)["name"], id: presets.getItem(i)["id"]});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentIndex:
|
currentIndex:
|
||||||
{
|
{
|
||||||
// Load previously selected preset.
|
// Load previously selected preset.
|
||||||
var index = Cura.SettingVisibilityPresetsModel.find("id", Cura.SettingVisibilityPresetsModel.activePreset);
|
var index = settingVisibilityPresetsModel.find("id", settingVisibilityPresetsModel.activePreset)
|
||||||
if(index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return index + 1; // "Custom selection" entry is added in front, so index is off by 1
|
return index
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivated:
|
onActivated:
|
||||||
{
|
{
|
||||||
base.inhibitSwitchToCustom = true;
|
var preset_id = settingVisibilityPresetsModel.getItem(index).id;
|
||||||
var preset_id = visibilityPresetsModel.get(index).id;
|
settingVisibilityPresetsModel.setActivePreset(preset_id);
|
||||||
Cura.SettingVisibilityPresetsModel.setActivePreset(preset_id);
|
|
||||||
|
|
||||||
UM.Preferences.setValue("cura/active_setting_visibility_preset", preset_id);
|
|
||||||
if (preset_id != "custom")
|
|
||||||
{
|
|
||||||
UM.Preferences.setValue("general/visible_settings", Cura.SettingVisibilityPresetsModel.getItem(index - 1).settings.join(";"));
|
|
||||||
// "Custom selection" entry is added in front, so index is off by 1
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Restore custom set from preference
|
|
||||||
UM.Preferences.setValue("general/visible_settings", UM.Preferences.getValue("cura/custom_visible_settings"));
|
|
||||||
}
|
|
||||||
base.inhibitSwitchToCustom = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,16 +167,7 @@ UM.PreferencesPage
|
|||||||
exclude: ["machine_settings", "command_line_settings"]
|
exclude: ["machine_settings", "command_line_settings"]
|
||||||
showAncestors: true
|
showAncestors: true
|
||||||
expanded: ["*"]
|
expanded: ["*"]
|
||||||
visibilityHandler: UM.SettingPreferenceVisibilityHandler
|
visibilityHandler: UM.SettingPreferenceVisibilityHandler {}
|
||||||
{
|
|
||||||
onVisibilityChanged:
|
|
||||||
{
|
|
||||||
if(Cura.SettingVisibilityPresetsModel.activePreset != "" && !base.inhibitSwitchToCustom)
|
|
||||||
{
|
|
||||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: Loader
|
delegate: Loader
|
||||||
|
@ -15,6 +15,7 @@ Item
|
|||||||
{
|
{
|
||||||
id: base;
|
id: base;
|
||||||
|
|
||||||
|
property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
|
||||||
property Action configureSettings
|
property Action configureSettings
|
||||||
property bool findingSettings
|
property bool findingSettings
|
||||||
property bool showingAllSettings
|
property bool showingAllSettings
|
||||||
@ -562,9 +563,9 @@ Item
|
|||||||
{
|
{
|
||||||
definitionsModel.hide(contextMenu.key);
|
definitionsModel.hide(contextMenu.key);
|
||||||
// visible settings have changed, so we're no longer showing a preset
|
// visible settings have changed, so we're no longer showing a preset
|
||||||
if (Cura.SettingVisibilityPresetsModel.activePreset != "" && !showingAllSettings)
|
if (settingVisibilityPresetsModel.activePreset != "" && !showingAllSettings)
|
||||||
{
|
{
|
||||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
settingVisibilityPresetsModel.setActivePreset("custom");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -594,16 +595,16 @@ Item
|
|||||||
definitionsModel.show(contextMenu.key);
|
definitionsModel.show(contextMenu.key);
|
||||||
}
|
}
|
||||||
// visible settings have changed, so we're no longer showing a preset
|
// visible settings have changed, so we're no longer showing a preset
|
||||||
if (Cura.SettingVisibilityPresetsModel.activePreset != "" && !showingAllSettings)
|
if (settingVisibilityPresetsModel.activePreset != "" && !showingAllSettings)
|
||||||
{
|
{
|
||||||
Cura.SettingVisibilityPresetsModel.setActivePreset("custom");
|
settingVisibilityPresetsModel.setActivePreset("custom");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MenuItem
|
MenuItem
|
||||||
{
|
{
|
||||||
//: Settings context menu action
|
//: Settings context menu action
|
||||||
text: catalog.i18nc("@action:menu", "Configure setting visiblity...");
|
text: catalog.i18nc("@action:menu", "Configure setting visibility...");
|
||||||
|
|
||||||
onTriggered: Cura.Actions.configureSettingVisibility.trigger(contextMenu);
|
onTriggered: Cura.Actions.configureSettingVisibility.trigger(contextMenu);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user