mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Fix MachineSettings dialog
CURA-4708 - Move material diameter and nozzle size to extruder tabs - Fix value bindings
This commit is contained in:
parent
0b7519dff2
commit
b246a102ed
2 changed files with 77 additions and 89 deletions
|
@ -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()
|
||||
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"] = stack.getMetaDataEntry("preferred_material")
|
||||
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]
|
||||
|
|
|
@ -292,18 +292,6 @@ Cura.MachineAction
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader
|
||||
{
|
||||
id: materialDiameterField
|
||||
visible: Cura.MachineManager.hasMaterials
|
||||
sourceComponent: numericTextFieldWithUnit
|
||||
property string settingKey: "material_diameter"
|
||||
property string unit: catalog.i18nc("@label", "mm")
|
||||
property string tooltip: catalog.i18nc("@tooltip", "The nominal diameter of filament supported by the printer. The exact diameter will be overridden by the material and/or the profile.")
|
||||
property var afterOnEditingFinished: manager.updateMaterialForDiameter
|
||||
property string label: catalog.i18nc("@label", "Material diameter")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -360,7 +348,6 @@ Cura.MachineAction
|
|||
if(currentIndex > 0)
|
||||
{
|
||||
contentItem.forceActiveFocus();
|
||||
Cura.ExtruderManager.setActiveExtruderIndex(currentIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,6 +384,25 @@ Cura.MachineAction
|
|||
property bool isExtruderSetting: true
|
||||
}
|
||||
|
||||
Loader
|
||||
{
|
||||
id: materialDiameterField
|
||||
visible: Cura.MachineManager.hasMaterials
|
||||
sourceComponent: numericTextFieldWithUnit
|
||||
property string settingKey: "material_diameter"
|
||||
property string label: catalog.i18nc("@label", "Material diameter")
|
||||
property string unit: catalog.i18nc("@label", "mm")
|
||||
property string tooltip: catalog.i18nc("@tooltip", "The nominal diameter of filament supported by the printer. The exact diameter will be overridden by the material and/or the profile.")
|
||||
property var afterOnEditingFinished:
|
||||
{
|
||||
if (settingsTabs.currentIndex > 0)
|
||||
{
|
||||
manager.updateMaterialForDiameter(settingsTabs.currentIndex - 1);
|
||||
}
|
||||
}
|
||||
property bool isExtruderSetting: true
|
||||
}
|
||||
|
||||
Loader
|
||||
{
|
||||
id: extruderOffsetXField
|
||||
|
@ -495,7 +501,7 @@ Cura.MachineAction
|
|||
{
|
||||
if(settingsTabs.currentIndex > 0)
|
||||
{
|
||||
return Cura.MachineManager.activeStackId;
|
||||
return Cura.ExtruderManager.extruderIds[String(settingsTabs.currentIndex - 1)];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -513,11 +519,11 @@ Cura.MachineAction
|
|||
checked: String(propertyProvider.properties.value).toLowerCase() != 'false'
|
||||
onClicked:
|
||||
{
|
||||
propertyProvider.setPropertyValue("value", checked);
|
||||
if(_forceUpdateOnChange)
|
||||
{
|
||||
manager.forceUpdate();
|
||||
}
|
||||
propertyProvider.setPropertyValue("value", checked);
|
||||
if(_forceUpdateOnChange)
|
||||
{
|
||||
manager.forceUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -548,7 +554,7 @@ Cura.MachineAction
|
|||
{
|
||||
if(settingsTabs.currentIndex > 0)
|
||||
{
|
||||
return Cura.MachineManager.activeStackId;
|
||||
return Cura.ExtruderManager.extruderIds[String(settingsTabs.currentIndex - 1)];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -581,7 +587,10 @@ Cura.MachineAction
|
|||
TextField
|
||||
{
|
||||
id: textField
|
||||
text: (propertyProvider.properties.value) ? propertyProvider.properties.value : ""
|
||||
text: {
|
||||
const value = propertyProvider.properties.value;
|
||||
return value ? value : "";
|
||||
}
|
||||
validator: RegExpValidator { regExp: _allowNegative ? /-?[0-9\.]{0,6}/ : /[0-9\.]{0,6}/ }
|
||||
onEditingFinished:
|
||||
{
|
||||
|
@ -590,12 +599,7 @@ Cura.MachineAction
|
|||
propertyProvider.setPropertyValue("value", text);
|
||||
if(_forceUpdateOnChange)
|
||||
{
|
||||
var extruderIndex = Cura.ExtruderManager.activeExtruderIndex;
|
||||
manager.forceUpdate();
|
||||
if(Cura.ExtruderManager.activeExtruderIndex != extruderIndex)
|
||||
{
|
||||
Cura.ExtruderManager.setActiveExtruderIndex(extruderIndex)
|
||||
}
|
||||
}
|
||||
if(_afterOnEditingFinished)
|
||||
{
|
||||
|
@ -641,7 +645,7 @@ Cura.MachineAction
|
|||
{
|
||||
if(settingsTabs.currentIndex > 0)
|
||||
{
|
||||
return Cura.MachineManager.activeStackId;
|
||||
return Cura.ExtruderManager.extruderIds[String(settingsTabs.currentIndex - 1)];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue