Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Ha <jackha@gmail.com>2018-01-31 19:08:32 +0300
committerJack Ha <jackha@gmail.com>2018-01-31 19:08:32 +0300
commitc42f1868124a5c8d0b67f3235671f2c30707895f (patch)
treef1ff3318b75c12b3de2cd16c39f66e335d9e07ce /plugins/UFPWriter
parent2fe9860bb913d2a3fd57303ec5010b81cfbbacb9 (diff)
CURA-4425 first thumbnail in UFP file; updated CuraSceneModel and PreviewPass
Diffstat (limited to 'plugins/UFPWriter')
-rw-r--r--plugins/UFPWriter/UFPWriter.py40
1 files changed, 31 insertions, 9 deletions
diff --git a/plugins/UFPWriter/UFPWriter.py b/plugins/UFPWriter/UFPWriter.py
index 7f471d03b2..4e7463735c 100644
--- a/plugins/UFPWriter/UFPWriter.py
+++ b/plugins/UFPWriter/UFPWriter.py
@@ -3,13 +3,29 @@
from charon.VirtualFile import VirtualFile #To open UFP files.
from charon.OpenMode import OpenMode #To indicate that we want to write to UFP files.
-from io import StringIO #For converting g-code to bytes.
+from io import BytesIO, StringIO #For converting g-code to bytes.
import os.path #To get the placeholder kitty icon.
+from UM.Application import Application
+from UM.Logger import Logger
from UM.Mesh.MeshWriter import MeshWriter #The writer we need to implement.
from UM.PluginRegistry import PluginRegistry #To get the g-code writer.
+from PyQt5.QtCore import QBuffer
+
+from cura.Snapshot import Snapshot
+
class UFPWriter(MeshWriter):
+ def __init__(self):
+ super().__init__()
+ self._snapshot = None
+ Application.getInstance().getOutputDeviceManager().writeStarted.connect(self._createSnapshot)
+
+ def _createSnapshot(self, *args):
+ # must be called from the main thread because of OpenGL
+ Logger.log("d", "Creating thumbnail image...")
+ self._snapshot = Snapshot.snapshot()
+
def write(self, stream, nodes, mode = MeshWriter.OutputMode.BinaryMode):
archive = VirtualFile()
archive.openStream(stream, "application/x-ufp", OpenMode.WriteOnly)
@@ -20,16 +36,22 @@ class UFPWriter(MeshWriter):
PluginRegistry.getInstance().getPluginObject("GCodeWriter").write(gcode_textio, None)
gcode = archive.getStream("/3D/model.gcode")
gcode.write(gcode_textio.getvalue().encode("UTF-8"))
- gcode.close()
archive.addRelation(virtual_path = "/3D/model.gcode", relation_type = "http://schemas.ultimaker.org/package/2018/relationships/gcode")
#Store the thumbnail.
- #TODO: Generate the thumbnail image. Below is just a placeholder.
- archive.addContentType(extension = "png", mime_type = "image/png")
- thumbnail = archive.getStream("/Metadata/thumbnail.png")
- thumbnail.write(open(os.path.join(os.path.dirname(__file__), "kitten.png"), "rb").read())
- thumbnail.close()
- archive.addRelation(virtual_path = "/Metadata/thumbnail.png", relation_type = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail", origin = "/3D/model.gcode")
+ if self._snapshot:
+ archive.addContentType(extension = "png", mime_type = "image/png")
+ thumbnail = archive.getStream("/Metadata/thumbnail.png")
+
+ thumbnail_buffer = QBuffer()
+ thumbnail_buffer.open(QBuffer.ReadWrite)
+ thumbnail_image = self._snapshot
+ thumbnail_image.save(thumbnail_buffer, "PNG")
+
+ thumbnail.write(thumbnail_buffer.data())
+ archive.addRelation(virtual_path = "/Metadata/thumbnail.png", relation_type = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail", origin = "/3D/model.gcode")
+ else:
+ Logger.log("d", "Thumbnail not created, cannot save it")
archive.close()
- return True \ No newline at end of file
+ return True