mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 02:07:51 -06:00
Fix typing.
part CURA-6600
This commit is contained in:
parent
83146a71a9
commit
745390e51f
10 changed files with 48 additions and 23 deletions
|
@ -77,6 +77,9 @@ class MachineNode(ContainerNode):
|
||||||
# Create the quality group for each available type.
|
# Create the quality group for each available type.
|
||||||
quality_groups = {}
|
quality_groups = {}
|
||||||
for quality_type, global_quality_node in self.global_qualities.items():
|
for quality_type, global_quality_node in self.global_qualities.items():
|
||||||
|
if not global_quality_node.container:
|
||||||
|
Logger.log("w", "Node {0} doesn't have a container.".format(global_quality_node.container_id))
|
||||||
|
continue
|
||||||
quality_groups[quality_type] = QualityGroup(name = global_quality_node.container.getMetaDataEntry("name", "Unnamed profile"), quality_type = quality_type)
|
quality_groups[quality_type] = QualityGroup(name = global_quality_node.container.getMetaDataEntry("name", "Unnamed profile"), quality_type = quality_type)
|
||||||
quality_groups[quality_type].node_for_global = global_quality_node
|
quality_groups[quality_type].node_for_global = global_quality_node
|
||||||
for extruder, qualities_per_type in enumerate(qualities_per_type_per_extruder):
|
for extruder, qualities_per_type in enumerate(qualities_per_type_per_extruder):
|
||||||
|
@ -116,7 +119,7 @@ class MachineNode(ContainerNode):
|
||||||
def getQualityChangesGroups(self, variant_names: List[str], material_bases: List[str], extruder_enabled: List[bool]) -> List[QualityChangesGroup]:
|
def getQualityChangesGroups(self, variant_names: List[str], material_bases: List[str], extruder_enabled: List[bool]) -> List[QualityChangesGroup]:
|
||||||
machine_quality_changes = ContainerRegistry.getInstance().findContainersMetadata(type = "quality_changes", definition = self.quality_definition) # All quality changes for each extruder.
|
machine_quality_changes = ContainerRegistry.getInstance().findContainersMetadata(type = "quality_changes", definition = self.quality_definition) # All quality changes for each extruder.
|
||||||
|
|
||||||
groups_by_name = {} # Group quality changes profiles by their display name. The display name must be unique for quality changes. This finds profiles that belong together in a group.
|
groups_by_name = {} #type: Dict[str, QualityChangesGroup] # Group quality changes profiles by their display name. The display name must be unique for quality changes. This finds profiles that belong together in a group.
|
||||||
for quality_changes in machine_quality_changes:
|
for quality_changes in machine_quality_changes:
|
||||||
name = quality_changes["name"]
|
name = quality_changes["name"]
|
||||||
if name not in groups_by_name:
|
if name not in groups_by_name:
|
||||||
|
@ -143,7 +146,7 @@ class MachineNode(ContainerNode):
|
||||||
# quality is taken.
|
# quality is taken.
|
||||||
# If there are no global qualities, an empty quality is returned.
|
# If there are no global qualities, an empty quality is returned.
|
||||||
def preferredGlobalQuality(self) -> QualityNode:
|
def preferredGlobalQuality(self) -> QualityNode:
|
||||||
return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities)))
|
return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values())))
|
||||||
|
|
||||||
## (Re)loads all variants under this printer.
|
## (Re)loads all variants under this printer.
|
||||||
def _loadAll(self):
|
def _loadAll(self):
|
||||||
|
|
|
@ -132,7 +132,7 @@ class MaterialManager(QObject):
|
||||||
# Fetch the available materials (ContainerNode) for the current active machine and extruder setup.
|
# Fetch the available materials (ContainerNode) for the current active machine and extruder setup.
|
||||||
materials = self.getAvailableMaterials(machine.definition.getId(), nozzle_name)
|
materials = self.getAvailableMaterials(machine.definition.getId(), nozzle_name)
|
||||||
compatible_material_diameter = str(round(extruder_stack.getCompatibleMaterialDiameter()))
|
compatible_material_diameter = str(round(extruder_stack.getCompatibleMaterialDiameter()))
|
||||||
result = {key: material for key, material in materials.items() if material.container.getMetaDataEntry("approximate_diameter") == compatible_material_diameter}
|
result = {key: material for key, material in materials.items() if material.container and material.container.getMetaDataEntry("approximate_diameter") == compatible_material_diameter}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -268,6 +268,8 @@ class MaterialManager(QObject):
|
||||||
|
|
||||||
@pyqtSlot("QVariant", str)
|
@pyqtSlot("QVariant", str)
|
||||||
def setMaterialName(self, material_node: "MaterialNode", name: str) -> None:
|
def setMaterialName(self, material_node: "MaterialNode", name: str) -> None:
|
||||||
|
if material_node.container is None:
|
||||||
|
return
|
||||||
root_material_id = material_node.container.getMetaDataEntry("base_file")
|
root_material_id = material_node.container.getMetaDataEntry("base_file")
|
||||||
if root_material_id is None:
|
if root_material_id is None:
|
||||||
return
|
return
|
||||||
|
@ -279,6 +281,8 @@ class MaterialManager(QObject):
|
||||||
|
|
||||||
@pyqtSlot("QVariant")
|
@pyqtSlot("QVariant")
|
||||||
def removeMaterial(self, material_node: "MaterialNode") -> None:
|
def removeMaterial(self, material_node: "MaterialNode") -> None:
|
||||||
|
if material_node.container is None:
|
||||||
|
return
|
||||||
root_material_id = material_node.container.getMetaDataEntry("base_file")
|
root_material_id = material_node.container.getMetaDataEntry("base_file")
|
||||||
if root_material_id is not None:
|
if root_material_id is not None:
|
||||||
self.removeMaterialByRootId(root_material_id)
|
self.removeMaterialByRootId(root_material_id)
|
||||||
|
@ -343,6 +347,9 @@ class MaterialManager(QObject):
|
||||||
#
|
#
|
||||||
@pyqtSlot("QVariant", result = str)
|
@pyqtSlot("QVariant", result = str)
|
||||||
def duplicateMaterial(self, material_node: MaterialNode, new_base_id: Optional[str] = None, new_metadata: Dict[str, Any] = None) -> Optional[str]:
|
def duplicateMaterial(self, material_node: MaterialNode, new_base_id: Optional[str] = None, new_metadata: Dict[str, Any] = None) -> Optional[str]:
|
||||||
|
if material_node.container is None:
|
||||||
|
Logger.log("e", "Material node {0} doesn't have container.".format(material_node.container_id))
|
||||||
|
return "ERROR"
|
||||||
root_material_id = cast(str, material_node.container.getMetaDataEntry("base_file", ""))
|
root_material_id = cast(str, material_node.container.getMetaDataEntry("base_file", ""))
|
||||||
return self.duplicateMaterialByRootId(root_material_id, new_base_id, new_metadata)
|
return self.duplicateMaterialByRootId(root_material_id, new_base_id, new_metadata)
|
||||||
|
|
||||||
|
@ -359,7 +366,11 @@ class MaterialManager(QObject):
|
||||||
machine_manager = application.getMachineManager()
|
machine_manager = application.getMachineManager()
|
||||||
extruder_stack = machine_manager.activeStack
|
extruder_stack = machine_manager.activeStack
|
||||||
|
|
||||||
machine_definition = application.getGlobalContainerStack().definition
|
global_stack = application.getGlobalContainerStack()
|
||||||
|
if global_stack is None:
|
||||||
|
Logger.log("e", "Global stack not present!")
|
||||||
|
return "ERROR"
|
||||||
|
machine_definition = global_stack.definition
|
||||||
root_material_id = machine_definition.getMetaDataEntry("preferred_material", default = "generic_pla")
|
root_material_id = machine_definition.getMetaDataEntry("preferred_material", default = "generic_pla")
|
||||||
|
|
||||||
approximate_diameter = str(extruder_stack.approximateMaterialDiameter)
|
approximate_diameter = str(extruder_stack.approximateMaterialDiameter)
|
||||||
|
|
|
@ -106,7 +106,10 @@ class BaseMaterialsModel(ListModel):
|
||||||
def _materialsListChanged(self, material: MaterialNode) -> None:
|
def _materialsListChanged(self, material: MaterialNode) -> None:
|
||||||
if material.variant.container_id != self._extruder_stack.variant.getId():
|
if material.variant.container_id != self._extruder_stack.variant.getId():
|
||||||
return
|
return
|
||||||
if material.variant.machine.container_id != cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack().definition.getId():
|
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
|
if not global_stack:
|
||||||
|
return
|
||||||
|
if material.variant.machine.container_id != global_stack.definition.getId():
|
||||||
return
|
return
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class QualityChangesGroup(QObject):
|
||||||
self.quality_type = quality_type
|
self.quality_type = quality_type
|
||||||
self.intent_category = intent_category
|
self.intent_category = intent_category
|
||||||
self.is_available = False
|
self.is_available = False
|
||||||
self.metadata_for_global = None # type: Optional[str]
|
self.metadata_for_global = {} # type: Dict[str, Any]
|
||||||
self.metadata_per_extruder = {} # type: Dict[int, Dict[str, Any]]
|
self.metadata_per_extruder = {} # type: Dict[int, Dict[str, Any]]
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
|
|
|
@ -5,6 +5,7 @@ from typing import Dict, Optional, List, Set
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSlot
|
from PyQt5.QtCore import QObject, pyqtSlot
|
||||||
|
|
||||||
|
from UM.Logger import Logger
|
||||||
from UM.Util import parseBool
|
from UM.Util import parseBool
|
||||||
|
|
||||||
from cura.Machines.ContainerNode import ContainerNode
|
from cura.Machines.ContainerNode import ContainerNode
|
||||||
|
@ -60,6 +61,9 @@ class QualityGroup(QObject):
|
||||||
self.node_for_global = node
|
self.node_for_global = node
|
||||||
|
|
||||||
# Update is_experimental flag
|
# Update is_experimental flag
|
||||||
|
if not node.container:
|
||||||
|
Logger.log("w", "Node {0} doesn't have a container.".format(node.container_id))
|
||||||
|
return
|
||||||
is_experimental = parseBool(node.container.getMetaDataEntry("is_experimental", False))
|
is_experimental = parseBool(node.container.getMetaDataEntry("is_experimental", False))
|
||||||
self.is_experimental |= is_experimental
|
self.is_experimental |= is_experimental
|
||||||
|
|
||||||
|
@ -67,5 +71,8 @@ class QualityGroup(QObject):
|
||||||
self.nodes_for_extruders[position] = node
|
self.nodes_for_extruders[position] = node
|
||||||
|
|
||||||
# Update is_experimental flag
|
# Update is_experimental flag
|
||||||
|
if not node.container:
|
||||||
|
Logger.log("w", "Node {0} doesn't have a container.".format(node.container_id))
|
||||||
|
return
|
||||||
is_experimental = parseBool(node.container.getMetaDataEntry("is_experimental", False))
|
is_experimental = parseBool(node.container.getMetaDataEntry("is_experimental", False))
|
||||||
self.is_experimental |= is_experimental
|
self.is_experimental |= is_experimental
|
||||||
|
|
|
@ -112,12 +112,10 @@ class QualityManager(QObject):
|
||||||
# Iterate over all quality_types in the machine node
|
# Iterate over all quality_types in the machine node
|
||||||
quality_group_dict = dict()
|
quality_group_dict = dict()
|
||||||
for node in nodes_to_check:
|
for node in nodes_to_check:
|
||||||
if node and node.quality_type_map:
|
if node and node.quality_type:
|
||||||
for quality_type, quality_node in node.quality_type_map.items():
|
quality_group = QualityGroup(node.getMetaDataEntry("name", ""), node.quality_type)
|
||||||
quality_group = QualityGroup(quality_node.getMetaDataEntry("name", ""), quality_type)
|
quality_group.setGlobalNode(node)
|
||||||
quality_group.setGlobalNode(quality_node)
|
quality_group_dict[node.quality_type] = quality_group
|
||||||
quality_group_dict[quality_type] = quality_group
|
|
||||||
break
|
|
||||||
|
|
||||||
return quality_group_dict
|
return quality_group_dict
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,9 @@ class ContainerManager(QObject):
|
||||||
# Update: In order for QML to use objects and sub objects, those (sub) objects must all be QObject. Is that what we want?
|
# Update: In order for QML to use objects and sub objects, those (sub) objects must all be QObject. Is that what we want?
|
||||||
@pyqtSlot("QVariant", str, str)
|
@pyqtSlot("QVariant", str, str)
|
||||||
def setContainerMetaDataEntry(self, container_node: "ContainerNode", entry_name: str, entry_value: str) -> bool:
|
def setContainerMetaDataEntry(self, container_node: "ContainerNode", entry_name: str, entry_value: str) -> bool:
|
||||||
|
if container_node.container is None:
|
||||||
|
Logger.log("w", "Container node {0} doesn't have a container.".format(container_node.container_id))
|
||||||
|
return False
|
||||||
root_material_id = container_node.container.getMetaDataEntry("base_file", "")
|
root_material_id = container_node.container.getMetaDataEntry("base_file", "")
|
||||||
if cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry().isReadOnly(root_material_id):
|
if cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry().isReadOnly(root_material_id):
|
||||||
Logger.log("w", "Cannot set metadata of read-only container %s.", root_material_id)
|
Logger.log("w", "Cannot set metadata of read-only container %s.", root_material_id)
|
||||||
|
@ -341,6 +344,9 @@ class ContainerManager(QObject):
|
||||||
@pyqtSlot("QVariant")
|
@pyqtSlot("QVariant")
|
||||||
def unlinkMaterial(self, material_node: "MaterialNode") -> None:
|
def unlinkMaterial(self, material_node: "MaterialNode") -> None:
|
||||||
# Get the material group
|
# Get the material group
|
||||||
|
if material_node.container is None:
|
||||||
|
Logger.log("w", "Material node {0} doesn't have a container.".format(material_node.container_id))
|
||||||
|
return
|
||||||
material_group = MaterialManager.getInstance().getMaterialGroup(material_node.container.getMetaDataEntry("base_file", ""))
|
material_group = MaterialManager.getInstance().getMaterialGroup(material_node.container.getMetaDataEntry("base_file", ""))
|
||||||
|
|
||||||
if material_group is None:
|
if material_group is None:
|
||||||
|
|
|
@ -28,6 +28,7 @@ from . import GlobalStack
|
||||||
|
|
||||||
import cura.CuraApplication
|
import cura.CuraApplication
|
||||||
from cura.Settings.cura_empty_instance_containers import empty_quality_container
|
from cura.Settings.cura_empty_instance_containers import empty_quality_container
|
||||||
|
from cura.Machines.ContainerTree import ContainerTree
|
||||||
from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch
|
from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch
|
||||||
from cura.ReaderWriters.ProfileReader import NoProfileException, ProfileReader
|
from cura.ReaderWriters.ProfileReader import NoProfileException, ProfileReader
|
||||||
|
|
||||||
|
@ -386,8 +387,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
# Check to make sure the imported profile actually makes sense in context of the current configuration.
|
# Check to make sure the imported profile actually makes sense in context of the current configuration.
|
||||||
# This prevents issues where importing a "draft" profile for a machine without "draft" qualities would report as
|
# This prevents issues where importing a "draft" profile for a machine without "draft" qualities would report as
|
||||||
# successfully imported but then fail to show up.
|
# successfully imported but then fail to show up.
|
||||||
quality_manager = cura.CuraApplication.CuraApplication.getInstance()._quality_manager
|
quality_group_dict = ContainerTree.getInstance().machines[definition_id]
|
||||||
quality_group_dict = quality_manager.getQualityGroupsForMachineDefinition(global_stack)
|
|
||||||
# "not_supported" profiles can be imported.
|
# "not_supported" profiles can be imported.
|
||||||
if quality_type != empty_quality_container.getMetaDataEntry("quality_type") and quality_type not in quality_group_dict:
|
if quality_type != empty_quality_container.getMetaDataEntry("quality_type") and quality_type not in quality_group_dict:
|
||||||
return catalog.i18nc("@info:status", "Could not find a quality type {0} for the current configuration.", quality_type)
|
return catalog.i18nc("@info:status", "Could not find a quality type {0} for the current configuration.", quality_type)
|
||||||
|
|
|
@ -24,6 +24,7 @@ from UM.Signal import postponeSignals, CompressTechnique
|
||||||
|
|
||||||
import cura.CuraApplication # Imported like this to prevent circular references.
|
import cura.CuraApplication # Imported like this to prevent circular references.
|
||||||
|
|
||||||
|
from cura.Machines.ContainerNode import ContainerNode
|
||||||
from cura.Machines.ContainerTree import ContainerTree
|
from cura.Machines.ContainerTree import ContainerTree
|
||||||
from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch, QualityManager
|
from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch, QualityManager
|
||||||
from cura.Machines.MaterialManager import MaterialManager
|
from cura.Machines.MaterialManager import MaterialManager
|
||||||
|
@ -1185,7 +1186,7 @@ class MachineManager(QObject):
|
||||||
def _setMaterial(self, position: str, material_node: Optional["MaterialNode"] = None) -> None:
|
def _setMaterial(self, position: str, material_node: Optional["MaterialNode"] = None) -> None:
|
||||||
if self._global_container_stack is None:
|
if self._global_container_stack is None:
|
||||||
return
|
return
|
||||||
if material_node:
|
if material_node and material_node.container:
|
||||||
material_container = material_node.container
|
material_container = material_node.container
|
||||||
self._global_container_stack.extruders[position].material = material_container
|
self._global_container_stack.extruders[position].material = material_container
|
||||||
root_material_id = material_container.getMetaDataEntry("base_file", None)
|
root_material_id = material_container.getMetaDataEntry("base_file", None)
|
||||||
|
@ -1239,6 +1240,9 @@ class MachineManager(QObject):
|
||||||
# The current quality type is not available so we use the preferred quality type if it's available,
|
# The current quality type is not available so we use the preferred quality type if it's available,
|
||||||
# otherwise use one of the available quality types.
|
# otherwise use one of the available quality types.
|
||||||
quality_type = sorted(list(available_quality_types))[0]
|
quality_type = sorted(list(available_quality_types))[0]
|
||||||
|
if self._global_container_stack is None:
|
||||||
|
Logger.log("e", "Global stack not present!")
|
||||||
|
return
|
||||||
preferred_quality_type = self._global_container_stack.getMetaDataEntry("preferred_quality_type")
|
preferred_quality_type = self._global_container_stack.getMetaDataEntry("preferred_quality_type")
|
||||||
if preferred_quality_type in available_quality_types:
|
if preferred_quality_type in available_quality_types:
|
||||||
quality_type = preferred_quality_type
|
quality_type = preferred_quality_type
|
||||||
|
@ -1549,7 +1553,7 @@ class MachineManager(QObject):
|
||||||
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
||||||
def hasNotSupportedQuality(self) -> bool:
|
def hasNotSupportedQuality(self) -> bool:
|
||||||
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
return global_container_stack and global_container_stack.quality == empty_quality_container and global_container_stack.qualityChanges == empty_quality_changes_container
|
return (not global_container_stack is None) and global_container_stack.quality == empty_quality_container and global_container_stack.qualityChanges == empty_quality_changes_container
|
||||||
|
|
||||||
def _updateUponMaterialMetadataChange(self) -> None:
|
def _updateUponMaterialMetadataChange(self) -> None:
|
||||||
if self._global_container_stack is None:
|
if self._global_container_stack is None:
|
||||||
|
|
|
@ -50,13 +50,6 @@ def test_getQualityGroups(quality_mocked_application):
|
||||||
assert "normal" in manager.getQualityGroups(mocked_stack)
|
assert "normal" in manager.getQualityGroups(mocked_stack)
|
||||||
|
|
||||||
|
|
||||||
def test_getQualityGroupsForMachineDefinition(quality_mocked_application):
|
|
||||||
manager = QualityManager(quality_mocked_application)
|
|
||||||
manager.initialize()
|
|
||||||
|
|
||||||
assert "normal" in manager.getQualityGroupsForMachineDefinition(mocked_stack)
|
|
||||||
|
|
||||||
|
|
||||||
def test_getQualityChangesGroup(quality_mocked_application):
|
def test_getQualityChangesGroup(quality_mocked_application):
|
||||||
manager = QualityManager(quality_mocked_application)
|
manager = QualityManager(quality_mocked_application)
|
||||||
manager.initialize()
|
manager.initialize()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue