mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-07 14:04:03 -06:00
Merge branch 'master' of https://github.com/Ultimaker/Cura
This commit is contained in:
commit
6a2be5a34a
3 changed files with 79 additions and 43 deletions
|
@ -47,6 +47,7 @@ from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENU
|
|||
from PyQt5.QtGui import QColor, QIcon
|
||||
from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType
|
||||
|
||||
import ast #For literal eval of extruder setting types.
|
||||
import platform
|
||||
import sys
|
||||
import os.path
|
||||
|
@ -92,7 +93,7 @@ class CuraApplication(QtApplication):
|
|||
|
||||
# Need to do this before ContainerRegistry tries to load the machines
|
||||
SettingDefinition.addSupportedProperty("global_only", DefinitionPropertyType.Function, default = False)
|
||||
SettingDefinition.addSettingType("extruder", int, str, UM.Settings.Validator)
|
||||
SettingDefinition.addSettingType("extruder", str, ast.literal_eval, UM.Settings.Validator)
|
||||
|
||||
super().__init__(name = "cura", version = CuraVersion, buildtype = CuraBuildType)
|
||||
|
||||
|
|
|
@ -82,8 +82,7 @@ class ExtruderManager(QObject):
|
|||
if not position:
|
||||
UM.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.
|
||||
name = container_registry.uniqueName(extruder_definition.getId()) #Make a name based on the ID of the definition.
|
||||
self.createExtruderTrain(extruder_definition, machine_definition, name, position)
|
||||
self.createExtruderTrain(extruder_definition, machine_definition, position)
|
||||
|
||||
#Gets the extruder trains that we just created as well as any that still existed.
|
||||
extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = machine_definition.getId())
|
||||
|
@ -92,67 +91,97 @@ class ExtruderManager(QObject):
|
|||
if extruder_trains:
|
||||
self.extrudersChanged.emit(machine_definition)
|
||||
|
||||
def createExtruderTrain(self, extruder_definition, machine_definition, extruder_train_id, position):
|
||||
## Creates a container stack for an extruder train.
|
||||
#
|
||||
# The container stack has an extruder definition at the bottom, which is
|
||||
# linked to a machine definition. Then it has a nozzle profile, a material
|
||||
# profile, a quality profile and a user profile, in that order.
|
||||
#
|
||||
# The resulting container stack is added to the registry.
|
||||
#
|
||||
# \param extruder_definition The extruder to create the extruder train
|
||||
# for.
|
||||
# \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.
|
||||
def createExtruderTrain(self, extruder_definition, machine_definition, position):
|
||||
#Cache some things.
|
||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
||||
machine_id = machine_definition.getId()
|
||||
|
||||
#Create a container stack for this extruder.
|
||||
container_stack = UM.Settings.ContainerStack(extruder_train_id)
|
||||
extruder_stack_id = container_registry.uniqueName(extruder_definition.getId())
|
||||
container_stack = UM.Settings.ContainerStack(extruder_stack_id)
|
||||
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("machine", machine_definition.getId())
|
||||
container_stack.addMetaDataEntry("position", position)
|
||||
container_stack.addContainer(extruder_definition)
|
||||
|
||||
"""
|
||||
Yes, I'm committing this code which needs to be transformed to work later.
|
||||
#Find the nozzle to use for this extruder.
|
||||
nozzle = container_registry.getEmptyInstanceContainer()
|
||||
if definition.getMetaDataEntry("has_nozzles", default = "False") == "True":
|
||||
if len(self._nozzles) >= 1: #First add any extruder. Later, overwrite with preference if the preference is valid.
|
||||
self._nozzle = self._nozzles[0]
|
||||
preferred_nozzle_id = definition.getMetaDataEntry("preferred_nozzle")
|
||||
if machine_definition.getMetaDataEntry("has_nozzles", default = "False") == "True":
|
||||
#First add any nozzle. Later, overwrite with preference if the preference is valid.
|
||||
nozzles = container_registry.findInstanceContainers(machine = machine_id, type = "nozzle")
|
||||
if len(nozzles) >= 1:
|
||||
nozzle = nozzles[0]
|
||||
preferred_nozzle_id = machine_definition.getMetaDataEntry("preferred_nozzle")
|
||||
if preferred_nozzle_id:
|
||||
for nozzle in self._nozzles:
|
||||
if nozzle.getId() == preferred_nozzle_id:
|
||||
self._nozzle = nozzle
|
||||
break
|
||||
self._container_stack.addContainer(self._nozzle)
|
||||
preferred_nozzles = container_registry.findInstanceContainers(id = preferred_nozzle_id, type = "nozzle")
|
||||
if len(preferred_nozzles) >= 1:
|
||||
nozzle = preferred_nozzles[0]
|
||||
else:
|
||||
UM.Logger.log("w", "The preferred nozzle \"%s\" of machine %s doesn't exist or is not a nozzle profile.", preferred_nozzle_id, machine_id)
|
||||
#And leave it at the default nozzle.
|
||||
container_stack.addContainer(nozzle)
|
||||
|
||||
#Find a material to use for this nozzle.
|
||||
self._material = container_registry.getEmptyInstanceContainer()
|
||||
if self._definition.getMetaDataEntry("has_materials", default = "False") == "True":
|
||||
if self._definition.getMetaDataEntry("has_nozzle_materials", default = "False") == "True":
|
||||
all_materials = container_registry.findInstanceContainers(type = "material", nozzle = self._nozzle.getId())
|
||||
material = container_registry.getEmptyInstanceContainer()
|
||||
if machine_definition.getMetaDataEntry("has_materials", default = "False") == "True":
|
||||
#First add any material. Later, overwrite with preference if the preference is valid.
|
||||
if machine_definition.getMetaDataEntry("has_nozzle_materials", default = "False") == "True":
|
||||
materials = container_registry.findInstanceContainers(type = "material", machine = machine_id, nozzle = nozzle.getId())
|
||||
else:
|
||||
all_materials = container_registry.findInstanceContainers(type = "material")
|
||||
if len(all_materials) >= 1:
|
||||
self._material = all_materials[0]
|
||||
preferred_material_id = self._definition.getMetaDataEntry("preferred_material")
|
||||
materials = container_registry.findInstanceContainers(type = "material", machine = machine_id)
|
||||
if len(materials) >= 1:
|
||||
material = materials[0]
|
||||
preferred_material_id = machine_definition.getMetaDataEntry("preferred_material")
|
||||
if preferred_material_id:
|
||||
preferred_material = container_registry.findInstanceContainers(type = "material", id = preferred_material_id.lower())
|
||||
if len(preferred_material) >= 1:
|
||||
self._material = preferred_material[0]
|
||||
self._container_stack.addContainer(self._material)
|
||||
preferred_materials = container_registry.findInstanceContainers(id = preferred_material_id, type = "material")
|
||||
if len(preferred_materials) >= 1:
|
||||
material = preferred_materials[0]
|
||||
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)
|
||||
#And leave it at the default material.
|
||||
container_stack.addContainer(material)
|
||||
|
||||
#Find a quality to use for this extruder.
|
||||
self._quality = container_registry.getEmptyInstanceContainer()
|
||||
if self._definition.getMetaDataEntry("has_machine_quality"):
|
||||
all_qualities = container_registry.findInstanceContainers(type = "quality")
|
||||
if len(all_qualities) >= 1:
|
||||
self._quality = all_qualities[0]
|
||||
preferred_quality_id = self._definition.getMetaDataEntry("preferred_quality")
|
||||
quality = container_registry.getEmptyInstanceContainer()
|
||||
if machine_definition.getMetaDataEntry("has_machine_quality"):
|
||||
#First add any quality. Later, overwrite with preference if the preference is valid.
|
||||
qualities = container_registry.findInstanceContainers(type = "quality")
|
||||
if len(qualities) >= 1:
|
||||
quality = qualities[0]
|
||||
preferred_quality_id = machine_definition.getMetaDataEntry("preferred_quality")
|
||||
if preferred_quality_id:
|
||||
preferred_quality = container_registry.findInstanceContainers(type = "quality", id = preferred_quality_id.lower())
|
||||
preferred_quality = container_registry.findInstanceContainers(id = preferred_quality_id.lower(), type = "quality")
|
||||
if len(preferred_quality) >= 1:
|
||||
self._quality = preferred_quality[0]
|
||||
self._container_stack.addContainer(self._quality)
|
||||
"""
|
||||
quality = preferred_quality[0]
|
||||
else:
|
||||
UM.Logger.log("w", "The preferred quality \"%s\" of machine %s doesn't exist or is not a quality profile.", preferred_quality_id, machine_id)
|
||||
#And leave it at the default quality.
|
||||
container_stack.addContainer(quality)
|
||||
|
||||
#Add an empty user profile.
|
||||
user_profile = UM.Settings.InstanceContainer(extruder_train_id + "_current_settings")
|
||||
user_profile.addMetaDataEntry("type", "user")
|
||||
user_profile.setDefinition(machine_definition)
|
||||
user_profile = container_registry.findInstanceContainers(id = extruder_stack_id + "_current_settings")
|
||||
if user_profile: #There was already a user profile, loaded from settings.
|
||||
user_profile = user_profile[0]
|
||||
else:
|
||||
user_profile = UM.Settings.InstanceContainer(extruder_stack_id + "_current_settings") #Add an empty user profile.
|
||||
user_profile.addMetaDataEntry("type", "user")
|
||||
user_profile.setDefinition(machine_definition)
|
||||
container_registry.addContainer(user_profile)
|
||||
container_stack.addContainer(user_profile)
|
||||
container_registry.addContainer(user_profile)
|
||||
|
||||
container_stack.setNextStack(UM.Application.getInstance().getGlobalContainerStack())
|
||||
|
||||
|
|
|
@ -427,7 +427,13 @@ class MachineManagerModel(QObject):
|
|||
def removeMachine(self, machine_id):
|
||||
# If the machine that is being removed is the currently active machine, set another machine as the active machine
|
||||
activate_new_machine = (self._global_container_stack and self._global_container_stack.getId() == machine_id)
|
||||
|
||||
current_settings_id = machine_id + "_current_settings"
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = current_settings_id)
|
||||
for container in containers:
|
||||
UM.Settings.ContainerRegistry.getInstance().removeContainer(container.getId())
|
||||
UM.Settings.ContainerRegistry.getInstance().removeContainer(machine_id)
|
||||
|
||||
if activate_new_machine:
|
||||
stacks = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(type = "machine")
|
||||
if stacks:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue