Add dataclass for ActiveQuality. Move some logic out of MachineManager into ActiveQuality.

CURA-9793
This commit is contained in:
Joey de l'Arago 2022-11-28 12:40:35 +01:00
parent f297909a82
commit 8dcccd941b
3 changed files with 49 additions and 37 deletions

View 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

View file

@ -40,6 +40,7 @@ from cura.Settings.cura_empty_instance_containers import (empty_definition_chang
empty_material_container, empty_quality_container,
empty_quality_changes_container, empty_intent_container)
from cura.UltimakerCloud.UltimakerCloudConstants import META_UM_LINKED_TO_ACCOUNT
from .ActiveQuality import ActiveQuality
from .CuraStackBuilder import CuraStackBuilder
@ -1633,47 +1634,20 @@ class MachineManager(QObject):
# - "my_profile - Engineering - Fine" (based on an intent)
@pyqtProperty("QList<QString>", notify = activeQualityDisplayNameChanged)
def activeQualityDisplayNameStringParts(self) -> List[str]:
result_map = self.activeQualityDisplayNameMap
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
return self.activeQualityDisplayNameMap.getStringParts()
@pyqtProperty("QVariantMap", notify = activeQualityDisplayNameChanged)
def activeQualityDisplayNameMap(self) -> Dict[str, Any]:
def activeQualityDisplayNameMap(self) -> ActiveQuality:
global_stack = self._application.getGlobalContainerStack()
if global_stack is None:
return {
"profile": "",
"intent_category": "",
"intent": "",
"custom_profile": None,
"is_experimental": False
}
return ActiveQuality()
return {
"profile": global_stack.quality.getName(),
"intent_category": self.activeIntentCategory,
"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,
"layer_height": self.activeQualityLayerHeight if self.isActiveQualitySupported else None,
"is_experimental": self.isActiveQualityExperimental and self.isActiveQualitySupported,
}
return ActiveQuality(profile = global_stack.quality.getName(),
intent_category = self.activeIntentCategory,
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,
layer_height = self.activeQualityLayerHeight if self.isActiveQualitySupported else None,
is_experimental = self.isActiveQualityExperimental and self.isActiveQualitySupported)
@pyqtSlot(str)
def setIntentByCategory(self, intent_category: str) -> None:

View file

@ -1,6 +1,7 @@
# Copyright (c) 2022 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import json
from dataclasses import asdict
from typing import cast, List, Dict
from Charon.VirtualFile import VirtualFile # To open UFP files.
@ -227,7 +228,7 @@ class UFPWriter(MeshWriter):
},
"intent": machine_manager.activeIntentCategory,
"quality": machine_manager.activeQualityOrQualityChangesName,
"quality_display_name": machine_manager.activeQualityDisplayNameMap,
"quality_display_name": asdict(machine_manager.activeQualityDisplayNameMap),
}
global_stack = cast(GlobalStack, Application.getInstance().getGlobalContainerStack())