mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-12-11 16:00:47 -07:00
Merge branch 'master' into feature_headless_docker
This commit is contained in:
commit
1a05fd5989
198 changed files with 9149 additions and 5490 deletions
|
|
@ -816,6 +816,22 @@ class ContainerManager(QObject):
|
|||
ContainerRegistry.getInstance().addContainer(container_to_add)
|
||||
return self._getMaterialContainerIdForActiveMachine(clone_of_original)
|
||||
|
||||
## Create a duplicate of a material or it's original entry
|
||||
#
|
||||
# \return \type{str} the id of the newly created container.
|
||||
@pyqtSlot(str, result = str)
|
||||
def duplicateOriginalMaterial(self, material_id):
|
||||
|
||||
# check if the given material has a base file (i.e. was shipped by default)
|
||||
base_file = self.getContainerMetaDataEntry(material_id, "base_file")
|
||||
|
||||
if base_file == "":
|
||||
# there is no base file, so duplicate by ID
|
||||
return self.duplicateMaterial(material_id)
|
||||
else:
|
||||
# there is a base file, so duplicate the original material
|
||||
return self.duplicateMaterial(base_file)
|
||||
|
||||
## Create a new material by cloning Generic PLA for the current material diameter and setting the GUID to something unqiue
|
||||
#
|
||||
# \return \type{str} the id of the newly created container.
|
||||
|
|
|
|||
|
|
@ -202,7 +202,6 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
for plugin_id, meta_data in self._getIOPlugins("profile_reader"):
|
||||
if meta_data["profile_reader"][0]["extension"] != extension:
|
||||
continue
|
||||
|
||||
profile_reader = plugin_registry.getPluginObject(plugin_id)
|
||||
try:
|
||||
profile_or_list = profile_reader.read(file_name) # Try to open the file with the profile reader.
|
||||
|
|
@ -269,6 +268,10 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
profile._id = new_id
|
||||
profile.setName(new_name)
|
||||
|
||||
# Set the unique Id to the profile, so it's generating a new one even if the user imports the same profile
|
||||
# It also solves an issue with importing profiles from G-Codes
|
||||
profile.setMetaDataEntry("id", new_id)
|
||||
|
||||
if "type" in profile.getMetaData():
|
||||
profile.setMetaDataEntry("type", "quality_changes")
|
||||
else:
|
||||
|
|
@ -515,6 +518,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:
|
||||
|
|
@ -525,15 +529,92 @@ 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.
|
||||
if machine.qualityChanges.getId() not in ("empty", "empty_quality_changes"):
|
||||
quality_changes_machine_definition_id = machine.qualityChanges.getDefinition().getId()
|
||||
else:
|
||||
whole_machine_definition = machine.definition
|
||||
machine_entry = machine.definition.getMetaDataEntry("machine")
|
||||
if machine_entry is not None:
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
whole_machine_definition = container_registry.findDefinitionContainers(id = machine_entry)[0]
|
||||
|
||||
quality_changes_machine_definition_id = "fdmprinter"
|
||||
if whole_machine_definition.getMetaDataEntry("has_machine_quality"):
|
||||
quality_changes_machine_definition_id = machine.definition.getMetaDataEntry("quality_definition",
|
||||
whole_machine_definition.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)
|
||||
|
||||
|
|
@ -562,6 +643,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:
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class MachineManager(QObject):
|
|||
self._auto_hotends_changed = {}
|
||||
|
||||
self._material_incompatible_message = Message(catalog.i18nc("@info:status",
|
||||
"The selected material is incompatible with the selected machine or configuration."),
|
||||
"The selected material is incompatible with the selected machine or configuration."),
|
||||
title = catalog.i18nc("@info:title", "Incompatible Material"))
|
||||
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(id = self.activeMaterialId)
|
||||
|
|
@ -135,7 +135,7 @@ class MachineManager(QObject):
|
|||
activeStackValidationChanged = pyqtSignal() # Emitted whenever a validation inside active container is changed
|
||||
stacksValidationChanged = pyqtSignal() # Emitted whenever a validation is changed
|
||||
|
||||
blurSettings = pyqtSignal() # Emitted to force fields in the advanced sidebar to un-focus, so they update properly
|
||||
blurSettings = pyqtSignal() # Emitted to force fields in the advanced sidebar to un-focus, so they update properly
|
||||
|
||||
outputDevicesChanged = pyqtSignal()
|
||||
|
||||
|
|
@ -144,8 +144,7 @@ class MachineManager(QObject):
|
|||
printer_output_device.hotendIdChanged.disconnect(self._onHotendIdChanged)
|
||||
printer_output_device.materialIdChanged.disconnect(self._onMaterialIdChanged)
|
||||
|
||||
self._printer_output_devices.clear()
|
||||
|
||||
self._printer_output_devices = []
|
||||
for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices():
|
||||
if isinstance(printer_output_device, PrinterOutputDevice):
|
||||
self._printer_output_devices.append(printer_output_device)
|
||||
|
|
@ -170,58 +169,70 @@ class MachineManager(QObject):
|
|||
def totalNumberOfSettings(self) -> int:
|
||||
return len(ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0].getAllKeys())
|
||||
|
||||
def _onHotendIdChanged(self, index: Union[str, int], hotend_id: str) -> None:
|
||||
if not self._global_container_stack:
|
||||
def _onHotendIdChanged(self):
|
||||
if not self._global_container_stack or not self._printer_output_devices:
|
||||
return
|
||||
|
||||
active_printer_model = self._printer_output_devices[0].activePrinter
|
||||
if not active_printer_model:
|
||||
return
|
||||
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(type = "variant", definition = self._global_container_stack.definition.getId(), name = hotend_id)
|
||||
if containers: # New material ID is known
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
machine_id = self.activeMachineId
|
||||
extruders = extruder_manager.getMachineExtruders(machine_id)
|
||||
matching_extruder = None
|
||||
for extruder in extruders:
|
||||
if str(index) == extruder.getMetaDataEntry("position"):
|
||||
matching_extruder = extruder
|
||||
break
|
||||
if matching_extruder and matching_extruder.variant.getName() != hotend_id:
|
||||
# Save the material that needs to be changed. Multiple changes will be handled by the callback.
|
||||
self._auto_hotends_changed[str(index)] = containers[0]["id"]
|
||||
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||
else:
|
||||
Logger.log("w", "No variant found for printer definition %s with id %s" % (self._global_container_stack.definition.getId(), hotend_id))
|
||||
change_found = False
|
||||
machine_id = self.activeMachineId
|
||||
extruders = sorted(ExtruderManager.getInstance().getMachineExtruders(machine_id),
|
||||
key=lambda k: k.getMetaDataEntry("position"))
|
||||
|
||||
def _onMaterialIdChanged(self, index: Union[str, int], material_id: str):
|
||||
if not self._global_container_stack:
|
||||
for extruder_model, extruder in zip(active_printer_model.extruders, extruders):
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(type="variant",
|
||||
definition=self._global_container_stack.definition.getId(),
|
||||
name=extruder_model.hotendID)
|
||||
if containers:
|
||||
# The hotend ID is known.
|
||||
machine_id = self.activeMachineId
|
||||
if extruder.variant.getName() != extruder_model.hotendID:
|
||||
change_found = True
|
||||
self._auto_hotends_changed[extruder.getMetaDataEntry("position")] = containers[0]["id"]
|
||||
|
||||
if change_found:
|
||||
# A change was found, let the output device handle this.
|
||||
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||
|
||||
def _onMaterialIdChanged(self):
|
||||
if not self._global_container_stack or not self._printer_output_devices:
|
||||
return
|
||||
|
||||
definition_id = "fdmprinter"
|
||||
if self._global_container_stack.getMetaDataEntry("has_machine_materials", False):
|
||||
definition_id = self.activeQualityDefinitionId
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(type = "material", definition = definition_id, GUID = material_id)
|
||||
if containers: # New material ID is known
|
||||
extruders = list(extruder_manager.getMachineExtruders(self.activeMachineId))
|
||||
matching_extruder = None
|
||||
for extruder in extruders:
|
||||
if str(index) == extruder.getMetaDataEntry("position"):
|
||||
matching_extruder = extruder
|
||||
break
|
||||
active_printer_model = self._printer_output_devices[0].activePrinter
|
||||
if not active_printer_model:
|
||||
return
|
||||
|
||||
if matching_extruder and matching_extruder.material.getMetaDataEntry("GUID") != material_id:
|
||||
# Save the material that needs to be changed. Multiple changes will be handled by the callback.
|
||||
if self._global_container_stack.definition.getMetaDataEntry("has_variants") and matching_extruder.variant:
|
||||
variant_id = self.getQualityVariantId(self._global_container_stack.definition, matching_extruder.variant)
|
||||
for container in containers:
|
||||
if container.get("variant") == variant_id:
|
||||
self._auto_materials_changed[str(index)] = container["id"]
|
||||
break
|
||||
else:
|
||||
# Just use the first result we found.
|
||||
self._auto_materials_changed[str(index)] = containers[0]["id"]
|
||||
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||
else:
|
||||
Logger.log("w", "No material definition found for printer definition %s and GUID %s" % (definition_id, material_id))
|
||||
change_found = False
|
||||
machine_id = self.activeMachineId
|
||||
extruders = sorted(ExtruderManager.getInstance().getMachineExtruders(machine_id),
|
||||
key=lambda k: k.getMetaDataEntry("position"))
|
||||
|
||||
for extruder_model, extruder in zip(active_printer_model.extruders, extruders):
|
||||
if extruder_model.activeMaterial is None:
|
||||
continue
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(type="material",
|
||||
definition=self._global_container_stack.definition.getId(),
|
||||
GUID=extruder_model.activeMaterial.guid)
|
||||
if containers:
|
||||
# The material is known.
|
||||
if extruder.material.getMetaDataEntry("GUID") != extruder_model.activeMaterial.guid:
|
||||
change_found = True
|
||||
if self._global_container_stack.definition.getMetaDataEntry("has_variants") and extruder.variant:
|
||||
variant_id = self.getQualityVariantId(self._global_container_stack.definition,
|
||||
extruder.variant)
|
||||
for container in containers:
|
||||
if container.get("variant") == variant_id:
|
||||
self._auto_materials_changed[extruder.getMetaDataEntry("position")] = container["id"]
|
||||
break
|
||||
else:
|
||||
# Just use the first result we found.
|
||||
self._auto_materials_changed[extruder.getMetaDataEntry("position")] = containers[0]["id"]
|
||||
if change_found:
|
||||
# A change was found, let the output device handle this.
|
||||
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||
|
||||
def _materialHotendChangedCallback(self, button):
|
||||
if button == QMessageBox.No:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue