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 cura.MachineAction import MachineAction
|
||||||
|
|
||||||
from UM.Application import Application
|
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.ContainerRegistry import ContainerRegistry
|
||||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||||
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
|
||||||
from cura.Settings.ExtruderManager import ExtruderManager
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
from cura.Settings.CuraStackBuilder import CuraStackBuilder
|
from cura.Settings.CuraStackBuilder import CuraStackBuilder
|
||||||
|
|
||||||
|
@ -36,7 +33,6 @@ class MachineSettingsAction(MachineAction):
|
||||||
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)
|
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
||||||
ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderStackChanged)
|
|
||||||
|
|
||||||
self._empty_container = self._container_registry.getEmptyInstanceContainer()
|
self._empty_container = self._container_registry.getEmptyInstanceContainer()
|
||||||
|
|
||||||
|
@ -67,7 +63,9 @@ class MachineSettingsAction(MachineAction):
|
||||||
self._global_container_stack, self._global_container_stack.getName() + "_settings")
|
self._global_container_stack, 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
|
||||||
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:
|
if container_index != self._container_index:
|
||||||
self._container_index = container_index
|
self._container_index = container_index
|
||||||
self.containerIndexChanged.emit()
|
self.containerIndexChanged.emit()
|
||||||
|
@ -82,17 +80,6 @@ class MachineSettingsAction(MachineAction):
|
||||||
if self._backend and self._backend.determineAutoSlicing():
|
if self._backend and self._backend.determineAutoSlicing():
|
||||||
self._backend.tickle()
|
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()
|
containerIndexChanged = pyqtSignal()
|
||||||
|
|
||||||
@pyqtProperty(int, notify = containerIndexChanged)
|
@pyqtProperty(int, notify = containerIndexChanged)
|
||||||
|
@ -217,8 +204,8 @@ class MachineSettingsAction(MachineAction):
|
||||||
|
|
||||||
Application.getInstance().globalContainerStackChanged.emit()
|
Application.getInstance().globalContainerStackChanged.emit()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot(int)
|
||||||
def updateMaterialForDiameter(self):
|
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
|
||||||
if not self._global_container_stack:
|
if not self._global_container_stack:
|
||||||
return
|
return
|
||||||
|
@ -226,24 +213,22 @@ class MachineSettingsAction(MachineAction):
|
||||||
if not self._global_container_stack.getMetaDataEntry("has_materials", False):
|
if not self._global_container_stack.getMetaDataEntry("has_materials", False):
|
||||||
return
|
return
|
||||||
|
|
||||||
material = ExtruderManager.getInstance().getActiveExtruderStack().material
|
extruder_stack = self._global_container_stack.extruders[str(extruder_position)]
|
||||||
material_diameter = material.getProperty("material_diameter", "value")
|
|
||||||
|
material_diameter = extruder_stack.material.getProperty("material_diameter", "value")
|
||||||
if not material_diameter:
|
if not material_diameter:
|
||||||
# in case of "empty" material
|
# in case of "empty" material
|
||||||
material_diameter = 0
|
material_diameter = 0
|
||||||
|
|
||||||
material_approximate_diameter = str(round(material_diameter))
|
material_approximate_diameter = str(round(material_diameter))
|
||||||
definition_changes = self._global_container_stack.definitionChanges
|
machine_diameter = extruder_stack.definitionChanges.getProperty("material_diameter", "value")
|
||||||
machine_diameter = definition_changes.getProperty("material_diameter", "value")
|
|
||||||
if not machine_diameter:
|
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))
|
machine_approximate_diameter = str(round(machine_diameter))
|
||||||
|
|
||||||
if material_approximate_diameter != machine_approximate_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.")
|
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):
|
if self._global_container_stack.getMetaDataEntry("has_machine_materials", False):
|
||||||
materials_definition = self._global_container_stack.definition.getId()
|
materials_definition = self._global_container_stack.definition.getId()
|
||||||
has_material_variants = self._global_container_stack.getMetaDataEntry("has_variants", False)
|
has_material_variants = self._global_container_stack.getMetaDataEntry("has_variants", False)
|
||||||
|
@ -251,45 +236,44 @@ class MachineSettingsAction(MachineAction):
|
||||||
materials_definition = "fdmprinter"
|
materials_definition = "fdmprinter"
|
||||||
has_material_variants = False
|
has_material_variants = False
|
||||||
|
|
||||||
for stack in stacks:
|
old_material = extruder_stack.material
|
||||||
old_material = stack.material
|
search_criteria = {
|
||||||
search_criteria = {
|
"type": "material",
|
||||||
"type": "material",
|
"approximate_diameter": machine_approximate_diameter,
|
||||||
"approximate_diameter": machine_approximate_diameter,
|
"material": old_material.getMetaDataEntry("material", "value"),
|
||||||
"material": old_material.getMetaDataEntry("material", "value"),
|
"supplier": old_material.getMetaDataEntry("supplier", "value"),
|
||||||
"supplier": old_material.getMetaDataEntry("supplier", "value"),
|
"color_name": old_material.getMetaDataEntry("color_name", "value"),
|
||||||
"color_name": old_material.getMetaDataEntry("color_name", "value"),
|
"definition": materials_definition
|
||||||
"definition": materials_definition
|
}
|
||||||
}
|
if has_material_variants:
|
||||||
if has_material_variants:
|
search_criteria["variant"] = extruder_stack.variant.getId()
|
||||||
search_criteria["variant"] = stack.variant.getId()
|
|
||||||
|
|
||||||
if old_material == self._empty_container:
|
if old_material == self._empty_container:
|
||||||
search_criteria.pop("material", None)
|
search_criteria.pop("material", None)
|
||||||
search_criteria.pop("supplier", None)
|
search_criteria.pop("supplier", None)
|
||||||
search_criteria.pop("definition", None)
|
search_criteria.pop("definition", None)
|
||||||
search_criteria["id"] = stack.getMetaDataEntry("preferred_material")
|
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)
|
materials = self._container_registry.findInstanceContainers(**search_criteria)
|
||||||
if not materials:
|
if not materials:
|
||||||
# Same material with new diameter is not found, search for generic version of the same material type
|
# Generic material with new diameter is not found, search for preferred material
|
||||||
search_criteria.pop("supplier", None)
|
search_criteria.pop("color_name", None)
|
||||||
search_criteria["color_name"] = "Generic"
|
search_criteria.pop("material", None)
|
||||||
materials = self._container_registry.findInstanceContainers(**search_criteria)
|
search_criteria["id"] = extruder_stack.getMetaDataEntry("preferred_material")
|
||||||
if not materials:
|
materials = self._container_registry.findInstanceContainers(**search_criteria)
|
||||||
# Generic material with new diameter is not found, search for preferred material
|
if not materials:
|
||||||
search_criteria.pop("color_name", None)
|
# Preferred material with new diameter is not found, search for any material
|
||||||
search_criteria.pop("material", None)
|
search_criteria.pop("id", None)
|
||||||
search_criteria["id"] = stack.getMetaDataEntry("preferred_material")
|
materials = self._container_registry.findInstanceContainers(**search_criteria)
|
||||||
materials = self._container_registry.findInstanceContainers(**search_criteria)
|
if not materials:
|
||||||
if not materials:
|
# Just use empty material as a final fallback
|
||||||
# Preferred material with new diameter is not found, search for any material
|
materials = [self._empty_container]
|
||||||
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)
|
if(currentIndex > 0)
|
||||||
{
|
{
|
||||||
contentItem.forceActiveFocus();
|
contentItem.forceActiveFocus();
|
||||||
Cura.ExtruderManager.setActiveExtruderIndex(currentIndex - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +384,25 @@ Cura.MachineAction
|
||||||
property bool isExtruderSetting: true
|
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
|
Loader
|
||||||
{
|
{
|
||||||
id: extruderOffsetXField
|
id: extruderOffsetXField
|
||||||
|
@ -495,7 +501,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
if(settingsTabs.currentIndex > 0)
|
if(settingsTabs.currentIndex > 0)
|
||||||
{
|
{
|
||||||
return Cura.MachineManager.activeStackId;
|
return Cura.ExtruderManager.extruderIds[String(settingsTabs.currentIndex - 1)];
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -513,11 +519,11 @@ Cura.MachineAction
|
||||||
checked: String(propertyProvider.properties.value).toLowerCase() != 'false'
|
checked: String(propertyProvider.properties.value).toLowerCase() != 'false'
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
propertyProvider.setPropertyValue("value", checked);
|
propertyProvider.setPropertyValue("value", checked);
|
||||||
if(_forceUpdateOnChange)
|
if(_forceUpdateOnChange)
|
||||||
{
|
{
|
||||||
manager.forceUpdate();
|
manager.forceUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,7 +554,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
if(settingsTabs.currentIndex > 0)
|
if(settingsTabs.currentIndex > 0)
|
||||||
{
|
{
|
||||||
return Cura.MachineManager.activeStackId;
|
return Cura.ExtruderManager.extruderIds[String(settingsTabs.currentIndex - 1)];
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -581,7 +587,10 @@ Cura.MachineAction
|
||||||
TextField
|
TextField
|
||||||
{
|
{
|
||||||
id: 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}/ }
|
validator: RegExpValidator { regExp: _allowNegative ? /-?[0-9\.]{0,6}/ : /[0-9\.]{0,6}/ }
|
||||||
onEditingFinished:
|
onEditingFinished:
|
||||||
{
|
{
|
||||||
|
@ -590,12 +599,7 @@ Cura.MachineAction
|
||||||
propertyProvider.setPropertyValue("value", text);
|
propertyProvider.setPropertyValue("value", text);
|
||||||
if(_forceUpdateOnChange)
|
if(_forceUpdateOnChange)
|
||||||
{
|
{
|
||||||
var extruderIndex = Cura.ExtruderManager.activeExtruderIndex;
|
|
||||||
manager.forceUpdate();
|
manager.forceUpdate();
|
||||||
if(Cura.ExtruderManager.activeExtruderIndex != extruderIndex)
|
|
||||||
{
|
|
||||||
Cura.ExtruderManager.setActiveExtruderIndex(extruderIndex)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(_afterOnEditingFinished)
|
if(_afterOnEditingFinished)
|
||||||
{
|
{
|
||||||
|
@ -641,7 +645,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
if(settingsTabs.currentIndex > 0)
|
if(settingsTabs.currentIndex > 0)
|
||||||
{
|
{
|
||||||
return Cura.MachineManager.activeStackId;
|
return Cura.ExtruderManager.extruderIds[String(settingsTabs.currentIndex - 1)];
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue