Browse Source

Merge pull request #13972 from Ultimaker/CURA-9793_extend_recommended_print_settings

[CURA-9793] Extend recommended print settings
Casper Lamboo 2 years ago
parent
commit
e558752ed0

+ 19 - 1
cura/Settings/ExtruderManager.py

@@ -2,13 +2,15 @@
 # Cura is released under the terms of the LGPLv3 or higher.
 
 from PyQt6.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant  # For communicating data and events to Qt.
+
+from UM.Application import Application
 from UM.FlameProfiler import pyqtSlot
 
 import cura.CuraApplication # To get the global container stack to find the current machine.
+from UM.Util import parseBool
 from cura.Settings.GlobalStack import GlobalStack
 from UM.Logger import Logger
 from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
-from UM.Scene.SceneNode import SceneNode
 from UM.Scene.Selection import Selection
 from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
 from UM.Settings.ContainerRegistry import ContainerRegistry  # Finding containers by ID.
@@ -45,6 +47,7 @@ class ExtruderManager(QObject):
         self._selected_object_extruders = []  # type: List[Union[str, "ExtruderStack"]]
 
         Selection.selectionChanged.connect(self.resetSelectedObjectExtruders)
+        Application.getInstance().globalContainerStackChanged.connect(self.emitGlobalStackExtrudersChanged)  # When the machine is swapped we must update the active machine extruders
 
     extrudersChanged = pyqtSignal(QVariant)
     """Signal to notify other components when the list of extruders for a machine definition changes."""
@@ -52,6 +55,21 @@ class ExtruderManager(QObject):
     activeExtruderChanged = pyqtSignal()
     """Notify when the user switches the currently active extruder."""
 
+    def emitGlobalStackExtrudersChanged(self):
+        # HACK
+        # The emit function can't be directly connected to another signal. This wrapper function is required.
+        # The extrudersChanged signal is emitted early when changing machines. This triggers it a second time
+        # after the extruder have changed properly. This is important for any QML using ExtruderManager.extruderIds
+        # This is a hack, but other behaviour relys on the updating in this order.
+        self.extrudersChanged.emit(self._application.getGlobalContainerStack().getId())
+
+    @pyqtProperty(int, notify = extrudersChanged)
+    def enabledExtruderCount(self) -> int:
+        global_container_stack = self._application.getGlobalContainerStack()
+        if global_container_stack:
+            return len([extruder for extruder in global_container_stack.extruderList if parseBool(extruder.getMetaDataEntry("enabled", "True"))])
+        return 0
+
     @pyqtProperty(str, notify = activeExtruderChanged)
     def activeExtruderStackId(self) -> Optional[str]:
         """Gets the unique identifier of the currently active extruder stack.

+ 0 - 13
cura/Settings/SimpleModeSettingsManager.py

@@ -42,21 +42,8 @@ class SimpleModeSettingsManager(QObject):
             for extruder_stack in global_stack.extruderList:
                 user_setting_keys.update(extruder_stack.userChanges.getAllKeys())
 
-        # remove settings that are visible in recommended (we don't show the reset button for those)
-        for skip_key in self.__ignored_custom_setting_keys:
-            if skip_key in user_setting_keys:
-                user_setting_keys.remove(skip_key)
-
         has_customized_user_settings = len(user_setting_keys) > 0
 
         if has_customized_user_settings != self._is_profile_customized:
             self._is_profile_customized = has_customized_user_settings
             self.isProfileCustomizedChanged.emit()
-
-    # These are the settings included in the Simple ("Recommended") Mode, so only when the other settings have been
-    # changed, we consider it as a user customized profile in the Simple ("Recommended") Mode.
-    __ignored_custom_setting_keys = ["support_enable",
-                                     "infill_sparse_density",
-                                     "gradual_infill_steps",
-                                     "adhesion_type",
-                                     "support_extruder_nr"]

+ 1 - 1
plugins/UM3NetworkPrinting/resources/qml/MonitorBuildplateConfiguration.qml

@@ -27,7 +27,7 @@ Item
     Row
     {
         height: parent.height
-        spacing: UM.Theme.getSize("print_setup_slider_handle").width // TODO: Theme! (Should be same as extruder spacing)
+        spacing: UM.Theme.getSize("slider_handle").width // TODO: Theme! (Should be same as extruder spacing)
 
         // This wrapper ensures that the buildplate icon is located centered
         // below an extruder icon.

+ 4 - 4
resources/qml/ColorDialog.qml

@@ -1,4 +1,4 @@
-// Copyright (c) 2022 Ultimaker B.V.
+// Copyright (c) 2022 UltiMaker
 // Cura is released under the terms of the LGPLv3 or higher.
 
 import QtQuick 2.15
@@ -6,8 +6,8 @@ import QtQuick.Controls 2.2
 import QtQuick.Window 2.1
 import QtQuick.Layouts 1.1
 
-import UM 1.5 as UM
-import Cura 1.1 as Cura
+import UM 1.7 as UM
+import Cura 1.7 as Cura
 
 
 /*
@@ -122,7 +122,7 @@ UM.Dialog
                         text = `#${text}`;
                     }
                 }
-                validator: RegularExpressionValidator { regularExpression: /^#([a-fA-F0-9]{0,6})$/ }
+                validator: UM.HexColorValidator {}
             }
 
             Rectangle

+ 2 - 5
resources/qml/ExtruderButton.qml

@@ -12,17 +12,14 @@ UM.ToolbarButton
     id: base
 
     property var extruder
-
-    text: catalog.i18ncp("@label %1 is filled in with the name of an extruder", "Print Selected Model with %1", "Print Selected Models with %1", UM.Selection.selectionCount).arg(extruder.name)
-
-    checked: Cura.ExtruderManager.selectedObjectExtruders.indexOf(extruder.id) != -1
-    enabled: UM.Selection.hasSelection && extruder.stack.isEnabled
+    property var extruderNumberFont: UM.Theme.getFont("small_emphasis")
 
     toolItem: ExtruderIcon
     {
         materialColor: extruder.color
         extruderEnabled: extruder.stack.isEnabled
         iconVariant: "default"
+        font: extruderNumberFont
         property int index: extruder.index
     }
 

+ 1 - 0
resources/qml/ExtruderIcon.qml

@@ -14,6 +14,7 @@ Item
     property bool extruderEnabled: true
     property var iconSize: UM.Theme.getSize("extruder_icon").width
     property string iconVariant: "medium"
+    property alias font: extruderNumberText.font
 
     implicitWidth: iconSize
     implicitHeight: iconSize

+ 20 - 11
resources/qml/MachineSettings/ComboBoxWithOptions.qml

@@ -68,18 +68,27 @@ UM.TooltipArea
         function updateModel()
         {
             clear()
-            // Options come in as a string-representation of an OrderedDict
-            if(propertyProvider.properties.options)
+
+            if(!propertyProvider.properties.options)
             {
-                var options = propertyProvider.properties.options.match(/^OrderedDict\(\[\((.*)\)\]\)$/);
-                if(options)
+                return
+            }
+
+            if (typeof propertyProvider.properties["options"] === "string")
+            {
+                return
+            }
+
+
+            for (var i = 0; i < propertyProvider.properties["options"].keys().length; i++)
+            {
+                var key = propertyProvider.properties["options"].keys()[i]
+                var value = propertyProvider.properties["options"][key]
+                append({ text: value, code: key })
+
+                if (propertyProvider.properties.value === key)
                 {
-                    options = options[1].split("), (");
-                    for(var i = 0; i < options.length; i++)
-                    {
-                        var option = options[i].substring(1, options[i].length - 1).split("', '");
-                        append({ text: option[1], value: option[0] });
-                    }
+                    comboBox.currentIndex = i
                 }
             }
         }
@@ -123,7 +132,7 @@ UM.TooltipArea
         onActivated:
         {
             var newValue = model.get(index).value
-            if (propertyProvider.properties.value != newValue)
+            if (propertyProvider.properties.value !== newValue && newValue !== undefined)
             {
                 if (setValueFunction !== null)
                 {

+ 1 - 1
resources/qml/MachineSettings/NumericTextFieldWithUnit.qml

@@ -59,7 +59,7 @@ UM.TooltipArea
     UM.SettingPropertyProvider
     {
         id: propertyProvider
-        watchedProperties: [ "value", "description" ]
+        watchedProperties: [ "value", "description", "validationState" ]
     }
 
     UM.Label

+ 14 - 20
resources/qml/PrintSetupSelector/PrintSetupSelectorContents.qml

@@ -67,6 +67,11 @@ Item
                 top: parent.top
             }
             visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended
+
+            function onModeChanged()
+            {
+                currentModeIndex = PrintSetupSelectorContents.Mode.Custom;
+            }
         }
 
         CustomPrintSetup
@@ -116,13 +121,21 @@ Item
         width: parent.width
         height: UM.Theme.getSize("default_lining").height
         color: UM.Theme.getColor("lining")
+        visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
     }
 
     Item
     {
         id: buttonRow
         property real padding: UM.Theme.getSize("default_margin").width
-        height: recommendedButton.height + 2 * padding + (draggableArea.visible ? draggableArea.height : 0)
+        height:
+        {
+            if (currentModeIndex == PrintSetupSelectorContents.Mode.Custom)
+            {
+                return recommendedButton.height + 2 * padding + (draggableArea.visible ? draggableArea.height : 0)
+            }
+            return 0
+        }
 
         anchors
         {
@@ -145,25 +158,6 @@ Item
             onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Recommended
         }
 
-        Cura.SecondaryButton
-        {
-            id: customSettingsButton
-            anchors.top: parent.top
-            anchors.right: parent.right
-            anchors.margins: UM.Theme.getSize("default_margin").width
-            leftPadding: UM.Theme.getSize("default_margin").width
-            rightPadding: UM.Theme.getSize("default_margin").width
-            text: catalog.i18nc("@button", "Custom")
-            iconSource: UM.Theme.getIcon("ChevronSingleRight")
-            isIconOnRightSide: true
-            visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended
-            onClicked:
-            {
-                currentModeIndex = PrintSetupSelectorContents.Mode.Custom
-                updateDragPosition();
-            }
-        }
-
         //Invisible area at the bottom with which you can resize the panel.
         MouseArea
         {

+ 17 - 69
resources/qml/PrintSetupSelector/Recommended/RecommendedAdhesionSelector.qml

@@ -1,89 +1,37 @@
-// Copyright (c) 2018 Ultimaker B.V.
+// Copyright (c) 2022 UltiMaker
 // Cura is released under the terms of the LGPLv3 or higher.
 
 import QtQuick 2.7
+import QtQuick.Layouts 1.3
 
 import UM 1.5 as UM
-import Cura 1.0 as Cura
+import Cura 1.7 as Cura
 
 
-//
-//  Adhesion
-//
-Item
+RecommendedSettingSection
 {
     id: enableAdhesionRow
-    height: enableAdhesionContainer.height
 
-    property real labelColumnWidth: Math.round(width / 3)
-    property var curaRecommendedMode: Cura.RecommendedMode {}
-
-    Cura.IconWithText
-    {
-        id: enableAdhesionRowTitle
-        anchors.top: parent.top
-        anchors.left: parent.left
-        source: UM.Theme.getIcon("Adhesion")
-        text: catalog.i18nc("@label", "Adhesion")
-        font: UM.Theme.getFont("medium")
-        width: labelColumnWidth
-        iconSize: UM.Theme.getSize("medium_button_icon").width
-    }
-
-    Item
-    {
-        id: enableAdhesionContainer
-        height: enableAdhesionCheckBox.height
-
-        anchors
-        {
-            left: enableAdhesionRowTitle.right
-            right: parent.right
-            verticalCenter: enableAdhesionRowTitle.verticalCenter
-        }
-
-        UM.CheckBox
-        {
-            id: enableAdhesionCheckBox
-            anchors.verticalCenter: parent.verticalCenter
-
-            //: Setting enable printing build-plate adhesion helper checkbox
-            enabled: recommendedPrintSetup.settingsEnabled
-
-            visible: platformAdhesionType.properties.enabled == "True"
-            checked: platformAdhesionType.properties.value != "skirt" && platformAdhesionType.properties.value != "none"
+    title: catalog.i18nc("@label", "Adhesion")
+    icon: UM.Theme.getIcon("Adhesion")
+    enableSectionSwitchVisible: platformAdhesionType.properties.enabled === "True"
+    enableSectionSwitchChecked: platformAdhesionType.properties.value !== "skirt" && platformAdhesionType.properties.value !== "none"
+    enableSectionSwitchEnabled: recommendedPrintSetup.settingsEnabled
+    tooltipText: catalog.i18nc("@label", "Enable printing a brim or raft. This will add a flat area around or under your object which is easy to cut off afterwards.")
 
-            MouseArea
-            {
-                id: adhesionMouseArea
-                anchors.fill: parent
-                hoverEnabled: true
-                // propagateComposedEvents used on adhesionTooltipMouseArea does not work with Controls Components.
-                // It only works with other MouseAreas, so this is required
-                onClicked: curaRecommendedMode.setAdhesion(!parent.checked)
-            }
-        }
-    }
-
-    MouseArea
-    {
-        id: adhesionTooltipMouseArea
-        anchors.fill: parent
-        propagateComposedEvents: true
-        hoverEnabled: true
-
-        onEntered:base.showTooltip(enableAdhesionCheckBox, Qt.point(-enableAdhesionContainer.x - UM.Theme.getSize("thick_margin").width, 0),
-                catalog.i18nc("@label", "Enable printing a brim or raft. This will add a flat area around or under your object which is easy to cut off afterwards."));
-        onExited: base.hideTooltip()
-    }
+    property var curaRecommendedMode: Cura.RecommendedMode {}
 
-    UM.SettingPropertyProvider
+    property UM.SettingPropertyProvider platformAdhesionType: UM.SettingPropertyProvider
     {
-        id: platformAdhesionType
         containerStack: Cura.MachineManager.activeMachine
         removeUnusedValue: false //Doesn't work with settings that are resolved.
         key: "adhesion_type"
         watchedProperties: [ "value", "resolve", "enabled" ]
         storeIndex: 0
     }
+
+    function onEnableSectionChanged(state)
+    {
+        curaRecommendedMode.setAdhesion(state)
+    }
 }

Some files were not shown because too many files changed in this diff