mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-05 13:03:59 -06:00
Update ProfilesModel to always use extruder stacks + some refactoring - CURA-4482
This commit is contained in:
parent
f0ed3bc588
commit
de34464e47
1 changed files with 33 additions and 37 deletions
|
@ -12,6 +12,11 @@ from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel
|
|||
from cura.QualityManager import QualityManager
|
||||
from cura.Settings.ExtruderManager import ExtruderManager
|
||||
|
||||
from typing import List, TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from cura.Settings.ExtruderStack import ExtruderStack
|
||||
|
||||
|
||||
## QML Model for listing the current list of valid quality profiles.
|
||||
#
|
||||
|
@ -28,9 +33,10 @@ class ProfilesModel(InstanceContainersModel):
|
|||
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._update)
|
||||
|
||||
Application.getInstance().getMachineManager().activeVariantChanged.connect(self._update)
|
||||
Application.getInstance().getMachineManager().activeStackChanged.connect(self._update)
|
||||
Application.getInstance().getMachineManager().activeMaterialChanged.connect(self._update)
|
||||
self._machine_manager = Application.getInstance().getMachineManager()
|
||||
self._machine_manager.activeVariantChanged.connect(self._update)
|
||||
self._machine_manager.activeStackChanged.connect(self._update)
|
||||
self._machine_manager.activeMaterialChanged.connect(self._update)
|
||||
|
||||
# Factory function, used by QML
|
||||
@staticmethod
|
||||
|
@ -54,17 +60,12 @@ class ProfilesModel(InstanceContainersModel):
|
|||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack is None:
|
||||
return []
|
||||
global_stack_definition = global_container_stack.getBottom()
|
||||
|
||||
global_stack_definition = global_container_stack.definition
|
||||
|
||||
# Get the list of extruders and place the selected extruder at the front of the list.
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
||||
materials = [global_container_stack.material]
|
||||
if active_extruder in extruder_stacks:
|
||||
extruder_stacks.remove(active_extruder)
|
||||
extruder_stacks = [active_extruder] + extruder_stacks
|
||||
materials = [extruder.material for extruder in extruder_stacks]
|
||||
extruder_stacks = self._getOrderedExtruderStacksList()
|
||||
materials = [extruder.material for extruder in extruder_stacks]
|
||||
|
||||
# Fetch the list of usable qualities across all extruders.
|
||||
# The actual list of quality profiles come from the first extruder in the extruder list.
|
||||
|
@ -87,35 +88,16 @@ class ProfilesModel(InstanceContainersModel):
|
|||
|
||||
## Re-computes the items in this model, and adds the layer height role.
|
||||
def _recomputeItems(self):
|
||||
#Some globals that we can re-use.
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack is None:
|
||||
return
|
||||
|
||||
# Detecting if the machine has multiple extrusion
|
||||
multiple_extrusion = global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
||||
# Get the list of extruders and place the selected extruder at the front of the list.
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
||||
if multiple_extrusion:
|
||||
# Place the active extruder at the front of the list.
|
||||
# This is a workaround checking if there is an active_extruder or not before moving it to the front of the list.
|
||||
# Actually, when a printer has multiple extruders, should exist always an active_extruder. However, in some
|
||||
# cases the active_extruder is still None.
|
||||
if active_extruder in extruder_stacks:
|
||||
extruder_stacks.remove(active_extruder)
|
||||
new_extruder_stacks = []
|
||||
if active_extruder is not None:
|
||||
new_extruder_stacks = [active_extruder]
|
||||
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)
|
||||
extruder_stacks = self._getOrderedExtruderStacksList()
|
||||
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
machine_manager = Application.getInstance().getMachineManager()
|
||||
|
||||
# Get a list of usable/available qualities for this machine and material
|
||||
qualities = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_container_stack, extruder_stacks)
|
||||
|
||||
unit = global_container_stack.getBottom().getProperty("layer_height", "unit")
|
||||
if not unit:
|
||||
|
@ -174,7 +156,7 @@ class ProfilesModel(InstanceContainersModel):
|
|||
# Quality-changes profile that has no value for layer height. Get the corresponding quality profile and ask that profile.
|
||||
quality_type = profile.getMetaDataEntry("quality_type", None)
|
||||
if quality_type:
|
||||
quality_results = machine_manager.determineQualityAndQualityChangesForQualityType(quality_type)
|
||||
quality_results = self._machine_manager.determineQualityAndQualityChangesForQualityType(quality_type)
|
||||
for quality_result in quality_results:
|
||||
if quality_result["stack"] is global_container_stack:
|
||||
quality = quality_result["quality"]
|
||||
|
@ -198,6 +180,20 @@ class ProfilesModel(InstanceContainersModel):
|
|||
self._setItemLayerHeight(item, global_container_stack.getRawProperty("layer_height", "value", skip_until_container = skip_until_container.getId()), unit) # Fall through to the currently loaded material.
|
||||
yield item
|
||||
|
||||
def _setItemLayerHeight(self, item, value, unit):
|
||||
## Get a list of extruder stacks with the active extruder at the front of the list.
|
||||
@staticmethod
|
||||
def _getOrderedExtruderStacksList() -> List["ExtruderStack"]:
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||
|
||||
if active_extruder in extruder_stacks:
|
||||
extruder_stacks.remove(active_extruder)
|
||||
extruder_stacks = [active_extruder] + extruder_stacks
|
||||
|
||||
return extruder_stacks
|
||||
|
||||
@staticmethod
|
||||
def _setItemLayerHeight(item, value, unit):
|
||||
item["layer_height"] = str(value) + unit
|
||||
item["layer_height_without_unit"] = str(value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue