mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-23 14:19:37 +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.Logger import Logger
|
||||||
from UM.Math.Matrix import Matrix
|
from UM.Math.Matrix import Matrix
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
|
from UM.OutputDevice import OutputDeviceError
|
||||||
|
from UM.Message import Message
|
||||||
from UM.Resources import Resources
|
from UM.Resources import Resources
|
||||||
from UM.Scene.SceneNode import SceneNode
|
from UM.Scene.SceneNode import SceneNode
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
@ -456,5 +458,40 @@ class ThreeMFWriter(MeshWriter):
|
|||||||
return extra_settings
|
return extra_settings
|
||||||
|
|
||||||
def exportUcp(self):
|
def exportUcp(self):
|
||||||
|
preferences = CuraApplication.getInstance().getPreferences()
|
||||||
|
if preferences.getValue("cura/dialog_on_ucp_project_save"):
|
||||||
self._config_dialog = UCPDialog()
|
self._config_dialog = UCPDialog()
|
||||||
self._config_dialog.show()
|
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):
|
def notifyClosed(self):
|
||||||
self._onFinished()
|
self._onFinished()
|
||||||
|
|
||||||
@pyqtSlot()
|
def save3mf(self):
|
||||||
def _onAccepted(self):
|
|
||||||
application = CuraApplication.getInstance()
|
application = CuraApplication.getInstance()
|
||||||
workspace_handler = application.getInstance().getWorkspaceFileHandler()
|
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)
|
Logger.logException("e", "Unable to write to file %s: %s", file_name, e)
|
||||||
self._onRejected()
|
self._onRejected()
|
||||||
|
|
||||||
@pyqtSlot()
|
def _onAccepted(self):
|
||||||
|
self.save3mf()
|
||||||
|
|
||||||
def _onRejected(self):
|
def _onRejected(self):
|
||||||
self._onFinished()
|
self._onFinished()
|
||||||
|
|
||||||
|
@ -47,7 +47,6 @@ Cura.Menu
|
|||||||
enabled: UM.WorkspaceFileHandler.enabled && saveProjectMenu.model.count == 1
|
enabled: UM.WorkspaceFileHandler.enabled && saveProjectMenu.model.count == 1
|
||||||
onTriggered:
|
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.args = args
|
||||||
@ -55,6 +54,11 @@ Cura.Menu
|
|||||||
}
|
}
|
||||||
else
|
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)
|
UM.OutputDeviceManager.requestWriteToDevice("local_file", PrintInformation.jobName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,23 +79,7 @@ Cura.Menu
|
|||||||
id: saveUCPMenu
|
id: saveUCPMenu
|
||||||
text: catalog.i18nc("@title:menu menubar:file", "&Save Universal Cura Project...")
|
text: catalog.i18nc("@title:menu menubar:file", "&Save Universal Cura Project...")
|
||||||
enabled: UM.WorkspaceFileHandler.enabled && CuraApplication.getPackageManager().allEnabledPackages.includes("3MFWriter")
|
enabled: UM.WorkspaceFileHandler.enabled && CuraApplication.getPackageManager().allEnabledPackages.includes("3MFWriter")
|
||||||
onTriggered:
|
onTriggered: CuraApplication.exportUcp()
|
||||||
{
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Cura.MenuSeparator { }
|
Cura.MenuSeparator { }
|
||||||
@ -102,8 +90,11 @@ Cura.Menu
|
|||||||
text: catalog.i18nc("@title:menu menubar:file", "&Export...")
|
text: catalog.i18nc("@title:menu menubar:file", "&Export...")
|
||||||
onTriggered:
|
onTriggered:
|
||||||
{
|
{
|
||||||
var localDeviceId = "local_file"
|
const args = {
|
||||||
UM.OutputDeviceManager.requestWriteToDevice(localDeviceId, PrintInformation.jobName, { "filter_by_machine": false, "preferred_mimetypes": "application/vnd.ms-package.3dmanufacturing-3dmodel+xml"})
|
"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...")
|
text: catalog.i18nc("@action:inmenu menubar:file", "Export Selection...")
|
||||||
enabled: UM.Selection.hasSelection
|
enabled: UM.Selection.hasSelection
|
||||||
icon.name: "document-save-as"
|
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 { }
|
Cura.MenuSeparator { }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user