From 3bfc0afc9383d458732ebe693cfaa1a309390771 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Mon, 30 Oct 2023 13:32:25 +0100 Subject: [PATCH] For makerbot files upload in cloud CURA-11138 --- .../resources/qml/SaveProjectFilesPage.qml | 3 +- .../src/DFFileExportAndUploadManager.py | 45 +++++++++++++++---- .../src/DigitalFactoryApiClient.py | 2 +- .../src/DigitalFactoryOutputDevice.py | 3 +- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/plugins/DigitalLibrary/resources/qml/SaveProjectFilesPage.qml b/plugins/DigitalLibrary/resources/qml/SaveProjectFilesPage.qml index 0a94a4f48a..311aa0bf7e 100644 --- a/plugins/DigitalLibrary/resources/qml/SaveProjectFilesPage.qml +++ b/plugins/DigitalLibrary/resources/qml/SaveProjectFilesPage.qml @@ -213,7 +213,8 @@ Item valueRole: "value" model: [ - { text: catalog.i18nc("@option", "Save Cura project and print file"), key: "3mf_ufp", value: ["3mf", "ufp"] }, + { text: catalog.i18nc("@option", "Save Cura project and .ufp print file"), key: "3mf_ufp", value: ["3mf", "ufp"] }, + { text: catalog.i18nc("@option", "Save Cura project and .makerbot print file"), key: "3mf_makerbot", value: ["3mf", "makerbot"] }, { text: catalog.i18nc("@option", "Save Cura project"), key: "3mf", value: ["3mf"] }, ] } diff --git a/plugins/DigitalLibrary/src/DFFileExportAndUploadManager.py b/plugins/DigitalLibrary/src/DFFileExportAndUploadManager.py index 26912abd9a..271fe652c8 100644 --- a/plugins/DigitalLibrary/src/DFFileExportAndUploadManager.py +++ b/plugins/DigitalLibrary/src/DFFileExportAndUploadManager.py @@ -27,7 +27,7 @@ from .ExportFileJob import ExportFileJob class DFFileExportAndUploadManager: """ Class responsible for exporting the scene and uploading the exported data to the Digital Factory Library. Since 3mf - and UFP files may need to be uploaded at the same time, this class keeps a single progress and success message for + and (UFP or makerbot) files may need to be uploaded at the same time, this class keeps a single progress and success message for both files and updates those messages according to the progress of both the file job uploads. """ def __init__(self, file_handlers: Dict[str, FileHandler], @@ -118,7 +118,7 @@ class DFFileExportAndUploadManager: library_project_id = self._library_project_id, source_file_id = self._source_file_id ) - self._api.requestUploadUFP(request, on_finished = self._uploadFileData, on_error = self._onRequestUploadPrintFileFailed) + self._api.requestUploadMeshFile(request, on_finished = self._uploadFileData, on_error = self._onRequestUploadPrintFileFailed) def _uploadFileData(self, file_upload_response: Union[DFLibraryFileUploadResponse, DFPrintJobUploadResponse]) -> None: """Uploads the exported file data after the file or print job upload has been registered at the Digital Factory @@ -279,22 +279,25 @@ class DFFileExportAndUploadManager: This means that something went wrong with the initial request to create a "file" entry in the digital library. """ reply_string = bytes(reply.readAll()).decode() - filename_ufp = self._file_name + ".ufp" - Logger.log("d", "An error occurred while uploading the print job file '{}' to the Digital Library project '{}': {}".format(filename_ufp, self._library_project_id, reply_string)) + if "ufp" in self._formats: + filename_meshfile = self._file_name + ".ufp" + elif "makerbot" in self._formats: + filename_meshfile = self._file_name + ".makerbot" + Logger.log("d", "An error occurred while uploading the print job file '{}' to the Digital Library project '{}': {}".format(filename_meshfile, self._library_project_id, reply_string)) with self._message_lock: # Set the progress to 100% when the upload job fails, to avoid having the progress message stuck - self._file_upload_job_metadata[filename_ufp]["upload_status"] = "failed" - self._file_upload_job_metadata[filename_ufp]["upload_progress"] = 100 + self._file_upload_job_metadata[filename_meshfile]["upload_status"] = "failed" + self._file_upload_job_metadata[filename_meshfile]["upload_progress"] = 100 human_readable_error = self.extractErrorTitle(reply_string) - self._file_upload_job_metadata[filename_ufp]["file_upload_failed_message"] = getBackwardsCompatibleMessage( + self._file_upload_job_metadata[filename_meshfile]["file_upload_failed_message"] = getBackwardsCompatibleMessage( title = "File upload error", - text = "Failed to upload the file '{}' to '{}'. {}".format(filename_ufp, self._library_project_name, human_readable_error), + text = "Failed to upload the file '{}' to '{}'. {}".format(filename_meshfile, self._library_project_name, human_readable_error), message_type_str = "ERROR", lifetime = 30 ) self._on_upload_error() - self._onFileUploadFinished(filename_ufp) + self._onFileUploadFinished(filename_meshfile) @staticmethod def extractErrorTitle(reply_body: Optional[str]) -> str: @@ -407,4 +410,28 @@ class DFFileExportAndUploadManager: job_ufp = ExportFileJob(self._file_handlers["ufp"], self._nodes, self._file_name, "ufp") job_ufp.finished.connect(self._onPrintFileExported) self._upload_jobs.append(job_ufp) + + if "makerbot" in self._formats and "makerbot" in self._file_handlers and self._file_handlers["makerbot"]: + filename_makerbot = self._file_name + ".makerbot" + metadata[filename_makerbot] = { + "export_job_output" : None, + "upload_progress" : -1, + "upload_status" : "", + "file_upload_response": None, + "file_upload_success_message": getBackwardsCompatibleMessage( + text = "'{}' was uploaded to '{}'.".format(filename_makerbot, self._library_project_name), + title = "Upload successful", + message_type_str = "POSITIVE", + lifetime = 30, + ), + "file_upload_failed_message": getBackwardsCompatibleMessage( + text = "Failed to upload the file '{}' to '{}'.".format(filename_makerbot, self._library_project_name), + title = "File upload error", + message_type_str = "ERROR", + lifetime = 30 + ) + } + job_makerbot = ExportFileJob(self._file_handlers["makerbot"], self._nodes, self._file_name, "makerbot") + job_makerbot.finished.connect(self._onPrintFileExported) + self._upload_jobs.append(job_makerbot) return metadata diff --git a/plugins/DigitalLibrary/src/DigitalFactoryApiClient.py b/plugins/DigitalLibrary/src/DigitalFactoryApiClient.py index 13c65f79c4..1168928588 100644 --- a/plugins/DigitalLibrary/src/DigitalFactoryApiClient.py +++ b/plugins/DigitalLibrary/src/DigitalFactoryApiClient.py @@ -313,7 +313,7 @@ class DigitalFactoryApiClient: error_callback = on_error, timeout = self.DEFAULT_REQUEST_TIMEOUT) - def requestUploadUFP(self, request: DFPrintJobUploadRequest, + def requestUploadMeshFile(self, request: DFPrintJobUploadRequest, on_finished: Callable[[DFPrintJobUploadResponse], Any], on_error: Optional[Callable[["QNetworkReply", "QNetworkReply.NetworkError"], None]] = None) -> None: """Requests the Digital Factory to register the upload of a file in a library project. diff --git a/plugins/DigitalLibrary/src/DigitalFactoryOutputDevice.py b/plugins/DigitalLibrary/src/DigitalFactoryOutputDevice.py index 0a10ea034c..0ed8f491f9 100644 --- a/plugins/DigitalLibrary/src/DigitalFactoryOutputDevice.py +++ b/plugins/DigitalLibrary/src/DigitalFactoryOutputDevice.py @@ -92,7 +92,8 @@ class DigitalFactoryOutputDevice(ProjectOutputDevice): if not self._controller.file_handlers: self._controller.file_handlers = { "3mf": CuraApplication.getInstance().getWorkspaceFileHandler(), - "ufp": CuraApplication.getInstance().getMeshFileHandler() + "ufp": CuraApplication.getInstance().getMeshFileHandler(), + "makerbot": CuraApplication.getInstance().getMeshFileHandler() } self._dialog = CuraApplication.getInstance().createQmlComponent(self._dialog_path, {"manager": self._controller})