mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-22 21:59:37 +08:00
Loading extruder stack files also for single extruder printers - CURA-4379
This commit is contained in:
parent
0900a0ff07
commit
402617af1e
@ -693,54 +693,53 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
|||||||
|
|
||||||
# --
|
# --
|
||||||
# load extruder stack files
|
# load extruder stack files
|
||||||
if extruder_count_from_global_stack > 1:
|
try:
|
||||||
try:
|
for extruder_stack_file in extruder_stack_files:
|
||||||
for extruder_stack_file in extruder_stack_files:
|
container_id = self._stripFileToId(extruder_stack_file)
|
||||||
container_id = self._stripFileToId(extruder_stack_file)
|
extruder_file_content = archive.open(extruder_stack_file, "r").read().decode("utf-8")
|
||||||
extruder_file_content = archive.open(extruder_stack_file, "r").read().decode("utf-8")
|
|
||||||
|
|
||||||
if self._resolve_strategies["machine"] == "override":
|
if self._resolve_strategies["machine"] == "override":
|
||||||
# deserialize new extruder stack over the current ones
|
# deserialize new extruder stack over the current ones
|
||||||
stack = self._overrideExtruderStack(global_stack, extruder_file_content)
|
stack = self._overrideExtruderStack(global_stack, extruder_file_content)
|
||||||
|
|
||||||
elif self._resolve_strategies["machine"] == "new":
|
elif self._resolve_strategies["machine"] == "new":
|
||||||
new_id = extruder_stack_id_map[container_id]
|
new_id = extruder_stack_id_map[container_id]
|
||||||
stack = ExtruderStack(new_id)
|
stack = ExtruderStack(new_id)
|
||||||
|
|
||||||
# HACK: the global stack can have a new name, so we need to make sure that this extruder stack
|
# HACK: the global stack can have a new name, so we need to make sure that this extruder stack
|
||||||
# references to the new name instead of the old one. Normally, this can be done after
|
# references to the new name instead of the old one. Normally, this can be done after
|
||||||
# deserialize() by setting the metadata, but in the case of ExtruderStack, deserialize()
|
# deserialize() by setting the metadata, but in the case of ExtruderStack, deserialize()
|
||||||
# also does addExtruder() to its machine stack, so we have to make sure that it's pointing
|
# also does addExtruder() to its machine stack, so we have to make sure that it's pointing
|
||||||
# to the right machine BEFORE deserialization.
|
# to the right machine BEFORE deserialization.
|
||||||
extruder_config = configparser.ConfigParser()
|
extruder_config = configparser.ConfigParser()
|
||||||
extruder_config.read_string(extruder_file_content)
|
extruder_config.read_string(extruder_file_content)
|
||||||
extruder_config.set("metadata", "machine", global_stack_id_new)
|
extruder_config.set("metadata", "machine", global_stack_id_new)
|
||||||
tmp_string_io = io.StringIO()
|
tmp_string_io = io.StringIO()
|
||||||
extruder_config.write(tmp_string_io)
|
extruder_config.write(tmp_string_io)
|
||||||
extruder_file_content = tmp_string_io.getvalue()
|
extruder_file_content = tmp_string_io.getvalue()
|
||||||
|
|
||||||
stack.deserialize(extruder_file_content)
|
stack.deserialize(extruder_file_content)
|
||||||
|
|
||||||
# Ensure a unique ID and name
|
# Ensure a unique ID and name
|
||||||
stack._id = new_id
|
stack._id = new_id
|
||||||
|
|
||||||
self._container_registry.addContainer(stack)
|
self._container_registry.addContainer(stack)
|
||||||
extruder_stacks_added.append(stack)
|
extruder_stacks_added.append(stack)
|
||||||
containers_added.append(stack)
|
containers_added.append(stack)
|
||||||
else:
|
else:
|
||||||
Logger.log("w", "Unknown resolve strategy: %s", self._resolve_strategies["machine"])
|
Logger.log("w", "Unknown resolve strategy: %s", self._resolve_strategies["machine"])
|
||||||
|
|
||||||
# Create a new definition_changes container if it was empty
|
# Create a new definition_changes container if it was empty
|
||||||
if stack.definitionChanges == self._container_registry.getEmptyInstanceContainer():
|
if stack.definitionChanges == self._container_registry.getEmptyInstanceContainer():
|
||||||
stack.setDefinitionChanges(CuraStackBuilder.createDefinitionChangesContainer(stack, stack._id + "_settings"))
|
stack.setDefinitionChanges(CuraStackBuilder.createDefinitionChangesContainer(stack, stack._id + "_settings"))
|
||||||
|
|
||||||
extruder_stacks.append(stack)
|
extruder_stacks.append(stack)
|
||||||
except:
|
except:
|
||||||
Logger.logException("w", "We failed to serialize the stack. Trying to clean up.")
|
Logger.logException("w", "We failed to serialize the stack. Trying to clean up.")
|
||||||
# Something went really wrong. Try to remove any data that we added.
|
# Something went really wrong. Try to remove any data that we added.
|
||||||
for container in containers_added:
|
for container in containers_added:
|
||||||
self._container_registry.removeContainer(container.getId())
|
self._container_registry.removeContainer(container.getId())
|
||||||
return
|
return
|
||||||
|
|
||||||
#
|
#
|
||||||
# Replacing the old containers if resolve is "new".
|
# Replacing the old containers if resolve is "new".
|
||||||
|
Loading…
x
Reference in New Issue
Block a user