Make ucp model available in workspace writer

CURA-11403
This commit is contained in:
c.lamboo 2024-02-20 13:47:51 +01:00
parent ec871782c7
commit efd6284f6e
2 changed files with 28 additions and 13 deletions

View file

@ -27,7 +27,7 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
super().__init__() super().__init__()
self._main_thread_lock = Lock() self._main_thread_lock = Lock()
self._success = False self._success = False
self._export_model = None self._ucp_model = None
self._stream = None self._stream = None
self._nodes = None self._nodes = None
self._mode = None self._mode = None
@ -35,8 +35,8 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
def setExportModel(self, model): def setExportModel(self, model):
if self._export_model != model: if self._ucp_model != model:
self._export_model = model self._ucp_model = model
def _write(self): def _write(self):
application = Application.getInstance() application = Application.getInstance()

View file

@ -7,6 +7,7 @@ from PyQt6.QtCore import pyqtSignal, QObject
import UM import UM
from UM.FlameProfiler import pyqtSlot from UM.FlameProfiler import pyqtSlot
from UM.Workspace.WorkspaceWriter import WorkspaceWriter
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
@ -45,24 +46,38 @@ class UCPDialog(QObject):
@pyqtSlot() @pyqtSlot()
def _onAccepted(self): def _onAccepted(self):
self._accepted = True application = CuraApplication.getInstance()
mesh_writer = CuraApplication.getInstance().getMeshFileHandler().getWriter("3MFWriter") workspace_handler = application.getInstance().getWorkspaceFileHandler()
mesh_writer.custom_data = "My custom data"
device = CuraApplication.getInstance().getOutputDeviceManager().getOutputDevice("local_file") # Set the model to the workspace writer
file_handler = UM.Qt.QtApplication.QtApplication.getInstance().getWorkspaceFileHandler() mesh_writer = workspace_handler.getWriter("3MFWriter")
nodes = [CuraApplication.getInstance().getController().getScene().getRoot()] mesh_writer.setExportModel(self._model)
device.requestWrite(nodes, "test.3mf", ["application/x-ucp"], file_handler,
# Open file dialog and write the file
device = application.getOutputDeviceManager().getOutputDevice("local_file")
nodes = [application.getController().getScene().getRoot()]
device.writeError.connect(self._onRejected)
device.writeSuccess.connect(self._onSuccess)
device.writeFinished.connect(self._onFinished)
device.requestWrite(nodes, application.getPrintInformation().jobName, ["application/x-ucp"], workspace_handler,
preferred_mimetype_list="application/x-ucp") preferred_mimetype_list="application/x-ucp")
#TODO: update _export_model in threeMFWorkspacewriter and set is_ucp is true
# = self._config_dialog.getModel()
self._onFinished()
@pyqtSlot() @pyqtSlot()
def _onRejected(self): def _onRejected(self):
self._onFinished() self._onFinished()
def _onSuccess(self):
self._accepted = True
self._onFinished()
def _onFinished(self): def _onFinished(self):
if not self._finished: # Make sure we don't send the finished signal twice, whatever happens if not self._finished: # Make sure we don't send the finished signal twice, whatever happens
self._finished = True self._finished = True
# Reset the model to the workspace writer
mesh_writer = CuraApplication.getInstance().getInstance().getWorkspaceFileHandler().getWriter("3MFWriter")
mesh_writer.setExportModel(None)
self.finished.emit(self._accepted) self.finished.emit(self._accepted)