Просмотр исходного кода

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.
Ghostkeeper 9 лет назад
Родитель
Сommit
edb7803760

+ 8 - 9
plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py

@@ -25,20 +25,19 @@ class RemovableDriveOutputDevice(OutputDevice):
 
 
         self._writing = False
         self._writing = False
 
 
-    def requestWrite(self, node, file_name = None):
+    def requestWrite(self, node, file_name = None, filter_by_machine = False):
         if self._writing:
         if self._writing:
             raise OutputDeviceError.DeviceBusyError()
             raise OutputDeviceError.DeviceBusyError()
 
 
         file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite() #Formats supported by this application.
         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()
             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:
         if file_name == None:
             for n in BreadthFirstIterator(node):
             for n in BreadthFirstIterator(node):

+ 2 - 2
resources/qml/Cura.qml

@@ -92,7 +92,7 @@ UM.MainWindow
                     text: catalog.i18nc("@action:inmenu menubar:file", "&Save Selection to File");
                     text: catalog.i18nc("@action:inmenu menubar:file", "&Save Selection to File");
                     enabled: UM.Selection.hasSelection;
                     enabled: UM.Selection.hasSelection;
                     iconName: "document-save-as";
                     iconName: "document-save-as";
-                    onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", Printer.jobName);
+                    onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", Printer.jobName, false);
                 }
                 }
                 Menu
                 Menu
                 {
                 {
@@ -108,7 +108,7 @@ UM.MainWindow
                         MenuItem
                         MenuItem
                         {
                         {
                             text: model.description;
                             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)
                         onObjectAdded: saveAllMenu.insertItem(index, object)
                         onObjectRemoved: saveAllMenu.removeItem(object)
                         onObjectRemoved: saveAllMenu.removeItem(object)

+ 1 - 1
resources/qml/SaveButton.qml

@@ -84,7 +84,7 @@ Rectangle {
             text: UM.OutputDeviceManager.activeDeviceShortDescription
             text: UM.OutputDeviceManager.activeDeviceShortDescription
             onClicked:
             onClicked:
             {
             {
-                UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, Printer.jobName)
+                UM.OutputDeviceManager.requestWriteToDevice(UM.OutputDeviceManager.activeDevice, Printer.jobName, true)
             }
             }
 
 
             style: ButtonStyle {
             style: ButtonStyle {