Skip to content

Commit

Permalink
Fix exporting binary/ascii STL
Browse files Browse the repository at this point in the history
CURA-11561
  • Loading branch information
wawanbreton committed Jan 25, 2024
1 parent 7b201fd commit 1281b54
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
8 changes: 4 additions & 4 deletions UM/Qt/Bindings/MeshWritersModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

from typing import List

from PyQt6.QtCore import Qt, pyqtSignal
from PyQt6.QtCore import Qt
from PyQt6.QtQml import QQmlEngine

from UM.Application import Application
from UM.OutputDevice.OutputDeviceManager import OutputDeviceManager
from UM.OutputDevice.ProjectOutputDevice import ProjectOutputDevice
from UM.Qt.ListModel import ListModel


Expand All @@ -22,14 +20,16 @@ class MeshWritersModel(ListModel):
"""

MimeTypeRole = Qt.ItemDataRole.UserRole + 1
DescriptionRole = Qt.ItemDataRole.UserRole + 2
ModeRole = Qt.ItemDataRole.UserRole + 2
DescriptionRole = Qt.ItemDataRole.UserRole + 3

def __init__(self, parent = None):
super().__init__(parent)
# Ensure that this model doesn't get garbage collected (Now the bound object is destroyed when the wrapper is)
QQmlEngine.setObjectOwnership(self, QQmlEngine.ObjectOwnership.CppOwnership)

self.addRoleName(self.MimeTypeRole, "mime_type")
self.addRoleName(self.ModeRole, "mode")
self.addRoleName(self.DescriptionRole, "description")

self.setItems(Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite())
20 changes: 15 additions & 5 deletions UM/Qt/Bindings/OutputDeviceManagerProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ def requestWriteToDevice(self, device_id: str, file_name: str, kwargs: Mapping[s
"""

limit_mimetypes = kwargs.get("limit_mimetypes", None)
limit_modes = kwargs.get("limit_modes", None)
file_type = kwargs.get("file_type", "mesh")
preferred_mimetypes = kwargs.get("preferred_mimetypes", None)
# On Windows, calling requestWrite() on LocalFileOutputDevice crashes when called from a signal
# handler attached to a QML MenuItem. So instead, defer the call to the next run of the event
# loop, since that does work.
Application.getInstance().callLater(self._writeToDevice, [Application.getInstance().getController().getScene().getRoot()], device_id, file_name, limit_mimetypes, file_type, preferred_mimetypes = preferred_mimetypes)
Application.getInstance().callLater(self._writeToDevice, [Application.getInstance().getController().getScene().getRoot()], device_id, file_name, limit_mimetypes, limit_modes, file_type, preferred_mimetypes = preferred_mimetypes)

@pyqtSlot(str, str, "QVariantMap")
def requestWriteSelectionToDevice(self, device_id: str, file_name: str, kwargs: Mapping[str, str]) -> None:
Expand All @@ -112,17 +113,25 @@ def requestWriteSelectionToDevice(self, device_id: str, file_name: str, kwargs:
if not Selection.hasSelection():
return

limit_mimetypes = kwargs.get("limit_mimetypes", False)
limit_mimetypes = kwargs.get("limit_mimetypes", None)
limit_modes = kwargs.get("limit_mimetypes", None)
preferred_mimetypes = kwargs.get("preferred_mimetypes", None)
# On Windows, calling requestWrite() on LocalFileOutputDevice crashes when called from a signal
# handler attached to a QML MenuItem. So instead, defer the call to the next run of the event
# loop, since that does work.
Application.getInstance().callLater(self._writeToDevice, Selection.getAllSelectedObjects(), device_id, file_name, limit_mimetypes, preferred_mimetypes = preferred_mimetypes)
Application.getInstance().callLater(self._writeToDevice, Selection.getAllSelectedObjects(), device_id, file_name, limit_mimetypes, limit_modes, preferred_mimetypes = preferred_mimetypes)

def _onActiveDeviceChanged(self) -> None:
self.activeDeviceChanged.emit()

def _writeToDevice(self, nodes: List[SceneNode], device_id: str, file_name: str, limit_mimetypes: bool, file_type: str = "mesh", **kwargs) -> None:
def _writeToDevice(self,
nodes: List[SceneNode],
device_id: str,
file_name: str,
limit_mimetypes: Optional[List[str]],
limit_modes: Optional[List[str]],
file_type: str = "mesh",
**kwargs) -> None:
"""Writes the specified node to the output device.
The output device to write with will be selected based on the device_id.
Expand All @@ -134,6 +143,7 @@ def _writeToDevice(self, nodes: List[SceneNode], device_id: str, file_name: str,
:param file_name: A suggestion for the file name to write
to. Can be freely ignored if providing a file name makes no sense.
:param limit_mimetypes: Limit the possible mimetypes to use for writing to these types.
:param limit_modes: If not None, limit available types to the ones given
:param file_type: What file handler to get the writer from.
"""

Expand All @@ -147,7 +157,7 @@ def _writeToDevice(self, nodes: List[SceneNode], device_id: str, file_name: str,
file_handler = UM.Qt.QtApplication.QtApplication.getInstance().getWorkspaceFileHandler()

try:
device.requestWrite(nodes, file_name, limit_mimetypes, file_handler, **kwargs)
device.requestWrite(nodes, file_name, limit_mimetypes, file_handler, limit_modes = limit_modes, **kwargs)
except OutputDeviceError.UserCanceledError:
pass
except OutputDeviceError.DeviceBusyError:
Expand Down
4 changes: 4 additions & 0 deletions plugins/LocalFileOutputDevice/LocalFileOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def requestWrite(self, nodes, file_name = None, limit_mimetypes = None, file_han
if limit_mimetypes:
file_types = list(filter(lambda i: i["mime_type"] in limit_mimetypes, file_types))

limit_modes = kwargs.get("limit_modes", None)
if limit_modes:
file_types = list(filter(lambda i: i["mode"] in limit_modes, file_types))

file_types = [ft for ft in file_types if not ft["hide_in_file_dialog"]]

if len(file_types) == 0:
Expand Down

0 comments on commit 1281b54

Please sign in to comment.