From b92ca508bbe521f1fb1383361c3bbb6f140e6c97 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 10 Nov 2016 15:42:20 +0100 Subject: [PATCH] Stacks are now loaded from workspace file CURA-1263 --- plugins/3MFReader/ThreeMFWorkspaceReader.py | 36 ++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/plugins/3MFReader/ThreeMFWorkspaceReader.py b/plugins/3MFReader/ThreeMFWorkspaceReader.py index c46b83bd1f..9046c5e6f3 100644 --- a/plugins/3MFReader/ThreeMFWorkspaceReader.py +++ b/plugins/3MFReader/ThreeMFWorkspaceReader.py @@ -2,6 +2,9 @@ from UM.Workspace.WorkspaceReader import WorkspaceReader from UM.Application import Application from UM.Logger import Logger +from UM.Settings.ContainerStack import ContainerStack + +import zipfile ## Base implementation for reading 3MF workspace files. class ThreeMFWorkspaceReader(WorkspaceReader): @@ -22,4 +25,35 @@ class ThreeMFWorkspaceReader(WorkspaceReader): return WorkspaceReader.PreReadResult.accepted def read(self, file_name): - pass + # Load all the nodes / meshdata of the workspace + nodes = self._3mf_mesh_reader.read(file_name) + if nodes is None: + nodes = [] + + + archive = zipfile.ZipFile(file_name, "r") + + cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")] + + # Get the stack(s) saved in the workspace. + container_stack_files = [name for name in cura_file_names if name.endswith(".stack.cfg")] + global_stack = None + extruder_stacks = [] + for container_stack_file in container_stack_files: + container_id = container_stack_file.replace("Cura/", "") + container_id = container_id.replace(".stack.cfg", "") + stack = ContainerStack(container_id) + + # Serialize stack by converting read data from bytes to string + stack.deserialize(archive.open(container_stack_file).read().decode("utf-8")) + + if stack.getMetaDataEntry("type") == "extruder_train": + extruder_stacks.append(stack) + else: + global_stack = stack + + # Check if the right machine type is active now + #Application.getInstance().getGlobalContainerStack().getBottom().getId() == + + + return nodes