mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-23 22:29:41 +08:00
Fix dialog_on_ucp_project_save
preference
CURA-11403
This commit is contained in:
parent
6f9fd3c46d
commit
3c305bb289
@ -10,6 +10,8 @@ from UM.Math.Vector import Vector
|
||||
from UM.Logger import Logger
|
||||
from UM.Math.Matrix import Matrix
|
||||
from UM.Application import Application
|
||||
from UM.OutputDevice import OutputDeviceError
|
||||
from UM.Message import Message
|
||||
from UM.Resources import Resources
|
||||
from UM.Scene.SceneNode import SceneNode
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
@ -456,5 +458,40 @@ class ThreeMFWriter(MeshWriter):
|
||||
return extra_settings
|
||||
|
||||
def exportUcp(self):
|
||||
self._config_dialog = UCPDialog()
|
||||
self._config_dialog.show()
|
||||
preferences = CuraApplication.getInstance().getPreferences()
|
||||
if preferences.getValue("cura/dialog_on_ucp_project_save"):
|
||||
self._config_dialog = UCPDialog()
|
||||
self._config_dialog.show()
|
||||
else:
|
||||
application = CuraApplication.getInstance()
|
||||
workspace_handler = application.getInstance().getWorkspaceFileHandler()
|
||||
|
||||
# Set the model to the workspace writer
|
||||
mesh_writer = workspace_handler.getWriter("3MFWriter")
|
||||
mesh_writer.setExportModel(SettingsExportModel())
|
||||
|
||||
# Open file dialog and write the file
|
||||
device = application.getOutputDeviceManager().getOutputDevice("local_file")
|
||||
nodes = [application.getController().getScene().getRoot()]
|
||||
|
||||
file_name = CuraApplication.getInstance().getPrintInformation().baseName
|
||||
|
||||
try:
|
||||
device.requestWrite(
|
||||
nodes,
|
||||
file_name,
|
||||
["application/vnd.ms-package.3dmanufacturing-3dmodel+xml"],
|
||||
workspace_handler,
|
||||
preferred_mimetype_list="application/vnd.ms-package.3dmanufacturing-3dmodel+xml"
|
||||
)
|
||||
except OutputDeviceError.UserCanceledError:
|
||||
self._onRejected()
|
||||
except Exception as e:
|
||||
message = Message(
|
||||
catalog.i18nc("@info:error", "Unable to write to file: {0}", file_name),
|
||||
title=catalog.i18nc("@info:title", "Error"),
|
||||
message_type=Message.MessageType.ERROR
|
||||
)
|
||||
message.show()
|
||||
Logger.logException("e", "Unable to write to file %s: %s", file_name, e)
|
||||
self._onRejected()
|
||||
|
@ -53,8 +53,7 @@ class UCPDialog(QObject):
|
||||
def notifyClosed(self):
|
||||
self._onFinished()
|
||||
|
||||
@pyqtSlot()
|
||||
def _onAccepted(self):
|
||||
def save3mf(self):
|
||||
application = CuraApplication.getInstance()
|
||||
workspace_handler = application.getInstance().getWorkspaceFileHandler()
|
||||
|
||||
@ -92,7 +91,9 @@ class UCPDialog(QObject):
|
||||
Logger.logException("e", "Unable to write to file %s: %s", file_name, e)
|
||||
self._onRejected()
|
||||
|
||||
@pyqtSlot()
|
||||
def _onAccepted(self):
|
||||
self.save3mf()
|
||||
|
||||
def _onRejected(self):
|
||||
self._onFinished()
|
||||
|
||||
|
@ -47,14 +47,18 @@ Cura.Menu
|
||||
enabled: UM.WorkspaceFileHandler.enabled && saveProjectMenu.model.count == 1
|
||||
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"))
|
||||
if (UM.Preferences.getValue("cura/dialog_on_project_save"))
|
||||
{
|
||||
saveWorkspaceDialog.args = args
|
||||
saveWorkspaceDialog.open()
|
||||
}
|
||||
else
|
||||
{
|
||||
const args = {
|
||||
"filter_by_machine": false,
|
||||
"file_type": "workspace",
|
||||
"preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
|
||||
};
|
||||
UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, args)
|
||||
}
|
||||
}
|
||||
@ -75,23 +79,7 @@ Cura.Menu
|
||||
id: saveUCPMenu
|
||||
text: catalog.i18nc("@title:menu menubar:file", "&Save Universal Cura Project...")
|
||||
enabled: UM.WorkspaceFileHandler.enabled && CuraApplication.getPackageManager().allEnabledPackages.includes("3MFWriter")
|
||||
onTriggered:
|
||||
{
|
||||
if (UM.Preferences.getValue("cura/dialog_on_ucp_project_save"))
|
||||
{
|
||||
CuraApplication.exportUcp()
|
||||
}
|
||||
else
|
||||
{
|
||||
const args = {
|
||||
"filter_by_machine": false,
|
||||
"file_type": "workspace",
|
||||
"preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
|
||||
"limit_mimetypes": ["application/vnd.ms-package.3dmanufacturing-3dmodel+xml"],
|
||||
};
|
||||
UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.baseName, args)
|
||||
}
|
||||
}
|
||||
onTriggered: CuraApplication.exportUcp()
|
||||
}
|
||||
|
||||
Cura.MenuSeparator { }
|
||||
@ -102,8 +90,11 @@ Cura.Menu
|
||||
text: catalog.i18nc("@title:menu menubar:file", "&Export...")
|
||||
onTriggered:
|
||||
{
|
||||
var localDeviceId = "local_file"
|
||||
UM.OutputDeviceManager.requestWriteToDevice(localDeviceId, PrintInformation.jobName, { "filter_by_machine": false, "preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml"})
|
||||
const args = {
|
||||
"filter_by_machine": false,
|
||||
"preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
|
||||
};
|
||||
UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +104,13 @@ Cura.Menu
|
||||
text: catalog.i18nc("@action:inmenu menubar:file", "Export Selection...")
|
||||
enabled: UM.Selection.hasSelection
|
||||
icon.name: "document-save-as"
|
||||
onTriggered: UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", PrintInformation.jobName, { "filter_by_machine": false, "preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml"})
|
||||
onTriggered: {
|
||||
const args = {
|
||||
"filter_by_machine": false,
|
||||
"preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
|
||||
};
|
||||
UM.OutputDeviceManager.requestWriteSelectionToDevice("local_file", PrintInformation.jobName, args);
|
||||
}
|
||||
}
|
||||
|
||||
Cura.MenuSeparator { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user