mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -06:00
Merge branch 'master' of https://github.com/Ultimaker/Cura
This commit is contained in:
commit
701ac7f91e
4 changed files with 41 additions and 3 deletions
|
@ -459,7 +459,7 @@ class ContainerManager(QObject):
|
|||
# \return \type{Dict} dict with a 'status' key containing the string 'success' or 'error', and a 'message' key
|
||||
# containing a message for the user
|
||||
@pyqtSlot(QUrl, result = "QVariantMap")
|
||||
def importContainer(self, file_url_or_string: Union[QUrl, str]) -> Dict[str, str]:
|
||||
def importMaterialContainer(self, file_url_or_string: Union[QUrl, str]) -> Dict[str, str]:
|
||||
if not file_url_or_string:
|
||||
return { "status": "error", "message": "Invalid path"}
|
||||
|
||||
|
@ -490,8 +490,9 @@ class ContainerManager(QObject):
|
|||
container.deserialize(f.read())
|
||||
except PermissionError:
|
||||
return { "status": "error", "message": "Permission denied when trying to read the file"}
|
||||
except Exception as ex:
|
||||
return {"status": "error", "message": str(ex)}
|
||||
|
||||
container.setName(container_id)
|
||||
container.setDirty(True)
|
||||
|
||||
self._container_registry.addContainer(container)
|
||||
|
|
|
@ -17,6 +17,8 @@ import UM.Dictionary
|
|||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
|
||||
from .XmlMaterialValidator import XmlMaterialValidater
|
||||
|
||||
## Handles serializing and deserializing material containers from an XML file
|
||||
class XmlMaterialProfile(InstanceContainer):
|
||||
CurrentFdmMaterialVersion = "1.3"
|
||||
|
@ -480,6 +482,10 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
if "adhesion_info" not in meta_data:
|
||||
meta_data["adhesion_info"] = ""
|
||||
|
||||
validation_message = XmlMaterialValidater.validateMaterialMetaDate(meta_data)
|
||||
if validation_message is not None:
|
||||
raise Exception("Not valid material profile: %s" % (validation_message))
|
||||
|
||||
property_values = {}
|
||||
properties = data.iterfind("./um:properties/*", self.__namespaces)
|
||||
for entry in properties:
|
||||
|
|
31
plugins/XmlMaterialProfile/XmlMaterialValidator.py
Normal file
31
plugins/XmlMaterialProfile/XmlMaterialValidator.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
|
||||
|
||||
class XmlMaterialValidater():
|
||||
|
||||
@classmethod
|
||||
def validateMaterialMetaDate(cls, validation_metadata):
|
||||
|
||||
if validation_metadata.get("GUID") is None:
|
||||
return "Missing GUID"
|
||||
|
||||
if validation_metadata.get("brand") is None:
|
||||
return "Missing Brand"
|
||||
|
||||
if validation_metadata.get("material") is None:
|
||||
return "Missing Material"
|
||||
|
||||
if validation_metadata.get("version") is None:
|
||||
return "Missing Version"
|
||||
|
||||
if validation_metadata.get("description") is None:
|
||||
return "Missing Description"
|
||||
|
||||
if validation_metadata.get("adhesion_info") is None:
|
||||
return "Missing Adhesion Info"
|
||||
|
||||
return None
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ UM.ManagementPage
|
|||
folder: CuraApplication.getDefaultPath("dialog_material_path")
|
||||
onAccepted:
|
||||
{
|
||||
var result = Cura.ContainerManager.importContainer(fileUrl)
|
||||
var result = Cura.ContainerManager.importMaterialContainer(fileUrl)
|
||||
|
||||
messageDialog.title = catalog.i18nc("@title:window", "Import Material")
|
||||
messageDialog.text = catalog.i18nc("@info:status Don't translate the XML tags <filename> or <message>!", "Could not import material <filename>%1</filename>: <message>%2</message>").arg(fileUrl).arg(result.message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue