mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Fix quality check in project loading
CURA-4617
This commit is contained in:
parent
46c6c6aa9b
commit
828fff5ee5
1 changed files with 45 additions and 75 deletions
|
@ -784,12 +784,16 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
#
|
#
|
||||||
has_not_supported = False
|
has_not_supported = False
|
||||||
for stack in [global_stack] + extruder_stacks:
|
for stack in [global_stack] + extruder_stacks:
|
||||||
if stack.quality.getId() == "empty_quality":
|
if stack.quality.getId() in ("empty", "empty_quality"):
|
||||||
has_not_supported = True
|
has_not_supported = True
|
||||||
break
|
break
|
||||||
|
available_quality = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_stack,
|
||||||
|
extruder_stacks)
|
||||||
if not has_not_supported:
|
if not has_not_supported:
|
||||||
available_quality = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_stack, extruder_stacks)
|
|
||||||
has_not_supported = not available_quality
|
has_not_supported = not available_quality
|
||||||
|
|
||||||
|
quality_has_been_changed = False
|
||||||
|
|
||||||
if has_not_supported:
|
if has_not_supported:
|
||||||
empty_quality_container = self._container_registry.findInstanceContainers(id = "empty_quality")[0]
|
empty_quality_container = self._container_registry.findInstanceContainers(id = "empty_quality")[0]
|
||||||
for stack in [global_stack] + extruder_stacks:
|
for stack in [global_stack] + extruder_stacks:
|
||||||
|
@ -797,84 +801,50 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
empty_quality_changes_container = self._container_registry.findInstanceContainers(id = "empty_quality_changes")[0]
|
empty_quality_changes_container = self._container_registry.findInstanceContainers(id = "empty_quality_changes")[0]
|
||||||
for stack in [global_stack] + extruder_stacks:
|
for stack in [global_stack] + extruder_stacks:
|
||||||
stack.replaceContainer(_ContainerIndexes.QualityChanges, empty_quality_changes_container)
|
stack.replaceContainer(_ContainerIndexes.QualityChanges, empty_quality_changes_container)
|
||||||
|
quality_has_been_changed = True
|
||||||
|
|
||||||
# Fix quality:
|
|
||||||
# The quality specified in an old project file can be wrong, for example, for UM2, it should be "um2_normal"
|
|
||||||
# but instead it was "normal". This should be fixed by setting it to the correct quality.
|
|
||||||
# Note that this only seems to happen on single-extrusion machines on the global stack, so we only apply the
|
|
||||||
# fix for that
|
|
||||||
quality = global_stack.quality
|
|
||||||
has_empty_quality = True
|
|
||||||
project_quality_is_not_supported = True
|
|
||||||
if quality.getId() not in ("empty", "empty_quality"):
|
|
||||||
has_empty_quality = False
|
|
||||||
quality_type = quality.getMetaDataEntry("quality_type")
|
|
||||||
search_criteria = {"type": "quality",
|
|
||||||
"quality_type": quality_type}
|
|
||||||
if parseBool(global_stack.definition.getMetaDataEntry("has_machine_quality", "False")):
|
|
||||||
search_criteria["definition"] = global_stack.definition.getId()
|
|
||||||
else:
|
else:
|
||||||
search_criteria["definition"] = "fdmprinter"
|
empty_quality_changes_container = self._container_registry.findInstanceContainers(id="empty_quality_changes")[0]
|
||||||
|
|
||||||
quality_containers = self._container_registry.findInstanceContainers(**search_criteria)
|
# The machine in the project has non-empty quality and there are usable qualities for this machine.
|
||||||
quality_containers = [q for q in quality_containers if q.getMetaDataEntry("material", "") == ""]
|
# We need to check if the current quality_type is still usable for this machine, if not, then the quality
|
||||||
if quality_containers:
|
# will be reset to the "preferred quality" if present, otherwise "normal".
|
||||||
global_stack.quality = quality_containers[0]
|
available_quality_types = [q.getMetaDataEntry("quality_type") for q in available_quality]
|
||||||
project_quality_is_not_supported = False
|
|
||||||
else:
|
if global_stack.quality.getMetaDataEntry("quality_type") not in available_quality_types:
|
||||||
search_criteria["definition"] = "fdmprinter"
|
quality_has_been_changed = True
|
||||||
quality_containers = self._container_registry.findInstanceContainers(**search_criteria)
|
|
||||||
quality_containers = [q for q in quality_containers if q.getMetaDataEntry("material", "") == ""]
|
# find the preferred quality
|
||||||
if quality_containers:
|
preferred_quality_id = global_stack.getMetaDataEntry("preferred_quality", None)
|
||||||
global_stack.quality = quality_containers[0]
|
if preferred_quality_id is not None:
|
||||||
project_quality_is_not_supported = False
|
definition_id = global_stack.definition.getId()
|
||||||
else:
|
if not parseBool(global_stack.getMetaDataEntry("has_machine_quality", "False")):
|
||||||
# the quality_type of the quality profile cannot be found.
|
definition_id = "fdmprinter"
|
||||||
# this can happen if a quality_type has been removed in a newer version, for example:
|
|
||||||
# "extra_coarse" is removed from 2.7 to 3.0
|
containers = self._container_registry.findInstanceContainers(id = preferred_quality_id,
|
||||||
# in this case, the quality will be reset to "normal"
|
|
||||||
quality_containers = self._container_registry.findInstanceContainers(
|
|
||||||
definition = global_stack.definition.getId(),
|
|
||||||
type = "quality",
|
type = "quality",
|
||||||
quality_type = "normal")
|
definition = definition_id)
|
||||||
quality_containers = [q for q in quality_containers if q.getMetaDataEntry("material", "") == ""]
|
containers = [c for c in containers if not c.getMetaDataEntry("material", "")]
|
||||||
if quality_containers:
|
if containers:
|
||||||
global_stack.quality = quality_containers[0]
|
global_stack.quality = containers[0]
|
||||||
|
global_stack.qualityChanges = empty_quality_changes_container
|
||||||
if not quality_containers:
|
# also find the quality containers for the extruders
|
||||||
# This should not happen!
|
for extruder_stack in extruder_stacks:
|
||||||
Logger.log("e", "Cannot find quality normal for global stack [%s] [%s]",
|
search_criteria = {"id": preferred_quality_id,
|
||||||
global_stack.getId(), global_stack.definition.getId())
|
"type": "quality",
|
||||||
has_empty_quality = True
|
"definition": definition_id}
|
||||||
|
if global_stack.getMetaDataEntry("has_machine_materials") and extruder_stack.material.getId() not in ("empty", "empty_material"):
|
||||||
if project_quality_is_not_supported:
|
search_criteria["material"] = extruder_stack.material.getId()
|
||||||
empty_quality_container = self._container_registry.findInstanceContainers(id = "empty_quality")[0]
|
containers = self._container_registry.findInstanceContainers(**search_criteria)
|
||||||
empty_quality_changes_container = self._container_registry.findInstanceContainers(id = "empty_quality_changes")[0]
|
if containers:
|
||||||
|
extruder_stack.quality = containers[0]
|
||||||
if has_empty_quality:
|
extruder_stack.qualityChanges = empty_quality_changes_container
|
||||||
for stack in [global_stack] + extruder_stacks:
|
|
||||||
stack.quality = empty_quality_container
|
|
||||||
stack.qualityChanges = empty_quality_changes_container
|
|
||||||
else:
|
else:
|
||||||
for stack in [global_stack] + extruder_stacks:
|
Logger.log("e", "Cannot find preferred quality for extruder [%s].", extruder_stack.getId())
|
||||||
stack.qualityChanges = empty_quality_changes_container
|
|
||||||
# for extruder stacks, the quality containers also need to be switched
|
|
||||||
for stack in extruder_stacks:
|
|
||||||
search_criteria = {"type": "quality",
|
|
||||||
"quality_type": "normal"}
|
|
||||||
if parseBool(global_stack.definition.getMetaDataEntry("has_machine_quality", "False")):
|
|
||||||
search_criteria["definition"] = global_stack.definition.getId()
|
|
||||||
else:
|
|
||||||
search_criteria["definition"] = "fdmprinter"
|
|
||||||
|
|
||||||
if parseBool(global_stack.getMetaDataEntry("has_machine_material")):
|
|
||||||
search_criteria["material"] = stack.material.getId()
|
|
||||||
|
|
||||||
quality_containers = self._container_registry.findInstanceContainers(**search_criteria)
|
|
||||||
if quality_containers:
|
|
||||||
stack.quality = quality_containers[0]
|
|
||||||
else:
|
else:
|
||||||
Logger.log("e", "Cannot find quality container for extruder stack [%s]", stack.getId())
|
# we cannot find the preferred quality. THIS SHOULD NOT HAPPEN
|
||||||
|
Logger.log("e", "Cannot find the preferred quality for machine [%s]", global_stack.getId())
|
||||||
|
|
||||||
# Replacing the old containers if resolve is "new".
|
# Replacing the old containers if resolve is "new".
|
||||||
# When resolve is "new", some containers will get renamed, so all the other containers that reference to those
|
# When resolve is "new", some containers will get renamed, so all the other containers that reference to those
|
||||||
|
@ -899,7 +869,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
changes_container_types = ("quality_changes", "definition_changes")
|
changes_container_types = ("quality_changes", "definition_changes")
|
||||||
if project_quality_is_not_supported:
|
if quality_has_been_changed:
|
||||||
# DO NOT replace quality_changes if the current quality_type is not supported
|
# DO NOT replace quality_changes if the current quality_type is not supported
|
||||||
changes_container_types = ("definition_changes",)
|
changes_container_types = ("definition_changes",)
|
||||||
for changes_container_type in changes_container_types:
|
for changes_container_type in changes_container_types:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue