some cleanup

This commit is contained in:
ChrisTerBeke 2019-07-30 15:20:59 +02:00
parent 56f58c741a
commit 1ec2ac4118
6 changed files with 15 additions and 28 deletions

View File

@ -17,11 +17,10 @@ from UM.Version import Version
from cura.CuraApplication import CuraApplication
from cura.PrinterOutput.NetworkedPrinterOutputDevice import AuthState
from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
from plugins.UM3NetworkPrinting.src.ExportFileJob import ExportFileJob
from .CloudApiClient import CloudApiClient
from ..ExportFileJob import ExportFileJob
from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice
from ..MeshFormatHandler import MeshFormatHandler
from ..Models.Http.CloudClusterResponse import CloudClusterResponse
from ..Models.Http.CloudClusterStatus import CloudClusterStatus
from ..Models.Http.CloudPrintJobUploadRequest import CloudPrintJobUploadRequest
@ -106,6 +105,7 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
super().connect()
Logger.log("i", "Connected to cluster %s", self.key)
CuraApplication.getInstance().getBackend().backendStateChange.connect(self._onBackendStateChange)
self._update()
## Disconnects the device
def disconnect(self) -> None:
@ -145,8 +145,6 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
super()._update()
if self._last_request_time and time() - self._last_request_time < self.CHECK_CLUSTER_INTERVAL:
return # Avoid calling the cloud too often
Logger.log("d", "Updating: %s - %s >= %s", time(), self._last_request_time, self.CHECK_CLUSTER_INTERVAL)
if self._account.isLoggedIn:
self.setAuthenticationState(AuthState.Authenticated)
self._last_request_time = time()

View File

@ -59,6 +59,7 @@ class CloudOutputDeviceManager:
self._running = True
if not self._update_timer.isActive():
self._update_timer.start()
self._getRemoteClusters()
self._update_timer.timeout.connect(self._getRemoteClusters)
## Stops running the cloud output device manager.
@ -84,7 +85,6 @@ class CloudOutputDeviceManager:
## Gets all remote clusters from the API.
def _getRemoteClusters(self) -> None:
print("getRemoteClusters")
self._api.getClusters(self._onGetRemoteClustersFinished)
## Callback for when the request for getting the clusters is finished.
@ -112,7 +112,7 @@ class CloudOutputDeviceManager:
new_devices[device.key] = device
# Remove output devices that disappeared.
keys = self._remote_clusters.keys()
keys = new_devices.keys()
removed_devices = [cluster for cluster in self._remote_clusters.values() if cluster.key not in keys]
for device in removed_devices:
device.disconnect()
@ -156,8 +156,8 @@ class CloudOutputDeviceManager:
device = self._remote_clusters[stored_cluster_id]
self._connectToOutputDevice(device, active_machine)
Logger.log("d", "Device connected by metadata cluster ID %s", stored_cluster_id)
# else:
# self._connectByNetworkKey(active_machine)
else:
self._connectByNetworkKey(active_machine)
## Tries to match the local network key to the cloud cluster host name.
def _connectByNetworkKey(self, active_machine: GlobalStack) -> None:
@ -167,9 +167,10 @@ class CloudOutputDeviceManager:
device = next((c for c in self._remote_clusters.values() if c.matchesNetworkKey(local_network_key)), None)
if not device:
return
print("CONNECT BY NETWORK KEY", local_network_key, device.key, device.name)
Logger.log("i", "Found cluster %s with network key %s", device, local_network_key)
active_machine.setMetaDataEntry(self.META_CLUSTER_ID, device.key)
self._connectToOutputDevice(device, active_machine)
# active_machine.setMetaDataEntry(self.META_CLUSTER_ID, device.key)
# self._connectToOutputDevice(device, active_machine)
## Connects to an output device and makes sure it is registered in the output device manager.
@staticmethod

View File

@ -91,10 +91,9 @@ class MeshFormatHandler:
machine_file_formats = global_stack.getMetaDataEntry("file_formats").split(";")
machine_file_formats = [file_type.strip() for file_type in machine_file_formats]
# TODO: re-enable UFP after Cura master branch works again
# # Exception for UM3 firmware version >=4.4: UFP is now supported and should be the preferred file format.
# if "application/x-ufp" not in machine_file_formats and Version(firmware_version) >= Version("4.4"):
# machine_file_formats = ["application/x-ufp"] + machine_file_formats
# Exception for UM3 firmware version >=4.4: UFP is now supported and should be the preferred file format.
if "application/x-ufp" not in machine_file_formats and Version(firmware_version) >= Version("4.4"):
machine_file_formats = ["application/x-ufp"] + machine_file_formats
# Take the intersection between file_formats and machine_file_formats.
format_by_mimetype = {f["mime_type"]: f for f in file_formats}

View File

@ -2,7 +2,6 @@
# Cura is released under the terms of the LGPLv3 or higher.
from typing import Optional
from UM.Logger import Logger
from cura.CuraApplication import CuraApplication
from cura.PrinterOutput.Models.MaterialOutputModel import MaterialOutputModel
@ -48,11 +47,9 @@ class ClusterPrinterConfigurationMaterial(BaseModel):
material_type = container.getMetaDataEntry("material")
name = container.getName()
else:
Logger.log("w", "Unable to find material with guid {guid}. Using data as provided by cluster"
.format(guid = self.guid))
color = self.color
brand = self.brand
material_type = self.material
name = "Empty" if self.material == "empty" else "Unknown"
return MaterialOutputModel(guid = self.guid, type = material_type, brand = brand, color = color, name = name)
return MaterialOutputModel(guid=self.guid, type=material_type, brand=brand, color=color, name=name)

View File

@ -12,13 +12,11 @@ from UM.Logger import Logger
from UM.Message import Message
from UM.i18n import i18nCatalog
from UM.Scene.SceneNode import SceneNode
from cura.CuraApplication import CuraApplication
from cura.PrinterOutput.NetworkedPrinterOutputDevice import AuthState
from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
from plugins.UM3NetworkPrinting.src.ExportFileJob import ExportFileJob
from .ClusterApiClient import ClusterApiClient
from ..MeshFormatHandler import MeshFormatHandler
from ..ExportFileJob import ExportFileJob
from ..SendMaterialJob import SendMaterialJob
from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice
@ -58,6 +56,7 @@ class NetworkOutputDevice(UltimakerNetworkedPrinterOutputDevice):
## Called when the connection to the cluster changes.
def connect(self) -> None:
super().connect()
self._update()
self.sendMaterialProfiles()
@pyqtProperty(QUrl, notify=activeCameraUrlChanged)

View File

@ -241,7 +241,6 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
for removed_job in removed_jobs:
if removed_job.assignedPrinter:
removed_job.assignedPrinter.updateActivePrintJob(None)
removed_job.stateChanged.disconnect(self._onPrintJobStateChanged)
self._print_jobs = new_print_jobs
self.printJobsChanged.emit()
@ -250,20 +249,14 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
# \param remote_job: The remote print job data.
def _createPrintJobModel(self, remote_job: ClusterPrintJobStatus) -> UM3PrintJobOutputModel:
model = remote_job.createOutputModel(ClusterOutputController(self))
model.stateChanged.connect(self._onPrintJobStateChanged)
if remote_job.printer_uuid:
self._updateAssignedPrinter(model, remote_job.printer_uuid)
return model
def _onPrintJobStateChanged(self) -> None:
pass
## Updates the printer assignment for the given print job model.
def _updateAssignedPrinter(self, model: UM3PrintJobOutputModel, printer_uuid: str) -> None:
printer = next((p for p in self._printers if printer_uuid == p.key), None)
if not printer:
Logger.log("w", "Missing printer %s for job %s in %s", model.assignedPrinter, model.key,
[p.key for p in self._printers])
return
printer.updateActivePrintJob(model)
model.updateAssignedPrinter(printer)