Move cloud flow checks back to UM3OutputDevice

Contributes to CL-1222
This commit is contained in:
Ian Paschal 2019-02-04 11:51:27 +01:00
parent 1244e30500
commit 2a3a1d6e35
2 changed files with 45 additions and 36 deletions

View file

@ -32,8 +32,6 @@ class CloudOutputDeviceManager:
# The translation catalog for this device. # The translation catalog for this device.
I18N_CATALOG = i18nCatalog("cura") I18N_CATALOG = i18nCatalog("cura")
cloudFlowIsPossible = Signal()
def __init__(self) -> None: def __init__(self) -> None:
# 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]
@ -44,9 +42,6 @@ class CloudOutputDeviceManager:
self._account = self._application.getCuraAPI().account # type: Account self._account = self._application.getCuraAPI().account # type: Account
self._api = CloudApiClient(self._account, self._onApiError) self._api = CloudApiClient(self._account, self._onApiError)
self._account.loginStateChanged.connect(self.checkCloudFlowIsPossible)
self.cloudFlowIsPossible.connect(self._onCloudFlowPossible)
# Create a timer to update the remote cluster list # Create a timer to update the remote cluster list
self._update_timer = QTimer() self._update_timer = QTimer()
self._update_timer.setInterval(int(self.CHECK_CLUSTER_INTERVAL * 1000)) self._update_timer.setInterval(int(self.CHECK_CLUSTER_INTERVAL * 1000))
@ -173,34 +168,3 @@ class CloudOutputDeviceManager:
self._application.globalContainerStackChanged.disconnect(self._connectToActiveMachine) self._application.globalContainerStackChanged.disconnect(self._connectToActiveMachine)
self._update_timer.timeout.disconnect(self._getRemoteClusters) self._update_timer.timeout.disconnect(self._getRemoteClusters)
self._onLoginStateChanged(is_logged_in = False) self._onLoginStateChanged(is_logged_in = False)
## Check if the prerequsites are in place to start the cloud flow
def checkCloudFlowIsPossible(self):
Logger.log("d", "Checking if cloud connection is possible...")
# Check #1: User is logged in with an Ultimaker account
if not self._account.isLoggedIn:
Logger.log("d", "Cloud Flow not possible: User not logged in!")
return
# Check #2: Machine has a network connection
if not self._application.getMachineManager().activeMachineHasActiveNetworkConnection:
Logger.log("d", "Cloud Flow not possible: Machine is not connected!")
# TODO: This should only be network connections, not cloud connections
return
# Check #3: Machine has correct firmware version
# Logger.log("d", "Cloud Flow not possible: Machine does not have necessary firmware!")
# return
# TODO: Check if machine is already set up to be cloud
self.cloudFlowIsPossible.emit()
Logger.log("d", "Cloud flow is ready to go!")
def _onCloudFlowPossible(self):
# Cloud flow is possible, so show the message
self._start_cloud_flow_message = Message(self.I18N_CATALOG.i18nc("@info:status", "Chain so thin when a breeze roll by, man it flow... man it flow..."))
self._start_cloud_flow_message.show()
return

View file

@ -45,6 +45,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
activePrinterChanged = pyqtSignal() activePrinterChanged = pyqtSignal()
activeCameraUrlChanged = pyqtSignal() activeCameraUrlChanged = pyqtSignal()
receivedPrintJobsChanged = pyqtSignal() receivedPrintJobsChanged = pyqtSignal()
cloudFlowIsPossible = pyqtSignal()
# Notify can only use signals that are defined by the class that they are in, not inherited ones. # Notify can only use signals that are defined by the class that they are in, not inherited ones.
# Therefore we create a private signal used to trigger the printersChanged signal. # Therefore we create a private signal used to trigger the printersChanged signal.
@ -54,6 +55,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
super().__init__(device_id = device_id, address = address, properties=properties, connection_type = ConnectionType.NetworkConnection, parent = parent) super().__init__(device_id = device_id, address = address, properties=properties, connection_type = ConnectionType.NetworkConnection, parent = parent)
self._api_prefix = "/cluster-api/v1/" self._api_prefix = "/cluster-api/v1/"
self._application = CuraApplication.getInstance()
self._number_of_extruders = 2 self._number_of_extruders = 2
self._dummy_lambdas = ( self._dummy_lambdas = (
@ -65,9 +68,18 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
self._monitor_view_qml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../resources/qml/MonitorStage.qml") self._monitor_view_qml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../resources/qml/MonitorStage.qml")
self._account = self._application.getCuraAPI().account
# Trigger the printersChanged signal when the private signal is triggered # Trigger the printersChanged signal when the private signal is triggered
self.printersChanged.connect(self._clusterPrintersChanged) self.printersChanged.connect(self._clusterPrintersChanged)
# Check if cloud flow is possible when user logs in
self._account.loginStateChanged.connect(self.checkCloudFlowIsPossible)
# Listen for when Cloud Flow is possible
self.cloudFlowIsPossible.connect(self._onCloudFlowPossible)
self._accepts_commands = True # type: bool self._accepts_commands = True # type: bool
# Cluster does not have authentication, so default to authenticated # Cluster does not have authentication, so default to authenticated
@ -665,6 +677,39 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
job = SendMaterialJob(device = self) job = SendMaterialJob(device = self)
job.run() job.run()
## Check if the prerequsites are in place to start the cloud flow
def checkCloudFlowIsPossible(self):
Logger.log("d", "Checking if cloud connection is possible...")
# Check #1: User is logged in with an Ultimaker account
if not self._account.isLoggedIn:
Logger.log("d", "Cloud Flow not possible: User not logged in!")
return
# Check #2: Machine has a network connection
if not self._application.getMachineManager().activeMachineHasActiveNetworkConnection:
Logger.log("d", "Cloud Flow not possible: Machine is not connected!")
# TODO: This should only be network connections, not cloud connections
return
# Check #3: Machine has correct firmware version
# Logger.log("d", "Cloud Flow not possible: Machine does not have necessary firmware!")
# return
# TODO: Check if machine is already set up to be cloud
self.cloudFlowIsPossible.emit()
Logger.log("d", "Cloud flow is ready to go!")
def _onCloudFlowPossible(self):
# Cloud flow is possible, so show the message
self._start_cloud_flow_message = Message(i18n_catalog.i18nc("@info:status", "Chain so thin when a breeze roll by, man it flow... man it flow..."))
self._start_cloud_flow_message.show()
return
def loadJsonFromReply(reply: QNetworkReply) -> Optional[List[Dict[str, Any]]]: def loadJsonFromReply(reply: QNetworkReply) -> Optional[List[Dict[str, Any]]]:
try: try: