mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Heaps to changes to get the Cura code through the type checker (with minimal checking).
CURA-2917
This commit is contained in:
parent
b2068ce99b
commit
14afd9eab7
@ -61,7 +61,7 @@ if(NOT ${URANIUM_SCRIPTS_DIR} STREQUAL "")
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(PythonInterp 3.4.0 REQUIRED)
|
find_package(PythonInterp 3.5.0 REQUIRED)
|
||||||
|
|
||||||
install(DIRECTORY resources
|
install(DIRECTORY resources
|
||||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/cura)
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/cura)
|
||||||
|
@ -42,7 +42,14 @@ from . import CuraSplashScreen
|
|||||||
from . import CameraImageProvider
|
from . import CameraImageProvider
|
||||||
from . import MachineActionManager
|
from . import MachineActionManager
|
||||||
|
|
||||||
import cura.Settings
|
from cura.Settings.MachineManager import MachineManager
|
||||||
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
|
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
|
||||||
|
from cura.Settings.ExtrudersModel import ExtrudersModel
|
||||||
|
from cura.Settings.ContainerSettingsModel import ContainerSettingsModel
|
||||||
|
from cura.Settings.MaterialSettingsVisibilityHandler import MaterialSettingsVisibilityHandler
|
||||||
|
from cura.Settings.QualitySettingsModel import QualitySettingsModel
|
||||||
|
from cura.Settings.ContainerManager import ContainerManager
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS
|
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS
|
||||||
from PyQt5.QtGui import QColor, QIcon
|
from PyQt5.QtGui import QColor, QIcon
|
||||||
@ -57,6 +64,8 @@ import urllib
|
|||||||
|
|
||||||
numpy.seterr(all="ignore")
|
numpy.seterr(all="ignore")
|
||||||
|
|
||||||
|
MYPY = False
|
||||||
|
if not MYPY:
|
||||||
try:
|
try:
|
||||||
from cura.CuraVersion import CuraVersion, CuraBuildType
|
from cura.CuraVersion import CuraVersion, CuraBuildType
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -77,6 +86,8 @@ class CuraApplication(QtApplication):
|
|||||||
Q_ENUMS(ResourceTypes)
|
Q_ENUMS(ResourceTypes)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
super().__init__(name = "cura", version = CuraVersion, buildtype = CuraBuildType)
|
||||||
|
|
||||||
Resources.addSearchPath(os.path.join(QtApplication.getInstallPrefix(), "share", "cura", "resources"))
|
Resources.addSearchPath(os.path.join(QtApplication.getInstallPrefix(), "share", "cura", "resources"))
|
||||||
if not hasattr(sys, "frozen"):
|
if not hasattr(sys, "frozen"):
|
||||||
Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources"))
|
Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources"))
|
||||||
@ -92,8 +103,8 @@ class CuraApplication(QtApplication):
|
|||||||
SettingDefinition.addSupportedProperty("resolve", DefinitionPropertyType.Function, default = None)
|
SettingDefinition.addSupportedProperty("resolve", DefinitionPropertyType.Function, default = None)
|
||||||
SettingDefinition.addSettingType("extruder", None, str, Validator)
|
SettingDefinition.addSettingType("extruder", None, str, Validator)
|
||||||
|
|
||||||
SettingFunction.registerOperator("extruderValues", cura.Settings.ExtruderManager.getExtruderValues)
|
SettingFunction.registerOperator("extruderValues", ExtruderManager.getExtruderValues)
|
||||||
SettingFunction.registerOperator("extruderValue", cura.Settings.ExtruderManager.getExtruderValue)
|
SettingFunction.registerOperator("extruderValue", ExtruderManager.getExtruderValue)
|
||||||
|
|
||||||
## Add the 4 types of profiles to storage.
|
## Add the 4 types of profiles to storage.
|
||||||
Resources.addStorageType(self.ResourceTypes.QualityInstanceContainer, "quality")
|
Resources.addStorageType(self.ResourceTypes.QualityInstanceContainer, "quality")
|
||||||
@ -112,11 +123,12 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
## Initialise the version upgrade manager with Cura's storage paths.
|
## Initialise the version upgrade manager with Cura's storage paths.
|
||||||
import UM.VersionUpgradeManager #Needs to be here to prevent circular dependencies.
|
import UM.VersionUpgradeManager #Needs to be here to prevent circular dependencies.
|
||||||
self._version_upgrade_manager = UM.VersionUpgradeManager.VersionUpgradeManager(
|
|
||||||
|
UM.VersionUpgradeManager.VersionUpgradeManager.getInstance().setCurrentVersions(
|
||||||
{
|
{
|
||||||
("quality", UM.Settings.InstanceContainer.Version): (self.ResourceTypes.QualityInstanceContainer, "application/x-uranium-instancecontainer"),
|
("quality", UM.Settings.InstanceContainer.InstanceContainer.Version): (self.ResourceTypes.QualityInstanceContainer, "application/x-uranium-instancecontainer"),
|
||||||
("machine_stack", UM.Settings.ContainerStack.Version): (self.ResourceTypes.MachineStack, "application/x-uranium-containerstack"),
|
("machine_stack", UM.Settings.ContainerStack.ContainerStack.Version): (self.ResourceTypes.MachineStack, "application/x-uranium-containerstack"),
|
||||||
("preferences", UM.Preferences.Version): (Resources.Preferences, "application/x-uranium-preferences")
|
("preferences", Preferences.Version): (Resources.Preferences, "application/x-uranium-preferences")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -125,7 +137,6 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
self._additional_components = {} # Components to add to certain areas in the interface
|
self._additional_components = {} # Components to add to certain areas in the interface
|
||||||
|
|
||||||
super().__init__(name = "cura", version = CuraVersion, buildtype = CuraBuildType)
|
|
||||||
|
|
||||||
self.setWindowIcon(QIcon(Resources.getPath(Resources.Images, "cura-icon.png")))
|
self.setWindowIcon(QIcon(Resources.getPath(Resources.Images, "cura-icon.png")))
|
||||||
|
|
||||||
@ -267,6 +278,9 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
self._recent_files.append(QUrl.fromLocalFile(f))
|
self._recent_files.append(QUrl.fromLocalFile(f))
|
||||||
|
|
||||||
|
def getContainerRegistry(self):
|
||||||
|
return CuraContainerRegistry.getInstance()
|
||||||
|
|
||||||
def _onEngineCreated(self):
|
def _onEngineCreated(self):
|
||||||
self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider())
|
self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider())
|
||||||
|
|
||||||
@ -418,8 +432,8 @@ class CuraApplication(QtApplication):
|
|||||||
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading interface..."))
|
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading interface..."))
|
||||||
|
|
||||||
# Initialise extruder so as to listen to global container stack changes before the first global container stack is set.
|
# Initialise extruder so as to listen to global container stack changes before the first global container stack is set.
|
||||||
cura.Settings.ExtruderManager.getInstance()
|
ExtruderManager.getInstance()
|
||||||
qmlRegisterSingletonType(cura.Settings.MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
|
qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
|
||||||
|
|
||||||
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
|
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
|
||||||
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
||||||
@ -440,7 +454,7 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
def getMachineManager(self, *args):
|
def getMachineManager(self, *args):
|
||||||
if self._machine_manager is None:
|
if self._machine_manager is None:
|
||||||
self._machine_manager = cura.Settings.MachineManager.createMachineManager()
|
self._machine_manager = MachineManager.createMachineManager()
|
||||||
return self._machine_manager
|
return self._machine_manager
|
||||||
|
|
||||||
## Get the machine action manager
|
## Get the machine action manager
|
||||||
@ -476,17 +490,17 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type")
|
qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type")
|
||||||
|
|
||||||
qmlRegisterType(cura.Settings.ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
||||||
|
|
||||||
qmlRegisterType(cura.Settings.ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel")
|
qmlRegisterType(ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel")
|
||||||
qmlRegisterType(cura.Settings.MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
|
qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
|
||||||
qmlRegisterType(cura.Settings.QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
|
qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
|
||||||
|
|
||||||
qmlRegisterSingletonType(cura.Settings.ContainerManager, "Cura", 1, 0, "ContainerManager", cura.Settings.ContainerManager.createContainerManager)
|
qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager)
|
||||||
|
|
||||||
qmlRegisterSingletonType(QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")), "Cura", 1, 0, "Actions")
|
qmlRegisterSingletonType(QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")), "Cura", 1, 0, "Actions")
|
||||||
|
|
||||||
engine.rootContext().setContextProperty("ExtruderManager", cura.Settings.ExtruderManager.getInstance())
|
engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.getInstance())
|
||||||
|
|
||||||
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
||||||
type_name = os.path.splitext(os.path.basename(path))[0]
|
type_name = os.path.splitext(os.path.basename(path))[0]
|
||||||
|
@ -7,7 +7,7 @@ from UM.Application import Application
|
|||||||
from UM.Qt.Duration import Duration
|
from UM.Qt.Duration import Duration
|
||||||
from UM.Preferences import Preferences
|
from UM.Preferences import Preferences
|
||||||
|
|
||||||
import cura.Settings.ExtruderManager
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import os.path
|
import os.path
|
||||||
@ -85,7 +85,7 @@ class PrintInformation(QObject):
|
|||||||
r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2
|
r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2
|
||||||
self._material_lengths = []
|
self._material_lengths = []
|
||||||
self._material_weights = []
|
self._material_weights = []
|
||||||
extruder_stacks = list(cura.Settings.ExtruderManager.getInstance().getMachineExtruders(Application.getInstance().getGlobalContainerStack().getId()))
|
extruder_stacks = list(ExtruderManager.getInstance().getMachineExtruders(Application.getInstance().getGlobalContainerStack().getId()))
|
||||||
for index, amount in enumerate(material_amounts):
|
for index, amount in enumerate(material_amounts):
|
||||||
## Find the right extruder stack. As the list isn't sorted because it's a annoying generator, we do some
|
## Find the right extruder stack. As the list isn't sorted because it's a annoying generator, we do some
|
||||||
# list comprehension filtering to solve this for us.
|
# list comprehension filtering to solve this for us.
|
||||||
|
@ -8,17 +8,19 @@ from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal, QUrl
|
|||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
|
|
||||||
import UM.PluginRegistry
|
import UM.PluginRegistry
|
||||||
import UM.Settings
|
|
||||||
import UM.SaveFile
|
import UM.SaveFile
|
||||||
import UM.Platform
|
import UM.Platform
|
||||||
import UM.MimeTypeDatabase
|
import UM.MimeTypeDatabase
|
||||||
import UM.Logger
|
import UM.Logger
|
||||||
|
|
||||||
import cura.Settings
|
from UM.Application import Application
|
||||||
|
|
||||||
from UM.MimeTypeDatabase import MimeTypeNotFoundError
|
from UM.MimeTypeDatabase import MimeTypeNotFoundError
|
||||||
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
|
|
||||||
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
|
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
## Manager class that contains common actions to deal with containers in Cura.
|
## Manager class that contains common actions to deal with containers in Cura.
|
||||||
@ -30,7 +32,7 @@ class ContainerManager(QObject):
|
|||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self._registry = UM.Settings.ContainerRegistry.getInstance()
|
self._registry = ContainerRegistry.getInstance()
|
||||||
self._container_name_filters = {}
|
self._container_name_filters = {}
|
||||||
|
|
||||||
## Create a duplicate of the specified container
|
## Create a duplicate of the specified container
|
||||||
@ -246,7 +248,7 @@ class ContainerManager(QObject):
|
|||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def isContainerUsed(self, container_id):
|
def isContainerUsed(self, container_id):
|
||||||
UM.Logger.log("d", "Checking if container %s is currently used in the active stacks", container_id)
|
UM.Logger.log("d", "Checking if container %s is currently used in the active stacks", container_id)
|
||||||
for stack in cura.Settings.ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
for stack in ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
||||||
if container_id in [child.getId() for child in stack.getContainers()]:
|
if container_id in [child.getId() for child in stack.getContainers()]:
|
||||||
UM.Logger.log("d", "The container is in use by %s", stack.getId())
|
UM.Logger.log("d", "The container is in use by %s", stack.getId())
|
||||||
return True
|
return True
|
||||||
@ -357,12 +359,12 @@ class ContainerManager(QObject):
|
|||||||
except MimeTypeNotFoundError:
|
except MimeTypeNotFoundError:
|
||||||
return { "status": "error", "message": "Could not determine mime type of file" }
|
return { "status": "error", "message": "Could not determine mime type of file" }
|
||||||
|
|
||||||
container_type = UM.Settings.ContainerRegistry.getContainerForMimeType(mime_type)
|
container_type = ContainerRegistry.getContainerForMimeType(mime_type)
|
||||||
if not container_type:
|
if not container_type:
|
||||||
return { "status": "error", "message": "Could not find a container to handle the specified file."}
|
return { "status": "error", "message": "Could not find a container to handle the specified file."}
|
||||||
|
|
||||||
container_id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(file_url)))
|
container_id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(file_url)))
|
||||||
container_id = UM.Settings.ContainerRegistry.getInstance().uniqueName(container_id)
|
container_id = ContainerRegistry.getInstance().uniqueName(container_id)
|
||||||
|
|
||||||
container = container_type(container_id)
|
container = container_type(container_id)
|
||||||
|
|
||||||
@ -374,7 +376,7 @@ class ContainerManager(QObject):
|
|||||||
|
|
||||||
container.setName(container_id)
|
container.setName(container_id)
|
||||||
|
|
||||||
UM.Settings.ContainerRegistry.getInstance().addContainer(container)
|
ContainerRegistry.getInstance().addContainer(container)
|
||||||
|
|
||||||
return { "status": "success", "message": "Successfully imported container {0}".format(container.getName()) }
|
return { "status": "success", "message": "Successfully imported container {0}".format(container.getName()) }
|
||||||
|
|
||||||
@ -386,13 +388,13 @@ class ContainerManager(QObject):
|
|||||||
# \return \type{bool} True if successful, False if not.
|
# \return \type{bool} True if successful, False if not.
|
||||||
@pyqtSlot(result = bool)
|
@pyqtSlot(result = bool)
|
||||||
def updateQualityChanges(self):
|
def updateQualityChanges(self):
|
||||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if not global_stack:
|
if not global_stack:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
UM.Application.getInstance().getMachineManager().blurSettings.emit()
|
Application.getInstance().getMachineManager().blurSettings.emit()
|
||||||
|
|
||||||
for stack in cura.Settings.ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
for stack in ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
||||||
# Find the quality_changes container for this stack and merge the contents of the top container into it.
|
# Find the quality_changes container for this stack and merge the contents of the top container into it.
|
||||||
quality_changes = stack.findContainer(type = "quality_changes")
|
quality_changes = stack.findContainer(type = "quality_changes")
|
||||||
if not quality_changes or quality_changes.isReadOnly():
|
if not quality_changes or quality_changes.isReadOnly():
|
||||||
@ -401,17 +403,17 @@ class ContainerManager(QObject):
|
|||||||
|
|
||||||
self._performMerge(quality_changes, stack.getTop())
|
self._performMerge(quality_changes, stack.getTop())
|
||||||
|
|
||||||
UM.Application.getInstance().getMachineManager().activeQualityChanged.emit()
|
Application.getInstance().getMachineManager().activeQualityChanged.emit()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
## Clear the top-most (user) containers of the active stacks.
|
## Clear the top-most (user) containers of the active stacks.
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def clearUserContainers(self):
|
def clearUserContainers(self):
|
||||||
UM.Application.getInstance().getMachineManager().blurSettings.emit()
|
Application.getInstance().getMachineManager().blurSettings.emit()
|
||||||
|
|
||||||
# Go through global and extruder stacks and clear their topmost container (the user settings).
|
# Go through global and extruder stacks and clear their topmost container (the user settings).
|
||||||
for stack in cura.Settings.ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
for stack in ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
||||||
stack.getTop().clear()
|
stack.getTop().clear()
|
||||||
|
|
||||||
## Create quality changes containers from the user containers in the active stacks.
|
## Create quality changes containers from the user containers in the active stacks.
|
||||||
@ -423,7 +425,7 @@ class ContainerManager(QObject):
|
|||||||
# \return \type{bool} True if the operation was successfully, False if not.
|
# \return \type{bool} True if the operation was successfully, False if not.
|
||||||
@pyqtSlot(result = bool)
|
@pyqtSlot(result = bool)
|
||||||
def createQualityChanges(self):
|
def createQualityChanges(self):
|
||||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if not global_stack:
|
if not global_stack:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -432,12 +434,12 @@ class ContainerManager(QObject):
|
|||||||
UM.Logger.log("w", "No quality container found in stack %s, cannot create profile", global_stack.getId())
|
UM.Logger.log("w", "No quality container found in stack %s, cannot create profile", global_stack.getId())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
UM.Application.getInstance().getMachineManager().blurSettings.emit()
|
Application.getInstance().getMachineManager().blurSettings.emit()
|
||||||
|
|
||||||
unique_name = UM.Settings.ContainerRegistry.getInstance().uniqueName(quality_container.getName())
|
unique_name = ContainerRegistry.getInstance().uniqueName(quality_container.getName())
|
||||||
|
|
||||||
# Go through the active stacks and create quality_changes containers from the user containers.
|
# Go through the active stacks and create quality_changes containers from the user containers.
|
||||||
for stack in cura.Settings.ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
for stack in ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
||||||
user_container = stack.getTop()
|
user_container = stack.getTop()
|
||||||
quality_container = stack.findContainer(type = "quality")
|
quality_container = stack.findContainer(type = "quality")
|
||||||
quality_changes_container = stack.findContainer(type = "quality_changes")
|
quality_changes_container = stack.findContainer(type = "quality_changes")
|
||||||
@ -541,7 +543,7 @@ class ContainerManager(QObject):
|
|||||||
container_type = containers[0].getMetaDataEntry("type")
|
container_type = containers[0].getMetaDataEntry("type")
|
||||||
if container_type == "quality":
|
if container_type == "quality":
|
||||||
for container in self._getFilteredContainers(name = quality_name, type = "quality"):
|
for container in self._getFilteredContainers(name = quality_name, type = "quality"):
|
||||||
for stack in cura.Settings.ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
for stack in ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
||||||
new_changes = self._createQualityChanges(container, new_name, stack.getId())
|
new_changes = self._createQualityChanges(container, new_name, stack.getId())
|
||||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_changes)
|
UM.Settings.ContainerRegistry.getInstance().addContainer(new_changes)
|
||||||
elif container_type == "quality_changes":
|
elif container_type == "quality_changes":
|
||||||
@ -620,7 +622,7 @@ class ContainerManager(QObject):
|
|||||||
#
|
#
|
||||||
# \return A generator that iterates over the list of containers matching the search criteria.
|
# \return A generator that iterates over the list of containers matching the search criteria.
|
||||||
def _getFilteredContainers(self, **kwargs):
|
def _getFilteredContainers(self, **kwargs):
|
||||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if not global_stack:
|
if not global_stack:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -635,7 +637,7 @@ class ContainerManager(QObject):
|
|||||||
|
|
||||||
material_ids = []
|
material_ids = []
|
||||||
if filter_by_material:
|
if filter_by_material:
|
||||||
for stack in cura.Settings.ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
for stack in ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks():
|
||||||
material_ids.append(stack.findContainer(type = "material").getId())
|
material_ids.append(stack.findContainer(type = "material").getId())
|
||||||
|
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||||
|
@ -3,11 +3,14 @@
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QObject, QVariant #For communicating data and events to Qt.
|
from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QObject, QVariant #For communicating data and events to Qt.
|
||||||
|
|
||||||
import UM.Application #To get the global container stack to find the current machine.
|
from UM.Application import Application #To get the global container stack to find the current machine.
|
||||||
import UM.Logger
|
from UM.Logger import Logger
|
||||||
import UM.Settings.ContainerRegistry #Finding containers by ID.
|
from UM.Settings.ContainerRegistry import ContainerRegistry #Finding containers by ID.
|
||||||
import UM.Settings.SettingFunction
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
|
from UM.Settings.SettingFunction import SettingFunction
|
||||||
|
from UM.Settings.ContainerStack import ContainerStack
|
||||||
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
## Manages all existing extruder stacks.
|
## Manages all existing extruder stacks.
|
||||||
#
|
#
|
||||||
@ -22,9 +25,12 @@ class ExtruderManager(QObject):
|
|||||||
## Registers listeners and such to listen to changes to the extruders.
|
## Registers listeners and such to listen to changes to the extruders.
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._extruder_trains = { } #Per machine, a dictionary of extruder container stack IDs.
|
|
||||||
self._active_extruder_index = 0
|
# Per machine, a dictionary of extruder container stack IDs.
|
||||||
UM.Application.getInstance().globalContainerStackChanged.connect(self.__globalContainerStackChanged)
|
self._extruder_trains = {} # type: Dict[str, Dict[str, ContainerStack]]
|
||||||
|
|
||||||
|
self._active_extruder_index = 0 # type: int
|
||||||
|
Application.getInstance().globalContainerStackChanged.connect(self.__globalContainerStackChanged)
|
||||||
self._addCurrentMachineExtruders()
|
self._addCurrentMachineExtruders()
|
||||||
|
|
||||||
## Gets the unique identifier of the currently active extruder stack.
|
## Gets the unique identifier of the currently active extruder stack.
|
||||||
@ -34,31 +40,31 @@ class ExtruderManager(QObject):
|
|||||||
#
|
#
|
||||||
# \return The unique ID of the currently active extruder stack.
|
# \return The unique ID of the currently active extruder stack.
|
||||||
@pyqtProperty(str, notify = activeExtruderChanged)
|
@pyqtProperty(str, notify = activeExtruderChanged)
|
||||||
def activeExtruderStackId(self):
|
def activeExtruderStackId(self) -> Optional[str]:
|
||||||
if not UM.Application.getInstance().getGlobalContainerStack():
|
if not Application.getInstance().getGlobalContainerStack():
|
||||||
return None # No active machine, so no active extruder.
|
return None # No active machine, so no active extruder.
|
||||||
try:
|
try:
|
||||||
return self._extruder_trains[UM.Application.getInstance().getGlobalContainerStack().getId()][str(self._active_extruder_index)].getId()
|
return self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][str(self._active_extruder_index)].getId()
|
||||||
except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong.
|
except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong.
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@pyqtProperty(int, notify = extrudersChanged)
|
@pyqtProperty(int, notify = extrudersChanged)
|
||||||
def extruderCount(self):
|
def extruderCount(self) -> int:
|
||||||
if not UM.Application.getInstance().getGlobalContainerStack():
|
if not Application.getInstance().getGlobalContainerStack():
|
||||||
return 0 # No active machine, so no extruders.
|
return 0 # No active machine, so no extruders.
|
||||||
return len(self._extruder_trains[UM.Application.getInstance().getGlobalContainerStack().getId()])
|
return len(self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()])
|
||||||
|
|
||||||
@pyqtProperty("QVariantMap", notify=extrudersChanged)
|
@pyqtProperty("QVariantMap", notify=extrudersChanged)
|
||||||
def extruderIds(self):
|
def extruderIds(self):
|
||||||
map = {}
|
map = {}
|
||||||
for position in self._extruder_trains[UM.Application.getInstance().getGlobalContainerStack().getId()]:
|
for position in self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()]:
|
||||||
map[position] = self._extruder_trains[UM.Application.getInstance().getGlobalContainerStack().getId()][position].getId()
|
map[position] = self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][position].getId()
|
||||||
return map
|
return map
|
||||||
|
|
||||||
@pyqtSlot(str, result = str)
|
@pyqtSlot(str, result = str)
|
||||||
def getQualityChangesIdByExtruderStackId(self, id):
|
def getQualityChangesIdByExtruderStackId(self, id: str) -> str:
|
||||||
for position in self._extruder_trains[UM.Application.getInstance().getGlobalContainerStack().getId()]:
|
for position in self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()]:
|
||||||
extruder = self._extruder_trains[UM.Application.getInstance().getGlobalContainerStack().getId()][position]
|
extruder = self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][position]
|
||||||
if extruder.getId() == id:
|
if extruder.getId() == id:
|
||||||
return extruder.findContainer(type = "quality_changes").getId()
|
return extruder.findContainer(type = "quality_changes").getId()
|
||||||
|
|
||||||
@ -75,7 +81,7 @@ class ExtruderManager(QObject):
|
|||||||
#
|
#
|
||||||
# \return The extruder manager.
|
# \return The extruder manager.
|
||||||
@classmethod
|
@classmethod
|
||||||
def getInstance(cls):
|
def getInstance(cls) -> 'ExtruderManager':
|
||||||
if not cls.__instance:
|
if not cls.__instance:
|
||||||
cls.__instance = ExtruderManager()
|
cls.__instance = ExtruderManager()
|
||||||
return cls.__instance
|
return cls.__instance
|
||||||
@ -84,16 +90,16 @@ class ExtruderManager(QObject):
|
|||||||
#
|
#
|
||||||
# \param index The index of the new active extruder.
|
# \param index The index of the new active extruder.
|
||||||
@pyqtSlot(int)
|
@pyqtSlot(int)
|
||||||
def setActiveExtruderIndex(self, index):
|
def setActiveExtruderIndex(self, index: int) -> None:
|
||||||
self._active_extruder_index = index
|
self._active_extruder_index = index
|
||||||
self.activeExtruderChanged.emit()
|
self.activeExtruderChanged.emit()
|
||||||
|
|
||||||
@pyqtProperty(int, notify = activeExtruderChanged)
|
@pyqtProperty(int, notify = activeExtruderChanged)
|
||||||
def activeExtruderIndex(self):
|
def activeExtruderIndex(self) -> int:
|
||||||
return self._active_extruder_index
|
return self._active_extruder_index
|
||||||
|
|
||||||
def getActiveExtruderStack(self):
|
def getActiveExtruderStack(self) -> ContainerStack:
|
||||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if global_container_stack:
|
if global_container_stack:
|
||||||
if global_container_stack.getId() in self._extruder_trains:
|
if global_container_stack.getId() in self._extruder_trains:
|
||||||
if str(self._active_extruder_index) in self._extruder_trains[global_container_stack.getId()]:
|
if str(self._active_extruder_index) in self._extruder_trains[global_container_stack.getId()]:
|
||||||
@ -102,7 +108,7 @@ class ExtruderManager(QObject):
|
|||||||
|
|
||||||
## Get an extruder stack by index
|
## Get an extruder stack by index
|
||||||
def getExtruderStack(self, index):
|
def getExtruderStack(self, index):
|
||||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if global_container_stack:
|
if global_container_stack:
|
||||||
if global_container_stack.getId() in self._extruder_trains:
|
if global_container_stack.getId() in self._extruder_trains:
|
||||||
if str(index) in self._extruder_trains[global_container_stack.getId()]:
|
if str(index) in self._extruder_trains[global_container_stack.getId()]:
|
||||||
@ -114,19 +120,19 @@ class ExtruderManager(QObject):
|
|||||||
#
|
#
|
||||||
# \param machine_definition The machine definition to add the extruders for.
|
# \param machine_definition The machine definition to add the extruders for.
|
||||||
# \param machine_id The machine_id to add the extruders for.
|
# \param machine_id The machine_id to add the extruders for.
|
||||||
def addMachineExtruders(self, machine_definition, machine_id):
|
def addMachineExtruders(self, machine_definition: DefinitionContainer, machine_id: str) -> None:
|
||||||
changed = False
|
changed = False
|
||||||
machine_definition_id = machine_definition.getId()
|
machine_definition_id = machine_definition.getId()
|
||||||
if machine_id not in self._extruder_trains:
|
if machine_id not in self._extruder_trains:
|
||||||
self._extruder_trains[machine_id] = { }
|
self._extruder_trains[machine_id] = { }
|
||||||
changed = True
|
changed = True
|
||||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
if container_registry:
|
if container_registry:
|
||||||
# Add the extruder trains that don't exist yet.
|
# Add the extruder trains that don't exist yet.
|
||||||
for extruder_definition in container_registry.findDefinitionContainers(machine = machine_definition_id):
|
for extruder_definition in container_registry.findDefinitionContainers(machine = machine_definition_id):
|
||||||
position = extruder_definition.getMetaDataEntry("position", None)
|
position = extruder_definition.getMetaDataEntry("position", None)
|
||||||
if not position:
|
if not position:
|
||||||
UM.Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.getId())
|
Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.getId())
|
||||||
if not container_registry.findContainerStacks(machine = machine_id, position = position): # Doesn't exist yet.
|
if not container_registry.findContainerStacks(machine = machine_id, position = position): # Doesn't exist yet.
|
||||||
self.createExtruderTrain(extruder_definition, machine_definition, position, machine_id)
|
self.createExtruderTrain(extruder_definition, machine_definition, position, machine_id)
|
||||||
changed = True
|
changed = True
|
||||||
@ -138,7 +144,7 @@ class ExtruderManager(QObject):
|
|||||||
|
|
||||||
# Make sure the next stack is a stack that contains only the machine definition
|
# Make sure the next stack is a stack that contains only the machine definition
|
||||||
if not extruder_train.getNextStack():
|
if not extruder_train.getNextStack():
|
||||||
shallow_stack = UM.Settings.ContainerStack(machine_id + "_shallow")
|
shallow_stack = ContainerStack(machine_id + "_shallow")
|
||||||
shallow_stack.addContainer(machine_definition)
|
shallow_stack.addContainer(machine_definition)
|
||||||
extruder_train.setNextStack(shallow_stack)
|
extruder_train.setNextStack(shallow_stack)
|
||||||
changed = True
|
changed = True
|
||||||
@ -157,14 +163,15 @@ class ExtruderManager(QObject):
|
|||||||
# \param machine_definition The machine that the extruder train belongs to.
|
# \param machine_definition The machine that the extruder train belongs to.
|
||||||
# \param position The position of this extruder train in the extruder slots of the machine.
|
# \param position The position of this extruder train in the extruder slots of the machine.
|
||||||
# \param machine_id The id of the "global" stack this extruder is linked to.
|
# \param machine_id The id of the "global" stack this extruder is linked to.
|
||||||
def createExtruderTrain(self, extruder_definition, machine_definition, position, machine_id):
|
def createExtruderTrain(self, extruder_definition: DefinitionContainer, machine_definition: DefinitionContainer,
|
||||||
|
position, machine_id: str) -> None:
|
||||||
# Cache some things.
|
# Cache some things.
|
||||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
machine_definition_id = machine_definition.getId()
|
machine_definition_id = machine_definition.getId()
|
||||||
|
|
||||||
# Create a container stack for this extruder.
|
# Create a container stack for this extruder.
|
||||||
extruder_stack_id = container_registry.uniqueName(extruder_definition.getId())
|
extruder_stack_id = container_registry.uniqueName(extruder_definition.getId())
|
||||||
container_stack = UM.Settings.ContainerStack(extruder_stack_id)
|
container_stack = ContainerStack(extruder_stack_id)
|
||||||
container_stack.setName(extruder_definition.getName()) # Take over the display name to display the stack with.
|
container_stack.setName(extruder_definition.getName()) # Take over the display name to display the stack with.
|
||||||
container_stack.addMetaDataEntry("type", "extruder_train")
|
container_stack.addMetaDataEntry("type", "extruder_train")
|
||||||
container_stack.addMetaDataEntry("machine", machine_id)
|
container_stack.addMetaDataEntry("machine", machine_id)
|
||||||
@ -184,7 +191,7 @@ class ExtruderManager(QObject):
|
|||||||
if len(preferred_variants) >= 1:
|
if len(preferred_variants) >= 1:
|
||||||
variant = preferred_variants[0]
|
variant = preferred_variants[0]
|
||||||
else:
|
else:
|
||||||
UM.Logger.log("w", "The preferred variant \"%s\" of machine %s doesn't exist or is not a variant profile.", preferred_variant_id, machine_id)
|
Logger.log("w", "The preferred variant \"%s\" of machine %s doesn't exist or is not a variant profile.", preferred_variant_id, machine_id)
|
||||||
# And leave it at the default variant.
|
# And leave it at the default variant.
|
||||||
container_stack.addContainer(variant)
|
container_stack.addContainer(variant)
|
||||||
|
|
||||||
@ -213,7 +220,7 @@ class ExtruderManager(QObject):
|
|||||||
if len(preferred_materials) >= 1:
|
if len(preferred_materials) >= 1:
|
||||||
material = preferred_materials[0]
|
material = preferred_materials[0]
|
||||||
else:
|
else:
|
||||||
UM.Logger.log("w", "The preferred material \"%s\" of machine %s doesn't exist or is not a material profile.", preferred_material_id, machine_id)
|
Logger.log("w", "The preferred material \"%s\" of machine %s doesn't exist or is not a material profile.", preferred_material_id, machine_id)
|
||||||
# And leave it at the default material.
|
# And leave it at the default material.
|
||||||
container_stack.addContainer(material)
|
container_stack.addContainer(material)
|
||||||
|
|
||||||
@ -232,11 +239,11 @@ class ExtruderManager(QObject):
|
|||||||
if preferred_quality:
|
if preferred_quality:
|
||||||
search_criteria["id"] = preferred_quality
|
search_criteria["id"] = preferred_quality
|
||||||
|
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||||
if not containers and preferred_quality:
|
if not containers and preferred_quality:
|
||||||
UM.Logger.log("w", "The preferred quality \"%s\" of machine %s doesn't exist or is not a quality profile.", preferred_quality, machine_id)
|
Logger.log("w", "The preferred quality \"%s\" of machine %s doesn't exist or is not a quality profile.", preferred_quality, machine_id)
|
||||||
search_criteria.pop("id", None)
|
search_criteria.pop("id", None)
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||||
if containers:
|
if containers:
|
||||||
quality = containers[0]
|
quality = containers[0]
|
||||||
|
|
||||||
@ -249,7 +256,7 @@ class ExtruderManager(QObject):
|
|||||||
if user_profile: # There was already a user profile, loaded from settings.
|
if user_profile: # There was already a user profile, loaded from settings.
|
||||||
user_profile = user_profile[0]
|
user_profile = user_profile[0]
|
||||||
else:
|
else:
|
||||||
user_profile = UM.Settings.InstanceContainer(extruder_stack_id + "_current_settings") # Add an empty user profile.
|
user_profile = InstanceContainer(extruder_stack_id + "_current_settings") # Add an empty user profile.
|
||||||
user_profile.addMetaDataEntry("type", "user")
|
user_profile.addMetaDataEntry("type", "user")
|
||||||
user_profile.addMetaDataEntry("extruder", extruder_stack_id)
|
user_profile.addMetaDataEntry("extruder", extruder_stack_id)
|
||||||
user_profile.setDefinition(machine_definition)
|
user_profile.setDefinition(machine_definition)
|
||||||
@ -258,7 +265,7 @@ class ExtruderManager(QObject):
|
|||||||
|
|
||||||
# Make sure the next stack is a stack that contains only the machine definition
|
# Make sure the next stack is a stack that contains only the machine definition
|
||||||
if not container_stack.getNextStack():
|
if not container_stack.getNextStack():
|
||||||
shallow_stack = UM.Settings.ContainerStack(machine_id + "_shallow")
|
shallow_stack = ContainerStack(machine_id + "_shallow")
|
||||||
shallow_stack.addContainer(machine_definition)
|
shallow_stack.addContainer(machine_definition)
|
||||||
container_stack.setNextStack(shallow_stack)
|
container_stack.setNextStack(shallow_stack)
|
||||||
|
|
||||||
@ -269,26 +276,25 @@ class ExtruderManager(QObject):
|
|||||||
# \param machine_id The machine to remove the extruders for.
|
# \param machine_id The machine to remove the extruders for.
|
||||||
def removeMachineExtruders(self, machine_id):
|
def removeMachineExtruders(self, machine_id):
|
||||||
for extruder in self.getMachineExtruders(machine_id):
|
for extruder in self.getMachineExtruders(machine_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "user", extruder = extruder.getId())
|
containers = ContainerRegistry.getInstance().findInstanceContainers(type = "user", extruder = extruder.getId())
|
||||||
for container in containers:
|
for container in containers:
|
||||||
UM.Settings.ContainerRegistry.getInstance().removeContainer(container.getId())
|
ContainerRegistry.getInstance().removeContainer(container.getId())
|
||||||
UM.Settings.ContainerRegistry.getInstance().removeContainer(extruder.getId())
|
ContainerRegistry.getInstance().removeContainer(extruder.getId())
|
||||||
|
|
||||||
## Returns extruders for a specific machine.
|
## Returns extruders for a specific machine.
|
||||||
#
|
#
|
||||||
# \param machine_id The machine to get the extruders of.
|
# \param machine_id The machine to get the extruders of.
|
||||||
def getMachineExtruders(self, machine_id):
|
def getMachineExtruders(self, machine_id):
|
||||||
if machine_id not in self._extruder_trains:
|
if machine_id not in self._extruder_trains:
|
||||||
UM.Logger.log("w", "Tried to get the extruder trains for machine %s, which doesn't exist.", machine_id)
|
Logger.log("w", "Tried to get the extruder trains for machine %s, which doesn't exist.", machine_id)
|
||||||
return
|
return []
|
||||||
for name in self._extruder_trains[machine_id]:
|
return [self._extruder_trains[machine_id][name] for name in self._extruder_trains[machine_id]]
|
||||||
yield self._extruder_trains[machine_id][name]
|
|
||||||
|
|
||||||
## Returns a generator that will iterate over the global stack and per-extruder stacks.
|
## Returns a generator that will iterate over the global stack and per-extruder stacks.
|
||||||
#
|
#
|
||||||
# The first generated element is the global container stack. After that any extruder stacks are generated.
|
# The first generated element is the global container stack. After that any extruder stacks are generated.
|
||||||
def getActiveGlobalAndExtruderStacks(self):
|
def getActiveGlobalAndExtruderStacks(self):
|
||||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if not global_stack:
|
if not global_stack:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -298,13 +304,13 @@ class ExtruderManager(QObject):
|
|||||||
for name in self._extruder_trains[global_id]:
|
for name in self._extruder_trains[global_id]:
|
||||||
yield self._extruder_trains[global_id][name]
|
yield self._extruder_trains[global_id][name]
|
||||||
|
|
||||||
def __globalContainerStackChanged(self):
|
def __globalContainerStackChanged(self) -> None:
|
||||||
self._addCurrentMachineExtruders()
|
self._addCurrentMachineExtruders()
|
||||||
self.activeExtruderChanged.emit()
|
self.activeExtruderChanged.emit()
|
||||||
|
|
||||||
## Adds the extruders of the currently active machine.
|
## Adds the extruders of the currently active machine.
|
||||||
def _addCurrentMachineExtruders(self):
|
def _addCurrentMachineExtruders(self) -> None:
|
||||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if global_stack and global_stack.getBottom():
|
if global_stack and global_stack.getBottom():
|
||||||
self.addMachineExtruders(global_stack.getBottom(), global_stack.getId())
|
self.addMachineExtruders(global_stack.getBottom(), global_stack.getId())
|
||||||
|
|
||||||
@ -318,7 +324,7 @@ class ExtruderManager(QObject):
|
|||||||
# If no extruder has the value, the list will contain the global value.
|
# If no extruder has the value, the list will contain the global value.
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getExtruderValues(key):
|
def getExtruderValues(key):
|
||||||
global_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()):
|
for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()):
|
||||||
@ -327,7 +333,7 @@ class ExtruderManager(QObject):
|
|||||||
if not value:
|
if not value:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if isinstance(value, UM.Settings.SettingFunction):
|
if isinstance(value, SettingFunction):
|
||||||
value = value(extruder)
|
value = value(extruder)
|
||||||
|
|
||||||
result.append(value)
|
result.append(value)
|
||||||
@ -363,9 +369,9 @@ class ExtruderManager(QObject):
|
|||||||
|
|
||||||
if extruder:
|
if extruder:
|
||||||
value = extruder.getRawProperty(key, "value")
|
value = extruder.getRawProperty(key, "value")
|
||||||
if isinstance(value, UM.Settings.SettingFunction):
|
if isinstance(value, SettingFunction):
|
||||||
value = value(extruder)
|
value = value(extruder)
|
||||||
else: #Just a value from global.
|
else: #Just a value from global.
|
||||||
value = UM.Application.getInstance().getGlobalContainerStack().getProperty(key, "value")
|
value = Application.getInstance().getGlobalContainerStack().getProperty(key, "value")
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
@ -5,7 +5,7 @@ from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty
|
|||||||
|
|
||||||
import UM.Qt.ListModel
|
import UM.Qt.ListModel
|
||||||
|
|
||||||
from . import ExtruderManager
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
|
|
||||||
## Model that holds extruders.
|
## Model that holds extruders.
|
||||||
#
|
#
|
||||||
@ -100,7 +100,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||||||
self.clear()
|
self.clear()
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_container_stack = UM.Application.Application.getInstance().getGlobalContainerStack()
|
||||||
if global_container_stack:
|
if global_container_stack:
|
||||||
if self._add_global:
|
if self._add_global:
|
||||||
material = global_container_stack.findContainer({ "type": "material" })
|
material = global_container_stack.findContainer({ "type": "material" })
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Copyright (c) 2016 Ultimaker B.V.
|
# Copyright (c) 2016 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the AGPLv3 or higher.
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
@ -7,13 +8,14 @@ from PyQt5.QtWidgets import QMessageBox
|
|||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
from UM.Preferences import Preferences
|
from UM.Preferences import Preferences
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
from UM.Settings.SettingRelation import RelationType
|
from UM.Settings.SettingRelation import RelationType
|
||||||
|
from UM.Settings.ContainerStack import ContainerStack
|
||||||
import UM.Settings
|
from UM.Settings.Validator import ValidatorState
|
||||||
|
|
||||||
from cura.PrinterOutputDevice import PrinterOutputDevice
|
from cura.PrinterOutputDevice import PrinterOutputDevice
|
||||||
from . import ExtruderManager
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
@ -24,8 +26,8 @@ class MachineManager(QObject):
|
|||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self._active_container_stack = None
|
self._active_container_stack = None # type: ContainerStack
|
||||||
self._global_container_stack = None
|
self._global_container_stack = None # type: ContainerStack
|
||||||
|
|
||||||
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
||||||
## When the global container is changed, active material probably needs to be updated.
|
## When the global container is changed, active material probably needs to be updated.
|
||||||
@ -47,10 +49,10 @@ class MachineManager(QObject):
|
|||||||
self.globalValueChanged.connect(self.activeStackChanged)
|
self.globalValueChanged.connect(self.activeStackChanged)
|
||||||
ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeStackChanged)
|
ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeStackChanged)
|
||||||
|
|
||||||
self._empty_variant_container = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = "empty_variant")[0]
|
self._empty_variant_container = ContainerRegistry.getInstance().findInstanceContainers(id = "empty_variant")[0]
|
||||||
self._empty_material_container = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = "empty_material")[0]
|
self._empty_material_container = ContainerRegistry.getInstance().findInstanceContainers(id = "empty_material")[0]
|
||||||
self._empty_quality_container = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = "empty_quality")[0]
|
self._empty_quality_container = ContainerRegistry.getInstance().findInstanceContainers(id = "empty_quality")[0]
|
||||||
self._empty_quality_changes_container = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = "empty_quality_changes")[0]
|
self._empty_quality_changes_container = ContainerRegistry.getInstance().findInstanceContainers(id = "empty_quality_changes")[0]
|
||||||
|
|
||||||
Preferences.getInstance().addPreference("cura/active_machine", "")
|
Preferences.getInstance().addPreference("cura/active_machine", "")
|
||||||
|
|
||||||
@ -84,7 +86,7 @@ class MachineManager(QObject):
|
|||||||
|
|
||||||
outputDevicesChanged = pyqtSignal()
|
outputDevicesChanged = pyqtSignal()
|
||||||
|
|
||||||
def _onOutputDevicesChanged(self):
|
def _onOutputDevicesChanged(self) -> None:
|
||||||
for printer_output_device in self._printer_output_devices:
|
for printer_output_device in self._printer_output_devices:
|
||||||
printer_output_device.hotendIdChanged.disconnect(self._onHotendIdChanged)
|
printer_output_device.hotendIdChanged.disconnect(self._onHotendIdChanged)
|
||||||
printer_output_device.materialIdChanged.disconnect(self._onMaterialIdChanged)
|
printer_output_device.materialIdChanged.disconnect(self._onMaterialIdChanged)
|
||||||
@ -103,14 +105,15 @@ class MachineManager(QObject):
|
|||||||
def printerOutputDevices(self):
|
def printerOutputDevices(self):
|
||||||
return self._printer_output_devices
|
return self._printer_output_devices
|
||||||
|
|
||||||
def _onHotendIdChanged(self, index, hotend_id):
|
def _onHotendIdChanged(self, index: Union[str,int], hotend_id: str) -> None:
|
||||||
if not self._global_container_stack:
|
if not self._global_container_stack:
|
||||||
return
|
return
|
||||||
|
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type="variant", definition=self._global_container_stack.getBottom().getId(), name=hotend_id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(type="variant", definition=self._global_container_stack.getBottom().getId(), name=hotend_id)
|
||||||
if containers: # New material ID is known
|
if containers: # New material ID is known
|
||||||
extruder_manager = ExtruderManager.getInstance()
|
extruder_manager = ExtruderManager.getInstance()
|
||||||
extruders = list(extruder_manager.getMachineExtruders(self.activeMachineId))
|
machine_id = self.activeMachineId
|
||||||
|
extruders = extruder_manager.getMachineExtruders(machine_id)
|
||||||
matching_extruder = None
|
matching_extruder = None
|
||||||
for extruder in extruders:
|
for extruder in extruders:
|
||||||
if str(index) == extruder.getMetaDataEntry("position"):
|
if str(index) == extruder.getMetaDataEntry("position"):
|
||||||
@ -147,7 +150,7 @@ class MachineManager(QObject):
|
|||||||
if self._global_container_stack.getMetaDataEntry("has_machine_materials", False):
|
if self._global_container_stack.getMetaDataEntry("has_machine_materials", False):
|
||||||
definition_id = self._global_container_stack.getBottom().getId()
|
definition_id = self._global_container_stack.getBottom().getId()
|
||||||
extruder_manager = ExtruderManager.getInstance()
|
extruder_manager = ExtruderManager.getInstance()
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "material", definition = definition_id, GUID = material_id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(type = "material", definition = definition_id, GUID = material_id)
|
||||||
if containers: # New material ID is known
|
if containers: # New material ID is known
|
||||||
extruders = list(extruder_manager.getMachineExtruders(self.activeMachineId))
|
extruders = list(extruder_manager.getMachineExtruders(self.activeMachineId))
|
||||||
matching_extruder = None
|
matching_extruder = None
|
||||||
@ -262,7 +265,7 @@ class MachineManager(QObject):
|
|||||||
changed_validation_state = self._active_container_stack.getProperty(key, property_name)
|
changed_validation_state = self._active_container_stack.getProperty(key, property_name)
|
||||||
else:
|
else:
|
||||||
changed_validation_state = self._global_container_stack.getProperty(key, property_name)
|
changed_validation_state = self._global_container_stack.getProperty(key, property_name)
|
||||||
if changed_validation_state in (UM.Settings.ValidatorState.Exception, UM.Settings.ValidatorState.MaximumError, UM.Settings.ValidatorState.MinimumError):
|
if changed_validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
|
||||||
self._active_stack_valid = False
|
self._active_stack_valid = False
|
||||||
self.activeValidationChanged.emit()
|
self.activeValidationChanged.emit()
|
||||||
else:
|
else:
|
||||||
@ -273,19 +276,19 @@ class MachineManager(QObject):
|
|||||||
self.activeStackChanged.emit()
|
self.activeStackChanged.emit()
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveMachine(self, stack_id):
|
def setActiveMachine(self, stack_id: str) -> None:
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = stack_id)
|
containers = ContainerRegistry.getInstance().findContainerStacks(id = stack_id)
|
||||||
if containers:
|
if containers:
|
||||||
Application.getInstance().setGlobalContainerStack(containers[0])
|
Application.getInstance().setGlobalContainerStack(containers[0])
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def addMachine(self, name, definition_id):
|
def addMachine(self, name: str, definition_id: str) -> None:
|
||||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
definitions = container_registry.findDefinitionContainers(id = definition_id)
|
definitions = container_registry.findDefinitionContainers(id = definition_id)
|
||||||
if definitions:
|
if definitions:
|
||||||
definition = definitions[0]
|
definition = definitions[0]
|
||||||
name = self._createUniqueName("machine", "", name, definition.getName())
|
name = self._createUniqueName("machine", "", name, definition.getName())
|
||||||
new_global_stack = UM.Settings.ContainerStack(name)
|
new_global_stack = ContainerStack(name)
|
||||||
new_global_stack.addMetaDataEntry("type", "machine")
|
new_global_stack.addMetaDataEntry("type", "machine")
|
||||||
container_registry.addContainer(new_global_stack)
|
container_registry.addContainer(new_global_stack)
|
||||||
|
|
||||||
@ -293,7 +296,7 @@ class MachineManager(QObject):
|
|||||||
material_instance_container = self._updateMaterialContainer(definition, variant_instance_container)
|
material_instance_container = self._updateMaterialContainer(definition, variant_instance_container)
|
||||||
quality_instance_container = self._updateQualityContainer(definition, variant_instance_container, material_instance_container)
|
quality_instance_container = self._updateQualityContainer(definition, variant_instance_container, material_instance_container)
|
||||||
|
|
||||||
current_settings_instance_container = UM.Settings.InstanceContainer(name + "_current_settings")
|
current_settings_instance_container = InstanceContainer(name + "_current_settings")
|
||||||
current_settings_instance_container.addMetaDataEntry("machine", name)
|
current_settings_instance_container.addMetaDataEntry("machine", name)
|
||||||
current_settings_instance_container.addMetaDataEntry("type", "user")
|
current_settings_instance_container.addMetaDataEntry("type", "user")
|
||||||
current_settings_instance_container.setDefinition(definitions[0])
|
current_settings_instance_container.setDefinition(definitions[0])
|
||||||
@ -321,8 +324,9 @@ class MachineManager(QObject):
|
|||||||
# \param new_name \type{string} Base name, which may not be unique
|
# \param new_name \type{string} Base name, which may not be unique
|
||||||
# \param fallback_name \type{string} Name to use when (stripped) new_name is empty
|
# \param fallback_name \type{string} Name to use when (stripped) new_name is empty
|
||||||
# \return \type{string} Name that is unique for the specified type and name/id
|
# \return \type{string} Name that is unique for the specified type and name/id
|
||||||
def _createUniqueName(self, container_type, current_name, new_name, fallback_name):
|
def _createUniqueName(self, container_type: str, current_name: str, new_name: str, fallback_name: str) -> str:
|
||||||
return UM.Settings.ContainerRegistry.getInstance().createUniqueName(container_type, current_name, new_name, fallback_name)
|
Logger.log('d', str(ContainerRegistry.getInstance()))
|
||||||
|
return ContainerRegistry.getInstance().createUniqueName(container_type, current_name, new_name, fallback_name)
|
||||||
|
|
||||||
## Convenience function to check if a stack has errors.
|
## Convenience function to check if a stack has errors.
|
||||||
def _checkStackForErrors(self, stack):
|
def _checkStackForErrors(self, stack):
|
||||||
@ -331,7 +335,7 @@ class MachineManager(QObject):
|
|||||||
|
|
||||||
for key in stack.getAllKeys():
|
for key in stack.getAllKeys():
|
||||||
validation_state = stack.getProperty(key, "validationState")
|
validation_state = stack.getProperty(key, "validationState")
|
||||||
if validation_state in (UM.Settings.ValidatorState.Exception, UM.Settings.ValidatorState.MaximumError, UM.Settings.ValidatorState.MinimumError):
|
if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -364,39 +368,39 @@ class MachineManager(QObject):
|
|||||||
# Note that the _active_stack_valid is cached due to performance issues
|
# Note that the _active_stack_valid is cached due to performance issues
|
||||||
# Calling _checkStackForErrors on every change is simply too expensive
|
# Calling _checkStackForErrors on every change is simply too expensive
|
||||||
@pyqtProperty(bool, notify = activeValidationChanged)
|
@pyqtProperty(bool, notify = activeValidationChanged)
|
||||||
def isActiveStackValid(self):
|
def isActiveStackValid(self) -> bool:
|
||||||
return bool(self._active_stack_valid)
|
return bool(self._active_stack_valid)
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeStackChanged)
|
@pyqtProperty(str, notify = activeStackChanged)
|
||||||
def activeUserProfileId(self):
|
def activeUserProfileId(self) -> str:
|
||||||
if self._active_container_stack:
|
if self._active_container_stack:
|
||||||
return self._active_container_stack.getTop().getId()
|
return self._active_container_stack.getTop().getId()
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify = globalContainerChanged)
|
@pyqtProperty(str, notify = globalContainerChanged)
|
||||||
def activeMachineName(self):
|
def activeMachineName(self) -> str:
|
||||||
if self._global_container_stack:
|
if self._global_container_stack:
|
||||||
return self._global_container_stack.getName()
|
return self._global_container_stack.getName()
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify = globalContainerChanged)
|
@pyqtProperty(str, notify = globalContainerChanged)
|
||||||
def activeMachineId(self):
|
def activeMachineId(self) -> str:
|
||||||
if self._global_container_stack:
|
if self._global_container_stack:
|
||||||
return self._global_container_stack.getId()
|
return self._global_container_stack.getId()
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeStackChanged)
|
@pyqtProperty(str, notify = activeStackChanged)
|
||||||
def activeStackId(self):
|
def activeStackId(self) -> str:
|
||||||
if self._active_container_stack:
|
if self._active_container_stack:
|
||||||
return self._active_container_stack.getId()
|
return self._active_container_stack.getId()
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeMaterialChanged)
|
@pyqtProperty(str, notify = activeMaterialChanged)
|
||||||
def activeMaterialName(self):
|
def activeMaterialName(self) -> str:
|
||||||
if self._active_container_stack:
|
if self._active_container_stack:
|
||||||
material = self._active_container_stack.findContainer({"type":"material"})
|
material = self._active_container_stack.findContainer({"type":"material"})
|
||||||
if material:
|
if material:
|
||||||
@ -405,7 +409,7 @@ class MachineManager(QObject):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify=activeMaterialChanged)
|
@pyqtProperty(str, notify=activeMaterialChanged)
|
||||||
def activeMaterialId(self):
|
def activeMaterialId(self) -> str:
|
||||||
if self._active_container_stack:
|
if self._active_container_stack:
|
||||||
material = self._active_container_stack.findContainer({"type": "material"})
|
material = self._active_container_stack.findContainer({"type": "material"})
|
||||||
if material:
|
if material:
|
||||||
@ -430,7 +434,7 @@ class MachineManager(QObject):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@pyqtProperty(str, notify=activeQualityChanged)
|
@pyqtProperty(str, notify=activeQualityChanged)
|
||||||
def activeQualityMaterialId(self):
|
def activeQualityMaterialId(self) -> str:
|
||||||
if self._active_container_stack:
|
if self._active_container_stack:
|
||||||
quality = self._active_container_stack.findContainer({"type": "quality"})
|
quality = self._active_container_stack.findContainer({"type": "quality"})
|
||||||
if quality:
|
if quality:
|
||||||
@ -478,8 +482,8 @@ class MachineManager(QObject):
|
|||||||
|
|
||||||
## Check if a container is read_only
|
## Check if a container is read_only
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def isReadOnly(self, container_id):
|
def isReadOnly(self, container_id) -> bool:
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
||||||
if not containers or not self._active_container_stack:
|
if not containers or not self._active_container_stack:
|
||||||
return True
|
return True
|
||||||
return containers[0].isReadOnly()
|
return containers[0].isReadOnly()
|
||||||
@ -499,7 +503,7 @@ class MachineManager(QObject):
|
|||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveMaterial(self, material_id):
|
def setActiveMaterial(self, material_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = material_id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(id = material_id)
|
||||||
if not containers or not self._active_container_stack:
|
if not containers or not self._active_container_stack:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -532,7 +536,7 @@ class MachineManager(QObject):
|
|||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveVariant(self, variant_id):
|
def setActiveVariant(self, variant_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = variant_id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(id = variant_id)
|
||||||
if not containers or not self._active_container_stack:
|
if not containers or not self._active_container_stack:
|
||||||
return
|
return
|
||||||
old_variant = self._active_container_stack.findContainer({"type": "variant"})
|
old_variant = self._active_container_stack.findContainer({"type": "variant"})
|
||||||
@ -541,7 +545,6 @@ class MachineManager(QObject):
|
|||||||
variant_index = self._active_container_stack.getContainerIndex(old_variant)
|
variant_index = self._active_container_stack.getContainerIndex(old_variant)
|
||||||
self._active_container_stack.replaceContainer(variant_index, containers[0])
|
self._active_container_stack.replaceContainer(variant_index, containers[0])
|
||||||
|
|
||||||
preferred_material = None
|
|
||||||
if old_material:
|
if old_material:
|
||||||
preferred_material_name = old_material.getName()
|
preferred_material_name = old_material.getName()
|
||||||
self.setActiveMaterial(self._updateMaterialContainer(self._global_container_stack.getBottom(), containers[0], preferred_material_name).id)
|
self.setActiveMaterial(self._updateMaterialContainer(self._global_container_stack.getBottom(), containers[0], preferred_material_name).id)
|
||||||
@ -550,7 +553,7 @@ class MachineManager(QObject):
|
|||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveQuality(self, quality_id):
|
def setActiveQuality(self, quality_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = quality_id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(id = quality_id)
|
||||||
if not containers or not self._global_container_stack:
|
if not containers or not self._global_container_stack:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -563,7 +566,7 @@ class MachineManager(QObject):
|
|||||||
quality_container = containers[0]
|
quality_container = containers[0]
|
||||||
elif container_type == "quality_changes":
|
elif container_type == "quality_changes":
|
||||||
quality_changes_container = containers[0]
|
quality_changes_container = containers[0]
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(
|
containers = ContainerRegistry.getInstance().findInstanceContainers(
|
||||||
quality_type = quality_changes_container.getMetaDataEntry("quality"))
|
quality_type = quality_changes_container.getMetaDataEntry("quality"))
|
||||||
if not containers:
|
if not containers:
|
||||||
Logger.log("e", "Could not find quality %s for changes %s, not changing quality", quality_changes_container.getMetaDataEntry("quality"), quality_changes_container.getId())
|
Logger.log("e", "Could not find quality %s for changes %s, not changing quality", quality_changes_container.getMetaDataEntry("quality"), quality_changes_container.getId())
|
||||||
@ -591,10 +594,10 @@ class MachineManager(QObject):
|
|||||||
else:
|
else:
|
||||||
criteria["definition"] = "fdmprinter"
|
criteria["definition"] = "fdmprinter"
|
||||||
|
|
||||||
stack_quality = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
stack_quality = ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||||
if not stack_quality:
|
if not stack_quality:
|
||||||
criteria.pop("extruder")
|
criteria.pop("extruder")
|
||||||
stack_quality = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
stack_quality = ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||||
if not stack_quality:
|
if not stack_quality:
|
||||||
stack_quality = quality_container
|
stack_quality = quality_container
|
||||||
else:
|
else:
|
||||||
@ -603,7 +606,7 @@ class MachineManager(QObject):
|
|||||||
stack_quality = stack_quality[0]
|
stack_quality = stack_quality[0]
|
||||||
|
|
||||||
if quality_changes_container != self._empty_quality_changes_container:
|
if quality_changes_container != self._empty_quality_changes_container:
|
||||||
stack_quality_changes = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(name = quality_changes_container.getName(), extruder = extruder_id)[0]
|
stack_quality_changes = ContainerRegistry.getInstance().findInstanceContainers(name = quality_changes_container.getName(), extruder = extruder_id)[0]
|
||||||
else:
|
else:
|
||||||
stack_quality_changes = self._empty_quality_changes_container
|
stack_quality_changes = self._empty_quality_changes_container
|
||||||
|
|
||||||
@ -683,7 +686,7 @@ class MachineManager(QObject):
|
|||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def renameMachine(self, machine_id, new_name):
|
def renameMachine(self, machine_id, new_name):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
containers = ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
||||||
if containers:
|
if containers:
|
||||||
new_name = self._createUniqueName("machine", containers[0].getName(), new_name, containers[0].getBottom().getName())
|
new_name = self._createUniqueName("machine", containers[0].getName(), new_name, containers[0].getBottom().getName())
|
||||||
containers[0].setName(new_name)
|
containers[0].setName(new_name)
|
||||||
@ -696,13 +699,13 @@ class MachineManager(QObject):
|
|||||||
|
|
||||||
ExtruderManager.getInstance().removeMachineExtruders(machine_id)
|
ExtruderManager.getInstance().removeMachineExtruders(machine_id)
|
||||||
|
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "user", machine = machine_id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(type = "user", machine = machine_id)
|
||||||
for container in containers:
|
for container in containers:
|
||||||
UM.Settings.ContainerRegistry.getInstance().removeContainer(container.getId())
|
ContainerRegistry.getInstance().removeContainer(container.getId())
|
||||||
UM.Settings.ContainerRegistry.getInstance().removeContainer(machine_id)
|
ContainerRegistry.getInstance().removeContainer(machine_id)
|
||||||
|
|
||||||
if activate_new_machine:
|
if activate_new_machine:
|
||||||
stacks = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(type = "machine")
|
stacks = ContainerRegistry.getInstance().findContainerStacks(type = "machine")
|
||||||
if stacks:
|
if stacks:
|
||||||
Application.getInstance().setGlobalContainerStack(stacks[0])
|
Application.getInstance().setGlobalContainerStack(stacks[0])
|
||||||
|
|
||||||
@ -743,7 +746,7 @@ class MachineManager(QObject):
|
|||||||
# \returns DefinitionID (string) if found, None otherwise
|
# \returns DefinitionID (string) if found, None otherwise
|
||||||
@pyqtSlot(str, result = str)
|
@pyqtSlot(str, result = str)
|
||||||
def getDefinitionByMachineId(self, machine_id):
|
def getDefinitionByMachineId(self, machine_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id=machine_id)
|
containers = ContainerRegistry.getInstance().findContainerStacks(id=machine_id)
|
||||||
if containers:
|
if containers:
|
||||||
return containers[0].getBottom().getId()
|
return containers[0].getBottom().getId()
|
||||||
|
|
||||||
@ -758,10 +761,10 @@ class MachineManager(QObject):
|
|||||||
containers = []
|
containers = []
|
||||||
preferred_variant = definition.getMetaDataEntry("preferred_variant")
|
preferred_variant = definition.getMetaDataEntry("preferred_variant")
|
||||||
if preferred_variant:
|
if preferred_variant:
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "variant", definition = definition.id, id = preferred_variant)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(type = "variant", definition = definition.id, id = preferred_variant)
|
||||||
|
|
||||||
if not containers:
|
if not containers:
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "variant", definition = definition.id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(type = "variant", definition = definition.id)
|
||||||
|
|
||||||
if containers:
|
if containers:
|
||||||
return containers[0]
|
return containers[0]
|
||||||
@ -789,7 +792,7 @@ class MachineManager(QObject):
|
|||||||
if preferred_material:
|
if preferred_material:
|
||||||
search_criteria["id"] = preferred_material
|
search_criteria["id"] = preferred_material
|
||||||
|
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||||
if containers:
|
if containers:
|
||||||
return containers[0]
|
return containers[0]
|
||||||
|
|
||||||
@ -798,14 +801,14 @@ class MachineManager(QObject):
|
|||||||
search_criteria.pop("name", None)
|
search_criteria.pop("name", None)
|
||||||
search_criteria.pop("id", None)
|
search_criteria.pop("id", None)
|
||||||
|
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||||
if containers:
|
if containers:
|
||||||
return containers[0]
|
return containers[0]
|
||||||
|
|
||||||
return self._empty_material_container
|
return self._empty_material_container
|
||||||
|
|
||||||
def _updateQualityContainer(self, definition, variant_container, material_container = None, preferred_quality_name = None):
|
def _updateQualityContainer(self, definition, variant_container, material_container = None, preferred_quality_name = None):
|
||||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
search_criteria = { "type": "quality" }
|
search_criteria = { "type": "quality" }
|
||||||
|
|
||||||
if definition.getMetaDataEntry("has_machine_quality"):
|
if definition.getMetaDataEntry("has_machine_quality"):
|
||||||
@ -870,7 +873,7 @@ class MachineManager(QObject):
|
|||||||
# \param preferred_quality_changes_name The name of the quality-changes to
|
# \param preferred_quality_changes_name The name of the quality-changes to
|
||||||
# pick, if any such quality-changes profile is available.
|
# pick, if any such quality-changes profile is available.
|
||||||
def _updateQualityChangesContainer(self, quality_type, preferred_quality_changes_name = None):
|
def _updateQualityChangesContainer(self, quality_type, preferred_quality_changes_name = None):
|
||||||
container_registry = UM.Settings.ContainerRegistry.getInstance() # Cache.
|
container_registry = ContainerRegistry.getInstance() # Cache.
|
||||||
search_criteria = { "type": "quality_changes" }
|
search_criteria = { "type": "quality_changes" }
|
||||||
|
|
||||||
search_criteria["quality"] = quality_type
|
search_criteria["quality"] = quality_type
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
# Copyright (c) 2016 Ultimaker B.V.
|
# Copyright (c) 2016 Ultimaker B.V.
|
||||||
# Uranium is released under the terms of the AGPLv3 or higher.
|
# Uranium is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
import UM.Settings.Models
|
from UM.Settings.Models.SettingVisibilityHandler import SettingVisibilityHandler
|
||||||
|
|
||||||
class MaterialSettingsVisibilityHandler(UM.Settings.Models.SettingVisibilityHandler):
|
class MaterialSettingsVisibilityHandler(SettingVisibilityHandler):
|
||||||
def __init__(self, parent = None, *args, **kwargs):
|
def __init__(self, parent = None, *args, **kwargs):
|
||||||
super().__init__(parent = parent, *args, **kwargs)
|
super().__init__(parent = parent, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -5,11 +5,10 @@ import collections
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, Qt
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, Qt
|
||||||
|
|
||||||
import UM.Application
|
|
||||||
import UM.Logger
|
import UM.Logger
|
||||||
import UM.Qt
|
import UM.Qt
|
||||||
import UM.Settings
|
from UM.Application import Application
|
||||||
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
|
||||||
class QualitySettingsModel(UM.Qt.ListModel.ListModel):
|
class QualitySettingsModel(UM.Qt.ListModel.ListModel):
|
||||||
KeyRole = Qt.UserRole + 1
|
KeyRole = Qt.UserRole + 1
|
||||||
@ -75,7 +74,7 @@ class QualitySettingsModel(UM.Qt.ListModel.ListModel):
|
|||||||
settings = collections.OrderedDict()
|
settings = collections.OrderedDict()
|
||||||
definition_container = UM.Application.getInstance().getGlobalContainerStack().getBottom()
|
definition_container = UM.Application.getInstance().getGlobalContainerStack().getBottom()
|
||||||
|
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = self._quality)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(id = self._quality)
|
||||||
if not containers:
|
if not containers:
|
||||||
UM.Logger.log("w", "Could not find a quality container with id %s", self._quality)
|
UM.Logger.log("w", "Could not find a quality container with id %s", self._quality)
|
||||||
return
|
return
|
||||||
@ -97,7 +96,7 @@ class QualitySettingsModel(UM.Qt.ListModel.ListModel):
|
|||||||
if self._material:
|
if self._material:
|
||||||
criteria["material"] = self._material
|
criteria["material"] = self._material
|
||||||
|
|
||||||
quality_container = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
quality_container = ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||||
if not quality_container:
|
if not quality_container:
|
||||||
UM.Logger.log("w", "Could not find a quality container matching quality changes %s", quality_changes_container.getId())
|
UM.Logger.log("w", "Could not find a quality container matching quality changes %s", quality_changes_container.getId())
|
||||||
return
|
return
|
||||||
@ -113,22 +112,22 @@ class QualitySettingsModel(UM.Qt.ListModel.ListModel):
|
|||||||
|
|
||||||
criteria["extruder"] = self._extruder_id
|
criteria["extruder"] = self._extruder_id
|
||||||
|
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||||
if not containers:
|
if not containers:
|
||||||
# Try again, this time without extruder
|
# Try again, this time without extruder
|
||||||
new_criteria = criteria.copy()
|
new_criteria = criteria.copy()
|
||||||
new_criteria.pop("extruder")
|
new_criteria.pop("extruder")
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**new_criteria)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(**new_criteria)
|
||||||
|
|
||||||
if not containers:
|
if not containers:
|
||||||
# Try again, this time without material
|
# Try again, this time without material
|
||||||
criteria.pop("material")
|
criteria.pop("material")
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||||
|
|
||||||
if not containers:
|
if not containers:
|
||||||
# Try again, this time without material or extruder
|
# Try again, this time without material or extruder
|
||||||
criteria.pop("extruder") # "material" has already been popped
|
criteria.pop("extruder") # "material" has already been popped
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||||
|
|
||||||
if not containers:
|
if not containers:
|
||||||
UM.Logger.log("Could not find any quality containers matching the search criteria %s" % str(criteria))
|
UM.Logger.log("Could not find any quality containers matching the search criteria %s" % str(criteria))
|
||||||
@ -136,7 +135,7 @@ class QualitySettingsModel(UM.Qt.ListModel.ListModel):
|
|||||||
|
|
||||||
if quality_changes_container:
|
if quality_changes_container:
|
||||||
criteria = {"type": "quality_changes", "quality": quality_type, "extruder": self._extruder_id, "definition": definition_id }
|
criteria = {"type": "quality_changes", "quality": quality_type, "extruder": self._extruder_id, "definition": definition_id }
|
||||||
changes = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
changes = ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||||
if changes:
|
if changes:
|
||||||
containers.extend(changes)
|
containers.extend(changes)
|
||||||
|
|
||||||
@ -154,9 +153,9 @@ class QualitySettingsModel(UM.Qt.ListModel.ListModel):
|
|||||||
|
|
||||||
user_value = None
|
user_value = None
|
||||||
if not self._extruder_id:
|
if not self._extruder_id:
|
||||||
user_value = UM.Application.getInstance().getGlobalContainerStack().getTop().getProperty(definition.key, "value")
|
user_value = Application.getInstance().getGlobalContainerStack().getTop().getProperty(definition.key, "value")
|
||||||
else:
|
else:
|
||||||
extruder_stack = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = self._extruder_id)
|
extruder_stack = ContainerRegistry.getInstance().findContainerStacks(id = self._extruder_id)
|
||||||
if extruder_stack:
|
if extruder_stack:
|
||||||
user_value = extruder_stack[0].getTop().getProperty(definition.key, "value")
|
user_value = extruder_stack[0].getTop().getProperty(definition.key, "value")
|
||||||
|
|
||||||
|
@ -1,13 +1,2 @@
|
|||||||
# Copyright (c) 2016 Ultimaker B.V.
|
# Copyright (c) 2016 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the AGPLv3 or higher.
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
from .MaterialSettingsVisibilityHandler import MaterialSettingsVisibilityHandler
|
|
||||||
from .ContainerManager import ContainerManager
|
|
||||||
from .ContainerSettingsModel import ContainerSettingsModel
|
|
||||||
from .CuraContainerRegistry import CuraContainerRegistry
|
|
||||||
from .ExtruderManager import ExtruderManager
|
|
||||||
from .ExtrudersModel import ExtrudersModel
|
|
||||||
from .MachineManager import MachineManager
|
|
||||||
from .MaterialSettingsVisibilityHandler import MaterialSettingsVisibilityHandler
|
|
||||||
from .SettingOverrideDecorator import SettingOverrideDecorator
|
|
||||||
from .QualitySettingsModel import QualitySettingsModel
|
|
||||||
|
@ -55,8 +55,5 @@ if Platform.isWindows() and hasattr(sys, "frozen"):
|
|||||||
sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w")
|
sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w")
|
||||||
sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w")
|
sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w")
|
||||||
|
|
||||||
# Force an instance of CuraContainerRegistry to be created and reused later.
|
|
||||||
cura.Settings.CuraContainerRegistry.getInstance()
|
|
||||||
|
|
||||||
app = cura.CuraApplication.CuraApplication.getInstance()
|
app = cura.CuraApplication.CuraApplication.getInstance()
|
||||||
app.run()
|
app.run()
|
||||||
|
@ -82,7 +82,7 @@ class CuraEngineBackend(Backend):
|
|||||||
self._onGlobalStackChanged()
|
self._onGlobalStackChanged()
|
||||||
|
|
||||||
self._active_extruder_stack = None
|
self._active_extruder_stack = None
|
||||||
cura.Settings.ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)
|
cura.Settings.ExtruderManager.ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)
|
||||||
self._onActiveExtruderChanged()
|
self._onActiveExtruderChanged()
|
||||||
|
|
||||||
# When you update a setting and other settings get changed through inheritance, many propertyChanged signals are fired.
|
# When you update a setting and other settings get changed through inheritance, many propertyChanged signals are fired.
|
||||||
@ -449,7 +449,7 @@ class CuraEngineBackend(Backend):
|
|||||||
if self._active_extruder_stack:
|
if self._active_extruder_stack:
|
||||||
self._active_extruder_stack.containersChanged.disconnect(self._onChanged)
|
self._active_extruder_stack.containersChanged.disconnect(self._onChanged)
|
||||||
|
|
||||||
self._active_extruder_stack = cura.Settings.ExtruderManager.getInstance().getActiveExtruderStack()
|
self._active_extruder_stack = cura.Settings.ExtruderManager.ExtruderManager.getInstance().getActiveExtruderStack()
|
||||||
if self._active_extruder_stack:
|
if self._active_extruder_stack:
|
||||||
self._active_extruder_stack.containersChanged.connect(self._onChanged)
|
self._active_extruder_stack.containersChanged.connect(self._onChanged)
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import cura.Settings.CuraContainerRegistry
|
|||||||
import UM.Application
|
import UM.Application
|
||||||
import UM.Settings.InstanceContainer
|
import UM.Settings.InstanceContainer
|
||||||
import UM.Settings.DefinitionContainer
|
import UM.Settings.DefinitionContainer
|
||||||
import UM.Logger
|
from UM.Logger import Logger
|
||||||
|
|
||||||
import UM.i18n
|
import UM.i18n
|
||||||
catalog = UM.i18n.i18nCatalog("cura")
|
catalog = UM.i18n.i18nCatalog("cura")
|
||||||
@ -19,10 +19,10 @@ class MachineSettingsAction(MachineAction):
|
|||||||
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
||||||
self._qml_url = "MachineSettingsAction.qml"
|
self._qml_url = "MachineSettingsAction.qml"
|
||||||
|
|
||||||
cura.Settings.CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
|
cura.Settings.CuraContainerRegistry.CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
|
||||||
|
|
||||||
def _reset(self):
|
def _reset(self):
|
||||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_container_stack = UM.Application.Application.getInstance().getGlobalContainerStack()
|
||||||
if global_container_stack:
|
if global_container_stack:
|
||||||
variant = global_container_stack.findContainer({"type": "variant"})
|
variant = global_container_stack.findContainer({"type": "variant"})
|
||||||
if variant and variant.getId() == "empty_variant":
|
if variant and variant.getId() == "empty_variant":
|
||||||
@ -39,28 +39,28 @@ class MachineSettingsAction(MachineAction):
|
|||||||
|
|
||||||
def _onContainerAdded(self, container):
|
def _onContainerAdded(self, container):
|
||||||
# Add this action as a supported action to all machine definitions
|
# Add this action as a supported action to all machine definitions
|
||||||
if isinstance(container, UM.Settings.DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
|
if isinstance(container, UM.Settings.DefinitionContainer.DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
|
||||||
if container.getProperty("machine_extruder_count", "value") > 1:
|
if container.getProperty("machine_extruder_count", "value") > 1:
|
||||||
# Multiextruder printers are not currently supported
|
# Multiextruder printers are not currently supported
|
||||||
UM.Logger.log("d", "Not attaching MachineSettingsAction to %s; Multi-extrusion printers are not supported", container.getId())
|
Logger.log("d", "Not attaching MachineSettingsAction to %s; Multi-extrusion printers are not supported", container.getId())
|
||||||
return
|
return
|
||||||
if container.getMetaDataEntry("has_variants", False):
|
if container.getMetaDataEntry("has_variants", False):
|
||||||
# Machines that use variants are not currently supported
|
# Machines that use variants are not currently supported
|
||||||
UM.Logger.log("d", "Not attaching MachineSettingsAction to %s; Machines that use variants are not supported", container.getId())
|
Logger.log("d", "Not attaching MachineSettingsAction to %s; Machines that use variants are not supported", container.getId())
|
||||||
return
|
return
|
||||||
|
|
||||||
UM.Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
UM.Application.Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def forceUpdate(self):
|
def forceUpdate(self):
|
||||||
# Force rebuilding the build volume by reloading the global container stack.
|
# Force rebuilding the build volume by reloading the global container stack.
|
||||||
# This is a bit of a hack, but it seems quick enough.
|
# This is a bit of a hack, but it seems quick enough.
|
||||||
UM.Application.getInstance().globalContainerStackChanged.emit()
|
UM.Application.Application.getInstance().globalContainerStackChanged.emit()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def updateHasMaterialsMetadata(self):
|
def updateHasMaterialsMetadata(self):
|
||||||
# Updates the has_materials metadata flag after switching gcode flavor
|
# Updates the has_materials metadata flag after switching gcode flavor
|
||||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
global_container_stack = UM.Application.Application.getInstance().getGlobalContainerStack()
|
||||||
if global_container_stack:
|
if global_container_stack:
|
||||||
definition = global_container_stack.getBottom()
|
definition = global_container_stack.getBottom()
|
||||||
if definition.getProperty("machine_gcode_flavor", "value") == "UltiGCode" and not definition.getMetaDataEntry("has_materials", False):
|
if definition.getProperty("machine_gcode_flavor", "value") == "UltiGCode" and not definition.getMetaDataEntry("has_materials", False):
|
||||||
|
@ -6,14 +6,14 @@ from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
|
|||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
from UM.Settings.SettingInstance import SettingInstance
|
from UM.Settings.SettingInstance import SettingInstance
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
import UM.Settings.Models
|
import UM.Settings.Models.SettingVisibilityHandler
|
||||||
|
|
||||||
from cura.Settings.ExtruderManager import ExtruderManager #To get global-inherits-stack setting values from different extruders.
|
from cura.Settings.ExtruderManager import ExtruderManager #To get global-inherits-stack setting values from different extruders.
|
||||||
from cura.Settings.SettingOverrideDecorator import SettingOverrideDecorator
|
from cura.Settings.SettingOverrideDecorator import SettingOverrideDecorator
|
||||||
|
|
||||||
## The per object setting visibility handler ensures that only setting
|
## The per object setting visibility handler ensures that only setting
|
||||||
# definitions that have a matching instance Container are returned as visible.
|
# definitions that have a matching instance Container are returned as visible.
|
||||||
class PerObjectSettingVisibilityHandler(UM.Settings.Models.SettingVisibilityHandler):
|
class PerObjectSettingVisibilityHandler(UM.Settings.Models.SettingVisibilityHandler.SettingVisibilityHandler):
|
||||||
def __init__(self, parent = None, *args, **kwargs):
|
def __init__(self, parent = None, *args, **kwargs):
|
||||||
super().__init__(parent = parent, *args, **kwargs)
|
super().__init__(parent = parent, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ from UM.Settings.Validator import ValidatorState
|
|||||||
from UM.View.GL.OpenGL import OpenGL
|
from UM.View.GL.OpenGL import OpenGL
|
||||||
|
|
||||||
import cura.Settings
|
import cura.Settings
|
||||||
|
import cura.Settings.ExtrudersModel
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ class SolidView(View):
|
|||||||
self._enabled_shader = None
|
self._enabled_shader = None
|
||||||
self._disabled_shader = None
|
self._disabled_shader = None
|
||||||
|
|
||||||
self._extruders_model = cura.Settings.ExtrudersModel()
|
self._extruders_model = cura.Settings.ExtrudersModel.ExtrudersModel()
|
||||||
|
|
||||||
def beginRendering(self):
|
def beginRendering(self):
|
||||||
scene = self.getController().getScene()
|
scene = self.getController().getScene()
|
||||||
|
@ -25,7 +25,7 @@ class Profile:
|
|||||||
#
|
#
|
||||||
# \param serialised A string with the contents of a profile.
|
# \param serialised A string with the contents of a profile.
|
||||||
# \param filename The supposed filename of the profile, without extension.
|
# \param filename The supposed filename of the profile, without extension.
|
||||||
def __init__(self, serialised, filename):
|
def __init__(self, serialised: str, filename: str):
|
||||||
self._filename = filename
|
self._filename = filename
|
||||||
|
|
||||||
parser = configparser.ConfigParser(interpolation = None)
|
parser = configparser.ConfigParser(interpolation = None)
|
||||||
|
@ -11,11 +11,11 @@ from UM.Logger import Logger
|
|||||||
from UM.Util import parseBool
|
from UM.Util import parseBool
|
||||||
|
|
||||||
import UM.Dictionary
|
import UM.Dictionary
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
import UM.Settings
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
|
||||||
## Handles serializing and deserializing material containers from an XML file
|
## Handles serializing and deserializing material containers from an XML file
|
||||||
class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
class XmlMaterialProfile(InstanceContainer):
|
||||||
def __init__(self, container_id, *args, **kwargs):
|
def __init__(self, container_id, *args, **kwargs):
|
||||||
super().__init__(container_id, *args, **kwargs)
|
super().__init__(container_id, *args, **kwargs)
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
base_file = self.getMetaDataEntry("base_file", None)
|
base_file = self.getMetaDataEntry("base_file", None)
|
||||||
|
|
||||||
if base_file != self.id:
|
if base_file != self.id:
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = base_file)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(id = base_file)
|
||||||
if containers:
|
if containers:
|
||||||
new_basefile = containers[0].duplicate(self.getMetaDataEntry("brand") + "_" + new_id, new_name)
|
new_basefile = containers[0].duplicate(self.getMetaDataEntry("brand") + "_" + new_id, new_name)
|
||||||
base_file = new_basefile.id
|
base_file = new_basefile.id
|
||||||
@ -33,14 +33,14 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
new_id = self.getMetaDataEntry("brand") + "_" + new_id + "_" + self.getDefinition().getId()
|
new_id = self.getMetaDataEntry("brand") + "_" + new_id + "_" + self.getDefinition().getId()
|
||||||
variant = self.getMetaDataEntry("variant")
|
variant = self.getMetaDataEntry("variant")
|
||||||
if variant:
|
if variant:
|
||||||
variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = variant)
|
variant_containers = ContainerRegistry.getInstance().findInstanceContainers(id = variant)
|
||||||
if variant_containers:
|
if variant_containers:
|
||||||
new_id += "_" + variant_containers[0].getName().replace(" ", "_")
|
new_id += "_" + variant_containers[0].getName().replace(" ", "_")
|
||||||
has_base_file = True
|
has_base_file = True
|
||||||
else:
|
else:
|
||||||
has_base_file = False
|
has_base_file = False
|
||||||
|
|
||||||
new_id = UM.Settings.ContainerRegistry.getInstance().createUniqueName("material", self._id, new_id, "")
|
new_id = ContainerRegistry.getInstance().createUniqueName("material", self._id, new_id, "")
|
||||||
result = super().duplicate(new_id, new_name)
|
result = super().duplicate(new_id, new_name)
|
||||||
if has_base_file:
|
if has_base_file:
|
||||||
result.setMetaDataEntry("base_file", base_file)
|
result.setMetaDataEntry("base_file", base_file)
|
||||||
@ -53,7 +53,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
super().setReadOnly(read_only)
|
super().setReadOnly(read_only)
|
||||||
|
|
||||||
basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is none, this is a basefile.
|
basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is none, this is a basefile.
|
||||||
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
for container in ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
||||||
container._read_only = read_only
|
container._read_only = read_only
|
||||||
|
|
||||||
## Overridden from InstanceContainer
|
## Overridden from InstanceContainer
|
||||||
@ -65,7 +65,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
|
|
||||||
basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is none, this is a basefile.
|
basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is none, this is a basefile.
|
||||||
# Update all containers that share GUID and basefile
|
# Update all containers that share GUID and basefile
|
||||||
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
for container in ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
||||||
container.setMetaData(copy.deepcopy(self._metadata))
|
container.setMetaData(copy.deepcopy(self._metadata))
|
||||||
|
|
||||||
## Overridden from InstanceContainer, similar to setMetaDataEntry.
|
## Overridden from InstanceContainer, similar to setMetaDataEntry.
|
||||||
@ -84,7 +84,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
basefile = self.getMetaDataEntry("base_file", self._id) # if basefile is none, this is a basefile.
|
basefile = self.getMetaDataEntry("base_file", self._id) # if basefile is none, this is a basefile.
|
||||||
# Update the basefile as well, this is actually what we're trying to do
|
# Update the basefile as well, this is actually what we're trying to do
|
||||||
# Update all containers that share GUID and basefile
|
# Update all containers that share GUID and basefile
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile)
|
||||||
for container in containers:
|
for container in containers:
|
||||||
container.setName(new_name)
|
container.setName(new_name)
|
||||||
|
|
||||||
@ -96,12 +96,12 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
super().setProperty(key, property_name, property_value)
|
super().setProperty(key, property_name, property_value)
|
||||||
|
|
||||||
basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is none, this is a basefile.
|
basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is none, this is a basefile.
|
||||||
for container in UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
for container in ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
||||||
container._dirty = True
|
container._dirty = True
|
||||||
|
|
||||||
## Overridden from InstanceContainer
|
## Overridden from InstanceContainer
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
registry = UM.Settings.ContainerRegistry.getInstance()
|
registry = ContainerRegistry.getInstance()
|
||||||
|
|
||||||
base_file = self.getMetaDataEntry("base_file", "")
|
base_file = self.getMetaDataEntry("base_file", "")
|
||||||
if base_file and self.id != base_file:
|
if base_file and self.id != base_file:
|
||||||
@ -296,7 +296,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
|
|
||||||
self.addMetaDataEntry("properties", property_values)
|
self.addMetaDataEntry("properties", property_values)
|
||||||
|
|
||||||
self.setDefinition(UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0])
|
self.setDefinition(ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0])
|
||||||
|
|
||||||
global_compatibility = True
|
global_compatibility = True
|
||||||
global_setting_values = {}
|
global_setting_values = {}
|
||||||
@ -336,7 +336,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
Logger.log("w", "Cannot create material for unknown machine %s", identifier.get("product"))
|
Logger.log("w", "Cannot create material for unknown machine %s", identifier.get("product"))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = machine_id)
|
definitions = ContainerRegistry.getInstance().findDefinitionContainers(id = machine_id)
|
||||||
if not definitions:
|
if not definitions:
|
||||||
Logger.log("w", "No definition found for machine ID %s", machine_id)
|
Logger.log("w", "No definition found for machine ID %s", machine_id)
|
||||||
continue
|
continue
|
||||||
@ -357,7 +357,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
|
|
||||||
new_material._dirty = False
|
new_material._dirty = False
|
||||||
|
|
||||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_material)
|
ContainerRegistry.getInstance().addContainer(new_material)
|
||||||
|
|
||||||
hotends = machine.iterfind("./um:hotend", self.__namespaces)
|
hotends = machine.iterfind("./um:hotend", self.__namespaces)
|
||||||
for hotend in hotends:
|
for hotend in hotends:
|
||||||
@ -365,10 +365,10 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
if hotend_id is None:
|
if hotend_id is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = hotend_id)
|
variant_containers = ContainerRegistry.getInstance().findInstanceContainers(id = hotend_id)
|
||||||
if not variant_containers:
|
if not variant_containers:
|
||||||
# It is not really properly defined what "ID" is so also search for variants by name.
|
# It is not really properly defined what "ID" is so also search for variants by name.
|
||||||
variant_containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(definition = definition.id, name = hotend_id)
|
variant_containers = ContainerRegistry.getInstance().findInstanceContainers(definition = definition.id, name = hotend_id)
|
||||||
|
|
||||||
if not variant_containers:
|
if not variant_containers:
|
||||||
Logger.log("d", "No variants found with ID or name %s for machine %s", hotend_id, definition.id)
|
Logger.log("d", "No variants found with ID or name %s for machine %s", hotend_id, definition.id)
|
||||||
@ -406,7 +406,7 @@ class XmlMaterialProfile(UM.Settings.InstanceContainer):
|
|||||||
new_hotend_material.setProperty(key, "value", value, definition)
|
new_hotend_material.setProperty(key, "value", value, definition)
|
||||||
|
|
||||||
new_hotend_material._dirty = False
|
new_hotend_material._dirty = False
|
||||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_hotend_material)
|
ContainerRegistry.getInstance().addContainer(new_hotend_material)
|
||||||
|
|
||||||
if not global_compatibility:
|
if not global_compatibility:
|
||||||
# Change the type of this container so it is not shown as an option in menus.
|
# Change the type of this container so it is not shown as an option in menus.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user