Merge branch 'feature_intent_container_tree' of github.com:Ultimaker/Cura into feature_intent_container_tree

This commit is contained in:
Jaime van Kessel 2019-08-21 09:43:04 +02:00
commit 80dd8a0061
13 changed files with 26 additions and 25 deletions

View file

@ -70,7 +70,7 @@ 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():
quality_groups[quality_type] = QualityGroup(name = global_quality_node.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 qualities_per_type_per_extruder: for extruder, qualities_per_type in qualities_per_type_per_extruder:
quality_groups[quality_type].nodes_for_extruders[extruder] = qualities_per_type[quality_type] quality_groups[quality_type].nodes_for_extruders[extruder] = qualities_per_type[quality_type]

View file

@ -270,7 +270,7 @@ class MaterialManager(QObject):
# Check if the material is active in any extruder train. In that case, the material shouldn't be removed! # Check if the material is active in any extruder train. In that case, the material shouldn't be removed!
# In the future we might enable this again, but right now, it's causing a ton of issues if we do (since it # In the future we might enable this again, but right now, it's causing a ton of issues if we do (since it
# corrupts the configuration) # corrupts the configuration)
root_material_id = material_node.getMetaDataEntry("base_file") root_material_id = material_node.container.getMetaDataEntry("base_file")
ids_to_remove = [metadata.get("id", "") for metadata in CuraContainerRegistry.getInstance().findInstanceContainersMetadata(base_file=root_material_id)] ids_to_remove = [metadata.get("id", "") for metadata in CuraContainerRegistry.getInstance().findInstanceContainersMetadata(base_file=root_material_id)]
for extruder_stack in CuraContainerRegistry.getInstance().findContainerStacks(type = "extruder_train"): for extruder_stack in CuraContainerRegistry.getInstance().findContainerStacks(type = "extruder_train"):
@ -280,7 +280,7 @@ 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:
root_material_id = material_node.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
if CuraContainerRegistry.getInstance().isReadOnly(root_material_id): if CuraContainerRegistry.getInstance().isReadOnly(root_material_id):
@ -291,7 +291,7 @@ class MaterialManager(QObject):
@pyqtSlot("QVariant") @pyqtSlot("QVariant")
def removeMaterial(self, material_node: "MaterialNode") -> None: def removeMaterial(self, material_node: "MaterialNode") -> None:
root_material_id = material_node.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)
@ -355,7 +355,7 @@ 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]:
root_material_id = cast(str, material_node.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)
# Create a new material by cloning Generic PLA for the current material diameter and generate a new GUID. # Create a new material by cloning Generic PLA for the current material diameter and generate a new GUID.

View file

@ -29,7 +29,7 @@ class FavoriteMaterialsModel(BaseMaterialsModel):
for root_material_id, container_node in self._available_materials.items(): for root_material_id, container_node in self._available_materials.items():
# Do not include the materials from a to-be-removed package # Do not include the materials from a to-be-removed package
if bool(container_node.getMetaDataEntry("removed", False)): if bool(container_node.container.getMetaDataEntry("removed", False)):
continue continue
# Only add results for favorite materials # Only add results for favorite materials

View file

@ -20,11 +20,11 @@ class GenericMaterialsModel(BaseMaterialsModel):
for root_material_id, container_node in self._available_materials.items(): for root_material_id, container_node in self._available_materials.items():
# Do not include the materials from a to-be-removed package # Do not include the materials from a to-be-removed package
if bool(container_node.getMetaDataEntry("removed", False)): if bool(container_node.container.getMetaDataEntry("removed", False)):
continue continue
# Only add results for generic materials # Only add results for generic materials
if container_node.getMetaDataEntry("brand", "unknown").lower() != "generic": if container_node.container.getMetaDataEntry("brand", "unknown").lower() != "generic":
continue continue
item = self._createMaterialItem(root_material_id, container_node) item = self._createMaterialItem(root_material_id, container_node)

View file

@ -38,18 +38,18 @@ class MaterialBrandsModel(BaseMaterialsModel):
# Part 1: Generate the entire tree of brands -> material types -> spcific materials # Part 1: Generate the entire tree of brands -> material types -> spcific materials
for root_material_id, container_node in self._available_materials.items(): for root_material_id, container_node in self._available_materials.items():
# Do not include the materials from a to-be-removed package # Do not include the materials from a to-be-removed package
if bool(container_node.getMetaDataEntry("removed", False)): if bool(container_node.container.getMetaDataEntry("removed", False)):
continue continue
# Add brands we haven't seen yet to the dict, skipping generics # Add brands we haven't seen yet to the dict, skipping generics
brand = container_node.getMetaDataEntry("brand", "") brand = container_node.container.getMetaDataEntry("brand", "")
if brand.lower() == "generic": if brand.lower() == "generic":
continue continue
if brand not in brand_group_dict: if brand not in brand_group_dict:
brand_group_dict[brand] = {} brand_group_dict[brand] = {}
# Add material types we haven't seen yet to the dict # Add material types we haven't seen yet to the dict
material_type = container_node.getMetaDataEntry("material", "") material_type = container_node.container.getMetaDataEntry("material", "")
if material_type not in brand_group_dict[brand]: if material_type not in brand_group_dict[brand]:
brand_group_dict[brand][material_type] = [] brand_group_dict[brand][material_type] = []

View file

@ -18,10 +18,10 @@ class QualityChangesGroup(QualityGroup):
self._container_registry = Application.getInstance().getContainerRegistry() self._container_registry = Application.getInstance().getContainerRegistry()
def addNode(self, node: "QualityNode") -> None: def addNode(self, node: "QualityNode") -> None:
extruder_position = node.getMetaDataEntry("position") extruder_position = node.container.getMetaDataEntry("position")
if extruder_position is None and self.node_for_global is not None or extruder_position in self.nodes_for_extruders: #We would be overwriting another node. if extruder_position is None and self.node_for_global is not None or extruder_position in self.nodes_for_extruders: #We would be overwriting another node.
ConfigurationErrorMessage.getInstance().addFaultyContainers(node.getMetaDataEntry("id")) ConfigurationErrorMessage.getInstance().addFaultyContainers(node.container_id)
return return
if extruder_position is None: # Then we're a global quality changes profile. if extruder_position is None: # Then we're a global quality changes profile.

View file

@ -60,12 +60,12 @@ class QualityGroup(QObject):
self.node_for_global = node self.node_for_global = node
# Update is_experimental flag # Update is_experimental flag
is_experimental = parseBool(node.getMetaDataEntry("is_experimental", False)) is_experimental = parseBool(node.container.getMetaDataEntry("is_experimental", False))
self.is_experimental |= is_experimental self.is_experimental |= is_experimental
def setExtruderNode(self, position: int, node: "ContainerNode") -> None: def setExtruderNode(self, position: int, node: "ContainerNode") -> None:
self.nodes_for_extruders[position] = node self.nodes_for_extruders[position] = node
# Update is_experimental flag # Update is_experimental flag
is_experimental = parseBool(node.getMetaDataEntry("is_experimental", False)) is_experimental = parseBool(node.container.getMetaDataEntry("is_experimental", False))
self.is_experimental |= is_experimental self.is_experimental |= is_experimental

View file

@ -165,7 +165,7 @@ class QualityManager(QObject):
Logger.log("i", "Removing quality changes group [%s]", quality_changes_group.name) Logger.log("i", "Removing quality changes group [%s]", quality_changes_group.name)
removed_quality_changes_ids = set() removed_quality_changes_ids = set()
for node in quality_changes_group.getAllNodes(): for node in quality_changes_group.getAllNodes():
container_id = node.getMetaDataEntry("id") container_id = node.container_id
self._container_registry.removeContainer(container_id) self._container_registry.removeContainer(container_id)
removed_quality_changes_ids.add(container_id) removed_quality_changes_ids.add(container_id)

View file

@ -83,7 +83,7 @@ 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:
root_material_id = container_node.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)
return False return False
@ -99,7 +99,7 @@ class ContainerManager(QObject):
sub_item_changed = False sub_item_changed = False
if entries: if entries:
root_name = entries.pop(0) root_name = entries.pop(0)
root = material_group.root_material_node.getMetaDataEntry(root_name) root = material_group.root_material_node.container.getMetaDataEntry(root_name)
item = root item = root
for _ in range(len(entries)): for _ in range(len(entries)):
@ -341,7 +341,7 @@ 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
material_group = MaterialManager.getInstance().getMaterialGroup(material_node.getMetaDataEntry("base_file", "")) material_group = MaterialManager.getInstance().getMaterialGroup(material_node.container.getMetaDataEntry("base_file", ""))
if material_group is None: if material_group is None:
Logger.log("w", "Unable to find material group for %s", material_node) Logger.log("w", "Unable to find material group for %s", material_node)

View file

@ -81,7 +81,7 @@ class IntentManager(QObject):
available_quality_types = {quality_group.quality_type for quality_group in quality_groups.values() if quality_group.node_for_global is not None} available_quality_types = {quality_group.quality_type for quality_group in quality_groups.values() if quality_group.node_for_global is not None}
final_intent_ids = set() # type: Set[str] final_intent_ids = set() # type: Set[str]
current_definition_id = global_stack.definition.getMetaDataEntry("id") current_definition_id = global_stack.definition.getId()
for extruder_stack in global_stack.extruderList: for extruder_stack in global_stack.extruderList:
nozzle_name = extruder_stack.variant.getMetaDataEntry("name") nozzle_name = extruder_stack.variant.getMetaDataEntry("name")
material_id = extruder_stack.material.getMetaDataEntry("base_file") material_id = extruder_stack.material.getMetaDataEntry("base_file")
@ -106,7 +106,7 @@ class IntentManager(QObject):
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
if global_stack is None: if global_stack is None:
return ["default"] return ["default"]
current_definition_id = global_stack.definition.getMetaDataEntry("id") current_definition_id = global_stack.definition.getId()
final_intent_categories = set() # type: Set[str] final_intent_categories = set() # type: Set[str]
for extruder_stack in global_stack.extruderList: for extruder_stack in global_stack.extruderList:
nozzle_name = extruder_stack.variant.getMetaDataEntry("name") nozzle_name = extruder_stack.variant.getMetaDataEntry("name")
@ -136,7 +136,7 @@ class IntentManager(QObject):
global_stack = application.getGlobalContainerStack() global_stack = application.getGlobalContainerStack()
if global_stack is None: if global_stack is None:
return return
current_definition_id = global_stack.definition.getMetaDataEntry("id") current_definition_id = global_stack.definition.getId()
for extruder_stack in global_stack.extruderList: for extruder_stack in global_stack.extruderList:
nozzle_name = extruder_stack.variant.getMetaDataEntry("name") nozzle_name = extruder_stack.variant.getMetaDataEntry("name")
material_id = extruder_stack.material.getMetaDataEntry("base_file") material_id = extruder_stack.material.getMetaDataEntry("base_file")

View file

@ -1254,7 +1254,7 @@ class MachineManager(QObject):
return return
if material_node: if material_node:
self._global_container_stack.extruders[position].material = CuraContainerRegistry.getInstance().findContainers(id = material_node.container_id)[0] self._global_container_stack.extruders[position].material = CuraContainerRegistry.getInstance().findContainers(id = material_node.container_id)[0]
root_material_id = material_node.getMetaDataEntry("base_file", None) root_material_id = material_node.container.getMetaDataEntry("base_file", None)
else: else:
self._global_container_stack.extruders[position].material = empty_material_container self._global_container_stack.extruders[position].material = empty_material_container
root_material_id = None root_material_id = None

View file

@ -7,6 +7,7 @@ from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest
from UM.Job import Job from UM.Job import Job
from UM.Logger import Logger from UM.Logger import Logger
from UM.Settings import ContainerRegistry
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from .Models.ClusterMaterial import ClusterMaterial from .Models.ClusterMaterial import ClusterMaterial
@ -171,7 +172,7 @@ class SendMaterialJob(Job):
# Find the latest version of all material containers in the registry. # Find the latest version of all material containers in the registry.
for root_material_id, material_group in material_group_dict.items(): for root_material_id, material_group in material_group_dict.items():
material_metadata = material_group.root_material_node.getMetadata() material_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = material_group.root_material_node.container_id)[0]
try: try:
# material version must be an int # material version must be an int

View file

@ -137,7 +137,7 @@ def test_getMaterialNode(application):
manager = MaterialManager(mocked_registry) manager = MaterialManager(mocked_registry)
manager._updateMaps() manager._updateMaps()
assert manager.getMaterialNode("fdmmachine", None, None, 3, "base_material").getMetaDataEntry("id") == "test" assert manager.getMaterialNode("fdmmachine", None, None, 3, "base_material").container_id == "test"
def test_getAvailableMaterialsForMachineExtruder(application): def test_getAvailableMaterialsForMachineExtruder(application):