mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 02:37:49 -06:00
Fix material update upon gcode flavour change
CURA-5060
This commit is contained in:
parent
a40be0c64a
commit
de72dd3455
3 changed files with 28 additions and 25 deletions
|
@ -357,10 +357,10 @@ class MaterialManager(QObject):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getDefaultMaterial(self, global_stack: "GlobalStack", extruder_variant_name: str) -> Optional["MaterialNode"]:
|
def getDefaultMaterial(self, global_stack: "GlobalStack", extruder_variant_name: Optional[str]) -> Optional["MaterialNode"]:
|
||||||
node = None
|
node = None
|
||||||
machine_definition = global_stack.definition
|
machine_definition = global_stack.definition
|
||||||
if parseBool(machine_definition.getMetaDataEntry("has_materials", False)):
|
if parseBool(global_stack.getMetaDataEntry("has_materials", False)):
|
||||||
material_diameter = machine_definition.getProperty("material_diameter", "value")
|
material_diameter = machine_definition.getProperty("material_diameter", "value")
|
||||||
if isinstance(material_diameter, SettingFunction):
|
if isinstance(material_diameter, SettingFunction):
|
||||||
material_diameter = material_diameter(global_stack)
|
material_diameter = material_diameter(global_stack)
|
||||||
|
|
|
@ -905,11 +905,13 @@ class MachineManager(QObject):
|
||||||
def _setMaterial(self, position, container_node = None):
|
def _setMaterial(self, position, container_node = None):
|
||||||
if container_node:
|
if container_node:
|
||||||
self._global_container_stack.extruders[position].material = container_node.getContainer()
|
self._global_container_stack.extruders[position].material = container_node.getContainer()
|
||||||
else:
|
|
||||||
self._global_container_stack.extruders[position].material = self._empty_material_container
|
|
||||||
# The _current_root_material_id is used in the MaterialMenu to see which material is selected
|
|
||||||
root_material_id = container_node.metadata["base_file"]
|
root_material_id = container_node.metadata["base_file"]
|
||||||
root_material_name = container_node.getContainer().getName()
|
root_material_name = container_node.getContainer().getName()
|
||||||
|
else:
|
||||||
|
self._global_container_stack.extruders[position].material = self._empty_material_container
|
||||||
|
root_material_id = None
|
||||||
|
root_material_name = None
|
||||||
|
# The _current_root_material_id is used in the MaterialMenu to see which material is selected
|
||||||
if root_material_id != self._current_root_material_id[position]:
|
if root_material_id != self._current_root_material_id[position]:
|
||||||
self._current_root_material_id[position] = root_material_id
|
self._current_root_material_id[position] = root_material_id
|
||||||
self._current_root_material_name[position] = root_material_name
|
self._current_root_material_name[position] = root_material_name
|
||||||
|
|
|
@ -26,6 +26,8 @@ class MachineSettingsAction(MachineAction):
|
||||||
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
||||||
self._qml_url = "MachineSettingsAction.qml"
|
self._qml_url = "MachineSettingsAction.qml"
|
||||||
|
|
||||||
|
self._application = Application.getInstance()
|
||||||
|
|
||||||
self._global_container_stack = None
|
self._global_container_stack = None
|
||||||
|
|
||||||
from cura.Settings.CuraContainerStack import _ContainerIndexes
|
from cura.Settings.CuraContainerStack import _ContainerIndexes
|
||||||
|
@ -34,16 +36,16 @@ class MachineSettingsAction(MachineAction):
|
||||||
self._container_registry = ContainerRegistry.getInstance()
|
self._container_registry = ContainerRegistry.getInstance()
|
||||||
self._container_registry.containerAdded.connect(self._onContainerAdded)
|
self._container_registry.containerAdded.connect(self._onContainerAdded)
|
||||||
self._container_registry.containerRemoved.connect(self._onContainerRemoved)
|
self._container_registry.containerRemoved.connect(self._onContainerRemoved)
|
||||||
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
self._application.globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
||||||
|
|
||||||
self._empty_container = self._container_registry.getEmptyInstanceContainer()
|
self._empty_container = self._container_registry.getEmptyInstanceContainer()
|
||||||
|
|
||||||
self._backend = Application.getInstance().getBackend()
|
self._backend = self._application.getBackend()
|
||||||
|
|
||||||
def _onContainerAdded(self, container):
|
def _onContainerAdded(self, container):
|
||||||
# Add this action as a supported action to all machine definitions
|
# Add this action as a supported action to all machine definitions
|
||||||
if isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
|
if isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine":
|
||||||
Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
self._application.getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
||||||
|
|
||||||
def _onContainerRemoved(self, container):
|
def _onContainerRemoved(self, container):
|
||||||
# Remove definition_changes containers when a stack is removed
|
# Remove definition_changes containers when a stack is removed
|
||||||
|
@ -61,11 +63,11 @@ class MachineSettingsAction(MachineAction):
|
||||||
# Make sure there is a definition_changes container to store the machine settings
|
# Make sure there is a definition_changes container to store the machine settings
|
||||||
definition_changes_container = self._global_container_stack.definitionChanges
|
definition_changes_container = self._global_container_stack.definitionChanges
|
||||||
if definition_changes_container == self._empty_container:
|
if definition_changes_container == self._empty_container:
|
||||||
definition_changes_container = CuraStackBuilder.createDefinitionChangesContainer(
|
CuraStackBuilder.createDefinitionChangesContainer(self._global_container_stack,
|
||||||
self._global_container_stack, self._global_container_stack.getName() + "_settings")
|
self._global_container_stack.getName() + "_settings")
|
||||||
|
|
||||||
# Notify the UI in which container to store the machine settings data
|
# Notify the UI in which container to store the machine settings data
|
||||||
from cura.Settings.CuraContainerStack import CuraContainerStack, _ContainerIndexes
|
from cura.Settings.CuraContainerStack import _ContainerIndexes
|
||||||
|
|
||||||
container_index = _ContainerIndexes.DefinitionChanges
|
container_index = _ContainerIndexes.DefinitionChanges
|
||||||
if container_index != self._container_index:
|
if container_index != self._container_index:
|
||||||
|
@ -107,13 +109,13 @@ class MachineSettingsAction(MachineAction):
|
||||||
def setMachineExtruderCount(self, extruder_count):
|
def setMachineExtruderCount(self, extruder_count):
|
||||||
# Note: this method was in this class before, but since it's quite generic and other plugins also need it
|
# Note: this method was in this class before, but since it's quite generic and other plugins also need it
|
||||||
# it was moved to the machine manager instead. Now this method just calls the machine manager.
|
# it was moved to the machine manager instead. Now this method just calls the machine manager.
|
||||||
Application.getInstance().getMachineManager().setActiveMachineExtruderCount(extruder_count)
|
self._application.getMachineManager().setActiveMachineExtruderCount(extruder_count)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def forceUpdate(self):
|
def forceUpdate(self):
|
||||||
# Force rebuilding the build volume by reloading the global container stack.
|
# Force rebuilding the build volume by reloading the global container stack.
|
||||||
# This is a bit of a hack, but it seems quick enough.
|
# This is a bit of a hack, but it seems quick enough.
|
||||||
Application.getInstance().globalContainerStackChanged.emit()
|
self._application.globalContainerStackChanged.emit()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def updateHasMaterialsMetadata(self):
|
def updateHasMaterialsMetadata(self):
|
||||||
|
@ -126,9 +128,11 @@ class MachineSettingsAction(MachineAction):
|
||||||
# In other words: only continue for the UM2 (extended), but not for the UM2+
|
# In other words: only continue for the UM2 (extended), but not for the UM2+
|
||||||
return
|
return
|
||||||
|
|
||||||
stacks = ExtruderManager.getInstance().getExtruderStacks()
|
machine_manager = self._application.getMachineManager()
|
||||||
|
extruder_positions = list(self._global_container_stack.extruders.keys())
|
||||||
has_materials = self._global_container_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode"
|
has_materials = self._global_container_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode"
|
||||||
|
|
||||||
|
material_node = None
|
||||||
if has_materials:
|
if has_materials:
|
||||||
if "has_materials" in self._global_container_stack.getMetaData():
|
if "has_materials" in self._global_container_stack.getMetaData():
|
||||||
self._global_container_stack.setMetaDataEntry("has_materials", True)
|
self._global_container_stack.setMetaDataEntry("has_materials", True)
|
||||||
|
@ -136,26 +140,23 @@ class MachineSettingsAction(MachineAction):
|
||||||
self._global_container_stack.addMetaDataEntry("has_materials", True)
|
self._global_container_stack.addMetaDataEntry("has_materials", True)
|
||||||
|
|
||||||
# Set the material container for each extruder to a sane default
|
# Set the material container for each extruder to a sane default
|
||||||
for stack in stacks:
|
material_manager = self._application.getMaterialManager()
|
||||||
material_container = stack.material
|
#material_manager.initialize()
|
||||||
if material_container == self._empty_container:
|
material_node = material_manager.getDefaultMaterial(self._global_container_stack, None)
|
||||||
machine_approximate_diameter = str(round(self._global_container_stack.getProperty("material_diameter", "value")))
|
|
||||||
search_criteria = { "type": "material", "definition": "fdmprinter", "id": self._global_container_stack.getMetaDataEntry("preferred_material"), "approximate_diameter": machine_approximate_diameter}
|
|
||||||
materials = self._container_registry.findInstanceContainers(**search_criteria)
|
|
||||||
if materials:
|
|
||||||
stack.material = materials[0]
|
|
||||||
else:
|
else:
|
||||||
# The metadata entry is stored in an ini, and ini files are parsed as strings only.
|
# The metadata entry is stored in an ini, and ini files are parsed as strings only.
|
||||||
# Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False.
|
# Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False.
|
||||||
if "has_materials" in self._global_container_stack.getMetaData():
|
if "has_materials" in self._global_container_stack.getMetaData():
|
||||||
self._global_container_stack.removeMetaDataEntry("has_materials")
|
self._global_container_stack.removeMetaDataEntry("has_materials")
|
||||||
|
|
||||||
for stack in stacks:
|
# set materials
|
||||||
stack.material = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
for position in extruder_positions:
|
||||||
|
machine_manager.setMaterial(position, material_node)
|
||||||
|
|
||||||
Application.getInstance().globalContainerStackChanged.emit()
|
self._application.globalContainerStackChanged.emit()
|
||||||
|
|
||||||
@pyqtSlot(int)
|
@pyqtSlot(int)
|
||||||
def updateMaterialForDiameter(self, extruder_position: int):
|
def updateMaterialForDiameter(self, extruder_position: int):
|
||||||
# Updates the material container to a material that matches the material diameter set for the printer
|
# Updates the material container to a material that matches the material diameter set for the printer
|
||||||
Application.getInstance().getExtruderManager().updateMaterialForDiameter(extruder_position)
|
self._application.getExtruderManager().updateMaterialForDiameter(extruder_position)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue