From edb7803760f03fecd67ba5b846c6470360ba9cda Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 10 Feb 2016 13:37:37 +0100 Subject: [PATCH] Make the machine file types filter optional for OutputDevice The call to OutputDevice from the save button filters by the file types available to the machine. The call to OutputDevice from the application menu doesn't. Contributes to issue CURA-611. --- .../RemovableDriveOutputDevice.py | 17 ++++++++--------- resources/qml/Cura.qml | 4 ++-- resources/qml/SaveButton.qml | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py b/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py index b18df75bc9..b1d6061848 100644 --- a/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py +++ b/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py @@ -25,20 +25,19 @@ class RemovableDriveOutputDevice(OutputDevice): self._writing = False - def requestWrite(self, node, file_name = None): + def requestWrite(self, node, file_name = None, filter_by_machine = False): if self._writing: raise OutputDeviceError.DeviceBusyError() file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite() #Formats supported by this application. - machine_file_formats = Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getFileFormats() - for file_format in file_formats: - if file_format["mime_type"] in machine_file_formats: - writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_format["mime_type"]) - extension = file_format["extension"] - break #We have a valid mesh writer, supported by the machine. Just pick the first one. - else: - Logger.log("e", "None of the file formats supported by this machine are supported by the application!") + if filter_by_machine: + machine_file_formats = Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getFileFormats() + file_formats = list(filter(lambda file_format: file_format["mime_type"] in machine_file_formats, file_formats)) #Take the intersection between file_formats and machine_file_formats. + if len(file_formats) == 0: + Logger.log("e", "There are no file formats available to write with!") raise OutputDeviceError.WriteRequestFailedError() + writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"]) #Just take the first file format available. + extension = file_format[0]["extension"] if file_name == None: for n in BreadthFirstIterator(node): diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index d8f2b4d4ad..a1e1ce4909 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -92,7 +92,7 @@ UM.MainWindow text: catalog.i18nc("@action:inmenu menubar:file", "&Save Selection to File"); enabled: UM.Selection.hasSelection; iconName: "document-save-as"; - onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", Printer.jobName); + onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", Printer.jobName, false); } Menu { @@ -108,7 +108,7 @@ UM.MainWindow MenuItem { text: model.description; - onTriggered: UM.OutputDeviceManager.requestWriteToDevice(model.id, Printer.jobName); + onTriggered: UM.OutputDeviceManager.requestWriteToDevice(model.id, Printer.jobName, false); } onObjectAdded: saveAllMenu.insertItem(index, object) onObjectRemoved: saveAllMenu.removeItem(object) diff --git a/resources/qml/SaveButton.qml b/resources/qml/SaveButton.qml index ce726afc04..4a29325007 100644 --- a/resources/qml/SaveButton.qml +++ b/resources/qml/SaveButton.qml @@ -84,7 +84,7 @@ Rectangle { text: UM.OutputDeviceManager.activeDeviceShortDescription onClicked: { - UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, Printer.jobName) + UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, Printer.jobName, true) } style: ButtonStyle {