def setNextStack(self, stack: ContainerStack) -> None: super().setNextStack(stack) stack.addExtruder(self) self.addMetaDataEntry("machine", stack.id) # For backward compatibility: Register the extruder with the Extruder Manager ExtruderManager.getInstance().registerExtruder(self, stack.id) # Now each machine will have at least one extruder stack. If this is the first extruder, the extruder-specific # settings such as nozzle size and material diameter should be moved from the machine's definition_changes to # the this extruder's definition_changes. # # We do this here because it is tooooo expansive to do it in the version upgrade: During the version upgrade, # when we are upgrading a definition_changes container file, there is NO guarantee that other files such as # machine an extruder stack files are upgraded before this, so we cannot read those files assuming they are in # the latest format. # # MORE: # For single-extrusion machines, nozzle size is saved in the global stack, so the nozzle size value should be # carried to the first extruder. # For material diameter, it was supposed to be applied to all extruders, so its value should be copied to all # extruders. keys_to_copy = ["material_diameter", "machine_nozzle_size" ] # these will be copied over to all extruders for key in keys_to_copy: # Since material_diameter is not on the extruder definition, we need to add it here # WARNING: this might be very dangerous and should be refactored ASAP! definition = stack.getSettingDefinition(key) if definition: self.definition.addDefinition(definition) # Only copy the value when this extruder doesn't have the value. if self.definitionChanges.hasProperty(key, "value"): continue setting_value = stack.definitionChanges.getProperty(key, "value") if setting_value is None: continue setting_definition = stack.getSettingDefinition(key) new_instance = SettingInstance(setting_definition, self.definitionChanges) new_instance.setProperty("value", setting_value) new_instance.resetState( ) # Ensure that the state is not seen as a user state. self.definitionChanges.addInstance(new_instance) self.definitionChanges.setDirty(True) # Make sure the material diameter is up to date for the extruder stack. if key == "material_diameter": position = self.getMetaDataEntry("position", "0") Application.getInstance().getExtruderManager( ).updateMaterialForDiameter(position)
def _checkStackForErrors(self, stack: ContainerStack) -> bool: top_of_stack = cast(InstanceContainer, stack.getTop()) # Cache for efficiency. changed_setting_keys = top_of_stack.getAllKeys() # Add all relations to changed settings as well. for key in top_of_stack.getAllKeys(): instance = top_of_stack.getInstance(key) if instance is None: continue self._addRelations(changed_setting_keys, instance.definition.relations) Job.yieldThread() for changed_setting_key in changed_setting_keys: validation_state = stack.getProperty(changed_setting_key, "validationState") if validation_state is None: definition = cast(SettingDefinition, stack.getSettingDefinition(changed_setting_key)) validator_type = SettingDefinition.getValidatorForType(definition.type) if validator_type: validator = validator_type(changed_setting_key) validation_state = validator(stack) if validation_state in ( ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError, ValidatorState.Invalid): Logger.log("w", "Setting %s is not valid, but %s. Aborting slicing.", changed_setting_key, validation_state) return True Job.yieldThread() return False
def setNextStack(self, stack: ContainerStack) -> None: super().setNextStack(stack) stack.addExtruder(self) self.addMetaDataEntry("machine", stack.id) # For backward compatibility: Register the extruder with the Extruder Manager ExtruderManager.getInstance().registerExtruder(self, stack.id) # Now each machine will have at least one extruder stack. If this is the first extruder, the extruder-specific # settings such as nozzle size and material diameter should be moved from the machine's definition_changes to # the this extruder's definition_changes. # # We do this here because it is tooooo expansive to do it in the version upgrade: During the version upgrade, # when we are upgrading a definition_changes container file, there is NO guarantee that other files such as # machine an extruder stack files are upgraded before this, so we cannot read those files assuming they are in # the latest format. if self.getMetaDataEntry("position") == "0": for key in _EXTRUDER_SPECIFIC_DEFINITION_CHANGES_SETTINGS: setting_value = stack.definitionChanges.getProperty( key, "value") if setting_value is None: continue setting_definition = stack.getSettingDefinition(key) new_instance = SettingInstance(setting_definition, self.definitionChanges) new_instance.setProperty("value", setting_value) new_instance.resetState( ) # Ensure that the state is not seen as a user state. self.definitionChanges.addInstance(new_instance) self.definitionChanges.setDirty(True) stack.definitionChanges.removeInstance(key, postpone_emit=True)
def setNextStack(self, stack: ContainerStack) -> None: super().setNextStack(stack) stack.addExtruder(self) self.addMetaDataEntry("machine", stack.id) # For backward compatibility: Register the extruder with the Extruder Manager ExtruderManager.getInstance().registerExtruder(self, stack.id) # Now each machine will have at least one extruder stack. If this is the first extruder, the extruder-specific # settings such as nozzle size and material diameter should be moved from the machine's definition_changes to # the this extruder's definition_changes. # # We do this here because it is tooooo expansive to do it in the version upgrade: During the version upgrade, # when we are upgrading a definition_changes container file, there is NO guarantee that other files such as # machine an extruder stack files are upgraded before this, so we cannot read those files assuming they are in # the latest format. # # MORE: # For single-extrusion machines, nozzle size is saved in the global stack, so the nozzle size value should be # carried to the first extruder. # For material diameter, it was supposed to be applied to all extruders, so its value should be copied to all # extruders. keys_to_copy = ["material_diameter", "machine_nozzle_size" ] # these will be copied over to all extruders for key in keys_to_copy: # Only copy the value when this extruder doesn't have the value. if self.definitionChanges.hasProperty(key, "value"): continue # WARNING: this might be very dangerous and should be refactored ASAP! # # We cannot add a setting definition of "material_diameter" into the extruder's definition at runtime # because all other machines which uses "fdmextruder" as the extruder definition will be affected. # # The problem is that single extrusion machines have their default material diameter defined in the global # definitions. Now we automatically create an extruder stack for those machines using "fdmextruder" # definition, which doesn't have the specific "material_diameter" and "machine_nozzle_size" defined for # each machine. This results in wrong values which can be found in the MachineSettings dialog. # # To solve this, we put "material_diameter" back into the "fdmextruder" definition because modifying it in # the extruder definition will affect all machines which uses the "fdmextruder" definition. Moreover, now # we also check the value defined in the machine definition. If present, the value defined in the global # stack's definition changes container will be copied. Otherwise, we will check if the default values in the # machine definition and the extruder definition are the same, and if not, the default value in the machine # definition will be copied to the extruder stack's definition changes. # setting_value_in_global_def_changes = stack.definitionChanges.getProperty( key, "value") setting_value_in_global_def = stack.definition.getProperty( key, "value") setting_value = setting_value_in_global_def if setting_value_in_global_def_changes is not None: setting_value = setting_value_in_global_def_changes if setting_value == self.definition.getProperty(key, "value"): continue setting_definition = stack.getSettingDefinition(key) new_instance = SettingInstance(setting_definition, self.definitionChanges) new_instance.setProperty("value", setting_value) new_instance.resetState( ) # Ensure that the state is not seen as a user state. self.definitionChanges.addInstance(new_instance) self.definitionChanges.setDirty(True) # Make sure the material diameter is up to date for the extruder stack. if key == "material_diameter": from cura.CuraApplication import CuraApplication machine_manager = CuraApplication.getInstance( ).getMachineManager() position = self.getMetaDataEntry("position", "0") func = lambda p=position: CuraApplication.getInstance( ).getExtruderManager().updateMaterialForDiameter(p) machine_manager.machine_extruder_material_update_dict[ stack.getId()].append(func)