Skip to content

Commit

Permalink
Include metadata of the ContainerStacks
Browse files Browse the repository at this point in the history
  • Loading branch information
EmJay276 committed Jun 21, 2024
1 parent d0e18c0 commit c0d71c6
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions SettingsExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from UM.Logger import Logger
from UM.i18n import i18nCatalog
from cura.CuraApplication import CuraApplication
from cura.Settings.CuraContainerStack import _ContainerIndexes

if TYPE_CHECKING:
from cura.Settings.CuraContainerStack import CuraContainerStack
from UM.Settings.Interfaces import ContainerInterface

catalog = i18nCatalog("calibration")

Expand Down Expand Up @@ -46,15 +46,13 @@ def export(self):
########################################################################
# Machine metadata
########################################################################
# add metadata for global_stack (= "machine")
global_stack_type = global_stack.getMetaDataEntry("type")
settings["metadata"][global_stack_type] = deepcopy(global_stack.getMetaData())
for key, value in settings["metadata"][global_stack_type].items():
# convert all metadata to string
settings["metadata"][global_stack_type][key] = str(value)
# get the current type and metadata of the global stack
container_type, metadata = self.get_container_metadata(global_stack)
# add metadata of the global stack
settings["metadata"][container_type] = metadata

########################################################################
# Extruder container stacks
# Extruder stacks
########################################################################
# get extruders
extruder_list = global_stack.extruderList
Expand All @@ -64,6 +62,12 @@ def export(self):
settings["metadata"]["extruders"] = {}

for i, extruder_stack in enumerate(extruder_list):
settings["metadata"]["extruders"][str(i)] = {}
# get the current type and metadata for the extruder_stack
container_type, metadata = self.get_container_metadata(extruder_stack)
# add metadata of the extruder_stack
settings["metadata"]["extruders"][str(i)] = metadata

metadata_dict, settings_dict = self.get_stack_data(extruder_stack)
settings["metadata"]["extruders"][str(i)] = metadata_dict
settings["settings"]["extruders"][str(i)] = settings_dict
Expand Down Expand Up @@ -115,20 +119,37 @@ def get_stack_data(self, container_stack: "CuraContainerStack") -> Tuple[Dict[st

# all containers inside the stack
for i, container in enumerate(container_stack.getContainers()):
# get the current container
name = _ContainerIndexes.IndexTypeMap[i]

# get the current type and metadata
container_type, container_metadata = self.get_container_metadata(container)
# add metadata of this container
metadata[name] = deepcopy(container.getMetaData())
for key, value in metadata[name].items():
# convert all metadata to string
metadata[name][key] = str(value)
metadata[container_type] = container_metadata

# dict to save container settings
settings[name] = {}
settings[container_type] = {}
# loop over all container settings
for key in container.getAllKeys():
# save settings with name and value in tmp dict
settings[name][key] = str(container.getProperty(key, 'value'))
settings[container_type][key] = str(container.getProperty(key, 'value'))

return metadata, settings

def get_container_metadata(self, container: "ContainerInterface") -> Tuple[str, Dict[str, Any]]:
"""
Get all metadata from this container and return it as a dictionary.
Args:
container (ContainerInterface): container to get the metadata from
Returns:
str: container_type
dict: metadata
"""
container_type = container.getMetaDataEntry("type")

metadata = deepcopy(container.getMetaData())
for key, value in metadata.items():
# convert all metadata to string
metadata[key] = str(value)

return container_type, metadata

0 comments on commit c0d71c6

Please sign in to comment.