|
@@ -528,6 +528,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
|
|
extruder_quality_changes_container = self.findInstanceContainers(name = machine.qualityChanges.getName(), extruder = extruder_id)
|
|
|
if extruder_quality_changes_container:
|
|
|
extruder_quality_changes_container = extruder_quality_changes_container[0]
|
|
|
+
|
|
|
quality_changes_id = extruder_quality_changes_container.getId()
|
|
|
extruder_stack.setQualityChangesById(quality_changes_id)
|
|
|
else:
|
|
@@ -538,15 +539,80 @@ class CuraContainerRegistry(ContainerRegistry):
|
|
|
if extruder_quality_changes_container:
|
|
|
quality_changes_id = extruder_quality_changes_container.getId()
|
|
|
extruder_stack.setQualityChangesById(quality_changes_id)
|
|
|
+ else:
|
|
|
+ # if we still cannot find a quality changes container for the extruder, create a new one
|
|
|
+ container_id = self.uniqueName(extruder_stack.getId() + "_user")
|
|
|
+ container_name = machine.qualityChanges.getName()
|
|
|
+ extruder_quality_changes_container = InstanceContainer(container_id)
|
|
|
+ extruder_quality_changes_container.setName(container_name)
|
|
|
+ extruder_quality_changes_container.addMetaDataEntry("type", "quality_changes")
|
|
|
+ extruder_quality_changes_container.addMetaDataEntry("setting_version", CuraApplication.SettingVersion)
|
|
|
+ extruder_quality_changes_container.addMetaDataEntry("extruder", extruder_stack.definition.getId())
|
|
|
+ extruder_quality_changes_container.addMetaDataEntry("quality_type", machine.qualityChanges.getMetaDataEntry("quality_type"))
|
|
|
+ extruder_quality_changes_container.setDefinition(machine.qualityChanges.getDefinition().getId())
|
|
|
|
|
|
if not extruder_quality_changes_container:
|
|
|
Logger.log("w", "Could not find quality_changes named [%s] for extruder [%s]",
|
|
|
machine.qualityChanges.getName(), extruder_stack.getId())
|
|
|
+ else:
|
|
|
+ # move all per-extruder settings to the extruder's quality changes
|
|
|
+ for qc_setting_key in machine.qualityChanges.getAllKeys():
|
|
|
+ settable_per_extruder = machine.getProperty(qc_setting_key, "settable_per_extruder")
|
|
|
+ if settable_per_extruder:
|
|
|
+ setting_value = machine.qualityChanges.getProperty(qc_setting_key, "value")
|
|
|
+
|
|
|
+ setting_definition = machine.getSettingDefinition(qc_setting_key)
|
|
|
+ new_instance = SettingInstance(setting_definition, definition_changes)
|
|
|
+ new_instance.setProperty("value", setting_value)
|
|
|
+ new_instance.resetState() # Ensure that the state is not seen as a user state.
|
|
|
+ extruder_quality_changes_container.addInstance(new_instance)
|
|
|
+ extruder_quality_changes_container.setDirty(True)
|
|
|
+
|
|
|
+ machine.qualityChanges.removeInstance(qc_setting_key, postpone_emit=True)
|
|
|
else:
|
|
|
extruder_stack.setQualityChangesById("empty_quality_changes")
|
|
|
|
|
|
self.addContainer(extruder_stack)
|
|
|
|
|
|
+ # Also need to fix the other qualities that are suitable for this machine. Those quality changes may still have
|
|
|
+ # per-extruder settings in the container for the machine instead of the extruder.
|
|
|
+ quality_changes_machine_definition_id = machine.qualityChanges.getDefinition().getId()
|
|
|
+ qcs = self.findInstanceContainers(type = "quality_changes", definition = quality_changes_machine_definition_id)
|
|
|
+ qc_groups = {} # map of qc names -> qc containers
|
|
|
+ for qc in qcs:
|
|
|
+ qc_name = qc.getName()
|
|
|
+ if qc_name not in qc_groups:
|
|
|
+ qc_groups[qc_name] = []
|
|
|
+ qc_groups[qc_name].append(qc)
|
|
|
+ # try to find from the quality changes cura directory too
|
|
|
+ quality_changes_container = self._findQualityChangesContainerInCuraFolder(machine.qualityChanges.getName())
|
|
|
+ if quality_changes_container:
|
|
|
+ qc_groups[qc_name].append(quality_changes_container)
|
|
|
+
|
|
|
+ for qc_name, qc_list in qc_groups.items():
|
|
|
+ qc_dict = {"global": None, "extruders": []}
|
|
|
+ for qc in qc_list:
|
|
|
+ extruder_def_id = qc.getMetaDataEntry("extruder")
|
|
|
+ if extruder_def_id is not None:
|
|
|
+ qc_dict["extruders"].append(qc)
|
|
|
+ else:
|
|
|
+ qc_dict["global"] = qc
|
|
|
+ if qc_dict["global"] is not None and len(qc_dict["extruders"]) == 1:
|
|
|
+ # move per-extruder settings
|
|
|
+ for qc_setting_key in qc_dict["global"].getAllKeys():
|
|
|
+ settable_per_extruder = machine.getProperty(qc_setting_key, "settable_per_extruder")
|
|
|
+ if settable_per_extruder:
|
|
|
+ setting_value = qc_dict["global"].getProperty(qc_setting_key, "value")
|
|
|
+
|
|
|
+ setting_definition = machine.getSettingDefinition(qc_setting_key)
|
|
|
+ new_instance = SettingInstance(setting_definition, definition_changes)
|
|
|
+ new_instance.setProperty("value", setting_value)
|
|
|
+ new_instance.resetState() # Ensure that the state is not seen as a user state.
|
|
|
+ qc_dict["extruders"][0].addInstance(new_instance)
|
|
|
+ qc_dict["extruders"][0].setDirty(True)
|
|
|
+
|
|
|
+ qc_dict["global"].removeInstance(qc_setting_key, postpone_emit=True)
|
|
|
+
|
|
|
# Set next stack at the end
|
|
|
extruder_stack.setNextStack(machine)
|
|
|
|
|
@@ -575,6 +641,9 @@ class CuraContainerRegistry(ContainerRegistry):
|
|
|
if parser["general"]["name"] == name:
|
|
|
# load the container
|
|
|
container_id = os.path.basename(file_path).replace(".inst.cfg", "")
|
|
|
+ if self.findInstanceContainers(id = container_id):
|
|
|
+ # this container is already in the registry, skip it
|
|
|
+ continue
|
|
|
|
|
|
instance_container = InstanceContainer(container_id)
|
|
|
with open(file_path, "r") as f:
|