mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-17 03:37:48 -06:00
Add dataclass for ActiveQuality. Move some logic out of MachineManager into ActiveQuality.
CURA-9793
This commit is contained in:
parent
f297909a82
commit
8dcccd941b
3 changed files with 49 additions and 37 deletions
37
cura/Settings/ActiveQuality.py
Normal file
37
cura/Settings/ActiveQuality.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from UM import i18nCatalog
|
||||||
|
|
||||||
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ActiveQuality:
|
||||||
|
""" Represents the active intent+profile combination, contains all information needed to display active quality. """
|
||||||
|
intent_category: str = "" # Name of the base intent. For example "visual" or "engineering".
|
||||||
|
intent_name: str = "" # Name of the base intent formatted for display. For Example "Visual" or "Engineering"
|
||||||
|
profile: str = "" # Name of the base profile. For example "Fine" or "Fast"
|
||||||
|
custom_profile: str = "" # Name of the custom profile, this is based on profile. For example "MyCoolCustomProfile"
|
||||||
|
layer_height: float = None # Layer height of quality in mm. For example 0.4
|
||||||
|
is_experimental: bool = False # If the quality experimental.
|
||||||
|
|
||||||
|
def getStringParts(self) -> List[str]:
|
||||||
|
string_parts = []
|
||||||
|
|
||||||
|
if self.custom_profile is not None:
|
||||||
|
string_parts.append(self.custom_profile)
|
||||||
|
|
||||||
|
if self.intent_category is not "default":
|
||||||
|
string_parts.append(f"{self.intent_name} - {self.profile}")
|
||||||
|
else:
|
||||||
|
string_parts.append(self.profile)
|
||||||
|
|
||||||
|
if self.layer_height:
|
||||||
|
string_parts.append(f"{self.layer_height}mm")
|
||||||
|
|
||||||
|
if self.is_experimental:
|
||||||
|
string_parts.append(catalog.i18nc("@label", "Experimental"))
|
||||||
|
|
||||||
|
return string_parts
|
||||||
|
|
|
@ -40,6 +40,7 @@ from cura.Settings.cura_empty_instance_containers import (empty_definition_chang
|
||||||
empty_material_container, empty_quality_container,
|
empty_material_container, empty_quality_container,
|
||||||
empty_quality_changes_container, empty_intent_container)
|
empty_quality_changes_container, empty_intent_container)
|
||||||
from cura.UltimakerCloud.UltimakerCloudConstants import META_UM_LINKED_TO_ACCOUNT
|
from cura.UltimakerCloud.UltimakerCloudConstants import META_UM_LINKED_TO_ACCOUNT
|
||||||
|
from .ActiveQuality import ActiveQuality
|
||||||
|
|
||||||
from .CuraStackBuilder import CuraStackBuilder
|
from .CuraStackBuilder import CuraStackBuilder
|
||||||
|
|
||||||
|
@ -1633,47 +1634,20 @@ class MachineManager(QObject):
|
||||||
# - "my_profile - Engineering - Fine" (based on an intent)
|
# - "my_profile - Engineering - Fine" (based on an intent)
|
||||||
@pyqtProperty("QList<QString>", notify = activeQualityDisplayNameChanged)
|
@pyqtProperty("QList<QString>", notify = activeQualityDisplayNameChanged)
|
||||||
def activeQualityDisplayNameStringParts(self) -> List[str]:
|
def activeQualityDisplayNameStringParts(self) -> List[str]:
|
||||||
result_map = self.activeQualityDisplayNameMap
|
return self.activeQualityDisplayNameMap.getStringParts()
|
||||||
string_parts = []
|
|
||||||
|
|
||||||
if result_map["custom_profile"] is not None:
|
|
||||||
string_parts.append(result_map["custom_profile"])
|
|
||||||
|
|
||||||
if result_map["intent_category"] is not "default":
|
|
||||||
string_parts.append(f"""{result_map["intent_name"]} - {result_map["profile"]}""")
|
|
||||||
else:
|
|
||||||
string_parts.append(result_map["profile"])
|
|
||||||
|
|
||||||
if result_map["layer_height"]:
|
|
||||||
string_parts.append(f"""{result_map["layer_height"]}mm""")
|
|
||||||
|
|
||||||
if result_map["is_experimental"]:
|
|
||||||
string_parts.append(catalog.i18nc("@label", "Experimental"))
|
|
||||||
|
|
||||||
return string_parts
|
|
||||||
|
|
||||||
@pyqtProperty("QVariantMap", notify = activeQualityDisplayNameChanged)
|
@pyqtProperty("QVariantMap", notify = activeQualityDisplayNameChanged)
|
||||||
def activeQualityDisplayNameMap(self) -> Dict[str, Any]:
|
def activeQualityDisplayNameMap(self) -> ActiveQuality:
|
||||||
global_stack = self._application.getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
return {
|
return ActiveQuality()
|
||||||
"profile": "",
|
|
||||||
"intent_category": "",
|
|
||||||
"intent": "",
|
|
||||||
"custom_profile": None,
|
|
||||||
"is_experimental": False
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return ActiveQuality(profile = global_stack.quality.getName(),
|
||||||
"profile": global_stack.quality.getName(),
|
intent_category = self.activeIntentCategory,
|
||||||
"intent_category": self.activeIntentCategory,
|
intent_name = IntentCategoryModel.translation(self.activeIntentCategory, "name", self.activeIntentCategory.title()),
|
||||||
"intent_name": IntentCategoryModel.translation(self.activeIntentCategory, "name", self.activeIntentCategory.title()),
|
custom_profile = self.activeQualityOrQualityChangesName if global_stack.qualityChanges is not empty_quality_changes_container else None,
|
||||||
"custom_profile": self.activeQualityOrQualityChangesName \
|
layer_height = self.activeQualityLayerHeight if self.isActiveQualitySupported else None,
|
||||||
if global_stack.qualityChanges is not empty_quality_changes_container \
|
is_experimental = self.isActiveQualityExperimental and self.isActiveQualitySupported)
|
||||||
else None,
|
|
||||||
"layer_height": self.activeQualityLayerHeight if self.isActiveQualitySupported else None,
|
|
||||||
"is_experimental": self.isActiveQualityExperimental and self.isActiveQualitySupported,
|
|
||||||
}
|
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setIntentByCategory(self, intent_category: str) -> None:
|
def setIntentByCategory(self, intent_category: str) -> None:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# Copyright (c) 2022 Ultimaker B.V.
|
# Copyright (c) 2022 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
|
import json
|
||||||
|
from dataclasses import asdict
|
||||||
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.
|
||||||
|
@ -227,7 +228,7 @@ class UFPWriter(MeshWriter):
|
||||||
},
|
},
|
||||||
"intent": machine_manager.activeIntentCategory,
|
"intent": machine_manager.activeIntentCategory,
|
||||||
"quality": machine_manager.activeQualityOrQualityChangesName,
|
"quality": machine_manager.activeQualityOrQualityChangesName,
|
||||||
"quality_display_name": machine_manager.activeQualityDisplayNameMap,
|
"quality_display_name": asdict(machine_manager.activeQualityDisplayNameMap),
|
||||||
}
|
}
|
||||||
|
|
||||||
global_stack = cast(GlobalStack, Application.getInstance().getGlobalContainerStack())
|
global_stack = cast(GlobalStack, Application.getInstance().getGlobalContainerStack())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue