Browse Source

CURA-4870 Match the printer type in the dropdown with one of the
available printer types in the group

Diego Prado Gesto 7 years ago
parent
commit
3629c3959e

+ 17 - 0
cura/Settings/MachineManager.py

@@ -451,6 +451,12 @@ class MachineManager(QObject):
     def stacksHaveErrors(self) -> bool:
         return bool(self._stacks_have_errors)
 
+    @pyqtProperty(str, notify = globalContainerChanged)
+    def activeMachineDefinitionName(self) -> str:
+        if self._global_container_stack:
+            return self._global_container_stack.definition.getName()
+        return ""
+
     @pyqtProperty(str, notify = globalContainerChanged)
     def activeMachineName(self) -> str:
         if self._global_container_stack:
@@ -1024,6 +1030,17 @@ class MachineManager(QObject):
                 self._setMaterial(position, new_material)
                 continue
 
+    def switchPrinterType(self, machine_type):
+        container_registry = ContainerRegistry.getInstance()
+        machine_definition = container_registry.findDefinitionContainers(name = machine_type)[0]
+        self._global_container_stack.definition = machine_definition
+        self.globalContainerChanged.emit()
+        # machine_stack = CuraStackBuilder.createMachine("ultimaker_s5" + "_instance", "ultimaker_s5")
+        # # if not machine_stack:
+        # #     raise Exception("No machine found for ID {}".format(machine_id))
+        # Logger.log("d", "Setting active machine to %s", machine_stack.getId())
+        # self.setActiveMachine(machine_stack.getId())
+
     @pyqtSlot(QObject)
     def applyRemoteConfiguration(self, configuration: ConfigurationModel):
         self.blurSettings.emit()

+ 1 - 1
resources/qml/Menus/ConfigurationMenu/ConfigurationListView.qml

@@ -57,7 +57,7 @@ Column
             section.criteria: ViewSection.FullString
             section.delegate: sectionHeading
 
-            model: outputDevice.uniqueConfigurations
+            model: (ouputDevice != null) ? outputDevice.uniqueConfigurations : []
             delegate: ConfigurationItem
             {
                 width: parent.width - UM.Theme.getSize("default_margin").width

+ 8 - 5
resources/qml/Menus/ConfigurationMenu/SyncButton.qml

@@ -18,13 +18,16 @@ Button
 
     function updateOnSync()
     {
-        for (var index in outputDevice.uniqueConfigurations)
+        if (outputDevice != undefined)
         {
-            var configuration = outputDevice.uniqueConfigurations[index]
-            if (Cura.MachineManager.matchesConfiguration(configuration))
+            for (var index in outputDevice.uniqueConfigurations)
             {
-                base.text = catalog.i18nc("@label:sync indicator", "Matched")
-                return
+                var configuration = outputDevice.uniqueConfigurations[index]
+                if (Cura.MachineManager.matchesConfiguration(configuration))
+                {
+                    base.text = catalog.i18nc("@label:sync indicator", "Matched")
+                    return
+                }
             }
         }
         base.text = catalog.i18nc("@label:sync indicator", "No match")

+ 4 - 4
resources/qml/Menus/PrinterTypeMenu.qml

@@ -1,8 +1,8 @@
 // Copyright (c) 2018 Ultimaker B.V.
 // Cura is released under the terms of the LGPLv3 or higher.
 
-import QtQuick 2.2
-import QtQuick.Controls 1.1
+import QtQuick 2.7
+import QtQuick.Controls 1.4
 
 import UM 1.3 as UM
 import Cura 1.0 as Cura
@@ -16,12 +16,12 @@ Menu
     Instantiator
     {
         id: printerTypeInstantiator
-        model: outputDevice != null ? outputDevice.connectedPrintersTypeCount : null
+        model: outputDevice != null ? outputDevice.connectedPrintersTypeCount : []
 
         MenuItem {
             text: modelData.machine_type
             checkable: true
-            checked: false
+            checked: Cura.MachineManager.activeMachineDefinitionName == modelData.machine_type
             exclusiveGroup: group
 //            onTriggered:
 //            {

+ 42 - 39
resources/qml/SidebarHeader.qml

@@ -17,6 +17,7 @@ Column
     property int currentExtruderIndex: Cura.ExtruderManager.activeExtruderIndex;
     property bool currentExtruderVisible: extrudersList.visible;
     property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
+    property bool hasManyPrinterTypes: printerConnected ? Cura.MachineManager.printerOutputDevices[0].connectedPrintersTypeCount.length > 1 : false
 
     spacing: Math.round(UM.Theme.getSize("sidebar_margin").width * 0.9)
 
@@ -35,45 +36,6 @@ Column
         width: height
     }
 
-    // Printer Type Row
-    Item
-    {
-        id: printerTypeSelectionRow
-        height: UM.Theme.getSize("sidebar_setup").height
-        visible: printerConnected && !sidebar.monitoringPrint && !sidebar.hideSettings
-
-        anchors
-        {
-            left: parent.left
-            leftMargin: UM.Theme.getSize("sidebar_margin").width
-            right: parent.right
-            rightMargin: UM.Theme.getSize("sidebar_margin").width
-        }
-
-        Label
-        {
-            id: configurationLabel
-            text: catalog.i18nc("@label", "Printer type");
-            width: Math.round(parent.width * 0.4 - UM.Theme.getSize("default_margin").width)
-            height: parent.height
-            verticalAlignment: Text.AlignVCenter
-            font: UM.Theme.getFont("default");
-            color: UM.Theme.getColor("text");
-        }
-
-        ToolButton
-        {
-            id: printerTypeSelection
-            text: catalog.i18nc("@label", "Printer type");
-            height: UM.Theme.getSize("setting_control").height
-            width: Math.round(parent.width * 0.7) + UM.Theme.getSize("sidebar_margin").width
-            anchors.right: parent.right
-            style: UM.Theme.styles.sidebar_header_button
-            activeFocusOnPress: true;
-            menu: PrinterTypeMenu { }
-        }
-    }
-
     // Extruder Row
     Item
     {
@@ -264,6 +226,47 @@ Column
         visible: !extruderSelectionRow.visible
     }
 
+    // Printer Type Row
+    Item
+    {
+        id: printerTypeSelectionRow
+        height: UM.Theme.getSize("sidebar_setup").height
+        visible: printerConnected && hasManyPrinterTypes && !sidebar.monitoringPrint && !sidebar.hideSettings
+
+        anchors
+        {
+            left: parent.left
+            leftMargin: UM.Theme.getSize("sidebar_margin").width
+            right: parent.right
+            rightMargin: UM.Theme.getSize("sidebar_margin").width
+        }
+
+        Label
+        {
+            id: configurationLabel
+            text: catalog.i18nc("@label", "Printer type");
+            width: Math.round(parent.width * 0.4 - UM.Theme.getSize("default_margin").width)
+            height: parent.height
+            verticalAlignment: Text.AlignVCenter
+            font: UM.Theme.getFont("default");
+            color: UM.Theme.getColor("text");
+        }
+
+        ToolButton
+        {
+            id: printerTypeSelection
+            text: Cura.MachineManager.activeMachineDefinitionName
+            tooltip: Cura.MachineManager.activeMachineDefinitionName
+            height: UM.Theme.getSize("setting_control").height
+            width: Math.round(parent.width * 0.7) + UM.Theme.getSize("sidebar_margin").width
+            anchors.right: parent.right
+            style: UM.Theme.styles.sidebar_header_button
+            activeFocusOnPress: true;
+
+            menu: PrinterTypeMenu { }
+        }
+    }
+
     // Material Row
     Item
     {