Get extruder configs to frontend.

When choosing the printer, all possible (single) extruder configs need to be shown for that printer.

CURA-9278
This commit is contained in:
Remco Burema 2022-09-08 13:36:42 +02:00
parent 5866560540
commit 04cd76cb3b
3 changed files with 53 additions and 51 deletions

View file

@ -24,60 +24,61 @@ class CompatibleMachineModel(ListModel):
def __init__(self, parent: Optional[QObject] = None) -> None: def __init__(self, parent: Optional[QObject] = None) -> None:
super().__init__(parent) super().__init__(parent)
self._filter_on_definition_id: Optional[str] = None
self._catalog = i18nCatalog("cura") self._catalog = i18nCatalog("cura")
self.addRoleName(self.NameRole, "name") self.addRoleName(self.NameRole, "name")
self.addRoleName(self.IdRole, "id") self.addRoleName(self.IdRole, "id")
self.addRoleName(self.ExtrudersRole, "extruders") self.addRoleName(self.ExtrudersRole, "extruders")
filterChanged = pyqtSignal(str)
@pyqtSlot(str)
def setFilter(self, abstract_machine_id: str) -> None:
# TODO??: defensive coding; check if machine is abstract & abort/log if not
self._filter_on_definition_id = abstract_machine_id
# Don't need a delayed update, since it's fire once on user click (either on 'print to cloud' or 'refresh').
# So, no signals that could come in (too) quickly.
self.filterChanged.emit(self._filter_on_definition_id)
self._update() self._update()
@pyqtProperty(str, fset=setFilter, notify=filterChanged)
def filter(self) -> str:
return self._filter_on_definition_id
def _update(self) -> None:
self.clear()
if not self._filter_on_definition_id or self._filter_on_definition_id == "":
# TODO?: log
return
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
machine_manager = CuraApplication.getInstance().getMachineManager() machine_manager = CuraApplication.getInstance().getMachineManager()
compatible_machines = machine_manager.getMachinesWithDefinition(self._filter_on_definition_id, online_only = True) machine_manager.globalContainerChanged.connect(self._update)
# TODO: Handle 0 compatible machines -> option to close window? Message in card? (remember the design has a refresh button!)
for container_stack in compatible_machines: def _update(self) -> None:
if parseBool(container_stack.getMetaDataEntry("hidden", False)) or parseBool(container_stack.getMetaDataEntry("is_abstract_machine", False)): self.clear()
continue
self.addItem(container_stack)
def addItem(self, container_stack: ContainerStack) -> None: from cura.CuraApplication import CuraApplication
extruders = CuraContainerRegistry.getInstance().findContainerStacks(type="extruder_train", machine=container_stack.getId()) machine_manager = CuraApplication.getInstance().getMachineManager()
self.appendItem({
"name": container_stack.getName(), # Need to loop over the output-devices, not the stacks, since we need all applicable configurations, not just the current loaded one.
"id": container_stack.getId(), for output_device in machine_manager.printerOutputDevices:
"extruders": [self.getExtruderModel(cast(ExtruderStack, extruder)) for extruder in extruders] for printer in output_device.printers:
extruder_configs = dict()
# initialize & add current active material:
for extruder in printer.extruders:
materials = [] if not extruder.activeMaterial else [{
"brand": extruder.activeMaterial.brand,
"name": extruder.activeMaterial.name,
"hexcolor": extruder.activeMaterial.color
}]
extruder_configs[extruder.getPosition()] = {
"position": extruder.getPosition(),
"core": extruder.hotendID,
"materials": materials
}
# add currently inactive, but possible materials:
for configuration in printer.availableConfigurations:
print(" CONFIG !")
for extruder in configuration.extruderConfigurations:
if not extruder.position in extruder_configs:
# TODO: log -- all extruders should be present in the init round, regardless of if a material was active
continue
extruder_configs[extruder.position]["materials"].append({
"brand": extruder.material.brand,
"name": extruder.material.name,
"hexcolor": extruder.material.color
}) })
def getExtruderModel(self, extruder: ExtruderStack) -> Dict: self.appendItem({
# Temp Dummy Data "name": printer.name,
# ExtruderConfigrationModel does what we want here "id": printer.uniqueName,
extruder_model = { "extruders": [extruder for extruder in extruder_configs.values()]
"core": extruder.quality.getMetaDataEntry("variant", ""), })
"materials": [{"name": "Ultimaker Blue", "color": "blue"}, {"name": "Ultimaker Red", "color": "red"}, {"name": "Ultimaker Orange", "color": "orange"}]
}
return extruder_model
# TODO: Handle 0 compatible machines -> option to close window? Message in card? (remember the design has a refresh button!)

View file

@ -27,10 +27,7 @@ UM.Dialog
{ {
id: contents id: contents
model: Cura.CompatibleMachineModel model: Cura.CompatibleMachineModel {}
{
filter: machine_id_filter
}
delegate: Cura.PrintSelectorCard delegate: Cura.PrintSelectorCard
{ {

View file

@ -1,3 +1,6 @@
// Copyright (c) 2022 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 2.9 import QtQuick.Controls 2.9
import QtQuick.Layouts 2.10 import QtQuick.Layouts 2.10
@ -5,7 +8,8 @@ import QtQuick.Layouts 2.10
import UM 1.5 as UM import UM 1.5 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
Rectangle { Rectangle
{
property alias name: printerTitle.text property alias name: printerTitle.text
property var extruders property var extruders
@ -78,7 +82,7 @@ Rectangle {
id: singleMaterialText id: singleMaterialText
anchors.left: extruderCore.right anchors.left: extruderCore.right
anchors.verticalCenter: extruderCore.verticalCenter anchors.verticalCenter: extruderCore.verticalCenter
text: modelData.materials.length == 1 ? modelDatamaterials[0].name : "test" text: modelData.materials.length == 1 ? modelData.materials[0].brand + " " + modelData.materials[0].name : ""
visible: modelData.materials.length == 1 visible: modelData.materials.length == 1
} }
@ -88,13 +92,13 @@ Rectangle {
anchors.top: extruderCore.bottom anchors.top: extruderCore.bottom
anchors.left: extruderCore.left anchors.left: extruderCore.left
anchors.topMargin: UM.Theme.getSize("narrow_margin").height anchors.topMargin: UM.Theme.getSize("narrow_margin").height
visible: modelData.materials.length > 1
Repeater Repeater
{ {
model: modelData.materials model: modelData.materials
visible: modelData.materials.length > 1
UM.Label UM.Label
{ {
text: modelData.name text: modelData.brand + " " + modelData.name
} }
} }
} }
@ -131,4 +135,4 @@ Rectangle {
} }
} }
} }
} }