mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-06 21:44:01 -06:00
Merge pull request #10327 from Ultimaker/CURA-6096_profile_database
Store metadata in database
This commit is contained in:
commit
b2eae08cc7
5 changed files with 93 additions and 0 deletions
|
@ -32,6 +32,10 @@ from cura.Machines.ContainerTree import ContainerTree
|
|||
from cura.ReaderWriters.ProfileReader import NoProfileException, ProfileReader
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
from .DatabaseHandlers.IntentDatabaseHandler import IntentDatabaseHandler
|
||||
from .DatabaseHandlers.QualityDatabaseHandler import QualityDatabaseHandler
|
||||
from .DatabaseHandlers.VariantDatabaseHandler import VariantDatabaseHandler
|
||||
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
|
||||
|
@ -44,6 +48,10 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
# is added, we check to see if an extruder stack needs to be added.
|
||||
self.containerAdded.connect(self._onContainerAdded)
|
||||
|
||||
self._database_handlers["variant"] = VariantDatabaseHandler()
|
||||
self._database_handlers["quality"] = QualityDatabaseHandler()
|
||||
self._database_handlers["intent"] = IntentDatabaseHandler()
|
||||
|
||||
@override(ContainerRegistry)
|
||||
def addContainer(self, container: ContainerInterface) -> bool:
|
||||
"""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…
Add table
Add a link
Reference in a new issue