mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
OutputDevices now take file_handler into account
CURA-1263
This commit is contained in:
parent
e30038435c
commit
304696c809
2 changed files with 14 additions and 6 deletions
|
@ -49,7 +49,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
self._printer_state = ""
|
self._printer_state = ""
|
||||||
self._printer_type = "unknown"
|
self._printer_type = "unknown"
|
||||||
|
|
||||||
def requestWrite(self, nodes, file_name = None, filter_by_machine = False):
|
def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None):
|
||||||
raise NotImplementedError("requestWrite needs to be implemented")
|
raise NotImplementedError("requestWrite needs to be implemented")
|
||||||
|
|
||||||
## Signals
|
## Signals
|
||||||
|
|
|
@ -6,7 +6,7 @@ import os.path
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
from UM.Mesh.WriteMeshJob import WriteMeshJob
|
from UM.FileHandler.WriteFileJob import WriteFileJob
|
||||||
from UM.Mesh.MeshWriter import MeshWriter
|
from UM.Mesh.MeshWriter import MeshWriter
|
||||||
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
|
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
|
||||||
from UM.OutputDevice.OutputDevice import OutputDevice
|
from UM.OutputDevice.OutputDevice import OutputDevice
|
||||||
|
@ -37,13 +37,17 @@ class RemovableDriveOutputDevice(OutputDevice):
|
||||||
# meshes.
|
# meshes.
|
||||||
# \param limit_mimetypes Should we limit the available MIME types to the
|
# \param limit_mimetypes Should we limit the available MIME types to the
|
||||||
# MIME types available to the currently active machine?
|
# MIME types available to the currently active machine?
|
||||||
def requestWrite(self, nodes, file_name = None, filter_by_machine = False):
|
def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None):
|
||||||
filter_by_machine = True # This plugin is indended to be used by machine (regardless of what it was told to do)
|
filter_by_machine = True # This plugin is indended to be used by machine (regardless of what it was told to do)
|
||||||
if self._writing:
|
if self._writing:
|
||||||
raise OutputDeviceError.DeviceBusyError()
|
raise OutputDeviceError.DeviceBusyError()
|
||||||
|
|
||||||
# Formats supported by this application (File types that we can actually write)
|
# Formats supported by this application (File types that we can actually write)
|
||||||
file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite()
|
if file_handler:
|
||||||
|
file_formats = file_handler.getSupportedFileTypesWrite()
|
||||||
|
else:
|
||||||
|
file_formats = Application.getInstance().getMeshFileHandler().getSupportedFileTypesWrite()
|
||||||
|
|
||||||
if filter_by_machine:
|
if filter_by_machine:
|
||||||
container = Application.getInstance().getGlobalContainerStack().findContainer({"file_formats": "*"})
|
container = Application.getInstance().getGlobalContainerStack().findContainer({"file_formats": "*"})
|
||||||
|
|
||||||
|
@ -58,7 +62,11 @@ class RemovableDriveOutputDevice(OutputDevice):
|
||||||
raise OutputDeviceError.WriteRequestFailedError()
|
raise OutputDeviceError.WriteRequestFailedError()
|
||||||
|
|
||||||
# Just take the first file format available.
|
# Just take the first file format available.
|
||||||
writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"])
|
if file_handler is not None:
|
||||||
|
writer = file_handler.getWriterByMimeType(file_formats[0]["mime_type"])
|
||||||
|
else:
|
||||||
|
writer = Application.getInstance().getMeshFileHandler().getWriterByMimeType(file_formats[0]["mime_type"])
|
||||||
|
|
||||||
extension = file_formats[0]["extension"]
|
extension = file_formats[0]["extension"]
|
||||||
|
|
||||||
if file_name is None:
|
if file_name is None:
|
||||||
|
@ -72,7 +80,7 @@ class RemovableDriveOutputDevice(OutputDevice):
|
||||||
Logger.log("d", "Writing to %s", file_name)
|
Logger.log("d", "Writing to %s", file_name)
|
||||||
# Using buffering greatly reduces the write time for many lines of gcode
|
# Using buffering greatly reduces the write time for many lines of gcode
|
||||||
self._stream = open(file_name, "wt", buffering = 1, encoding = "utf-8")
|
self._stream = open(file_name, "wt", buffering = 1, encoding = "utf-8")
|
||||||
job = WriteMeshJob(writer, self._stream, nodes, MeshWriter.OutputMode.TextMode)
|
job = WriteFileJob(writer, self._stream, nodes, MeshWriter.OutputMode.TextMode)
|
||||||
job.setFileName(file_name)
|
job.setFileName(file_name)
|
||||||
job.progress.connect(self._onProgress)
|
job.progress.connect(self._onProgress)
|
||||||
job.finished.connect(self._onFinished)
|
job.finished.connect(self._onFinished)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue