From a45af1da25a475c874aec843dda384bda5814af3 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Fri, 15 Jan 2021 09:50:23 +0100 Subject: [PATCH 1/7] Add save projects submenu CURA-7866 --- resources/qml/Menus/FileMenu.qml | 14 ++++++- resources/qml/Menus/SaveProjectMenu.qml | 53 +++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 resources/qml/Menus/SaveProjectMenu.qml diff --git a/resources/qml/Menus/FileMenu.qml b/resources/qml/Menus/FileMenu.qml index 94fc2358e1..5ea1c9bc06 100644 --- a/resources/qml/Menus/FileMenu.qml +++ b/resources/qml/Menus/FileMenu.qml @@ -4,7 +4,7 @@ import QtQuick 2.2 import QtQuick.Controls 1.1 -import UM 1.2 as UM +import UM 1.6 as UM import Cura 1.0 as Cura Menu @@ -37,8 +37,9 @@ Menu MenuItem { id: saveWorkspaceMenu - shortcut: StandardKey.Save + shortcut: visible ? StandardKey.Save : "" text: catalog.i18nc("@title:menu menubar:file", "&Save Project...") + visible: saveProjectMenu.model.count == 1 onTriggered: { var args = { "filter_by_machine": false, "file_type": "workspace", "preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml" }; @@ -54,6 +55,15 @@ Menu } } + UM.ProjectOutputDevicesModel { id: projectOutputDevicesModel } + + SaveProjectMenu + { + id: saveProjectMenu + model: projectOutputDevicesModel + visible: model.count > 1 + } + MenuSeparator { } MenuItem diff --git a/resources/qml/Menus/SaveProjectMenu.qml b/resources/qml/Menus/SaveProjectMenu.qml new file mode 100644 index 0000000000..51894674f0 --- /dev/null +++ b/resources/qml/Menus/SaveProjectMenu.qml @@ -0,0 +1,53 @@ +// Copyright (c) 2021 Ultimaker B.V. +// Cura is released under the terms of the LGPLv3 or higher. + +import QtQuick 2.2 +import QtQuick.Controls 1.1 + +import UM 1.6 as UM +import Cura 1.1 as Cura + +import "../Dialogs" + +Menu +{ + id: saveProjectMenu + title: catalog.i18nc("@title:menu menubar:file", "Save project...") + property alias model: projectOutputDevices.model + + Instantiator + { + id: projectOutputDevices + MenuItem + { + text: model.name + onTriggered: + { + var args = { "filter_by_machine": false, "file_type": "workspace", "preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml" }; + if (UM.Preferences.getValue("cura/dialog_on_project_save")) + { + saveWorkspaceDialog.deviceId = model.id + saveWorkspaceDialog.args = args + saveWorkspaceDialog.open() + } + else + { + UM.OutputDeviceManager.requestWriteToDevice(model.id, PrintInformation.jobName, args) + } + } + // Unassign the shortcuts when the submenu is invisible (i.e. when there is only one file provider) to avoid ambiguous shortcuts. + // When there is a signle file provider, the openAction is assigned with the Ctrl+O shortcut instead. + shortcut: saveProjectMenu.visible ? model.shortcut : "" + } + onObjectAdded: saveProjectMenu.insertItem(index, object) + onObjectRemoved: saveProjectMenu.removeItem(object) + } + + WorkspaceSummaryDialog + { + id: saveWorkspaceDialog + property var args + property var deviceId + onYes: UM.OutputDeviceManager.requestWriteToDevice(deviceId, PrintInformation.jobName, args) + } +} From 2774ec7bdf8b9c98beb9a244f1a2b90b57ddec1f Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Fri, 15 Jan 2021 17:42:42 +0100 Subject: [PATCH 2/7] Remove unnecessary kwargs CURA-7865 --- resources/qml/Menus/SaveProjectMenu.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/Menus/SaveProjectMenu.qml b/resources/qml/Menus/SaveProjectMenu.qml index 51894674f0..f855af5120 100644 --- a/resources/qml/Menus/SaveProjectMenu.qml +++ b/resources/qml/Menus/SaveProjectMenu.qml @@ -23,7 +23,7 @@ Menu text: model.name onTriggered: { - var args = { "filter_by_machine": false, "file_type": "workspace", "preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml" }; + var args = { "file_type": "workspace" }; if (UM.Preferences.getValue("cura/dialog_on_project_save")) { saveWorkspaceDialog.deviceId = model.id From fc718892d94226b29f97ae44801177586c9d61d0 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Mon, 18 Jan 2021 12:10:15 +0100 Subject: [PATCH 3/7] Add default text in the ComboBox The Cura.ComboBox component can now display a default text when there are no items in its model and another text when there is no item selected. CURA-7865 --- resources/qml/Widgets/ComboBox.qml | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/resources/qml/Widgets/ComboBox.qml b/resources/qml/Widgets/ComboBox.qml index d4c526e265..26324d7773 100644 --- a/resources/qml/Widgets/ComboBox.qml +++ b/resources/qml/Widgets/ComboBox.qml @@ -15,6 +15,18 @@ ComboBox { id: control + UM.I18nCatalog + { + id: catalog + name: "cura" + } + + property var defaultTextOnEmptyModel: catalog.i18nc("@label", "No items to select from") // Text displayed in the combobox when the model is empty + property var defaultTextOnEmptyIndex: "" // Text displayed in the combobox when the model has items but no item is selected + enabled: model.count > 0 + + onVisibleChanged: { popup.close() } + states: [ State { @@ -67,11 +79,22 @@ ComboBox anchors.verticalCenter: parent.verticalCenter anchors.right: downArrow.left - text: control.currentText + text: + { + if (control.model.count == 0) + { + return control.defaultTextOnEmptyModel != "" ? control.defaultTextOnEmptyModel : control.defaultTextOnEmptyIndex + } + else + { + return control.currentIndex == -1 ? control.defaultTextOnEmptyIndex : control.currentText + } + } + textFormat: Text.PlainText renderType: Text.NativeRendering font: UM.Theme.getFont("default") - color: UM.Theme.getColor("setting_control_text") + color: control.currentIndex == -1 ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text") elide: Text.ElideRight verticalAlignment: Text.AlignVCenter } @@ -81,6 +104,7 @@ ComboBox y: control.height - UM.Theme.getSize("default_lining").height width: control.width implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").width + bottomMargin: UM.Theme.getSize("default_margin").height padding: UM.Theme.getSize("default_lining").width contentItem: ListView @@ -133,7 +157,7 @@ ComboBox text: delegateItem.text textFormat: Text.PlainText renderType: Text.NativeRendering - color: control.contentItem.color + color: UM.Theme.getColor("setting_control_text") font: UM.Theme.getFont("default") elide: Text.ElideRight verticalAlignment: Text.AlignVCenter From f1e152955c716977cdd6554f79b17b279cb6aaf7 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Mon, 18 Jan 2021 18:00:05 +0100 Subject: [PATCH 4/7] Correct the Menu title CURA-7865 --- resources/qml/Menus/SaveProjectMenu.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/Menus/SaveProjectMenu.qml b/resources/qml/Menus/SaveProjectMenu.qml index f855af5120..35c511344b 100644 --- a/resources/qml/Menus/SaveProjectMenu.qml +++ b/resources/qml/Menus/SaveProjectMenu.qml @@ -12,7 +12,7 @@ import "../Dialogs" Menu { id: saveProjectMenu - title: catalog.i18nc("@title:menu menubar:file", "Save project...") + title: catalog.i18nc("@title:menu menubar:file", "Save Project...") property alias model: projectOutputDevices.model Instantiator From b7e613a271c6294c91c1bcb861487aeee878ad72 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 19 Jan 2021 21:39:16 +0100 Subject: [PATCH 5/7] Remove file_type argument from the saveWorkspaceDialog Because we also want to export ufp files, which are not workspace files. CURA-7865 --- resources/qml/Menus/SaveProjectMenu.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/qml/Menus/SaveProjectMenu.qml b/resources/qml/Menus/SaveProjectMenu.qml index 35c511344b..100e6f2ea4 100644 --- a/resources/qml/Menus/SaveProjectMenu.qml +++ b/resources/qml/Menus/SaveProjectMenu.qml @@ -23,7 +23,7 @@ Menu text: model.name onTriggered: { - var args = { "file_type": "workspace" }; + var args = {}; if (UM.Preferences.getValue("cura/dialog_on_project_save")) { saveWorkspaceDialog.deviceId = model.id @@ -35,8 +35,8 @@ Menu UM.OutputDeviceManager.requestWriteToDevice(model.id, PrintInformation.jobName, args) } } - // Unassign the shortcuts when the submenu is invisible (i.e. when there is only one file provider) to avoid ambiguous shortcuts. - // When there is a signle file provider, the openAction is assigned with the Ctrl+O shortcut instead. + // Unassign the shortcuts when the submenu is invisible (i.e. when there is only one project output device) to avoid ambiguous shortcuts. + // When there is only the LocalFileOutputDevice, the Ctrl+S shortcut is assigned to the saveWorkspaceMenu MenuItem shortcut: saveProjectMenu.visible ? model.shortcut : "" } onObjectAdded: saveProjectMenu.insertItem(index, object) From a72a58cca194c605d8894ba7f04cebeb359da991 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Wed, 20 Jan 2021 11:23:48 +0100 Subject: [PATCH 6/7] Comment out the generation of the snapshot While generating UFP files from outside the main thread, the snapshot generation crashes Cura due to the OpenGL context. To avoid that, for the time being, we comment out the generation of the snapshot. CURA-7865 --- plugins/UFPWriter/UFPWriter.py | 36 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/plugins/UFPWriter/UFPWriter.py b/plugins/UFPWriter/UFPWriter.py index 6179872b2d..08c2f3252f 100644 --- a/plugins/UFPWriter/UFPWriter.py +++ b/plugins/UFPWriter/UFPWriter.py @@ -72,24 +72,24 @@ class UFPWriter(MeshWriter): gcode.write(gcode_textio.getvalue().encode("UTF-8")) archive.addRelation(virtual_path = "/3D/model.gcode", relation_type = "http://schemas.ultimaker.org/package/2018/relationships/gcode") - self._createSnapshot() - - # Store the thumbnail. - if self._snapshot: - archive.addContentType(extension = "png", mime_type = "image/png") - thumbnail = archive.getStream("/Metadata/thumbnail.png") - - thumbnail_buffer = QBuffer() - thumbnail_buffer.open(QBuffer.ReadWrite) - thumbnail_image = self._snapshot - thumbnail_image.save(thumbnail_buffer, "PNG") - - thumbnail.write(thumbnail_buffer.data()) - archive.addRelation(virtual_path = "/Metadata/thumbnail.png", - relation_type = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail", - origin = "/3D/model.gcode") - else: - Logger.log("d", "Thumbnail not created, cannot save it") + # self._createSnapshot() + # + # # Store the thumbnail. + # if self._snapshot: + # archive.addContentType(extension = "png", mime_type = "image/png") + # thumbnail = archive.getStream("/Metadata/thumbnail.png") + # + # thumbnail_buffer = QBuffer() + # thumbnail_buffer.open(QBuffer.ReadWrite) + # thumbnail_image = self._snapshot + # thumbnail_image.save(thumbnail_buffer, "PNG") + # + # thumbnail.write(thumbnail_buffer.data()) + # archive.addRelation(virtual_path = "/Metadata/thumbnail.png", + # relation_type = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail", + # origin = "/3D/model.gcode") + # else: + # Logger.log("d", "Thumbnail not created, cannot save it") # Store the material. application = CuraApplication.getInstance() From 32df06c2801c78cd8375f45a975625805bb7da41 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Wed, 20 Jan 2021 12:51:13 +0100 Subject: [PATCH 7/7] Add TODO comment to explain the commenting out of the snapshot CURA-7865 --- plugins/UFPWriter/UFPWriter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/UFPWriter/UFPWriter.py b/plugins/UFPWriter/UFPWriter.py index 08c2f3252f..af208209e4 100644 --- a/plugins/UFPWriter/UFPWriter.py +++ b/plugins/UFPWriter/UFPWriter.py @@ -72,6 +72,7 @@ class UFPWriter(MeshWriter): gcode.write(gcode_textio.getvalue().encode("UTF-8")) archive.addRelation(virtual_path = "/3D/model.gcode", relation_type = "http://schemas.ultimaker.org/package/2018/relationships/gcode") + # TODO temporarily commented out, as is causes a crash whenever the UFPWriter is called outside of the main thread # self._createSnapshot() # # # Store the thumbnail.