mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 10:17:52 -06:00
WIP - CURA-4451
This commit is contained in:
parent
7bf854aa0f
commit
9b62b48509
3 changed files with 95 additions and 27 deletions
|
@ -178,12 +178,32 @@ class QualityManager:
|
|||
def findAllUsableQualitiesForMachineAndExtruders(self, global_container_stack: "GlobalStack", extruder_stacks: List["ExtruderStack"]) -> List[InstanceContainer]:
|
||||
global_machine_definition = global_container_stack.getBottom()
|
||||
|
||||
machine_manager = Application.getInstance().getMachineManager()
|
||||
active_stack_id = machine_manager.activeStackId
|
||||
|
||||
materials = []
|
||||
|
||||
# TODO: fix this
|
||||
if extruder_stacks:
|
||||
# Multi-extruder machine detected.
|
||||
materials = [stack.material for stack in extruder_stacks]
|
||||
# Multi-extruder machine detected
|
||||
for stack in extruder_stacks:
|
||||
if stack.getId() == active_stack_id and machine_manager.newMaterial:
|
||||
materials.append(machine_manager.newMaterial)
|
||||
else:
|
||||
materials.append(stack.material)
|
||||
else:
|
||||
# Machine with one extruder.
|
||||
materials = [global_container_stack.material]
|
||||
# Machine with one extruder
|
||||
if global_container_stack.getId() == active_stack_id and machine_manager.newMaterial:
|
||||
materials.append(machine_manager.newMaterial)
|
||||
else:
|
||||
materials.append(global_container_stack.material)
|
||||
|
||||
# if extruder_stacks:
|
||||
# # Multi-extruder machine detected.
|
||||
# materials = [stack.material for stack in extruder_stacks]
|
||||
# else:
|
||||
# # Machine with one extruder.
|
||||
# materials = [global_container_stack.material]
|
||||
|
||||
quality_types = self.findAllQualityTypesForMachineAndMaterials(global_machine_definition, materials)
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ class MachineManager(QObject):
|
|||
# Used to store the new containers until after confirming the dialog
|
||||
self._new_variant_container = None
|
||||
self._new_material_container = None
|
||||
self._new_quality_containers = []
|
||||
|
||||
self._error_check_timer = QTimer()
|
||||
self._error_check_timer.setInterval(250)
|
||||
|
@ -70,10 +71,10 @@ class MachineManager(QObject):
|
|||
|
||||
self._stacks_have_errors = None
|
||||
|
||||
self._empty_variant_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._empty_material_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._empty_quality_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._empty_quality_changes_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||
self._empty_variant_container = ContainerRegistry.getInstance().findContainers(id = "empty_variant")[0]
|
||||
self._empty_material_container = ContainerRegistry.getInstance().findContainers(id = "empty_material")[0]
|
||||
self._empty_quality_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality")[0]
|
||||
self._empty_quality_changes_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality_changes")[0]
|
||||
|
||||
self._onGlobalContainerChanged()
|
||||
|
||||
|
@ -147,6 +148,14 @@ class MachineManager(QObject):
|
|||
|
||||
self.outputDevicesChanged.emit()
|
||||
|
||||
@property
|
||||
def newVariant(self):
|
||||
return self._new_variant_container
|
||||
|
||||
@property
|
||||
def newMaterial(self):
|
||||
return self._new_material_container
|
||||
|
||||
@pyqtProperty("QVariantList", notify = outputDevicesChanged)
|
||||
def printerOutputDevices(self):
|
||||
return self._printer_output_devices
|
||||
|
@ -818,6 +827,7 @@ class MachineManager(QObject):
|
|||
if old_material:
|
||||
preferred_material_name = old_material.getName()
|
||||
preferred_material_id = self._updateMaterialContainer(self._global_container_stack.getBottom(), self._global_container_stack, containers[0], preferred_material_name).id
|
||||
Logger.log("d", "preferred_material_id=%s", preferred_material_id)
|
||||
self.setActiveMaterial(preferred_material_id)
|
||||
else:
|
||||
Logger.log("w", "While trying to set the active variant, no variant was found to replace.")
|
||||
|
@ -854,20 +864,20 @@ class MachineManager(QObject):
|
|||
if new_quality_settings_list is None:
|
||||
return
|
||||
|
||||
name_changed_connect_stacks = [] # Connect these stacks to the name changed callback
|
||||
self._new_quality_containers.clear()
|
||||
|
||||
for setting_info in new_quality_settings_list:
|
||||
stack = setting_info["stack"]
|
||||
stack_quality = setting_info["quality"]
|
||||
stack_quality_changes = setting_info["quality_changes"]
|
||||
|
||||
name_changed_connect_stacks.append(stack_quality)
|
||||
name_changed_connect_stacks.append(stack_quality_changes)
|
||||
self._replaceQualityOrQualityChangesInStack(stack, stack_quality, postpone_emit = True)
|
||||
self._replaceQualityOrQualityChangesInStack(stack, stack_quality_changes, postpone_emit = True)
|
||||
Logger.log("d", "=======================setting new quality=%s, %s", stack.getId(), stack_quality.getId())
|
||||
|
||||
# Connect to onQualityNameChanged
|
||||
for stack in name_changed_connect_stacks:
|
||||
stack.nameChanged.connect(self._onQualityNameChanged)
|
||||
self._new_quality_containers.append({
|
||||
"stack": stack,
|
||||
"quality": stack_quality,
|
||||
"quality_changes": stack_quality_changes
|
||||
})
|
||||
|
||||
has_user_interaction = False
|
||||
|
||||
|
@ -890,13 +900,24 @@ class MachineManager(QObject):
|
|||
# before the user decided to keep or discard any of their changes using the dialog.
|
||||
# The Application.onDiscardOrKeepProfileChangesClosed signal triggers this method.
|
||||
def _executeDelayedActiveContainerStackChanges(self):
|
||||
if self._new_variant_container is not None:
|
||||
self._active_container_stack.variant = self._new_variant_container
|
||||
self._new_variant_container = None
|
||||
|
||||
if self._new_material_container is not None:
|
||||
self._active_container_stack.material = self._new_material_container
|
||||
self._new_material_container = None
|
||||
|
||||
if self._new_variant_container is not None:
|
||||
self._active_container_stack.variant = self._new_variant_container
|
||||
self._new_variant_container = None
|
||||
if self._new_quality_containers:
|
||||
for new_quality in self._new_quality_containers:
|
||||
Logger.log("d", "stack=%s, quality=%s", new_quality["stack"].getId(), new_quality["quality"].getId())
|
||||
self._replaceQualityOrQualityChangesInStack(new_quality["stack"], new_quality["quality"], postpone_emit = True)
|
||||
self._replaceQualityOrQualityChangesInStack(new_quality["stack"], new_quality["quality_changes"], postpone_emit = True)
|
||||
|
||||
for new_quality in self._new_quality_containers:
|
||||
new_quality["stack"].nameChanged.connect(self._onQualityNameChanged)
|
||||
|
||||
self._new_quality_containers.clear()
|
||||
|
||||
## Cancel set changes for material and variant in the active container stack.
|
||||
# Used for ignoring any changes when switching between printers (setActiveMachine)
|
||||
|
@ -926,6 +947,11 @@ class MachineManager(QObject):
|
|||
|
||||
for stack in stacks:
|
||||
material = stack.material
|
||||
|
||||
# TODO: fix this
|
||||
if self._new_material_container and stack.getId() == self._active_container_stack.getId():
|
||||
material = self._new_material_container
|
||||
|
||||
quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material])
|
||||
if not quality:
|
||||
# No quality profile is found for this quality type.
|
||||
|
@ -963,8 +989,12 @@ class MachineManager(QObject):
|
|||
else:
|
||||
Logger.log("e", "Could not find the global quality changes container with name %s", quality_changes_name)
|
||||
return None
|
||||
|
||||
material = global_container_stack.material
|
||||
|
||||
if self._new_material_container and self._active_container_stack.getId() == global_container_stack.getId():
|
||||
material = self._new_material_container
|
||||
|
||||
# For the global stack, find a quality which matches the quality_type in
|
||||
# the quality changes profile and also satisfies any material constraints.
|
||||
quality_type = global_quality_changes.getMetaDataEntry("quality_type")
|
||||
|
@ -991,6 +1021,10 @@ class MachineManager(QObject):
|
|||
quality_changes = self._empty_quality_changes_container
|
||||
|
||||
material = stack.material
|
||||
|
||||
if self._new_material_container and self._active_container_stack.getId() == stack.getId():
|
||||
material = self._new_material_container
|
||||
|
||||
quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material])
|
||||
if not quality: #No quality profile found for this quality type.
|
||||
quality = self._empty_quality_container
|
||||
|
|
|
@ -6,6 +6,7 @@ from collections import OrderedDict
|
|||
from PyQt5.QtCore import Qt
|
||||
|
||||
from UM.Application import Application
|
||||
from UM.Logger import Logger
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel
|
||||
|
||||
|
@ -71,12 +72,6 @@ class ProfilesModel(InstanceContainersModel):
|
|||
# The actual list of quality profiles come from the first extruder in the extruder list.
|
||||
result = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_container_stack, extruder_stacks)
|
||||
|
||||
if len(result) == 0:
|
||||
# If not qualities are found we dynamically create a not supported container for this machine + material combination
|
||||
not_supported_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality")[0]
|
||||
result.append(not_supported_container)
|
||||
return result
|
||||
|
||||
# The usable quality types are set
|
||||
quality_type_set = set([x.getMetaDataEntry("quality_type") for x in result])
|
||||
|
||||
|
@ -90,6 +85,14 @@ class ProfilesModel(InstanceContainersModel):
|
|||
if quality.getMetaDataEntry("quality_type") not in quality_type_set:
|
||||
result.append(quality)
|
||||
|
||||
Logger.log("d", "====================quality=%s", quality.getId())
|
||||
|
||||
if len(result) == 0:
|
||||
# If not qualities are found we dynamically create a not supported container for this machine + material combination
|
||||
not_supported_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality")[0]
|
||||
result.append(not_supported_container)
|
||||
# return result
|
||||
|
||||
return result
|
||||
|
||||
## Re-computes the items in this model, and adds the layer height role.
|
||||
|
@ -121,7 +124,8 @@ class ProfilesModel(InstanceContainersModel):
|
|||
extruder_stacks = new_extruder_stacks + extruder_stacks
|
||||
|
||||
# Get a list of usable/available qualities for this machine and material
|
||||
qualities = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_container_stack, extruder_stacks)
|
||||
qualities = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
|
||||
extruder_stacks)
|
||||
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
machine_manager = Application.getInstance().getMachineManager()
|
||||
|
@ -166,15 +170,25 @@ class ProfilesModel(InstanceContainersModel):
|
|||
for item in containers:
|
||||
profile = container_registry.findContainers(id = item["id"])
|
||||
|
||||
Logger.log("d", "profile=%s, id=%s", profile, item["id"])
|
||||
|
||||
# when the profile is not supported
|
||||
if not profile:
|
||||
self._setItemLayerHeight(item, "", "")
|
||||
item["available"] = False
|
||||
yield None
|
||||
yield item
|
||||
continue
|
||||
|
||||
profile = profile[0]
|
||||
|
||||
if profile.getId() == "empty_quality":
|
||||
self._setItemLayerHeight(item, "", "")
|
||||
item["available"] = True
|
||||
yield item
|
||||
continue
|
||||
|
||||
item["available"] = profile in qualities
|
||||
Logger.log("d", "---- profile available = [%s] , qualities = [%s]", item["available"], [q.getId() for q in qualities])
|
||||
|
||||
# Easy case: This profile defines its own layer height.
|
||||
if profile.hasProperty("layer_height", "value"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue