Merge pull request #13886 from Ultimaker/9773-add_quality_type_to_ufp_files

Add quality type to ufp files
This commit is contained in:
Joey de l'Arago 2022-11-28 13:19:09 +01:00 committed by GitHub
commit ff65c1a670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 93 additions and 76 deletions

View File

@ -0,0 +1,48 @@
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 getMainStringParts(self) -> List[str]:
string_parts = []
if self.custom_profile is not None:
string_parts.append(self.custom_profile)
else:
string_parts.append(self.profile)
if self.intent_category is not "default":
string_parts.append(self.intent_name)
return string_parts
def getTailStringParts(self) -> List[str]:
string_parts = []
if self.custom_profile is not None:
string_parts.append(self.profile)
if self.intent_category is not "default":
string_parts.append(self.intent_name)
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
def getStringParts(self) -> List[str]:
return self.getMainStringParts() + self.getTailStringParts()

View File

@ -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
@ -1631,33 +1632,31 @@ class MachineManager(QObject):
# Examples: # Examples:
# - "my_profile - Fine" (only based on a default quality, no intent involved) # - "my_profile - Fine" (only based on a default quality, no intent involved)
# - "my_profile - Engineering - Fine" (based on an intent) # - "my_profile - Engineering - Fine" (based on an intent)
@pyqtProperty("QVariantMap", notify = activeQualityDisplayNameChanged) @pyqtProperty("QList<QString>", notify = activeQualityDisplayNameChanged)
def activeQualityDisplayNameMap(self) -> Dict[str, str]: def activeQualityDisplayNameStringParts(self) -> List[str]:
return self.activeQualityDisplayNameMap().getStringParts()
@pyqtProperty("QList<QString>", notify = activeQualityDisplayNameChanged)
def activeQualityDisplayNameMainStringParts(self) -> List[str]:
return self.activeQualityDisplayNameMap().getMainStringParts()
@pyqtProperty("QList<QString>", notify = activeQualityDisplayNameChanged)
def activeQualityDisplayNameTailStringParts(self) -> List[str]:
return self.activeQualityDisplayNameMap().getTailStringParts()
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 {"main": "", return ActiveQuality()
"suffix": ""}
display_name = global_stack.quality.getName() return ActiveQuality(
profile = global_stack.quality.getName(),
intent_category = self.activeIntentCategory intent_category = self.activeIntentCategory,
if intent_category != "default": intent_name = IntentCategoryModel.translation(self.activeIntentCategory, "name", self.activeIntentCategory.title()),
intent_display_name = IntentCategoryModel.translation(intent_category, custom_profile = self.activeQualityOrQualityChangesName if global_stack.qualityChanges is not empty_quality_changes_container else None,
"name", layer_height = self.activeQualityLayerHeight if self.isActiveQualitySupported else None,
intent_category.title()) is_experimental = self.isActiveQualityExperimental and self.isActiveQualitySupported
display_name = "{intent_name} - {the_rest}".format(intent_name = intent_display_name, )
the_rest = display_name)
main_part = display_name
suffix_part = ""
# Not a custom quality
if global_stack.qualityChanges != empty_quality_changes_container:
main_part = self.activeQualityOrQualityChangesName
suffix_part = display_name
return {"main": main_part,
"suffix": suffix_part}
@pyqtSlot(str) @pyqtSlot(str)
def setIntentByCategory(self, intent_category: str) -> None: def setIntentByCategory(self, intent_category: str) -> None:
@ -1776,7 +1775,9 @@ class MachineManager(QObject):
@pyqtProperty(bool, notify = activeQualityGroupChanged) @pyqtProperty(bool, notify = activeQualityGroupChanged)
def hasNotSupportedQuality(self) -> bool: def hasNotSupportedQuality(self) -> bool:
global_container_stack = self._application.getGlobalContainerStack() global_container_stack = self._application.getGlobalContainerStack()
return (not global_container_stack is None) and global_container_stack.quality == empty_quality_container and global_container_stack.qualityChanges == empty_quality_changes_container return global_container_stack is not None\
and global_container_stack.quality == empty_quality_container \
and global_container_stack.qualityChanges == empty_quality_changes_container
@pyqtProperty(bool, notify = activeQualityGroupChanged) @pyqtProperty(bool, notify = activeQualityGroupChanged)
def isActiveQualityCustom(self) -> bool: def isActiveQualityCustom(self) -> bool:

View File

@ -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.
@ -225,8 +226,7 @@ class UFPWriter(MeshWriter):
"changes": {}, "changes": {},
"all_settings": {}, "all_settings": {},
}, },
"intent": machine_manager.activeIntentCategory, "quality": asdict(machine_manager.activeQualityDisplayNameMap()),
"quality": machine_manager.activeQualityOrQualityChangesName,
} }
global_stack = cast(GlobalStack, Application.getInstance().getGlobalContainerStack()) global_stack = cast(GlobalStack, Application.getInstance().getGlobalContainerStack())

View File

@ -56,7 +56,7 @@ UM.Dialog
UM.Label UM.Label
{ {
id: infoText id: infoText
text: catalog.i18nc("@text:window, %1 is a profile name", "You have customized some profile settings. Would you like to Keep these changed settings after switching profiles? Alternatively, you can discard the changes to load the defaults from '%1'.").arg(Cura.MachineManager.activeQualityDisplayNameMap["main"]) text: catalog.i18nc("@text:window, %1 is a profile name", "You have customized some profile settings. Would you like to Keep these changed settings after switching profiles? Alternatively, you can discard the changes to load the defaults from '%1'.").arg(Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - "))
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
@ -83,7 +83,7 @@ UM.Dialog
columnHeaders: [ columnHeaders: [
catalog.i18nc("@title:column", "Profile settings"), catalog.i18nc("@title:column", "Profile settings"),
Cura.MachineManager.activeQualityDisplayNameMap["main"], Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - "),
catalog.i18nc("@title:column", "Current changes") catalog.i18nc("@title:column", "Current changes")
] ]
model: UM.TableModel model: UM.TableModel

View File

@ -67,7 +67,7 @@ Item
UM.Label UM.Label
{ {
id: textLabel id: textLabel
text: Cura.MachineManager.activeQualityDisplayNameMap["main"] text: Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - ")
Layout.margins: 0 Layout.margins: 0
Layout.maximumWidth: Math.floor(parent.width * 0.7) // Always leave >= 30% for the rest of the row. Layout.maximumWidth: Math.floor(parent.width * 0.7) // Always leave >= 30% for the rest of the row.
height: contentHeight height: contentHeight
@ -77,7 +77,19 @@ Item
UM.Label UM.Label
{ {
text: activeQualityDetailText() text:
{
const string_parts = Cura.MachineManager.activeQualityDisplayNameTailStringParts;
if (string_parts.length === 0)
{
return "";
}
else
{
` - ${string_parts.join(" - ")}`
}
}
color: UM.Theme.getColor("text_detail") color: UM.Theme.getColor("text_detail")
Layout.margins: 0 Layout.margins: 0
Layout.fillWidth: true Layout.fillWidth: true
@ -85,32 +97,6 @@ Item
height: contentHeight height: contentHeight
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
function activeQualityDetailText()
{
var resultMap = Cura.MachineManager.activeQualityDisplayNameMap
var resultSuffix = resultMap["suffix"]
var result = ""
if (Cura.MachineManager.isActiveQualityExperimental)
{
resultSuffix += " (Experimental)"
}
if (Cura.MachineManager.isActiveQualitySupported)
{
if (Cura.MachineManager.activeQualityLayerHeight > 0)
{
if (resultSuffix)
{
result += " - " + resultSuffix
}
result += " - "
result += Cura.MachineManager.activeQualityLayerHeight + "mm"
}
}
return result
}
} }
} }

View File

@ -17,26 +17,8 @@ RowLayout
{ {
source: UM.Theme.getIcon("Sliders", "medium") source: UM.Theme.getIcon("Sliders", "medium")
iconSize: UM.Theme.getSize("button_icon").width iconSize: UM.Theme.getSize("button_icon").width
text:
{
if (Cura.MachineManager.activeStack)
{
var resultMap = Cura.MachineManager.activeQualityDisplayNameMap
var text = resultMap["main"]
if (resultMap["suffix"])
{
text += " - " + resultMap["suffix"]
}
if (!Cura.MachineManager.hasNotSupportedQuality) text: Cura.MachineManager.activeQualityDisplayNameStringParts.join(" - ")
{
text += " - " + layerHeight.properties.value + "mm"
text += Cura.MachineManager.isActiveQualityExperimental ? " - " + catalog.i18nc("@label", "Experimental") : ""
}
return text
}
return ""
}
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
elide: Text.ElideMiddle elide: Text.ElideMiddle
wrapMode: Text.NoWrap wrapMode: Text.NoWrap