diff --git a/plugins/3MFWriter/ThreeMFWorkspaceWriter.py b/plugins/3MFWriter/ThreeMFWorkspaceWriter.py index cff938788b..2536f5dacb 100644 --- a/plugins/3MFWriter/ThreeMFWorkspaceWriter.py +++ b/plugins/3MFWriter/ThreeMFWorkspaceWriter.py @@ -33,7 +33,7 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter): if self._ucp_model != model: self._ucp_model = model - def write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode): + def _write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode): application = Application.getInstance() machine_manager = application.getMachineManager() @@ -125,6 +125,11 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter): return True + def write(self, stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode): + success = self._write(stream, nodes, mode=WorkspaceWriter.OutputMode.BinaryMode) + self._ucp_model = None + return success + @staticmethod def _writePluginMetadataToArchive(archive: zipfile.ZipFile) -> None: file_name_template = "%s/plugin_metadata.json" diff --git a/plugins/3MFWriter/ThreeMFWriter.py b/plugins/3MFWriter/ThreeMFWriter.py index 6e3dc86890..ce9ea33fbd 100644 --- a/plugins/3MFWriter/ThreeMFWriter.py +++ b/plugins/3MFWriter/ThreeMFWriter.py @@ -10,6 +10,7 @@ from UM.Math.Vector import Vector from UM.Logger import Logger from UM.Math.Matrix import Matrix from UM.Application import Application +from UM.Resources import Resources from UM.Scene.SceneNode import SceneNode from UM.Settings.ContainerRegistry import ContainerRegistry @@ -20,7 +21,8 @@ from cura.Utils.Threading import call_on_qt_thread from cura.Scene.CuraSceneNode import CuraSceneNode from cura.Snapshot import Snapshot -from PyQt6.QtCore import QBuffer +from PyQt6.QtCore import Qt, QBuffer +from PyQt6.QtGui import QImage, QPainter import pySavitar as Savitar from .UCPDialog import UCPDialog @@ -170,6 +172,23 @@ class ThreeMFWriter(MeshWriter): def getArchive(self): return self._archive + def _addShareLogoToThumbnail(self, primary_image): + # Load the icon png image + icon_image = QImage(Resources.getPath(Resources.Images, "cura-share.png")) + + # Resize icon_image to be 1/3 of primary_image size + new_width = int(primary_image.width() / 4) + new_height = int(primary_image.height() / 4) + icon_image = icon_image.scaled(new_width, new_height, Qt.AspectRatioMode.KeepAspectRatio) + # Create a QPainter to draw on the image + painter = QPainter(primary_image) + + # Draw the icon in the top-left corner (adjust coordinates as needed) + icon_position = (10, 10) + painter.drawImage(icon_position[0], icon_position[1], icon_image) + + painter.end() + def write(self, stream, nodes, mode = MeshWriter.OutputMode.BinaryMode, export_settings_model = None) -> bool: self._archive = None # Reset archive archive = zipfile.ZipFile(stream, "w", compression = zipfile.ZIP_DEFLATED) @@ -194,6 +213,8 @@ class ThreeMFWriter(MeshWriter): # Attempt to add a thumbnail snapshot = self._createSnapshot() if snapshot: + if export_settings_model != None: + self._addShareLogoToThumbnail(snapshot) thumbnail_buffer = QBuffer() thumbnail_buffer.open(QBuffer.OpenModeFlag.ReadWrite) snapshot.save(thumbnail_buffer, "PNG") diff --git a/resources/images/cura-share.png b/resources/images/cura-share.png new file mode 100644 index 0000000000..60de85194c Binary files /dev/null and b/resources/images/cura-share.png differ