Merge pull request #9153 from Ultimaker/CURA-7865_Save_file_in_existing_project_mvp

CURA-7865 Save file in existing project mvp
This commit is contained in:
Remco Burema 2021-01-20 19:18:39 +01:00 committed by GitHub
commit 0ba3833995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 111 additions and 23 deletions

View File

@ -72,24 +72,25 @@ class UFPWriter(MeshWriter):
gcode.write(gcode_textio.getvalue().encode("UTF-8")) 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") archive.addRelation(virtual_path = "/3D/model.gcode", relation_type = "http://schemas.ultimaker.org/package/2018/relationships/gcode")
self._createSnapshot() # TODO temporarily commented out, as is causes a crash whenever the UFPWriter is called outside of the main thread
# self._createSnapshot()
# Store the thumbnail. #
if self._snapshot: # # Store the thumbnail.
archive.addContentType(extension = "png", mime_type = "image/png") # if self._snapshot:
thumbnail = archive.getStream("/Metadata/thumbnail.png") # archive.addContentType(extension = "png", mime_type = "image/png")
# thumbnail = archive.getStream("/Metadata/thumbnail.png")
thumbnail_buffer = QBuffer() #
thumbnail_buffer.open(QBuffer.ReadWrite) # thumbnail_buffer = QBuffer()
thumbnail_image = self._snapshot # thumbnail_buffer.open(QBuffer.ReadWrite)
thumbnail_image.save(thumbnail_buffer, "PNG") # thumbnail_image = self._snapshot
# thumbnail_image.save(thumbnail_buffer, "PNG")
thumbnail.write(thumbnail_buffer.data()) #
archive.addRelation(virtual_path = "/Metadata/thumbnail.png", # thumbnail.write(thumbnail_buffer.data())
relation_type = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail", # archive.addRelation(virtual_path = "/Metadata/thumbnail.png",
origin = "/3D/model.gcode") # relation_type = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",
else: # origin = "/3D/model.gcode")
Logger.log("d", "Thumbnail not created, cannot save it") # else:
# Logger.log("d", "Thumbnail not created, cannot save it")
# Store the material. # Store the material.
application = CuraApplication.getInstance() application = CuraApplication.getInstance()

View File

@ -4,7 +4,7 @@
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.1 import QtQuick.Controls 1.1
import UM 1.2 as UM import UM 1.6 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
Menu Menu
@ -37,8 +37,9 @@ Menu
MenuItem MenuItem
{ {
id: saveWorkspaceMenu id: saveWorkspaceMenu
shortcut: StandardKey.Save shortcut: visible ? StandardKey.Save : ""
text: catalog.i18nc("@title:menu menubar:file", "&Save Project...") text: catalog.i18nc("@title:menu menubar:file", "&Save Project...")
visible: saveProjectMenu.model.count == 1
onTriggered: onTriggered:
{ {
var args = { "filter_by_machine": false, "file_type": "workspace", "preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml" }; 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 { } MenuSeparator { }
MenuItem MenuItem

View File

@ -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 = {};
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 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)
onObjectRemoved: saveProjectMenu.removeItem(object)
}
WorkspaceSummaryDialog
{
id: saveWorkspaceDialog
property var args
property var deviceId
onYes: UM.OutputDeviceManager.requestWriteToDevice(deviceId, PrintInformation.jobName, args)
}
}

View File

@ -15,6 +15,18 @@ ComboBox
{ {
id: control 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: [ states: [
State State
{ {
@ -67,11 +79,22 @@ ComboBox
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.right: downArrow.left 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 textFormat: Text.PlainText
renderType: Text.NativeRendering renderType: Text.NativeRendering
font: UM.Theme.getFont("default") 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 elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
@ -81,6 +104,7 @@ ComboBox
y: control.height - UM.Theme.getSize("default_lining").height y: control.height - UM.Theme.getSize("default_lining").height
width: control.width width: control.width
implicitHeight: contentItem.implicitHeight + 2 * UM.Theme.getSize("default_lining").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 padding: UM.Theme.getSize("default_lining").width
contentItem: ListView contentItem: ListView
@ -133,7 +157,7 @@ ComboBox
text: delegateItem.text text: delegateItem.text
textFormat: Text.PlainText textFormat: Text.PlainText
renderType: Text.NativeRendering renderType: Text.NativeRendering
color: control.contentItem.color color: UM.Theme.getColor("setting_control_text")
font: UM.Theme.getFont("default") font: UM.Theme.getFont("default")
elide: Text.ElideRight elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter