Merge remote-tracking branch 'origin/CURA-11403_save-PAP' into CURA-11403_save-PAP

This commit is contained in:
c.lamboo 2024-02-21 16:51:00 +01:00
commit 6f9fd3c46d
3 changed files with 28 additions and 2 deletions

View File

@ -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"

View File

@ -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")

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB