Take the machine_extruder_count into consideration when opening project

CURA-7646
This commit is contained in:
Kostas Karmas 2020-08-10 14:56:37 +02:00
parent 2828f45e89
commit b9d5f0dc15

View File

@ -663,7 +663,12 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
# We need to create a new machine
machine_name = self._container_registry.uniqueName(self._machine_info.name)
global_stack = CuraStackBuilder.createMachine(machine_name, self._machine_info.definition_id)
# Printers with modifiable number of extruders (such as CFFF) will specify a machine_extruder_count in their
# quality_changes file. If that's the case, take the extruder count into account when creating the machine
# or else the extruderList will return only the first extruder, leading to missing non-global settings in
# the other extruders. See CURA-7646
machine_extruder_count = self._getMachineExtruderCount() # type: Optional[int]
global_stack = CuraStackBuilder.createMachine(machine_name, self._machine_info.definition_id, machine_extruder_count)
if global_stack: # Only switch if creating the machine was successful.
extruder_stack_dict = {str(position): extruder for position, extruder in enumerate(global_stack.extruderList)}
@ -918,6 +923,24 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
self._machine_info.quality_changes_info.name = quality_changes_name
def _getMachineExtruderCount(self) -> Optional[int]:
"""
Extracts the machine extruder count from the definition_changes file of the printer. If it is not specified in
the file, None is returned instead.
:return: The count of the machine's extruders
"""
machine_extruder_count = None
if self._machine_info.definition_changes_info \
and "values" in self._machine_info.definition_changes_info.parser \
and "machine_extruder_count" in self._machine_info.definition_changes_info.parser["values"]:
try:
machine_extruder_count = int(self._machine_info.definition_changes_info.parser["values"]["machine_extruder_count"])
except ValueError:
Logger.log("w", "'machine_extruder_count' in file '{file_name}' is not a number."
.format(file_name = self._machine_info.definition_changes_info.file_name))
return machine_extruder_count
def _createNewQualityChanges(self, quality_type: str, intent_category: Optional[str], name: str, global_stack: GlobalStack, extruder_stack: Optional[ExtruderStack]) -> InstanceContainer:
"""Helper class to create a new quality changes profile.