mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -06:00
Move the machines from machinelist into their own model
CURA-6011
This commit is contained in:
parent
a18203b286
commit
226d052468
5 changed files with 97 additions and 53 deletions
|
@ -51,6 +51,7 @@ from cura.Arranging.ArrangeObjectsJob import ArrangeObjectsJob
|
||||||
from cura.Arranging.ArrangeObjectsAllBuildPlatesJob import ArrangeObjectsAllBuildPlatesJob
|
from cura.Arranging.ArrangeObjectsAllBuildPlatesJob import ArrangeObjectsAllBuildPlatesJob
|
||||||
from cura.Arranging.ShapeArray import ShapeArray
|
from cura.Arranging.ShapeArray import ShapeArray
|
||||||
from cura.MultiplyObjectsJob import MultiplyObjectsJob
|
from cura.MultiplyObjectsJob import MultiplyObjectsJob
|
||||||
|
from cura.PrintersModel import PrintersModel
|
||||||
from cura.Scene.ConvexHullDecorator import ConvexHullDecorator
|
from cura.Scene.ConvexHullDecorator import ConvexHullDecorator
|
||||||
from cura.Operations.SetParentOperation import SetParentOperation
|
from cura.Operations.SetParentOperation import SetParentOperation
|
||||||
from cura.Scene.SliceableObjectDecorator import SliceableObjectDecorator
|
from cura.Scene.SliceableObjectDecorator import SliceableObjectDecorator
|
||||||
|
@ -955,6 +956,7 @@ class CuraApplication(QtApplication):
|
||||||
qmlRegisterType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel")
|
qmlRegisterType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel")
|
||||||
qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer")
|
qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer")
|
||||||
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
|
||||||
|
qmlRegisterType(PrintersModel, "Cura", 1, 0, "PrintersModel")
|
||||||
|
|
||||||
qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel")
|
qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel")
|
||||||
qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel")
|
qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel")
|
||||||
|
|
65
cura/PrintersModel.py
Normal file
65
cura/PrintersModel.py
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from UM.Qt.ListModel import ListModel
|
||||||
|
|
||||||
|
from PyQt5.QtCore import pyqtProperty, Qt, pyqtSignal
|
||||||
|
|
||||||
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
from UM.Settings.ContainerStack import ContainerStack
|
||||||
|
|
||||||
|
from cura.PrinterOutputDevice import ConnectionType
|
||||||
|
|
||||||
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
|
|
||||||
|
class PrintersModel(ListModel):
|
||||||
|
NameRole = Qt.UserRole + 1
|
||||||
|
IdRole = Qt.UserRole + 2
|
||||||
|
HasRemoteConnectionRole = Qt.UserRole + 3
|
||||||
|
ConnectionTypeRole = Qt.UserRole + 4
|
||||||
|
MetaDataRole = Qt.UserRole + 5
|
||||||
|
|
||||||
|
def __init__(self, parent = None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.addRoleName(self.NameRole, "name")
|
||||||
|
self.addRoleName(self.IdRole, "id")
|
||||||
|
self.addRoleName(self.HasRemoteConnectionRole, "hasRemoteConnection")
|
||||||
|
self.addRoleName(self.ConnectionTypeRole, "connectionType")
|
||||||
|
self.addRoleName(self.MetaDataRole, "metadata")
|
||||||
|
self._container_stacks = []
|
||||||
|
|
||||||
|
# Listen to changes
|
||||||
|
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerChanged)
|
||||||
|
ContainerRegistry.getInstance().containerMetaDataChanged.connect(self._onContainerChanged)
|
||||||
|
ContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChanged)
|
||||||
|
self._filter_dict = {}
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
## Handler for container added/removed events from registry
|
||||||
|
def _onContainerChanged(self, container):
|
||||||
|
# We only need to update when the added / removed container GlobalStack
|
||||||
|
if isinstance(container, GlobalStack):
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
## Handler for container name change events.
|
||||||
|
def _onContainerNameChanged(self):
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
def _update(self) -> None:
|
||||||
|
items = []
|
||||||
|
for container in self._container_stacks:
|
||||||
|
container.nameChanged.disconnect(self._onContainerNameChanged)
|
||||||
|
|
||||||
|
container_stacks = ContainerRegistry.getInstance().findContainerStacks(type = "machine")
|
||||||
|
|
||||||
|
for container_stack in container_stacks:
|
||||||
|
connection_type = container_stack.getMetaDataEntry("connection_type")
|
||||||
|
has_remote_connection = connection_type in [str(ConnectionType.NetworkConnection), str(ConnectionType.CloudConnection), str(ConnectionType.ClusterConnection)]
|
||||||
|
|
||||||
|
# TODO: Remove reference to connect group name.
|
||||||
|
items.append({"name": container_stack.getMetaDataEntry("connect_group_name", container_stack.getName()),
|
||||||
|
"id": container_stack.getId(),
|
||||||
|
"hasRemoteConnection": has_remote_connection,
|
||||||
|
"connectionType": connection_type})
|
||||||
|
items.sort(key=lambda i: not i["hasRemoteConnection"])
|
||||||
|
self.setItems(items)
|
|
@ -283,6 +283,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
|
|
||||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if global_container_stack and device.getId() == global_container_stack.getMetaDataEntry("um_network_key"):
|
if global_container_stack and device.getId() == global_container_stack.getMetaDataEntry("um_network_key"):
|
||||||
|
global_container_stack.setMetaDataEntry("connection_type", str(device.getConnectionType()))
|
||||||
device.connect()
|
device.connect()
|
||||||
device.connectionStateChanged.connect(self._onDeviceConnectionStateChanged)
|
device.connectionStateChanged.connect(self._onDeviceConnectionStateChanged)
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,12 @@ Cura.ExpandablePopup
|
||||||
scroll.height = Math.min(height, maximumHeight)
|
scroll.height = Math.min(height, maximumHeight)
|
||||||
popup.height = scroll.height + buttonRow.height
|
popup.height = scroll.height + buttonRow.height
|
||||||
}
|
}
|
||||||
|
Component.onCompleted:
|
||||||
|
{
|
||||||
|
scroll.height = Math.min(height, maximumHeight)
|
||||||
|
popup.height = scroll.height + buttonRow.height
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,46 +7,48 @@ import QtQuick.Controls 2.3
|
||||||
import UM 1.2 as UM
|
import UM 1.2 as UM
|
||||||
import Cura 1.0 as Cura
|
import Cura 1.0 as Cura
|
||||||
|
|
||||||
Column
|
ListView
|
||||||
{
|
{
|
||||||
id: machineSelectorList
|
id: listView
|
||||||
|
height: childrenRect.height
|
||||||
|
width: 200
|
||||||
|
model: Cura.PrintersModel {}
|
||||||
|
section.property: "hasRemoteConnection"
|
||||||
|
|
||||||
Label
|
section.delegate: Label
|
||||||
{
|
{
|
||||||
text: catalog.i18nc("@label", "Connected printers")
|
text: section == "true" ? catalog.i18nc("@label", "Connected printers") : catalog.i18nc("@label", "Preset printers")
|
||||||
visible: networkedPrintersModel.items.length > 0
|
width: parent.width
|
||||||
leftPadding: UM.Theme.getSize("default_margin").width
|
leftPadding: UM.Theme.getSize("default_margin").width
|
||||||
height: visible ? contentHeight + 2 * UM.Theme.getSize("default_margin").height : 0
|
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
font: UM.Theme.getFont("medium")
|
font: UM.Theme.getFont("medium")
|
||||||
color: UM.Theme.getColor("text_medium")
|
color: UM.Theme.getColor("text_medium")
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delegate: MachineSelectorButton
|
||||||
|
{
|
||||||
|
text: model.name
|
||||||
|
width: listView.width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Repeater
|
Repeater
|
||||||
{
|
{
|
||||||
id: networkedPrinters
|
id: networkedPrinters
|
||||||
|
|
||||||
model: UM.ContainerStacksModel
|
model: Cura.PrintersModel
|
||||||
{
|
{
|
||||||
id: networkedPrintersModel
|
id: networkedPrintersModel
|
||||||
property var umConnectionTypes: [Cura.PrinterOutputDevice.NetworkConnection,
|
|
||||||
Cura.PrinterOutputDevice.ClusterConnection,
|
|
||||||
Cura.PrinterOutputDevice.CloudConnection
|
|
||||||
]
|
|
||||||
filter:
|
|
||||||
{
|
|
||||||
"type": "machine",
|
|
||||||
"um_network_key": "*",
|
|
||||||
"hidden": "False",
|
|
||||||
"um_connection_type": "[" + umConnectionTypes.join(",") + "]"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: MachineSelectorButton
|
delegate: MachineSelectorButton
|
||||||
{
|
{
|
||||||
text: model.metadata["connect_group_name"]
|
text: model.name //model.metadata["connect_group_name"]
|
||||||
checked: Cura.MachineManager.activeMachineNetworkGroupName == model.metadata["connect_group_name"]
|
//checked: Cura.MachineManager.activeMachineNetworkGroupName == model.metadata["connect_group_name"]
|
||||||
outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
|
outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
|
||||||
|
|
||||||
Connections
|
Connections
|
||||||
|
@ -55,37 +57,5 @@ Column
|
||||||
onActiveMachineNetworkGroupNameChanged: checked = Cura.MachineManager.activeMachineNetworkGroupName == model.metadata["connect_group_name"]
|
onActiveMachineNetworkGroupNameChanged: checked = Cura.MachineManager.activeMachineNetworkGroupName == model.metadata["connect_group_name"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
Label
|
|
||||||
{
|
|
||||||
text: catalog.i18nc("@label", "Preset printers")
|
|
||||||
visible: virtualPrintersModel.items.length > 0
|
|
||||||
leftPadding: UM.Theme.getSize("default_margin").width
|
|
||||||
height: visible ? contentHeight + 2 * UM.Theme.getSize("default_margin").height : 0
|
|
||||||
renderType: Text.NativeRendering
|
|
||||||
font: UM.Theme.getFont("medium")
|
|
||||||
color: UM.Theme.getColor("text_medium")
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
}
|
|
||||||
|
|
||||||
Repeater
|
|
||||||
{
|
|
||||||
id: virtualPrinters
|
|
||||||
|
|
||||||
model: UM.ContainerStacksModel
|
|
||||||
{
|
|
||||||
id: virtualPrintersModel
|
|
||||||
filter:
|
|
||||||
{
|
|
||||||
"type": "machine", "um_network_key": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate: MachineSelectorButton
|
|
||||||
{
|
|
||||||
text: model.name
|
|
||||||
checked: Cura.MachineManager.activeMachineId == model.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue