mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 06:19:05 +08:00
Merge pull request #10327 from Ultimaker/CURA-6096_profile_database
Store metadata in database
This commit is contained in:
commit
b2eae08cc7
@ -32,6 +32,10 @@ from cura.Machines.ContainerTree import ContainerTree
|
|||||||
from cura.ReaderWriters.ProfileReader import NoProfileException, ProfileReader
|
from cura.ReaderWriters.ProfileReader import NoProfileException, ProfileReader
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
|
from .DatabaseHandlers.IntentDatabaseHandler import IntentDatabaseHandler
|
||||||
|
from .DatabaseHandlers.QualityDatabaseHandler import QualityDatabaseHandler
|
||||||
|
from .DatabaseHandlers.VariantDatabaseHandler import VariantDatabaseHandler
|
||||||
|
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
@ -44,6 +48,10 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||||||
# is added, we check to see if an extruder stack needs to be added.
|
# is added, we check to see if an extruder stack needs to be added.
|
||||||
self.containerAdded.connect(self._onContainerAdded)
|
self.containerAdded.connect(self._onContainerAdded)
|
||||||
|
|
||||||
|
self._database_handlers["variant"] = VariantDatabaseHandler()
|
||||||
|
self._database_handlers["quality"] = QualityDatabaseHandler()
|
||||||
|
self._database_handlers["intent"] = IntentDatabaseHandler()
|
||||||
|
|
||||||
@override(ContainerRegistry)
|
@override(ContainerRegistry)
|
||||||
def addContainer(self, container: ContainerInterface) -> bool:
|
def addContainer(self, container: ContainerInterface) -> bool:
|
||||||
"""Overridden from ContainerRegistry
|
"""Overridden from ContainerRegistry
|
||||||
|
25
cura/Settings/DatabaseHandlers/IntentDatabaseHandler.py
Normal file
25
cura/Settings/DatabaseHandlers/IntentDatabaseHandler.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from UM.Settings.SQLQueryFactory import SQLQueryFactory
|
||||||
|
from UM.Settings.DatabaseContainerMetadataController import DatabaseMetadataContainerController
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
|
|
||||||
|
|
||||||
|
class IntentDatabaseHandler(DatabaseMetadataContainerController):
|
||||||
|
"""The Database handler for Intent containers"""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
super().__init__(SQLQueryFactory(table = "intent",
|
||||||
|
fields = {
|
||||||
|
"id": "text",
|
||||||
|
"name": "text",
|
||||||
|
"quality_type": "text",
|
||||||
|
"intent_category": "text",
|
||||||
|
"variant": "text",
|
||||||
|
"definition": "text",
|
||||||
|
"material": "text",
|
||||||
|
"version": "text",
|
||||||
|
"setting_version": "text"
|
||||||
|
}))
|
||||||
|
self._container_type = InstanceContainer
|
38
cura/Settings/DatabaseHandlers/QualityDatabaseHandler.py
Normal file
38
cura/Settings/DatabaseHandlers/QualityDatabaseHandler.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from UM.Settings.SQLQueryFactory import SQLQueryFactory, metadata_type
|
||||||
|
from UM.Settings.DatabaseContainerMetadataController import DatabaseMetadataContainerController
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
|
|
||||||
|
|
||||||
|
class QualityDatabaseHandler(DatabaseMetadataContainerController):
|
||||||
|
"""The Database handler for Quality containers"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(SQLQueryFactory(table = "quality",
|
||||||
|
fields = {
|
||||||
|
"id": "text",
|
||||||
|
"name": "text",
|
||||||
|
"quality_type": "text",
|
||||||
|
"material": "text",
|
||||||
|
"variant": "text",
|
||||||
|
"global_quality": "bool",
|
||||||
|
"definition": "text",
|
||||||
|
"version": "text",
|
||||||
|
"setting_version": "text"
|
||||||
|
}))
|
||||||
|
self._container_type = InstanceContainer
|
||||||
|
|
||||||
|
def groomMetadata(self, metadata: metadata_type) -> metadata_type:
|
||||||
|
"""
|
||||||
|
Ensures that the metadata is in the order of the field keys and has the right size.
|
||||||
|
if the metadata doesn't contains a key which is stored in the DB it will add it as
|
||||||
|
an empty string. Key, value pairs that are not stored in the DB are dropped.
|
||||||
|
If the `global_quality` isn't set it well default to 'False'
|
||||||
|
|
||||||
|
:param metadata: The container metadata
|
||||||
|
"""
|
||||||
|
if "global_quality" not in metadata:
|
||||||
|
metadata["global_quality"] = "False"
|
||||||
|
return super().groomMetadata(metadata)
|
22
cura/Settings/DatabaseHandlers/VariantDatabaseHandler.py
Normal file
22
cura/Settings/DatabaseHandlers/VariantDatabaseHandler.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from UM.Settings.SQLQueryFactory import SQLQueryFactory
|
||||||
|
from UM.Settings.DatabaseContainerMetadataController import DatabaseMetadataContainerController
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
|
|
||||||
|
|
||||||
|
class VariantDatabaseHandler(DatabaseMetadataContainerController):
|
||||||
|
"""The Database handler for Variant containers"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(SQLQueryFactory(table = "variant",
|
||||||
|
fields = {
|
||||||
|
"id": "text",
|
||||||
|
"name": "text",
|
||||||
|
"hardware_type": "text",
|
||||||
|
"definition": "text",
|
||||||
|
"version": "text",
|
||||||
|
"setting_version": "text"
|
||||||
|
}))
|
||||||
|
self._container_type = InstanceContainer
|
0
cura/Settings/DatabaseHandlers/__init__.py
Normal file
0
cura/Settings/DatabaseHandlers/__init__.py
Normal file
Loading…
x
Reference in New Issue
Block a user