|
@@ -7,14 +7,11 @@ from UM.FlameProfiler import pyqtSlot
|
|
|
from cura.MachineAction import MachineAction
|
|
|
|
|
|
from UM.Application import Application
|
|
|
-from UM.Preferences import Preferences
|
|
|
-from UM.Settings.InstanceContainer import InstanceContainer
|
|
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
|
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
|
|
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
|
|
from UM.Logger import Logger
|
|
|
|
|
|
-from cura.CuraApplication import CuraApplication
|
|
|
from cura.Settings.ExtruderManager import ExtruderManager
|
|
|
from cura.Settings.CuraStackBuilder import CuraStackBuilder
|
|
|
|
|
@@ -36,7 +33,6 @@ class MachineSettingsAction(MachineAction):
|
|
|
self._container_registry.containerAdded.connect(self._onContainerAdded)
|
|
|
self._container_registry.containerRemoved.connect(self._onContainerRemoved)
|
|
|
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
|
|
- ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderStackChanged)
|
|
|
|
|
|
self._empty_container = self._container_registry.getEmptyInstanceContainer()
|
|
|
|
|
@@ -67,7 +63,9 @@ class MachineSettingsAction(MachineAction):
|
|
|
self._global_container_stack, self._global_container_stack.getName() + "_settings")
|
|
|
|
|
|
# Notify the UI in which container to store the machine settings data
|
|
|
- container_index = self._global_container_stack.getContainerIndex(definition_changes_container)
|
|
|
+ from cura.Settings.CuraContainerStack import CuraContainerStack, _ContainerIndexes
|
|
|
+
|
|
|
+ container_index = _ContainerIndexes.DefinitionChanges
|
|
|
if container_index != self._container_index:
|
|
|
self._container_index = container_index
|
|
|
self.containerIndexChanged.emit()
|
|
@@ -82,17 +80,6 @@ class MachineSettingsAction(MachineAction):
|
|
|
if self._backend and self._backend.determineAutoSlicing():
|
|
|
self._backend.tickle()
|
|
|
|
|
|
- def _onActiveExtruderStackChanged(self):
|
|
|
- extruder_container_stack = ExtruderManager.getInstance().getActiveExtruderStack()
|
|
|
- if not self._global_container_stack or not extruder_container_stack:
|
|
|
- return
|
|
|
-
|
|
|
- # Make sure there is a definition_changes container to store the machine settings
|
|
|
- definition_changes_container = extruder_container_stack.definitionChanges
|
|
|
- if definition_changes_container == self._empty_container:
|
|
|
- definition_changes_container = CuraStackBuilder.createDefinitionChangesContainer(
|
|
|
- extruder_container_stack, extruder_container_stack.getId() + "_settings")
|
|
|
-
|
|
|
containerIndexChanged = pyqtSignal()
|
|
|
|
|
|
@pyqtProperty(int, notify = containerIndexChanged)
|
|
@@ -217,8 +204,8 @@ class MachineSettingsAction(MachineAction):
|
|
|
|
|
|
Application.getInstance().globalContainerStackChanged.emit()
|
|
|
|
|
|
- @pyqtSlot()
|
|
|
- def updateMaterialForDiameter(self):
|
|
|
+ @pyqtSlot(int)
|
|
|
+ def updateMaterialForDiameter(self, extruder_position: int):
|
|
|
# Updates the material container to a material that matches the material diameter set for the printer
|
|
|
if not self._global_container_stack:
|
|
|
return
|
|
@@ -226,24 +213,22 @@ class MachineSettingsAction(MachineAction):
|
|
|
if not self._global_container_stack.getMetaDataEntry("has_materials", False):
|
|
|
return
|
|
|
|
|
|
- material = ExtruderManager.getInstance().getActiveExtruderStack().material
|
|
|
- material_diameter = material.getProperty("material_diameter", "value")
|
|
|
+ extruder_stack = self._global_container_stack.extruders[str(extruder_position)]
|
|
|
+
|
|
|
+ material_diameter = extruder_stack.material.getProperty("material_diameter", "value")
|
|
|
if not material_diameter:
|
|
|
# in case of "empty" material
|
|
|
material_diameter = 0
|
|
|
|
|
|
material_approximate_diameter = str(round(material_diameter))
|
|
|
- definition_changes = self._global_container_stack.definitionChanges
|
|
|
- machine_diameter = definition_changes.getProperty("material_diameter", "value")
|
|
|
+ machine_diameter = extruder_stack.definitionChanges.getProperty("material_diameter", "value")
|
|
|
if not machine_diameter:
|
|
|
- machine_diameter = self._global_container_stack.definition.getProperty("material_diameter", "value")
|
|
|
+ machine_diameter = extruder_stack.definition.getProperty("material_diameter", "value")
|
|
|
machine_approximate_diameter = str(round(machine_diameter))
|
|
|
|
|
|
if material_approximate_diameter != machine_approximate_diameter:
|
|
|
Logger.log("i", "The the currently active material(s) do not match the diameter set for the printer. Finding alternatives.")
|
|
|
|
|
|
- stacks = ExtruderManager.getInstance().getExtruderStacks()
|
|
|
-
|
|
|
if self._global_container_stack.getMetaDataEntry("has_machine_materials", False):
|
|
|
materials_definition = self._global_container_stack.definition.getId()
|
|
|
has_material_variants = self._global_container_stack.getMetaDataEntry("has_variants", False)
|
|
@@ -251,45 +236,44 @@ class MachineSettingsAction(MachineAction):
|
|
|
materials_definition = "fdmprinter"
|
|
|
has_material_variants = False
|
|
|
|
|
|
- for stack in stacks:
|
|
|
- old_material = stack.material
|
|
|
- search_criteria = {
|
|
|
- "type": "material",
|
|
|
- "approximate_diameter": machine_approximate_diameter,
|
|
|
- "material": old_material.getMetaDataEntry("material", "value"),
|
|
|
- "supplier": old_material.getMetaDataEntry("supplier", "value"),
|
|
|
- "color_name": old_material.getMetaDataEntry("color_name", "value"),
|
|
|
- "definition": materials_definition
|
|
|
- }
|
|
|
- if has_material_variants:
|
|
|
- search_criteria["variant"] = stack.variant.getId()
|
|
|
-
|
|
|
- if old_material == self._empty_container:
|
|
|
- search_criteria.pop("material", None)
|
|
|
- search_criteria.pop("supplier", None)
|
|
|
- search_criteria.pop("definition", None)
|
|
|
- search_criteria["id"] = stack.getMetaDataEntry("preferred_material")
|
|
|
-
|
|
|
+ old_material = extruder_stack.material
|
|
|
+ search_criteria = {
|
|
|
+ "type": "material",
|
|
|
+ "approximate_diameter": machine_approximate_diameter,
|
|
|
+ "material": old_material.getMetaDataEntry("material", "value"),
|
|
|
+ "supplier": old_material.getMetaDataEntry("supplier", "value"),
|
|
|
+ "color_name": old_material.getMetaDataEntry("color_name", "value"),
|
|
|
+ "definition": materials_definition
|
|
|
+ }
|
|
|
+ if has_material_variants:
|
|
|
+ search_criteria["variant"] = extruder_stack.variant.getId()
|
|
|
+
|
|
|
+ if old_material == self._empty_container:
|
|
|
+ search_criteria.pop("material", None)
|
|
|
+ search_criteria.pop("supplier", None)
|
|
|
+ search_criteria.pop("definition", None)
|
|
|
+ search_criteria["id"] = extruder_stack.getMetaDataEntry("preferred_material")
|
|
|
+
|
|
|
+ materials = self._container_registry.findInstanceContainers(**search_criteria)
|
|
|
+ if not materials:
|
|
|
+ # Same material with new diameter is not found, search for generic version of the same material type
|
|
|
+ search_criteria.pop("supplier", None)
|
|
|
+ search_criteria["color_name"] = "Generic"
|
|
|
materials = self._container_registry.findInstanceContainers(**search_criteria)
|
|
|
- if not materials:
|
|
|
- # Same material with new diameter is not found, search for generic version of the same material type
|
|
|
- search_criteria.pop("supplier", None)
|
|
|
- search_criteria["color_name"] = "Generic"
|
|
|
- materials = self._container_registry.findInstanceContainers(**search_criteria)
|
|
|
- if not materials:
|
|
|
- # Generic material with new diameter is not found, search for preferred material
|
|
|
- search_criteria.pop("color_name", None)
|
|
|
- search_criteria.pop("material", None)
|
|
|
- search_criteria["id"] = stack.getMetaDataEntry("preferred_material")
|
|
|
- materials = self._container_registry.findInstanceContainers(**search_criteria)
|
|
|
- if not materials:
|
|
|
- # Preferred material with new diameter is not found, search for any material
|
|
|
- search_criteria.pop("id", None)
|
|
|
- materials = self._container_registry.findInstanceContainers(**search_criteria)
|
|
|
- if not materials:
|
|
|
- # Just use empty material as a final fallback
|
|
|
- materials = [self._empty_container]
|
|
|
+ if not materials:
|
|
|
+ # Generic material with new diameter is not found, search for preferred material
|
|
|
+ search_criteria.pop("color_name", None)
|
|
|
+ search_criteria.pop("material", None)
|
|
|
+ search_criteria["id"] = extruder_stack.getMetaDataEntry("preferred_material")
|
|
|
+ materials = self._container_registry.findInstanceContainers(**search_criteria)
|
|
|
+ if not materials:
|
|
|
+ # Preferred material with new diameter is not found, search for any material
|
|
|
+ search_criteria.pop("id", None)
|
|
|
+ materials = self._container_registry.findInstanceContainers(**search_criteria)
|
|
|
+ if not materials:
|
|
|
+ # Just use empty material as a final fallback
|
|
|
+ materials = [self._empty_container]
|
|
|
|
|
|
- Logger.log("i", "Selecting new material: %s" % materials[0].getId())
|
|
|
+ Logger.log("i", "Selecting new material: %s" % materials[0].getId())
|
|
|
|
|
|
- stack.material = materials[0]
|
|
|
+ extruder_stack.material = materials[0]
|