|
@@ -1,10 +1,11 @@
|
|
# Copyright (c) 2019 Ultimaker B.V.
|
|
# Copyright (c) 2019 Ultimaker B.V.
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
-from typing import Dict, List, Optional
|
|
|
|
|
|
|
|
|
|
+from typing import Dict, List, Optional
|
|
from PyQt5.QtCore import QTimer
|
|
from PyQt5.QtCore import QTimer
|
|
|
|
|
|
from UM import i18nCatalog
|
|
from UM import i18nCatalog
|
|
|
|
+from UM.Logger import Logger # To log errors talking to the API.
|
|
from UM.Signal import Signal
|
|
from UM.Signal import Signal
|
|
from cura.API import Account
|
|
from cura.API import Account
|
|
from cura.CuraApplication import CuraApplication
|
|
from cura.CuraApplication import CuraApplication
|
|
@@ -13,6 +14,7 @@ from cura.Settings.GlobalStack import GlobalStack
|
|
from .CloudApiClient import CloudApiClient
|
|
from .CloudApiClient import CloudApiClient
|
|
from .CloudOutputDevice import CloudOutputDevice
|
|
from .CloudOutputDevice import CloudOutputDevice
|
|
from ..Models.Http.CloudClusterResponse import CloudClusterResponse
|
|
from ..Models.Http.CloudClusterResponse import CloudClusterResponse
|
|
|
|
+from ..Messages.CloudPrinterDetectedMessage import CloudPrinterDetectedMessage
|
|
|
|
|
|
|
|
|
|
## The cloud output device manager is responsible for using the Ultimaker Cloud APIs to manage remote clusters.
|
|
## The cloud output device manager is responsible for using the Ultimaker Cloud APIs to manage remote clusters.
|
|
@@ -36,7 +38,7 @@ class CloudOutputDeviceManager:
|
|
# Persistent dict containing the remote clusters for the authenticated user.
|
|
# Persistent dict containing the remote clusters for the authenticated user.
|
|
self._remote_clusters = {} # type: Dict[str, CloudOutputDevice]
|
|
self._remote_clusters = {} # type: Dict[str, CloudOutputDevice]
|
|
self._account = CuraApplication.getInstance().getCuraAPI().account # type: Account
|
|
self._account = CuraApplication.getInstance().getCuraAPI().account # type: Account
|
|
- self._api = CloudApiClient(self._account, on_error=lambda error: print(error))
|
|
|
|
|
|
+ self._api = CloudApiClient(self._account, on_error = lambda error: Logger.log("e", str(error)))
|
|
self._account.loginStateChanged.connect(self._onLoginStateChanged)
|
|
self._account.loginStateChanged.connect(self._onLoginStateChanged)
|
|
|
|
|
|
# Create a timer to update the remote cluster list
|
|
# Create a timer to update the remote cluster list
|
|
@@ -108,6 +110,7 @@ class CloudOutputDeviceManager:
|
|
)
|
|
)
|
|
self._remote_clusters[device.getId()] = device
|
|
self._remote_clusters[device.getId()] = device
|
|
self.discoveredDevicesChanged.emit()
|
|
self.discoveredDevicesChanged.emit()
|
|
|
|
+ self._checkIfNewClusterWasAdded(device.clusterData.cluster_id)
|
|
self._connectToActiveMachine()
|
|
self._connectToActiveMachine()
|
|
|
|
|
|
def _onDiscoveredDeviceUpdated(self, cluster_data: CloudClusterResponse) -> None:
|
|
def _onDiscoveredDeviceUpdated(self, cluster_data: CloudClusterResponse) -> None:
|
|
@@ -179,3 +182,10 @@ class CloudOutputDeviceManager:
|
|
output_device_manager = CuraApplication.getInstance().getOutputDeviceManager()
|
|
output_device_manager = CuraApplication.getInstance().getOutputDeviceManager()
|
|
if device.key not in output_device_manager.getOutputDeviceIds():
|
|
if device.key not in output_device_manager.getOutputDeviceIds():
|
|
output_device_manager.addOutputDevice(device)
|
|
output_device_manager.addOutputDevice(device)
|
|
|
|
+
|
|
|
|
+ ## Checks if Cura has a machine stack (printer) for the given cluster ID and shows a message if it hasn't.
|
|
|
|
+ def _checkIfNewClusterWasAdded(self, cluster_id: str) -> None:
|
|
|
|
+ container_registry = CuraApplication.getInstance().getContainerRegistry()
|
|
|
|
+ cloud_machines = container_registry.findContainersMetadata(**{self.META_CLUSTER_ID: "*"}) # all cloud machines
|
|
|
|
+ if not any(machine[self.META_CLUSTER_ID] == cluster_id for machine in cloud_machines):
|
|
|
|
+ CloudPrinterDetectedMessage().show()
|