Duplicate print jobs were being sent when printing via cloud from abstract printers.

This was due to the connect function not being called on the CloudOutputDevice used to print on the cloud. This function is only called when it becomes an active printer (AbstractCloudOutputDevice is the active printer instead now).

The fix is to always listen for signals to reset the print job even when not the active printer.

I've chosen different signals now so there is not too much spam on the reset function.

The BackendStateDone signal catches new slices. The SceneChanged signal catches ufp files being loaded (These do not trigger BackendState changes)

CURA-9678
This commit is contained in:
Joey de l'Arago 2022-09-23 10:32:03 +02:00
parent ecf38b23bd
commit c729b87f3c

View file

@ -10,7 +10,6 @@ from PyQt6.QtGui import QDesktopServices
from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest # Parse errors specific to print job uploading. from PyQt6.QtNetwork import QNetworkReply, QNetworkRequest # Parse errors specific to print job uploading.
from UM import i18nCatalog from UM import i18nCatalog
from UM.Backend.Backend import BackendState
from UM.FileHandler.FileHandler import FileHandler from UM.FileHandler.FileHandler import FileHandler
from UM.Logger import Logger from UM.Logger import Logger
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
@ -18,6 +17,8 @@ from UM.Version import Version
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from cura.PrinterOutput.NetworkedPrinterOutputDevice import AuthState from cura.PrinterOutput.NetworkedPrinterOutputDevice import AuthState
from cura.PrinterOutput.PrinterOutputDevice import ConnectionType from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
from cura.Scene.GCodeListDecorator import GCodeListDecorator
from cura.Scene.SliceableObjectDecorator import SliceableObjectDecorator
from .CloudApiClient import CloudApiClient from .CloudApiClient import CloudApiClient
from ..ExportFileJob import ExportFileJob from ..ExportFileJob import ExportFileJob
@ -110,6 +111,9 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
self._pre_upload_print_job = None # type: Optional[CloudPrintJobResponse] self._pre_upload_print_job = None # type: Optional[CloudPrintJobResponse]
self._uploaded_print_job = None # type: Optional[CloudPrintJobResponse] self._uploaded_print_job = None # type: Optional[CloudPrintJobResponse]
CuraApplication.getInstance().getBackend().backendDone.connect(self._resetPrintJob)
CuraApplication.getInstance().getController().getScene().sceneChanged.connect(self._onSceneChanged)
def connect(self) -> None: def connect(self) -> None:
"""Connects this device.""" """Connects this device."""
@ -117,8 +121,6 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
return return
Logger.log("i", "Attempting to connect to cluster %s", self.key) Logger.log("i", "Attempting to connect to cluster %s", self.key)
super().connect() super().connect()
CuraApplication.getInstance().getBackend().backendStateChange.connect(self._onBackendStateChange)
self._update() self._update()
def disconnect(self) -> None: def disconnect(self) -> None:
@ -128,11 +130,14 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
return return
super().disconnect() super().disconnect()
Logger.log("i", "Disconnected from cluster %s", self.key) Logger.log("i", "Disconnected from cluster %s", self.key)
CuraApplication.getInstance().getBackend().backendStateChange.disconnect(self._onBackendStateChange)
def _onBackendStateChange(self, _: BackendState) -> None: def _onSceneChanged(self, node: SceneNode):
"""Resets the print job that was uploaded to force a new upload, runs whenever the user re-slices.""" # This will reset the print job if a ufp file is loaded. This forces a new upload when printing via cloud from ufp.
if node.getDecorator(GCodeListDecorator) or node.getDecorator(SliceableObjectDecorator):
self._resetPrintJob()
def _resetPrintJob(self) -> None:
"""Resets the print job that was uploaded to force a new upload, runs whenever slice finishes."""
self._tool_path = None self._tool_path = None
self._pre_upload_print_job = None self._pre_upload_print_job = None
self._uploaded_print_job = None self._uploaded_print_job = None