From 97a1aa1a2b0ba417c8fc1127e5f108aa7eb4a44b Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Thu, 7 Jun 2018 10:54:23 +0200 Subject: [PATCH 1/3] Fix a crash in MaterialManager when the brand of the material is None. Fix other possible cases when the type or the color are also None. --- plugins/XmlMaterialProfile/XmlMaterialProfile.py | 16 ++++++++++------ resources/qml/Preferences/MaterialsPage.qml | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index f0d6915f04..148471fb6d 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -518,9 +518,10 @@ class XmlMaterialProfile(InstanceContainer): meta_data["name"] = label.text else: meta_data["name"] = self._profile_name(material.text, color.text) - meta_data["brand"] = brand.text - meta_data["material"] = material.text - meta_data["color_name"] = color.text + + meta_data["brand"] = brand.text if brand.text is not None else "Unknown Brand" + meta_data["material"] = material.text if material.text is not None else "Unknown Type" + meta_data["color_name"] = color.text if color.text is not None else "Unknown Color" continue # setting_version is derived from the "version" tag in the schema earlier, so don't set it here @@ -811,9 +812,10 @@ class XmlMaterialProfile(InstanceContainer): base_metadata["name"] = label.text else: base_metadata["name"] = cls._profile_name(material.text, color.text) - base_metadata["brand"] = brand.text - base_metadata["material"] = material.text - base_metadata["color_name"] = color.text + + base_metadata["brand"] = brand.text if brand.text is not None else "Unknown Brand" + base_metadata["material"] = material.text if material.text is not None else "Unknown Type" + base_metadata["color_name"] = color.text if color.text is not None else "Unknown Color" continue #Setting_version is derived from the "version" tag in the schema earlier, so don't set it here. @@ -976,6 +978,8 @@ class XmlMaterialProfile(InstanceContainer): @classmethod def _profile_name(cls, material_name, color_name): + if material_name is None: + return "Unknown Material" if color_name != "Generic": return "%s %s" % (color_name, material_name) else: diff --git a/resources/qml/Preferences/MaterialsPage.qml b/resources/qml/Preferences/MaterialsPage.qml index 042bd09828..4e071ccf84 100644 --- a/resources/qml/Preferences/MaterialsPage.qml +++ b/resources/qml/Preferences/MaterialsPage.qml @@ -482,7 +482,7 @@ Item { var currentItem = materialsModel.getItem(materialListView.currentIndex); - materialProperties.name = currentItem.name; + materialProperties.name = currentItem.name ? currentItem.name : "Unknown"; materialProperties.guid = currentItem.guid; materialProperties.brand = currentItem.brand ? currentItem.brand : "Unknown"; From f828c135f833a77972d261c7cdda9b6717dd12a1 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 6 Jun 2018 11:00:09 +0200 Subject: [PATCH 2/3] CURA-5249 replaced the extruder value of -1 by the more explicit defaultExtruderPosition, so now Cura is aware of the actual extruder position being used. Fixes linked icon next to support settings, like support_angle. --- cura/CuraApplication.py | 1 + cura/Settings/ExtruderManager.py | 5 +++++ plugins/CuraEngineBackend/StartSliceJob.py | 5 ----- resources/definitions/fdmprinter.def.json | 4 ++-- resources/qml/Settings/SettingExtruder.qml | 9 +-------- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 05070e4432..2a2283d3a5 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -181,6 +181,7 @@ class CuraApplication(QtApplication): SettingFunction.registerOperator("extruderValues", ExtruderManager.getExtruderValues) SettingFunction.registerOperator("extruderValue", ExtruderManager.getExtruderValue) SettingFunction.registerOperator("resolveOrValue", ExtruderManager.getResolveOrValue) + SettingFunction.registerOperator("defaultExtruderPosition", ExtruderManager.getDefaultExtruderPosition) ## Add the 4 types of profiles to storage. Resources.addStorageType(self.ResourceTypes.QualityInstanceContainer, "quality") diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index 51e7e81fef..7e7fe45cb2 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -557,6 +557,11 @@ class ExtruderManager(QObject): return result + ## Return the default extruder position from the machine manager + @staticmethod + def getDefaultExtruderPosition() -> str: + return Application.getInstance().getMachineManager().defaultExtruderPosition + ## Get all extruder values for a certain setting. # # This is exposed to qml for display purposes diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index 0297a34385..467351dd4b 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -287,14 +287,9 @@ class StartSliceJob(Job): # \return A dictionary of replacement tokens to the values they should be # replaced with. def _buildReplacementTokens(self, stack) -> dict: - default_extruder_position = int(Application.getInstance().getMachineManager().defaultExtruderPosition) result = {} for key in stack.getAllKeys(): - setting_type = stack.definition.getProperty(key, "type") value = stack.getProperty(key, "value") - if setting_type == "extruder" and value == -1: - # replace with the default value - value = default_extruder_position result[key] = value Job.yieldThread() diff --git a/resources/definitions/fdmprinter.def.json b/resources/definitions/fdmprinter.def.json index 25fe841ee4..1c43225472 100644 --- a/resources/definitions/fdmprinter.def.json +++ b/resources/definitions/fdmprinter.def.json @@ -3621,7 +3621,7 @@ "description": "The extruder train to use for printing the support. This is used in multi-extrusion.", "type": "extruder", "default_value": "0", - "value": "-1", + "value": "defaultExtruderPosition()", "enabled": "(support_enable or support_tree_enable) and extruders_enabled_count > 1", "settable_per_mesh": false, "settable_per_extruder": false, @@ -4362,7 +4362,7 @@ "description": "The extruder train to use for printing the skirt/brim/raft. This is used in multi-extrusion.", "type": "extruder", "default_value": "0", - "value": "-1", + "value": "defaultExtruderPosition()", "enabled": "extruders_enabled_count > 1 and resolveOrValue('adhesion_type') != 'none'", "settable_per_mesh": false, "settable_per_extruder": false diff --git a/resources/qml/Settings/SettingExtruder.qml b/resources/qml/Settings/SettingExtruder.qml index 38b1c2cab0..2239628e3f 100644 --- a/resources/qml/Settings/SettingExtruder.qml +++ b/resources/qml/Settings/SettingExtruder.qml @@ -93,14 +93,7 @@ SettingItem { target: control property: "currentIndex" - value: - { - if(propertyProvider.properties.value == -1) - { - return control.getIndexByPosition(Cura.MachineManager.defaultExtruderPosition); - } - return propertyProvider.properties.value - } + value: control.getIndexByPosition(propertyProvider.properties.value) // Sometimes when the value is already changed, the model is still being built. // The when clause ensures that the current index is not updated when this happens. when: control.model.items.length > 0 From 624bbbeb4ae67059b486d830f6e11e928d37eb98 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 7 Jun 2018 11:36:30 +0200 Subject: [PATCH 3/3] Account for the fact that createMachine can return None Contributes to issue CURA-5337. See also #3787. --- cura/Settings/MachineManager.py | 4 +++- plugins/3MFReader/ThreeMFWorkspaceReader.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 5c6769bc7d..124cff73d8 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -1236,7 +1236,7 @@ class MachineManager(QObject): ## Given a printer definition name, select the right machine instance. In case it doesn't exist, create a new # instance with the same network key. @pyqtSlot(str) - def switchPrinterType(self, machine_name: str): + def switchPrinterType(self, machine_name: str) -> None: # Don't switch if the user tries to change to the same type of printer if self.activeMachineDefinitionName == machine_name: return @@ -1247,6 +1247,8 @@ class MachineManager(QObject): # If there is no machine, then create a new one and set it to the non-hidden instance if not new_machine: new_machine = CuraStackBuilder.createMachine(machine_definition_id + "_sync", machine_definition_id) + if not new_machine: + return new_machine.addMetaDataEntry("um_network_key", self.activeMachineNetworkKey) new_machine.addMetaDataEntry("connect_group_name", self.activeMachineNetworkGroupName) new_machine.addMetaDataEntry("hidden", False) diff --git a/plugins/3MFReader/ThreeMFWorkspaceReader.py b/plugins/3MFReader/ThreeMFWorkspaceReader.py index 76afb6b47e..9375e5d6ee 100755 --- a/plugins/3MFReader/ThreeMFWorkspaceReader.py +++ b/plugins/3MFReader/ThreeMFWorkspaceReader.py @@ -606,9 +606,10 @@ class ThreeMFWorkspaceReader(WorkspaceReader): machine_name = self._container_registry.uniqueName(self._machine_info.name) global_stack = CuraStackBuilder.createMachine(machine_name, self._machine_info.definition_id) - extruder_stack_dict = global_stack.extruders + if global_stack: #Only switch if creating the machine was successful. + extruder_stack_dict = global_stack.extruders - self._container_registry.addContainer(global_stack) + self._container_registry.addContainer(global_stack) else: # Find the machine global_stack = self._container_registry.findContainerStacks(name = self._machine_info.name, type = "machine")[0]