Skip to content

Commit

Permalink
Fix 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 c0d71c6 commit a4974f7
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions SettingsExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from UM.Logger import Logger
from UM.i18n import i18nCatalog
from cura.CuraApplication import CuraApplication
from cura.Settings.CuraContainerStack import CuraContainerStack, _ContainerIndexes

if TYPE_CHECKING:
from cura.Settings.CuraContainerStack import CuraContainerStack
Expand Down Expand Up @@ -40,16 +41,10 @@ def export(self):
Logger.log("d", "Retrieving metadata and settings ...")

# dict to save all settings
settings = {"metadata": {},
"settings": {}}

########################################################################
# Machine metadata
########################################################################
# 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
settings = {"metadata": {"global" : {},
"extruders": {}},
"settings": {"global" : {},
"extruders": {}}}

########################################################################
# Extruder stacks
Expand All @@ -58,16 +53,7 @@ def export(self):
extruder_list = global_stack.extruderList

# add metadata and settings for each extruder
settings["settings"]["extruders"] = {}
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 @@ -117,10 +103,19 @@ def get_stack_data(self, container_stack: "CuraContainerStack") -> Tuple[Dict[st
for key in container_stack.getAllKeys():
settings["all"][key] = container_stack.getProperty(key, "value")

# get the current type and metadata for the container_stack
stack_type, stack_metadata = self.get_container_metadata(container_stack)
# add metadata of the container_stack
metadata[stack_type] = stack_metadata

# all containers inside the stack
for i, container in enumerate(container_stack.getContainers()):
# get container type
# this is not done by "self.get_container_metadata" to avoid "definition" being called "extruder" for
# extruders and "machine" for the global stack
container_type = _ContainerIndexes.IndexTypeMap[i]
# get the current type and metadata
container_type, container_metadata = self.get_container_metadata(container)
_, container_metadata = self.get_container_metadata(container)
# add metadata of this container
metadata[container_type] = container_metadata

Expand Down Expand Up @@ -149,7 +144,7 @@ def get_container_metadata(self, container: "ContainerInterface") -> Tuple[str,

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

return container_type, metadata

0 comments on commit a4974f7

Please sign in to comment.