diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index fe1bb6a990..ee38055a98 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -241,6 +241,13 @@ class ExtruderManager(QObject): result.append(extruder_stack.getProperty(setting_key, prop)) return result + def extruderValueWithDefault(self, value): + machine_manager = self._application.getMachineManager() + if value == "-1": + return machine_manager.defaultExtruderPosition + else: + return value + ## Gets the extruder stacks that are actually being used at the moment. # # An extruder stack is being used if it is the extruder to print any mesh @@ -252,7 +259,7 @@ class ExtruderManager(QObject): # # \return A list of extruder stacks. def getUsedExtruderStacks(self) -> List["ContainerStack"]: - global_stack = Application.getInstance().getGlobalContainerStack() + global_stack = self._application.getGlobalContainerStack() container_registry = ContainerRegistry.getInstance() used_extruder_stack_ids = set() @@ -302,16 +309,19 @@ class ExtruderManager(QObject): # Check support extruders if support_enabled: - used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("support_infill_extruder_nr", "value"))]) - used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("support_extruder_nr_layer_0", "value"))]) + used_extruder_stack_ids.add(self.extruderIds[self.extruderValueWithDefault(str(global_stack.getProperty("support_infill_extruder_nr", "value")))]) + used_extruder_stack_ids.add(self.extruderIds[self.extruderValueWithDefault(str(global_stack.getProperty("support_extruder_nr_layer_0", "value")))]) if support_bottom_enabled: - used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("support_bottom_extruder_nr", "value"))]) + used_extruder_stack_ids.add(self.extruderIds[self.extruderValueWithDefault(str(global_stack.getProperty("support_bottom_extruder_nr", "value")))]) if support_roof_enabled: - used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("support_roof_extruder_nr", "value"))]) + used_extruder_stack_ids.add(self.extruderIds[self.extruderValueWithDefault(str(global_stack.getProperty("support_roof_extruder_nr", "value")))]) # The platform adhesion extruder. Not used if using none. if global_stack.getProperty("adhesion_type", "value") != "none": - used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("adhesion_extruder_nr", "value"))]) + extruder_nr = str(global_stack.getProperty("adhesion_extruder_nr", "value")) + if extruder_nr == "-1": + extruder_nr = Application.getInstance().getMachineManager().defaultExtruderPosition + used_extruder_stack_ids.add(self.extruderIds[extruder_nr]) try: return [container_registry.findContainerStacks(id = stack_id)[0] for stack_id in used_extruder_stack_ids] diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 5faebd4dac..b46078176f 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -699,7 +699,6 @@ class MachineManager(QObject): return containers[0].definition.getId() ## Update extruder number to a valid value when the number of extruders are changed, or when an extruder is changed - # \return if any properties has been added def correctExtruderSettings(self): extruder_count = self._global_container_stack.getProperty("machine_extruder_count", "value") @@ -717,22 +716,6 @@ class MachineManager(QObject): self._global_container_stack.userChanges.removeInstance(setting_key) Logger.log("d", "Reset [%s] because its old value [%s] is no longer valid (2)", setting_key, old_value) - added_properties = False - for setting_key in self._global_container_stack.definition.getAllKeys(): - if not self._global_container_stack.getProperty(setting_key, "type") in ("extruder", "optional_extruder"): - continue - current_value = self._global_container_stack.getProperty(setting_key, "value") - if current_value is None: - continue - if current_value == "-1": - continue - if not self._global_container_stack.extruders[str(current_value)].isEnabled: - self._global_container_stack.userChanges.setProperty(setting_key, "value", str(self._default_extruder_position)) - added_properties = True - Logger.log("d", "Change [%s] to [%s] because its value [%s] is not valid", setting_key, self._default_extruder_position, current_value) - - return added_properties - ## Set the amount of extruders on the active machine (global stack) # \param extruder_count int the number of extruders to set def setActiveMachineExtruderCount(self, extruder_count): diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 3982a0ad06..86c181213e 100755 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -91,6 +91,8 @@ class CuraEngineBackend(QObject, Backend): self._onGlobalStackChanged() Application.getInstance().stacksValidationFinished.connect(self._onStackErrorCheckFinished) + # extruder enable / disable. Actually wanted to use machine manager here, but the initialization order causes it to crash + ExtruderManager.getInstance().extrudersChanged.connect(self._extruderChanged) # A flag indicating if an error check was scheduled # If so, we will stop the auto-slice timer and start upon the error check @@ -773,3 +775,9 @@ class CuraEngineBackend(QObject, Backend): def tickle(self): if self._use_timer: self._change_timer.start() + + def _extruderChanged(self): + for build_plate_number in range(Application.getInstance().getMultiBuildPlateModel().maxBuildPlate + 1): + if build_plate_number not in self._build_plates_to_be_sliced: + self._build_plates_to_be_sliced.append(build_plate_number) + self._invokeSlice() diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index cdf33eac26..c426044ae2 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -280,9 +280,15 @@ 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 = Application.getInstance().getMachineManager().defaultExtruderPosition result = {} for key in stack.getAllKeys(): - result[key] = stack.getProperty(key, "value") + setting_type = stack.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() result["print_bed_temperature"] = result["material_bed_temperature"] # Renamed settings. diff --git a/resources/definitions/fdmprinter.def.json b/resources/definitions/fdmprinter.def.json index 8c67462667..b926dc0abc 100644 --- a/resources/definitions/fdmprinter.def.json +++ b/resources/definitions/fdmprinter.def.json @@ -3458,7 +3458,7 @@ "label": "Support Extruder", "description": "The extruder train to use for printing the support. This is used in multi-extrusion.", "type": "extruder", - "default_value": "0", + "default_value": "-1", "enabled": "(support_enable or support_tree_enable) and machine_extruder_count > 1", "settable_per_mesh": false, "settable_per_extruder": false, @@ -3468,7 +3468,7 @@ "label": "Support Infill Extruder", "description": "The extruder train to use for printing the infill of the support. This is used in multi-extrusion.", "type": "extruder", - "default_value": "0", + "default_value": "-1", "value": "support_extruder_nr", "enabled": "(support_enable or support_tree_enable) and machine_extruder_count > 1", "settable_per_mesh": false, @@ -3479,7 +3479,7 @@ "label": "First Layer Support Extruder", "description": "The extruder train to use for printing the first layer of support infill. This is used in multi-extrusion.", "type": "extruder", - "default_value": "0", + "default_value": "-1", "value": "support_extruder_nr", "enabled": "(support_enable or support_tree_enable) and machine_extruder_count > 1", "settable_per_mesh": false, @@ -3490,7 +3490,7 @@ "label": "Support Interface Extruder", "description": "The extruder train to use for printing the roofs and floors of the support. This is used in multi-extrusion.", "type": "extruder", - "default_value": "0", + "default_value": "-1", "value": "support_extruder_nr", "enabled": "(support_enable or support_tree_enable) and machine_extruder_count > 1", "settable_per_mesh": false, @@ -3502,7 +3502,7 @@ "label": "Support Roof Extruder", "description": "The extruder train to use for printing the roofs of the support. This is used in multi-extrusion.", "type": "extruder", - "default_value": "0", + "default_value": "-1", "value": "support_interface_extruder_nr", "enabled": "(support_enable or support_tree_enable) and machine_extruder_count > 1", "settable_per_mesh": false, @@ -3513,7 +3513,7 @@ "label": "Support Floor Extruder", "description": "The extruder train to use for printing the floors of the support. This is used in multi-extrusion.", "type": "extruder", - "default_value": "0", + "default_value": "-1", "value": "support_interface_extruder_nr", "enabled": "(support_enable or support_tree_enable) and machine_extruder_count > 1", "settable_per_mesh": false, @@ -4184,7 +4184,7 @@ "label": "Build Plate Adhesion Extruder", "description": "The extruder train to use for printing the skirt/brim/raft. This is used in multi-extrusion.", "type": "extruder", - "default_value": "0", + "default_value": "-1", "enabled": "machine_extruder_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 3db5d327f4..2a2e213142 100644 --- a/resources/qml/Settings/SettingExtruder.qml +++ b/resources/qml/Settings/SettingExtruder.qml @@ -72,6 +72,24 @@ SettingItem value: control.currentText != "" ? control.model.getItem(control.currentIndex).color : "" } + Binding + { + target: control + property: "currentIndex" + value: + { + if(propertyProvider.properties.value == -1) + { + // TODO: accidently the extruder position is also the index. fix it + return Cura.MachineManager.defaultExtruderPosition; + } + return 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 + } + indicator: UM.RecolorImage { id: downArrow