mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-13 01:37:51 -06:00
Don't use material groups to find just the root container
Just look it up in the container registry. If you know the ID, this look-up is just a dictionary look-up as well. Contributes to issue CURA-6600.
This commit is contained in:
parent
882e60bf95
commit
bb0c9c80dc
2 changed files with 19 additions and 22 deletions
|
@ -87,14 +87,15 @@ class ContainerManager(QObject):
|
||||||
Logger.log("w", "Container node {0} doesn't have a container.".format(container_node.container_id))
|
Logger.log("w", "Container node {0} doesn't have a container.".format(container_node.container_id))
|
||||||
return False
|
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):
|
container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry()
|
||||||
|
if container_registry.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
|
||||||
|
root_material_query = container_registry.findContainers(id = root_material_id)
|
||||||
material_group = MaterialManager.getInstance().getMaterialGroup(root_material_id)
|
if not root_material_query:
|
||||||
if material_group is None:
|
Logger.log("w", "Unable to find root material: {root_material}.".format(root_material = root_material_id))
|
||||||
Logger.log("w", "Unable to find material group for: %s.", root_material_id)
|
|
||||||
return False
|
return False
|
||||||
|
root_material = root_material_query[0]
|
||||||
|
|
||||||
entries = entry_name.split("/")
|
entries = entry_name.split("/")
|
||||||
entry_name = entries.pop()
|
entry_name = entries.pop()
|
||||||
|
@ -102,7 +103,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.container.getMetaDataEntry(root_name)
|
root = root_material.getMetaDataEntry(root_name)
|
||||||
|
|
||||||
item = root
|
item = root
|
||||||
for _ in range(len(entries)):
|
for _ in range(len(entries)):
|
||||||
|
@ -115,11 +116,9 @@ class ContainerManager(QObject):
|
||||||
entry_name = root_name
|
entry_name = root_name
|
||||||
entry_value = root
|
entry_value = root
|
||||||
|
|
||||||
container = material_group.root_material_node.container
|
root_material.setMetaDataEntry(entry_name, entry_value)
|
||||||
if container is not None:
|
|
||||||
container.setMetaDataEntry(entry_name, entry_value)
|
|
||||||
if sub_item_changed: #If it was only a sub-item that has changed then the setMetaDataEntry won't correctly notice that something changed, and we must manually signal that the metadata changed.
|
if sub_item_changed: #If it was only a sub-item that has changed then the setMetaDataEntry won't correctly notice that something changed, and we must manually signal that the metadata changed.
|
||||||
container.metaDataChanged.emit(container)
|
root_material.metaDataChanged.emit(root_material)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@pyqtSlot(str, result = str)
|
@pyqtSlot(str, result = str)
|
||||||
|
@ -355,11 +354,11 @@ class ContainerManager(QObject):
|
||||||
if material_node.container is None:
|
if material_node.container is None:
|
||||||
Logger.log("w", "Material node {0} doesn't have a container.".format(material_node.container_id))
|
Logger.log("w", "Material node {0} doesn't have a container.".format(material_node.container_id))
|
||||||
return
|
return
|
||||||
material_group = MaterialManager.getInstance().getMaterialGroup(material_node.container.getMetaDataEntry("base_file", ""))
|
root_material_query = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry().findInstanceContainers(id = material_node.getMetaDataEntry("base_file", ""))
|
||||||
|
if not root_material_query:
|
||||||
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)
|
||||||
return
|
return
|
||||||
|
root_material = root_material_query[0]
|
||||||
|
|
||||||
# Generate a new GUID
|
# Generate a new GUID
|
||||||
new_guid = str(uuid.uuid4())
|
new_guid = str(uuid.uuid4())
|
||||||
|
@ -367,9 +366,7 @@ class ContainerManager(QObject):
|
||||||
# Update the GUID
|
# Update the GUID
|
||||||
# NOTE: We only need to set the root material container because XmlMaterialProfile.setMetaDataEntry() will
|
# NOTE: We only need to set the root material container because XmlMaterialProfile.setMetaDataEntry() will
|
||||||
# take care of the derived containers too
|
# take care of the derived containers too
|
||||||
container = material_group.root_material_node.container
|
root_material.setMetaDataEntry("GUID", new_guid)
|
||||||
if container is not None:
|
|
||||||
container.setMetaDataEntry("GUID", new_guid)
|
|
||||||
|
|
||||||
def _performMerge(self, merge_into: InstanceContainer, merge: InstanceContainer, clear_settings: bool = True) -> None:
|
def _performMerge(self, merge_into: InstanceContainer, merge: InstanceContainer, clear_settings: bool = True) -> None:
|
||||||
if merge == merge_into:
|
if merge == merge_into:
|
||||||
|
|
|
@ -81,7 +81,7 @@ class UFPWriter(MeshWriter):
|
||||||
# Store the material.
|
# Store the material.
|
||||||
application = CuraApplication.getInstance()
|
application = CuraApplication.getInstance()
|
||||||
machine_manager = application.getMachineManager()
|
machine_manager = application.getMachineManager()
|
||||||
material_manager = application.getMaterialManager()
|
container_registry = application.getContainerRegistry()
|
||||||
global_stack = machine_manager.activeMachine
|
global_stack = machine_manager.activeMachine
|
||||||
|
|
||||||
material_extension = "xml.fdm_material"
|
material_extension = "xml.fdm_material"
|
||||||
|
@ -107,12 +107,12 @@ class UFPWriter(MeshWriter):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
material_root_id = material.getMetaDataEntry("base_file")
|
material_root_id = material.getMetaDataEntry("base_file")
|
||||||
material_group = material_manager.getMaterialGroup(material_root_id)
|
material_root_query = container_registry.findContainers(id = material_root_id)
|
||||||
if material_group is None:
|
if not material_root_query:
|
||||||
Logger.log("e", "Cannot find material container with root id [%s]", material_root_id)
|
Logger.log("e", "Cannot find material container with root id {root_id}".format(root_id = material_root_id))
|
||||||
return False
|
return False
|
||||||
|
material_container = material_root_query[0]
|
||||||
|
|
||||||
material_container = material_group.root_material_node.container
|
|
||||||
try:
|
try:
|
||||||
serialized_material = material_container.serialize()
|
serialized_material = material_container.serialize()
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue