mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 02:37:49 -06:00
Fixes for selecting active variant, material and quality - CURA-4482
This commit is contained in:
parent
4701518404
commit
bc6984a0ed
4 changed files with 58 additions and 42 deletions
|
@ -405,6 +405,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
def _addExtruderStackForSingleExtrusionMachine(self, machine, extruder_id):
|
||||
new_extruder_id = extruder_id
|
||||
|
||||
# if extruders are defined in the machine definition use those instead
|
||||
if machine.extruders and len(machine.extruders) > 0:
|
||||
new_extruder_id = machine.extruders["0"].getId()
|
||||
|
||||
|
@ -415,13 +416,12 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
return
|
||||
|
||||
extruder_definition = extruder_definitions[0]
|
||||
unique_name = self.uniqueName(machine.getId() + " " + new_extruder_id)
|
||||
unique_name = self.uniqueName(machine.getName() + " " + new_extruder_id)
|
||||
|
||||
extruder_stack = ExtruderStack.ExtruderStack(unique_name)
|
||||
extruder_stack.setName(extruder_definition.getName())
|
||||
extruder_stack.setDefinition(extruder_definition)
|
||||
extruder_stack.addMetaDataEntry("machine", machine.getId())
|
||||
extruder_stack.addMetaDataEntry("position", "0")
|
||||
extruder_stack.addMetaDataEntry("position", extruder_definition.getMetaDataEntry("position"))
|
||||
extruder_stack.setNextStack(machine)
|
||||
|
||||
if machine.userChanges:
|
||||
|
@ -429,7 +429,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
extruder_stack.setUserChanges(machine.userChanges)
|
||||
else:
|
||||
# create empty user changes container otherwise
|
||||
user_container = InstanceContainer(extruder_stack.getId() + "_user")
|
||||
user_container = InstanceContainer(extruder_stack.id + "_user")
|
||||
user_container.addMetaDataEntry("type", "user")
|
||||
user_container.addMetaDataEntry("machine", extruder_stack.getId())
|
||||
from cura.CuraApplication import CuraApplication
|
||||
|
@ -438,7 +438,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
extruder_stack.setUserChanges(user_container)
|
||||
self.addContainer(user_container)
|
||||
|
||||
# extruder_stack.setVariantById("default")
|
||||
extruder_stack.setVariantById("default")
|
||||
extruder_stack.setMaterialById("default")
|
||||
extruder_stack.setQualityById("default")
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class CuraStackBuilder:
|
|||
if not extruder_definition:
|
||||
# create extruder stack for single extrusion machines that have no separate extruder definition files
|
||||
extruder_definition = registry.findDefinitionContainers(id = "fdmextruder")[0]
|
||||
new_extruder_id = registry.uniqueName(machine_definition.getId() + " " + "fdmextruder")
|
||||
new_extruder_id = registry.uniqueName(machine_definition.getName() + " " + extruder_definition.id)
|
||||
new_extruder = cls.createExtruderStack(
|
||||
new_extruder_id,
|
||||
definition=extruder_definition,
|
||||
|
|
|
@ -543,9 +543,8 @@ class ExtruderManager(QObject):
|
|||
self._global_container_stack_definition_id = global_container_stack.getBottom().getId()
|
||||
self.globalContainerStackDefinitionChanged.emit()
|
||||
|
||||
# If the global container changed, the number of extruders could be changed and so the active_extruder_index is updated
|
||||
if self._active_extruder_index == -1:
|
||||
self.setActiveExtruderIndex(0)
|
||||
# If the global container changed, the machine changed and might have extruders that were not registered yet
|
||||
self._addCurrentMachineExtruders()
|
||||
|
||||
self.resetSelectedObjectExtruders()
|
||||
|
||||
|
@ -554,21 +553,29 @@ class ExtruderManager(QObject):
|
|||
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||
extruders_changed = False
|
||||
|
||||
if global_stack and global_stack.getBottom():
|
||||
if global_stack:
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
machine_id = global_stack.getBottom().getId()
|
||||
global_stack_id = global_stack.getId()
|
||||
|
||||
# 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_id)
|
||||
extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = global_stack_id)
|
||||
|
||||
# Make sure the extruder trains for the new machine can be placed in the set of sets
|
||||
if global_stack_id not in self._extruder_trains:
|
||||
self._extruder_trains[global_stack_id] = {}
|
||||
extruders_changed = True
|
||||
|
||||
# Register the extruder trains by position
|
||||
for extruder_train in extruder_trains:
|
||||
self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train
|
||||
self._extruder_trains[global_stack_id][extruder_train.getMetaDataEntry("position")] = extruder_train
|
||||
|
||||
# regardless of what the next stack is, we have to set it again, because of signal routing. ???
|
||||
extruder_train.setNextStack(global_stack)
|
||||
extruders_changed = True
|
||||
|
||||
if extruders_changed:
|
||||
self.extrudersChanged.emit(machine_id)
|
||||
self.extrudersChanged.emit(global_stack_id)
|
||||
self.setActiveExtruderIndex(0)
|
||||
|
||||
## Get all extruder values for a certain setting.
|
||||
#
|
||||
|
|
|
@ -386,15 +386,6 @@ class MachineManager(QObject):
|
|||
else:
|
||||
Logger.log("w", "Failed creating a new machine!")
|
||||
|
||||
## Create a name that is not empty and unique
|
||||
# \param container_type \type{string} Type of the container (machine, quality, ...)
|
||||
# \param current_name \type{} Current name of the container, which may be an acceptable option
|
||||
# \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
|
||||
# \return \type{string} Name that is unique for the specified type and name/id
|
||||
def _createUniqueName(self, container_type: str, current_name: str, new_name: str, fallback_name: str) -> str:
|
||||
return ContainerRegistry.getInstance().createUniqueName(container_type, current_name, new_name, fallback_name)
|
||||
|
||||
def _checkStacksHaveErrors(self) -> bool:
|
||||
if self._global_container_stack is None: #No active machine.
|
||||
return False
|
||||
|
@ -950,15 +941,12 @@ class MachineManager(QObject):
|
|||
global_container_stack = self._global_container_stack
|
||||
if not global_container_stack:
|
||||
return []
|
||||
|
||||
global_machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.getBottom())
|
||||
|
||||
extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
|
||||
if extruder_stacks:
|
||||
stacks = extruder_stacks
|
||||
else:
|
||||
stacks = [global_container_stack]
|
||||
|
||||
for stack in stacks:
|
||||
# find qualities for extruders
|
||||
for stack in extruder_stacks:
|
||||
material = stack.material
|
||||
|
||||
# TODO: fix this
|
||||
|
@ -966,19 +954,33 @@ class MachineManager(QObject):
|
|||
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.
|
||||
quality = self._empty_quality_container
|
||||
result.append({"stack": stack, "quality": quality, "quality_changes": empty_quality_changes})
|
||||
|
||||
if extruder_stacks:
|
||||
# Add an extra entry for the global stack.
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [], global_quality = "True")
|
||||
result.append({
|
||||
"stack": stack,
|
||||
"quality": quality,
|
||||
"quality_changes": empty_quality_changes
|
||||
})
|
||||
|
||||
# also find a global quality for the machine
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [], global_quality = True)
|
||||
|
||||
# if there is not global quality but we're using a single extrusion machine, copy the quality of the first extruder - CURA-4482
|
||||
if not global_quality and len(extruder_stacks) == 1:
|
||||
global_quality = result[0]["quality"]
|
||||
|
||||
# if there is still no global quality, set it to empty (not supported)
|
||||
if not global_quality:
|
||||
global_quality = self._empty_quality_container
|
||||
|
||||
result.append({"stack": global_container_stack, "quality": global_quality, "quality_changes": empty_quality_changes})
|
||||
result.append({
|
||||
"stack": global_container_stack,
|
||||
"quality": global_quality,
|
||||
"quality_changes": empty_quality_changes
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
|
@ -1030,7 +1032,7 @@ class MachineManager(QObject):
|
|||
|
||||
material = extruder_stack.material
|
||||
|
||||
if self._new_material_container and self._active_container_stack.getId() == stack.getId():
|
||||
if self._new_material_container and self._active_container_stack.getId() == extruder_stack.getId():
|
||||
material = self._new_material_container
|
||||
|
||||
quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material])
|
||||
|
@ -1047,6 +1049,12 @@ class MachineManager(QObject):
|
|||
|
||||
# append the global quality changes
|
||||
global_quality = quality_manager.findQualityByQualityType(quality_type, global_machine_definition, [material], global_quality = True)
|
||||
|
||||
# if there is not global quality but we're using a single extrusion machine, copy the quality of the first extruder - CURA-4482
|
||||
if not global_quality and len(extruder_stacks) == 1:
|
||||
global_quality = result[0]["quality_changes"]
|
||||
|
||||
# if still no global quality changes are found we set it to empty (not supported)
|
||||
if not global_quality:
|
||||
global_quality = self._empty_quality_container
|
||||
|
||||
|
@ -1163,10 +1171,11 @@ class MachineManager(QObject):
|
|||
|
||||
@pyqtSlot(str, str)
|
||||
def renameMachine(self, machine_id: str, new_name: str):
|
||||
containers = ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
||||
if containers:
|
||||
new_name = self._createUniqueName("machine", containers[0].getName(), new_name, containers[0].getBottom().getName())
|
||||
containers[0].setName(new_name)
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
machine_stack = container_registry.findContainerStacks(id = machine_id)
|
||||
if machine_stack:
|
||||
new_name = container_registry.createUniqueName("machine", machine_stack[0].getName(), new_name, machine_stack[0].getBottom().getName())
|
||||
machine_stack[0].setName(new_name)
|
||||
self.globalContainerChanged.emit()
|
||||
|
||||
@pyqtSlot(str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue