mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-30 15:54:32 +08:00
Save settings to json file in .ufp
CURA-9224
This commit is contained in:
parent
4b2d03fe1d
commit
42c3eb0c64
@ -1,6 +1,6 @@
|
|||||||
# Copyright (c) 2021 Ultimaker B.V.
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
import json
|
||||||
from typing import cast, List, Dict
|
from typing import cast, List, Dict
|
||||||
|
|
||||||
from Charon.VirtualFile import VirtualFile # To open UFP files.
|
from Charon.VirtualFile import VirtualFile # To open UFP files.
|
||||||
@ -10,6 +10,7 @@ from io import StringIO # For converting g-code to bytes.
|
|||||||
|
|
||||||
from PyQt6.QtCore import QBuffer
|
from PyQt6.QtCore import QBuffer
|
||||||
|
|
||||||
|
from UM.Application import Application
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Mesh.MeshWriter import MeshWriter # The writer we need to implement.
|
from UM.Mesh.MeshWriter import MeshWriter # The writer we need to implement.
|
||||||
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType
|
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType
|
||||||
@ -18,11 +19,13 @@ from UM.PluginRegistry import PluginRegistry # To get the g-code writer.
|
|||||||
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
||||||
from UM.Scene.SceneNode import SceneNode
|
from UM.Scene.SceneNode import SceneNode
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
from cura.Utils.Threading import call_on_qt_thread
|
from cura.Utils.Threading import call_on_qt_thread
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
|
|
||||||
METADATA_OBJECTS_PATH = "metadata/objects"
|
METADATA_OBJECTS_PATH = "metadata/objects"
|
||||||
|
SETTINGS_PATH = "Cura/settings.json"
|
||||||
|
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
@ -74,6 +77,19 @@ class UFPWriter(MeshWriter):
|
|||||||
Logger.error(error_msg)
|
Logger.error(error_msg)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
#Write settings
|
||||||
|
try:
|
||||||
|
archive.addContentType(extension="json", mime_type="application/json")
|
||||||
|
setting_textio = StringIO()
|
||||||
|
json.dump(self._getSettings(), setting_textio, separators=(", ", ": "), indent=4)
|
||||||
|
settings = archive.getStream(SETTINGS_PATH)
|
||||||
|
settings.write(setting_textio.getvalue().encode("UTF-8"))
|
||||||
|
except EnvironmentError as e:
|
||||||
|
error_msg = catalog.i18nc("@info:error", "Can't write to UFP file:") + " " + str(e)
|
||||||
|
self.setInformation(error_msg)
|
||||||
|
Logger.error(error_msg)
|
||||||
|
return False
|
||||||
|
|
||||||
# Attempt to store the thumbnail, if any:
|
# Attempt to store the thumbnail, if any:
|
||||||
backend = CuraApplication.getInstance().getBackend()
|
backend = CuraApplication.getInstance().getBackend()
|
||||||
snapshot = None if getattr(backend, "getLatestSnapshot", None) is None else backend.getLatestSnapshot()
|
snapshot = None if getattr(backend, "getLatestSnapshot", None) is None else backend.getLatestSnapshot()
|
||||||
@ -162,6 +178,10 @@ class UFPWriter(MeshWriter):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _writePluginMetadataToArchive() -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _writeObjectList(archive):
|
def _writeObjectList(archive):
|
||||||
"""Write a json list of object names to the METADATA_OBJECTS_PATH metadata field
|
"""Write a json list of object names to the METADATA_OBJECTS_PATH metadata field
|
||||||
@ -190,3 +210,21 @@ class UFPWriter(MeshWriter):
|
|||||||
return [{"name": item.getName()}
|
return [{"name": item.getName()}
|
||||||
for item in DepthFirstIterator(node)
|
for item in DepthFirstIterator(node)
|
||||||
if item.getMeshData() is not None and not item.callDecoration("isNonPrintingMesh")]
|
if item.getMeshData() is not None and not item.callDecoration("isNonPrintingMesh")]
|
||||||
|
|
||||||
|
def _getSettings(self) -> Dict[str, Dict[str, Dict[str, str]]]:
|
||||||
|
container_registry = Application.getInstance().getContainerRegistry()
|
||||||
|
|
||||||
|
global_stack = cast(GlobalStack, Application.getInstance().getGlobalContainerStack())
|
||||||
|
quality_changes = global_stack.qualityChanges
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
"extruder_1": {
|
||||||
|
"changes": {},
|
||||||
|
"default": {}
|
||||||
|
},
|
||||||
|
"extruder_2": {
|
||||||
|
"changes": {},
|
||||||
|
"default": {}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return settings
|
||||||
|
Loading…
x
Reference in New Issue
Block a user