From d53e9f92632954354f8cfa550eb8a102c072bac7 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Fri, 7 Sep 2018 14:12:19 +0200 Subject: [PATCH 01/10] Remove not used files. After the refactor, these files are no longer used. --- plugins/UM3NetworkPrinting/MonitorItem.qml | 54 --- .../UM3NetworkPrinting/OpenPanelButton.qml | 71 --- .../UM3NetworkPrinting/PrinterInfoBlock.qml | 431 ------------------ plugins/UM3NetworkPrinting/PrinterTile.qml | 54 --- 4 files changed, 610 deletions(-) delete mode 100644 plugins/UM3NetworkPrinting/MonitorItem.qml delete mode 100644 plugins/UM3NetworkPrinting/OpenPanelButton.qml delete mode 100644 plugins/UM3NetworkPrinting/PrinterInfoBlock.qml delete mode 100644 plugins/UM3NetworkPrinting/PrinterTile.qml diff --git a/plugins/UM3NetworkPrinting/MonitorItem.qml b/plugins/UM3NetworkPrinting/MonitorItem.qml deleted file mode 100644 index bbbc3feee6..0000000000 --- a/plugins/UM3NetworkPrinting/MonitorItem.qml +++ /dev/null @@ -1,54 +0,0 @@ -import QtQuick 2.2 - - -import UM 1.3 as UM -import Cura 1.0 as Cura - -Component -{ - Item - { - width: maximumWidth - height: maximumHeight - Image - { - id: cameraImage - width: Math.min(sourceSize.width === 0 ? 800 * screenScaleFactor : sourceSize.width, maximumWidth) - height: Math.floor((sourceSize.height === 0 ? 600 * screenScaleFactor : sourceSize.height) * width / sourceSize.width) - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - z: 1 - Component.onCompleted: - { - if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) - { - OutputDevice.activePrinter.camera.start() - } - } - onVisibleChanged: - { - if(visible) - { - if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) - { - OutputDevice.activePrinter.camera.start() - } - } else - { - if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) - { - OutputDevice.activePrinter.camera.stop() - } - } - } - source: - { - if(OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null && OutputDevice.activePrinter.camera.latestImage) - { - return OutputDevice.activePrinter.camera.latestImage; - } - return ""; - } - } - } -} \ No newline at end of file diff --git a/plugins/UM3NetworkPrinting/OpenPanelButton.qml b/plugins/UM3NetworkPrinting/OpenPanelButton.qml deleted file mode 100644 index 4bc1728f76..0000000000 --- a/plugins/UM3NetworkPrinting/OpenPanelButton.qml +++ /dev/null @@ -1,71 +0,0 @@ -import QtQuick 2.2 -import QtQuick.Controls 1.1 -import QtQuick.Controls.Styles 1.1 - -import UM 1.1 as UM - -Button { - objectName: "openPanelSaveAreaButton" - id: openPanelSaveAreaButton - - UM.I18nCatalog { id: catalog; name: "cura"; } - - height: UM.Theme.getSize("save_button_save_to_button").height - tooltip: catalog.i18nc("@info:tooltip", "Opens the print jobs page with your default web browser.") - text: catalog.i18nc("@action:button", "View print jobs") - - // FIXME: This button style is copied and duplicated from SaveButton.qml - style: ButtonStyle { - background: Rectangle - { - border.width: UM.Theme.getSize("default_lining").width - border.color: - { - if(!control.enabled) - return UM.Theme.getColor("action_button_disabled_border"); - else if(control.pressed) - return UM.Theme.getColor("print_button_ready_pressed_border"); - else if(control.hovered) - return UM.Theme.getColor("print_button_ready_hovered_border"); - else - return UM.Theme.getColor("print_button_ready_border"); - } - color: - { - if(!control.enabled) - return UM.Theme.getColor("action_button_disabled"); - else if(control.pressed) - return UM.Theme.getColor("print_button_ready_pressed"); - else if(control.hovered) - return UM.Theme.getColor("print_button_ready_hovered"); - else - return UM.Theme.getColor("print_button_ready"); - } - - Behavior on color { ColorAnimation { duration: 50; } } - - implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("sidebar_margin").width * 2) - - Label { - id: actualLabel - anchors.centerIn: parent - color: - { - if(!control.enabled) - return UM.Theme.getColor("action_button_disabled_text"); - else if(control.pressed) - return UM.Theme.getColor("print_button_ready_text"); - else if(control.hovered) - return UM.Theme.getColor("print_button_ready_text"); - else - return UM.Theme.getColor("print_button_ready_text"); - } - font: UM.Theme.getFont("action_button") - text: control.text; - } - } - label: Item { } - } - - -} diff --git a/plugins/UM3NetworkPrinting/PrinterInfoBlock.qml b/plugins/UM3NetworkPrinting/PrinterInfoBlock.qml deleted file mode 100644 index 0217767a40..0000000000 --- a/plugins/UM3NetworkPrinting/PrinterInfoBlock.qml +++ /dev/null @@ -1,431 +0,0 @@ -import QtQuick 2.2 -import QtQuick.Controls 1.4 -import QtQuick.Controls.Styles 1.4 - -import UM 1.3 as UM - -Rectangle -{ - function strPadLeft(string, pad, length) - { - return (new Array(length + 1).join(pad) + string).slice(-length); - } - - function getPrettyTime(time) - { - return OutputDevice.formatDuration(time) - } - - function formatPrintJobPercent(printJob) - { - if (printJob == null) - { - return ""; - } - if (printJob.timeTotal === 0) - { - return ""; - } - return Math.min(100, Math.round(printJob.timeElapsed / printJob.timeTotal * 100)) + "%"; - } - - function printerStatusText(printer) - { - switch (printer.state) - { - case "pre_print": - return catalog.i18nc("@label:status", "Preparing to print") - case "printing": - return catalog.i18nc("@label:status", "Printing"); - case "idle": - return catalog.i18nc("@label:status", "Available"); - case "unreachable": - return catalog.i18nc("@label:status", "Lost connection with the printer"); - case "maintenance": - return catalog.i18nc("@label:status", "Unavailable"); - default: - return catalog.i18nc("@label:status", "Unknown"); - } - } - - id: printerDelegate - - property var printer: null - property var printJob: printer != null ? printer.activePrintJob: null - - border.width: UM.Theme.getSize("default_lining").width - border.color: mouse.containsMouse ? emphasisColor : lineColor - z: mouse.containsMouse ? 1 : 0 // Push this item up a bit on mouse over to ensure that the highlighted bottom border is visible. - - MouseArea - { - id: mouse - anchors.fill:parent - onClicked: OutputDevice.setActivePrinter(printer) - hoverEnabled: true; - - // Only clickable if no printer is selected - enabled: OutputDevice.activePrinter == null && printer.state !== "unreachable" - } - - Row - { - anchors.left: parent.left - anchors.right: parent.right - anchors.top: parent.top - anchors.bottom: parent.bottom - anchors.margins: UM.Theme.getSize("default_margin").width - - Rectangle - { - width: Math.round(parent.width / 3) - height: parent.height - - Label // Print job name - { - id: jobNameLabel - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - anchors.rightMargin: UM.Theme.getSize("default_margin").width - - text: printJob != null ? printJob.name : "" - font: UM.Theme.getFont("default_bold") - elide: Text.ElideRight - - } - - Label - { - id: jobOwnerLabel - anchors.top: jobNameLabel.bottom - anchors.left: parent.left - anchors.right: parent.right - anchors.rightMargin: UM.Theme.getSize("default_margin").width - text: printJob != null ? printJob.owner : "" - opacity: 0.50 - elide: Text.ElideRight - } - - Label - { - id: totalTimeLabel - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.right: parent.right - anchors.rightMargin: UM.Theme.getSize("default_margin").width - text: printJob != null ? getPrettyTime(printJob.timeTotal) : "" - opacity: 0.65 - font: UM.Theme.getFont("default") - elide: Text.ElideRight - } - } - - Rectangle - { - width: Math.round(parent.width / 3 * 2) - height: parent.height - - Label // Friendly machine name - { - id: printerNameLabel - anchors.top: parent.top - anchors.left: parent.left - width: Math.round(parent.width / 2 - UM.Theme.getSize("default_margin").width - showCameraIcon.width) - text: printer.name - font: UM.Theme.getFont("default_bold") - elide: Text.ElideRight - } - - Label // Machine variant - { - id: printerTypeLabel - anchors.top: printerNameLabel.bottom - width: Math.round(parent.width / 2 - UM.Theme.getSize("default_margin").width) - text: printer.type - anchors.left: parent.left - elide: Text.ElideRight - font: UM.Theme.getFont("very_small") - opacity: 0.50 - } - - Rectangle // Camera icon - { - id: showCameraIcon - width: 40 * screenScaleFactor - height: width - radius: width - anchors.right: printProgressArea.left - anchors.rightMargin: UM.Theme.getSize("default_margin").width - color: emphasisColor - opacity: printer != null && printer.state === "unreachable" ? 0.3 : 1 - - Image - { - width: parent.width - height: width - anchors.right: parent.right - anchors.rightMargin: parent.rightMargin - source: "camera-icon.svg" - } - } - - Row // PrintCore config - { - id: extruderInfo - anchors.bottom: parent.bottom - - width: Math.round(parent.width / 2 - UM.Theme.getSize("default_margin").width) - height: childrenRect.height - - spacing: UM.Theme.getSize("default_margin").width - - PrintCoreConfiguration - { - id: leftExtruderInfo - width: Math.round((parent.width - extruderSeperator.width) / 2) - printCoreConfiguration: printer.extruders[0] - } - - Rectangle - { - id: extruderSeperator - width: UM.Theme.getSize("default_lining").width - height: parent.height - color: lineColor - } - - PrintCoreConfiguration - { - id: rightExtruderInfo - width: Math.round((parent.width - extruderSeperator.width) / 2) - printCoreConfiguration: printer.extruders[1] - } - } - - Rectangle // Print progress - { - id: printProgressArea - anchors.right: parent.right - anchors.top: parent.top - height: showExtended ? parent.height: printProgressTitleBar.height - width: Math.round(parent.width / 2 - UM.Theme.getSize("default_margin").width) - border.width: UM.Theme.getSize("default_lining").width - border.color: lineColor - radius: cornerRadius - property var showExtended: { - if(printJob != null) - { - var extendStates = ["sent_to_printer", "wait_for_configuration", "printing", "pre_print", "post_print", "wait_cleanup", "queued"]; - return extendStates.indexOf(printJob.state) !== -1; - } - return printer.state == "disabled" - } - - Item // Status and Percent - { - id: printProgressTitleBar - - property var showPercent: { - return printJob != null && (["printing", "post_print", "pre_print", "sent_to_printer"].indexOf(printJob.state) !== -1); - } - - width: parent.width - //TODO: hardcoded value - height: 40 * screenScaleFactor - anchors.left: parent.left - - Label - { - id: statusText - anchors.left: parent.left - anchors.leftMargin: UM.Theme.getSize("default_margin").width - anchors.right: progressText.left - anchors.rightMargin: UM.Theme.getSize("default_margin").width - anchors.verticalCenter: parent.verticalCenter - text: { - if (printer.state == "disabled") - { - return catalog.i18nc("@label:status", "Disabled"); - } - - if (printer.state === "unreachable") - { - return printerStatusText(printer); - } - - if (printJob != null) - { - switch (printJob.state) - { - case "printing": - case "post_print": - return catalog.i18nc("@label:status", "Printing") - case "wait_for_configuration": - return catalog.i18nc("@label:status", "Reserved") - case "wait_cleanup": - case "wait_user_action": - return catalog.i18nc("@label:status", "Finished") - case "pre_print": - case "sent_to_printer": - return catalog.i18nc("@label", "Preparing to print") - case "queued": - return catalog.i18nc("@label:status", "Action required"); - case "pausing": - case "paused": - return catalog.i18nc("@label:status", "Paused"); - case "resuming": - return catalog.i18nc("@label:status", "Resuming"); - case "aborted": - return catalog.i18nc("@label:status", "Print aborted"); - default: - // If print job has unknown status show printer.status - return printerStatusText(printer); - } - } - return printerStatusText(printer); - } - - elide: Text.ElideRight - font: UM.Theme.getFont("small") - } - - Label - { - id: progressText - anchors.right: parent.right - anchors.rightMargin: UM.Theme.getSize("default_margin").width - anchors.top: statusText.top - - text: formatPrintJobPercent(printJob) - visible: printProgressTitleBar.showPercent - //TODO: Hardcoded value - opacity: 0.65 - font: UM.Theme.getFont("very_small") - } - - Image - { - width: statusText.height - height: width - anchors.right: parent.right - anchors.rightMargin: UM.Theme.getSize("default_margin").width - anchors.top: statusText.top - - visible: !printProgressTitleBar.showPercent - - source: { - if (printer.state == "disabled") - { - return "blocked-icon.svg"; - } - - if (printer.state === "unreachable") - { - return ""; - } - - if (printJob != null) - { - if(printJob.state === "queued") - { - return "action-required-icon.svg"; - } - else if (printJob.state === "wait_cleanup") - { - return "checkmark-icon.svg"; - } - } - return ""; // We're not going to show it, so it will not be resolved as a url. - } - } - - Rectangle - { - //TODO: This will become a progress bar in the future - width: parent.width - height: UM.Theme.getSize("default_lining").height - anchors.bottom: parent.bottom - anchors.left: parent.left - visible: printProgressArea.showExtended - color: lineColor - } - } - - Column - { - anchors.left: parent.left - anchors.leftMargin: UM.Theme.getSize("default_margin").width - - anchors.top: printProgressTitleBar.bottom - anchors.topMargin: UM.Theme.getSize("default_margin").height - - width: parent.width - 2 * UM.Theme.getSize("default_margin").width - - visible: printProgressArea.showExtended - - Label // Status detail - { - text: - { - if (printer.state == "disabled") - { - return catalog.i18nc("@label", "Not accepting print jobs"); - } - - if (printer.state === "unreachable") - { - return ""; - } - - if(printJob != null) - { - switch (printJob.state) - { - case "printing": - case "post_print": - return catalog.i18nc("@label", "Finishes at: ") + OutputDevice.getTimeCompleted(printJob.timeTotal - printJob.timeElapsed) - case "wait_cleanup": - return catalog.i18nc("@label", "Clear build plate") - case "sent_to_printer": - case "pre_print": - return catalog.i18nc("@label", "Preparing to print") - case "wait_for_configuration": - return catalog.i18nc("@label", "Not accepting print jobs") - case "queued": - return catalog.i18nc("@label", "Waiting for configuration change"); - default: - return ""; - } - } - return ""; - } - anchors.left: parent.left - anchors.right: parent.right - elide: Text.ElideRight - wrapMode: Text.Wrap - - font: UM.Theme.getFont("default") - } - - Label // Status 2nd row - { - text: { - if(printJob != null) - { - if(printJob.state == "printing" || printJob.state == "post_print") - { - return OutputDevice.getDateCompleted(printJob.timeTotal - printJob.timeElapsed) - } - } - return ""; - } - - elide: Text.ElideRight - font: UM.Theme.getFont("default") - } - } - } - } - } -} diff --git a/plugins/UM3NetworkPrinting/PrinterTile.qml b/plugins/UM3NetworkPrinting/PrinterTile.qml deleted file mode 100644 index 3d03e93688..0000000000 --- a/plugins/UM3NetworkPrinting/PrinterTile.qml +++ /dev/null @@ -1,54 +0,0 @@ -import QtQuick 2.2 -import QtQuick.Controls 1.4 -import QtQuick.Controls.Styles 1.4 - -import UM 1.3 as UM -import Cura 1.0 as Cura - -Rectangle -{ - id: base - width: 250 * screenScaleFactor - height: 250 * screenScaleFactor - signal clicked() - MouseArea - { - anchors.fill:parent - onClicked: base.clicked() - } - Rectangle - { - // TODO: Actually add UM icon / picture - width: 100 * screenScaleFactor - height: 100 * screenScaleFactor - border.width: UM.Theme.getSize("default_lining").width - anchors.horizontalCenter: parent.horizontalCenter - anchors.top: parent.top - anchors.topMargin: UM.Theme.getSize("default_margin").height - } - Label - { - id: nameLabel - anchors.bottom: ipLabel.top - anchors.bottomMargin: UM.Theme.getSize("default_margin").height - anchors.left: parent.left - anchors.right: parent.right - anchors.leftMargin: UM.Theme.getSize("default_margin").width - anchors.rightMargin: UM.Theme.getSize("default_margin").width - text: modelData.friendly_name.toString() - font: UM.Theme.getFont("large") - elide: Text.ElideMiddle; - height: UM.Theme.getSize("section").height; - } - Label - { - id: ipLabel - text: modelData.ip_address.toString() - anchors.bottom: parent.bottom - anchors.bottomMargin: UM.Theme.getSize("default_margin").height - font: UM.Theme.getFont("default") - height:10 * screenScaleFactor - anchors.horizontalCenter: parent.horizontalCenter - } -} - From 4cde6c05ae1f5e948075956f224c902b0fa409fb Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 7 Sep 2018 15:23:09 +0200 Subject: [PATCH 02/10] Switch most usages of containerStackId to containerStack for settingPropertyProvider This mostly makes the code a bit more logic and also decreases the number of searches in the registry --- .../MachineSettingsAction.qml | 14 ++++++++------ .../PerObjectSettingsPanel.qml | 7 +++---- .../PostProcessingPlugin/PostProcessingPlugin.qml | 2 +- resources/qml/Cura.qml | 4 ++-- resources/qml/Menus/ContextMenu.qml | 2 +- resources/qml/MonitorSidebar.qml | 4 ++-- resources/qml/PrepareSidebar.qml | 4 ++-- resources/qml/PrintMonitor.qml | 6 +++--- resources/qml/PrinterOutput/ExtruderBox.qml | 2 +- resources/qml/Settings/SettingItem.qml | 2 +- resources/qml/SidebarHeader.qml | 2 +- resources/qml/SidebarSimple.qml | 9 ++++----- 12 files changed, 29 insertions(+), 29 deletions(-) diff --git a/plugins/MachineSettingsAction/MachineSettingsAction.qml b/plugins/MachineSettingsAction/MachineSettingsAction.qml index b12f8f8696..8c2262b5b7 100644 --- a/plugins/MachineSettingsAction/MachineSettingsAction.qml +++ b/plugins/MachineSettingsAction/MachineSettingsAction.qml @@ -16,6 +16,8 @@ Cura.MachineAction property var extrudersModel: Cura.ExtrudersModel{} property int extruderTabsCount: 0 + property var activeMachineId: Cura.MachineManager.activeMachine != null ? Cura.MachineManager.activeMachine.id : "" + Connections { target: base.extrudersModel @@ -511,7 +513,7 @@ Cura.MachineAction } return ""; } - return Cura.MachineManager.activeMachineId; + return base.activeMachineId } key: settingKey watchedProperties: [ "value", "description" ] @@ -564,7 +566,7 @@ Cura.MachineAction } return ""; } - return Cura.MachineManager.activeMachineId; + return base.activeMachineId } key: settingKey watchedProperties: [ "value", "description" ] @@ -655,7 +657,7 @@ Cura.MachineAction } return ""; } - return Cura.MachineManager.activeMachineId; + return base.activeMachineId } key: settingKey watchedProperties: [ "value", "options", "description" ] @@ -754,7 +756,7 @@ Cura.MachineAction } return ""; } - return Cura.MachineManager.activeMachineId; + return base.activeMachineId } key: settingKey watchedProperties: [ "value", "description" ] @@ -879,7 +881,7 @@ Cura.MachineAction { id: machineExtruderCountProvider - containerStackId: Cura.MachineManager.activeMachineId + containerStackId: base.activeMachineId key: "machine_extruder_count" watchedProperties: [ "value", "description" ] storeIndex: manager.containerIndex @@ -889,7 +891,7 @@ Cura.MachineAction { id: machineHeadPolygonProvider - containerStackId: Cura.MachineManager.activeMachineId + containerStackId: base.acthiveMachineId key: "machine_head_with_fans_polygon" watchedProperties: [ "value" ] storeIndex: manager.containerIndex diff --git a/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml b/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml index a2790dcf08..596fbd2e99 100644 --- a/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml +++ b/plugins/PerObjectSettingsTool/PerObjectSettingsPanel.qml @@ -17,7 +17,6 @@ Item { width: childrenRect.width; height: childrenRect.height; - property var all_categories_except_support: [ "machine_settings", "resolution", "shell", "infill", "material", "speed", "travel", "cooling", "platform_adhesion", "dual", "meshfix", "blackmagic", "experimental"] @@ -45,7 +44,7 @@ Item { UM.SettingPropertyProvider { id: meshTypePropertyProvider - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine watchedProperties: [ "enabled" ] } @@ -518,7 +517,7 @@ Item { { id: machineExtruderCount - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_extruder_count" watchedProperties: [ "value" ] storeIndex: 0 @@ -528,7 +527,7 @@ Item { { id: printSequencePropertyProvider - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "print_sequence" watchedProperties: [ "value" ] storeIndex: 0 diff --git a/plugins/PostProcessingPlugin/PostProcessingPlugin.qml b/plugins/PostProcessingPlugin/PostProcessingPlugin.qml index b8d7258ef2..e91fc73cf4 100644 --- a/plugins/PostProcessingPlugin/PostProcessingPlugin.qml +++ b/plugins/PostProcessingPlugin/PostProcessingPlugin.qml @@ -384,7 +384,7 @@ UM.Dialog UM.SettingPropertyProvider { id: inheritStackProvider - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: model.key ? model.key : "None" watchedProperties: [ "limit_to_extruder" ] } diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index c22fea38b4..b9febdeb32 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -306,7 +306,7 @@ UM.MainWindow { id: machineExtruderCount - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_extruder_count" watchedProperties: [ "value" ] storeIndex: 0 @@ -1054,7 +1054,7 @@ UM.MainWindow { restart(); } - else if(Cura.MachineManager.activeMachineId == null || Cura.MachineManager.activeMachineId == "") + else if(Cura.MachineManager.activeMachine == null) { addMachineDialog.open(); } diff --git a/resources/qml/Menus/ContextMenu.qml b/resources/qml/Menus/ContextMenu.qml index e35aef5f20..1ea402d815 100644 --- a/resources/qml/Menus/ContextMenu.qml +++ b/resources/qml/Menus/ContextMenu.qml @@ -103,7 +103,7 @@ Menu { id: machineExtruderCount - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_extruder_count" watchedProperties: [ "value" ] } diff --git a/resources/qml/MonitorSidebar.qml b/resources/qml/MonitorSidebar.qml index b761b05380..80bd5c1a2e 100644 --- a/resources/qml/MonitorSidebar.qml +++ b/resources/qml/MonitorSidebar.qml @@ -181,7 +181,7 @@ Rectangle { id: machineExtruderCount - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_extruder_count" watchedProperties: [ "value" ] storeIndex: 0 @@ -191,7 +191,7 @@ Rectangle { id: machineHeatedBed - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_heated_bed" watchedProperties: [ "value" ] storeIndex: 0 diff --git a/resources/qml/PrepareSidebar.qml b/resources/qml/PrepareSidebar.qml index 703cbb8844..78b6a22ef9 100644 --- a/resources/qml/PrepareSidebar.qml +++ b/resources/qml/PrepareSidebar.qml @@ -595,7 +595,7 @@ Rectangle { id: machineExtruderCount - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_extruder_count" watchedProperties: [ "value" ] storeIndex: 0 @@ -605,7 +605,7 @@ Rectangle { id: machineHeatedBed - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_heated_bed" watchedProperties: [ "value" ] storeIndex: 0 diff --git a/resources/qml/PrintMonitor.qml b/resources/qml/PrintMonitor.qml index 7727f9cb52..3bfcea7025 100644 --- a/resources/qml/PrintMonitor.qml +++ b/resources/qml/PrintMonitor.qml @@ -78,18 +78,18 @@ Column UM.SettingPropertyProvider { id: bedTemperature - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "material_bed_temperature" watchedProperties: ["value", "minimum_value", "maximum_value", "resolve"] storeIndex: 0 - property var resolve: Cura.MachineManager.activeStackId != Cura.MachineManager.activeMachineId ? properties.resolve : "None" + property var resolve: Cura.MachineManager.activeStack != Cura.MachineManager.activeMachine ? properties.resolve : "None" } UM.SettingPropertyProvider { id: machineExtruderCount - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_extruder_count" watchedProperties: ["value"] } diff --git a/resources/qml/PrinterOutput/ExtruderBox.qml b/resources/qml/PrinterOutput/ExtruderBox.qml index 56c86f1034..f0abd4cd6c 100644 --- a/resources/qml/PrinterOutput/ExtruderBox.qml +++ b/resources/qml/PrinterOutput/ExtruderBox.qml @@ -23,7 +23,7 @@ Item watchedProperties: ["value", "minimum_value", "maximum_value", "resolve"] storeIndex: 0 - property var resolve: Cura.MachineManager.activeStackId != Cura.MachineManager.activeMachineId ? properties.resolve : "None" + property var resolve: Cura.MachineManager.activeStack != Cura.MachineManager.activeMachine ? properties.resolve : "None" } Rectangle diff --git a/resources/qml/Settings/SettingItem.qml b/resources/qml/Settings/SettingItem.qml index 48b3cd306d..34bf9df921 100644 --- a/resources/qml/Settings/SettingItem.qml +++ b/resources/qml/Settings/SettingItem.qml @@ -139,7 +139,7 @@ Item { { id: linkedSettingIcon; - visible: Cura.MachineManager.activeStackId != Cura.MachineManager.activeMachineId && (!definition.settable_per_extruder || String(globalPropertyProvider.properties.limit_to_extruder) != "-1") && base.showLinkedSettingIcon + visible: Cura.MachineManager.activeStack != Cura.MachineManager.activeMachine && (!definition.settable_per_extruder || String(globalPropertyProvider.properties.limit_to_extruder) != "-1") && base.showLinkedSettingIcon height: parent.height; width: height; diff --git a/resources/qml/SidebarHeader.qml b/resources/qml/SidebarHeader.qml index 6ee33dd2f2..02bcfde29a 100644 --- a/resources/qml/SidebarHeader.qml +++ b/resources/qml/SidebarHeader.qml @@ -607,7 +607,7 @@ Column { id: machineExtruderCount - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "machine_extruder_count" watchedProperties: [ "value" ] storeIndex: 0 diff --git a/resources/qml/SidebarSimple.qml b/resources/qml/SidebarSimple.qml index 4b229d9807..e962d7fc8f 100644 --- a/resources/qml/SidebarSimple.qml +++ b/resources/qml/SidebarSimple.qml @@ -20,7 +20,6 @@ Item property variant minimumPrintTime: PrintInformation.minimumPrintTime; property variant maximumPrintTime: PrintInformation.maximumPrintTime; property bool settingsEnabled: Cura.ExtruderManager.activeExtruderStackId || extrudersEnabledCount.properties.value == 1 - Component.onCompleted: PrintInformation.enabled = true Component.onDestruction: PrintInformation.enabled = false UM.I18nCatalog { id: catalog; name: "cura" } @@ -1116,7 +1115,7 @@ Item UM.SettingPropertyProvider { id: platformAdhesionType - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "adhesion_type" watchedProperties: [ "value", "enabled" ] storeIndex: 0 @@ -1125,7 +1124,7 @@ Item UM.SettingPropertyProvider { id: supportEnabled - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "support_enable" watchedProperties: [ "value", "enabled", "description" ] storeIndex: 0 @@ -1134,7 +1133,7 @@ Item UM.SettingPropertyProvider { id: extrudersEnabledCount - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "extruders_enabled_count" watchedProperties: [ "value" ] storeIndex: 0 @@ -1143,7 +1142,7 @@ Item UM.SettingPropertyProvider { id: supportExtruderNr - containerStackId: Cura.MachineManager.activeMachineId + containerStack: Cura.MachineManager.activeMachine key: "support_extruder_nr" watchedProperties: [ "value" ] storeIndex: 0 From 20ec8828ed826b843d18a83f607b14034b1d5635 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 7 Sep 2018 15:32:07 +0200 Subject: [PATCH 03/10] Fix incorrect type hinting The type hinting indicated that the property was a dict, but it could also be None. In cases where it was None, it would cause an exception, which was also fixed (since unpacking None will break) --- cura/Settings/MachineManager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index d65bbfddd9..a1d824a5da 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -385,7 +385,9 @@ class MachineManager(QObject): # \param definition_id \type{str} definition id that needs to look for # \param metadata_filter \type{dict} list of metadata keys and values used for filtering @staticmethod - def getMachine(definition_id: str, metadata_filter: Dict[str, str] = None) -> Optional["GlobalStack"]: + def getMachine(definition_id: str, metadata_filter: Optional[Dict[str, str]] = None) -> Optional["GlobalStack"]: + if metadata_filter is None: + metadata_filter = {} machines = CuraContainerRegistry.getInstance().findContainerStacks(type = "machine", **metadata_filter) for machine in machines: if machine.definition.getId() == definition_id: From 638f9fb94158145c60556e51c35003f253973270 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 7 Sep 2018 16:02:54 +0200 Subject: [PATCH 04/10] Remove unused functions --- cura/Settings/ExtruderManager.py | 27 +-------------------------- cura/Settings/UserChangesModel.py | 4 +++- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index e046082b5f..a7cb15d806 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -91,16 +91,6 @@ class ExtruderManager(QObject): return extruder_stack_ids - @pyqtSlot(str, result = str) - def getQualityChangesIdByExtruderStackId(self, extruder_stack_id: str) -> str: - global_container_stack = self._application.getGlobalContainerStack() - if global_container_stack is not None: - for position in self._extruder_trains[global_container_stack.getId()]: - extruder = self._extruder_trains[global_container_stack.getId()][position] - if extruder.getId() == extruder_stack_id: - return extruder.qualityChanges.getId() - return "" - ## Changes the active extruder by index. # # \param index The index of the new active extruder. @@ -214,9 +204,6 @@ class ExtruderManager(QObject): if changed: self.extrudersChanged.emit(machine_id) - def getAllExtruderValues(self, setting_key): - return self.getAllExtruderSettings(setting_key, "value") - ## Gets a property of a setting for all extruders. # # \param setting_key \type{str} The setting to get the property of. @@ -336,19 +323,6 @@ class ExtruderManager(QObject): return [] return [self._extruder_trains[machine_id][name] for name in self._extruder_trains[machine_id]] - ## Returns a list containing the global stack and active extruder stacks. - # - # The first element is the global container stack, followed by any extruder stacks. - # \return \type{List[ContainerStack]} - def getActiveGlobalAndExtruderStacks(self) -> Optional[List[Union["ExtruderStack", "GlobalStack"]]]: - global_stack = self._application.getGlobalContainerStack() - if not global_stack: - return None - - result = [global_stack] - result.extend(self.getActiveExtruderStacks()) - return result - ## Returns the list of active extruder stacks, taking into account the machine extruder count. # # \return \type{List[ContainerStack]} a list of @@ -358,6 +332,7 @@ class ExtruderManager(QObject): return [] result = [] + if global_stack.getId() in self._extruder_trains: for extruder in sorted(self._extruder_trains[global_stack.getId()]): result.append(self._extruder_trains[global_stack.getId()][extruder]) diff --git a/cura/Settings/UserChangesModel.py b/cura/Settings/UserChangesModel.py index 93274d61c9..95674e5ecd 100644 --- a/cura/Settings/UserChangesModel.py +++ b/cura/Settings/UserChangesModel.py @@ -43,7 +43,9 @@ class UserChangesModel(ListModel): global_stack = Application.getInstance().getGlobalContainerStack() if not global_stack: return - stacks = ExtruderManager.getInstance().getActiveGlobalAndExtruderStacks() + + stacks = [global_stack] + stacks.extend(global_stack.extruders.values()) # Check if the definition container has a translation file and ensure it's loaded. definition = global_stack.getBottom() From a8fc6aabcc6d59712e8c6b1b05ddcef73191ba28 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 7 Sep 2018 16:27:56 +0200 Subject: [PATCH 05/10] Switch incorrect usage of getMachineExtruders to getActiveExtruderStacks --- cura/BuildVolume.py | 4 +-- cura/Scene/ConvexHullDecorator.py | 4 +-- cura/Settings/ExtruderManager.py | 30 +++++++------------ cura/Settings/ExtrudersModel.py | 2 +- cura/Settings/MachineManager.py | 10 +++---- .../CuraEngineBackend/CuraEngineBackend.py | 2 +- .../ProcessSlicedLayersJob.py | 2 +- plugins/CuraEngineBackend/StartSliceJob.py | 2 +- 8 files changed, 24 insertions(+), 32 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index b029665abd..10ae8bb87a 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -528,7 +528,7 @@ class BuildVolume(SceneNode): def _onStackChanged(self): if self._global_container_stack: self._global_container_stack.propertyChanged.disconnect(self._onSettingPropertyChanged) - extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()) + extruders = ExtruderManager.getInstance().getActiveExtruderStacks() for extruder in extruders: extruder.propertyChanged.disconnect(self._onSettingPropertyChanged) @@ -536,7 +536,7 @@ class BuildVolume(SceneNode): if self._global_container_stack: self._global_container_stack.propertyChanged.connect(self._onSettingPropertyChanged) - extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()) + extruders = ExtruderManager.getInstance().getActiveExtruderStacks() for extruder in extruders: extruder.propertyChanged.connect(self._onSettingPropertyChanged) diff --git a/cura/Scene/ConvexHullDecorator.py b/cura/Scene/ConvexHullDecorator.py index 367144abfc..ea54d64642 100644 --- a/cura/Scene/ConvexHullDecorator.py +++ b/cura/Scene/ConvexHullDecorator.py @@ -304,7 +304,7 @@ class ConvexHullDecorator(SceneNodeDecorator): if self._global_stack: self._global_stack.propertyChanged.disconnect(self._onSettingValueChanged) self._global_stack.containersChanged.disconnect(self._onChanged) - extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_stack.getId()) + extruders = ExtruderManager.getInstance().getActiveExtruderStacks() for extruder in extruders: extruder.propertyChanged.disconnect(self._onSettingValueChanged) @@ -314,7 +314,7 @@ class ConvexHullDecorator(SceneNodeDecorator): self._global_stack.propertyChanged.connect(self._onSettingValueChanged) self._global_stack.containersChanged.connect(self._onChanged) - extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_stack.getId()) + extruders = ExtruderManager.getInstance().getActiveExtruderStacks() for extruder in extruders: extruder.propertyChanged.connect(self._onSettingValueChanged) diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index a7cb15d806..65a7764508 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -12,11 +12,10 @@ from UM.Scene.Selection import Selection from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator from UM.Settings.ContainerRegistry import ContainerRegistry # Finding containers by ID. from UM.Settings.SettingFunction import SettingFunction -from UM.Settings.SettingInstance import SettingInstance from UM.Settings.ContainerStack import ContainerStack from UM.Settings.PropertyEvaluationContext import PropertyEvaluationContext -from typing import Optional, List, TYPE_CHECKING, Union, Dict +from typing import Optional, List, TYPE_CHECKING, Dict, List if TYPE_CHECKING: from cura.Settings.ExtruderStack import ExtruderStack @@ -38,9 +37,10 @@ class ExtruderManager(QObject): self._application = cura.CuraApplication.CuraApplication.getInstance() - self._extruder_trains = {} # Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders. + # Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders. + self._extruder_trains = {} # type: Dict[str, List[ExtruderStack]] self._active_extruder_index = -1 # Indicates the index of the active extruder stack. -1 means no active extruder stack - self._selected_object_extruders = [] + self._selected_object_extruders = [] # type: List[ExtruderStack] self._addCurrentMachineExtruders() Selection.selectionChanged.connect(self.resetSelectedObjectExtruders) @@ -68,7 +68,7 @@ class ExtruderManager(QObject): ## Return extruder count according to extruder trains. @pyqtProperty(int, notify = extrudersChanged) - def extruderCount(self): + def extruderCount(self) -> int: if not self._application.getGlobalContainerStack(): return 0 # No active machine, so no extruders. try: @@ -83,11 +83,7 @@ class ExtruderManager(QObject): global_container_stack = self._application.getGlobalContainerStack() if global_container_stack: - global_stack_id = global_container_stack.getId() - - if global_stack_id in self._extruder_trains: - for position in self._extruder_trains[global_stack_id]: - extruder_stack_ids[position] = self._extruder_trains[global_stack_id][position].getId() + extruder_stack_ids = {position: extruder.id for position, extruder in global_container_stack.extruders.items()} return extruder_stack_ids @@ -109,7 +105,7 @@ class ExtruderManager(QObject): @pyqtSlot(int, result = str) def getExtruderName(self, index): try: - return list(self.getActiveExtruderStacks())[index].getName() + return self.getActiveExtruderStacks()[index].getName() except IndexError: return "" @@ -318,7 +314,7 @@ class ExtruderManager(QObject): ## Returns extruders for a specific machine. # # \param machine_id The machine to get the extruders of. - def getMachineExtruders(self, machine_id: str): + def getMachineExtruders(self, machine_id: str) -> List["ExtruderStack"]: if machine_id not in self._extruder_trains: return [] return [self._extruder_trains[machine_id][name] for name in self._extruder_trains[machine_id]] @@ -331,11 +327,7 @@ class ExtruderManager(QObject): if not global_stack: return [] - result = [] - - if global_stack.getId() in self._extruder_trains: - for extruder in sorted(self._extruder_trains[global_stack.getId()]): - result.append(self._extruder_trains[global_stack.getId()][extruder]) + result = list(global_stack.extruders.values()) machine_extruder_count = global_stack.getProperty("machine_extruder_count", "value") @@ -404,7 +396,7 @@ class ExtruderManager(QObject): global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() result = [] - for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()): + for extruder in ExtruderManager.getInstance().getActiveExtruderStacks(): if not extruder.isEnabled: continue # only include values from extruders that are "active" for the current machine instance @@ -446,7 +438,7 @@ class ExtruderManager(QObject): } result = [] - for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()): + for extruder in ExtruderManager.getInstance().getActiveExtruderStacks(): # only include values from extruders that are "active" for the current machine instance if int(extruder.getMetaDataEntry("position")) >= global_stack.getProperty("machine_extruder_count", "value", context = context): continue diff --git a/cura/Settings/ExtrudersModel.py b/cura/Settings/ExtrudersModel.py index f179dabd5a..37cb68af32 100644 --- a/cura/Settings/ExtrudersModel.py +++ b/cura/Settings/ExtrudersModel.py @@ -171,7 +171,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel): # get machine extruder count for verification machine_extruder_count = global_container_stack.getProperty("machine_extruder_count", "value") - for extruder in Application.getInstance().getExtruderManager().getMachineExtruders(global_container_stack.getId()): + for extruder in Application.getInstance().getExtruderManager().getActiveExtruderStacks(): position = extruder.getMetaDataEntry("position", default = "0") # Get the position try: position = int(position) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index a1d824a5da..ed543fcee1 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -414,7 +414,7 @@ class MachineManager(QObject): # Not a very pretty solution, but the extruder manager doesn't really know how many extruders there are machine_extruder_count = self._global_container_stack.getProperty("machine_extruder_count", "value") - extruder_stacks = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()) + extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStacks() count = 1 # we start with the global stack for stack in extruder_stacks: md = stack.getMetaData() @@ -437,7 +437,7 @@ class MachineManager(QObject): if self._global_container_stack.getTop().findInstances(): return True - stacks = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())) + stacks = ExtruderManager.getInstance().getActiveExtruderStacks() for stack in stacks: if stack.getTop().findInstances(): return True @@ -450,7 +450,7 @@ class MachineManager(QObject): return 0 num_user_settings = 0 num_user_settings += len(self._global_container_stack.getTop().findInstances()) - stacks = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())) + stacks = ExtruderManager.getInstance().getActiveExtruderStacks() for stack in stacks: num_user_settings += len(stack.getTop().findInstances()) return num_user_settings @@ -475,7 +475,7 @@ class MachineManager(QObject): stack = ExtruderManager.getInstance().getActiveExtruderStack() stacks = [stack] else: - stacks = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()) + stacks = ExtruderManager.getInstance().getActiveExtruderStacks() for stack in stacks: if stack is not None: @@ -640,7 +640,7 @@ class MachineManager(QObject): if self._active_container_stack is None or self._global_container_stack is None: return new_value = self._active_container_stack.getProperty(key, "value") - extruder_stacks = [stack for stack in ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())] + extruder_stacks = [stack for stack in ExtruderManager.getInstance().getActiveExtruderStacks()] # check in which stack the value has to be replaced for extruder_stack in extruder_stacks: diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 9a5c95b04d..91a9ee0e7b 100755 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -343,7 +343,7 @@ class CuraEngineBackend(QObject, Backend): if not self._global_container_stack: Logger.log("w", "Global container stack not assigned to CuraEngineBackend!") return - extruders = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())) + extruders = ExtruderManager.getInstance().getActiveExtruderStacks() error_keys = [] #type: List[str] for extruder in extruders: error_keys.extend(extruder.getErrorKeys()) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 3bd6d79198..3953625c7e 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -178,7 +178,7 @@ class ProcessSlicedLayersJob(Job): # Find out colors per extruder global_container_stack = Application.getInstance().getGlobalContainerStack() manager = ExtruderManager.getInstance() - extruders = list(manager.getMachineExtruders(global_container_stack.getId())) + extruders = manager.getActiveExtruderStacks() if extruders: material_color_map = numpy.zeros((len(extruders), 4), dtype=numpy.float32) for extruder in extruders: diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index 1295390c22..28e442033b 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -333,7 +333,7 @@ class StartSliceJob(Job): "-1": self._buildReplacementTokens(global_stack) } - for extruder_stack in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()): + for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks(): extruder_nr = extruder_stack.getProperty("extruder_nr", "value") self._all_extruders_settings[str(extruder_nr)] = self._buildReplacementTokens(extruder_stack) From e6d0a9cc6a2ec30c15cb56d2e6890a44f12b051e Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 7 Sep 2018 16:33:44 +0200 Subject: [PATCH 06/10] Add missing typing --- cura/Settings/ExtruderManager.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index 65a7764508..680461ccac 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -4,7 +4,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant # For communicating data and events to Qt. from UM.FlameProfiler import pyqtSlot -import cura.CuraApplication #To get the global container stack to find the current machine. +import cura.CuraApplication # To get the global container stack to find the current machine. from UM.Logger import Logger from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Scene.SceneNode import SceneNode @@ -15,7 +15,7 @@ from UM.Settings.SettingFunction import SettingFunction from UM.Settings.ContainerStack import ContainerStack from UM.Settings.PropertyEvaluationContext import PropertyEvaluationContext -from typing import Optional, List, TYPE_CHECKING, Dict, List +from typing import Optional, TYPE_CHECKING, Dict, List, Any if TYPE_CHECKING: from cura.Settings.ExtruderStack import ExtruderStack @@ -103,7 +103,7 @@ class ExtruderManager(QObject): # # \param index The index of the extruder whose name to get. @pyqtSlot(int, result = str) - def getExtruderName(self, index): + def getExtruderName(self, index: int) -> str: try: return self.getActiveExtruderStacks()[index].getName() except IndexError: @@ -181,7 +181,7 @@ class ExtruderManager(QObject): result.append(stack) return result - def registerExtruder(self, extruder_train, machine_id): + def registerExtruder(self, extruder_train: "ExtruderStack", machine_id: str) -> None: changed = False if machine_id not in self._extruder_trains: @@ -205,7 +205,7 @@ class ExtruderManager(QObject): # \param setting_key \type{str} The setting to get the property of. # \param property \type{str} The property to get. # \return \type{List} the list of results - def getAllExtruderSettings(self, setting_key: str, prop: str): + def getAllExtruderSettings(self, setting_key: str, prop: str) -> List: result = [] for index in self.extruderIds: extruder_stack_id = self.extruderIds[str(index)] @@ -304,7 +304,7 @@ class ExtruderManager(QObject): ## Removes the container stack and user profile for the extruders for a specific machine. # # \param machine_id The machine to remove the extruders for. - def removeMachineExtruders(self, machine_id: str): + def removeMachineExtruders(self, machine_id: str) -> None: for extruder in self.getMachineExtruders(machine_id): ContainerRegistry.getInstance().removeContainer(extruder.userChanges.getId()) ContainerRegistry.getInstance().removeContainer(extruder.getId()) @@ -373,7 +373,7 @@ class ExtruderManager(QObject): # After 3.4, all single-extrusion machines have their own extruder definition files instead of reusing # "fdmextruder". We need to check a machine here so its extruder definition is correct according to this. - def _fixSingleExtrusionMachineExtruderDefinition(self, global_stack): + def _fixSingleExtrusionMachineExtruderDefinition(self, global_stack: "GlobalStack") -> None: expected_extruder_definition_0_id = global_stack.getMetaDataEntry("machine_extruder_trains")["0"] extruder_stack_0 = global_stack.extruders["0"] if extruder_stack_0.definition.getId() != expected_extruder_definition_0_id: @@ -392,7 +392,7 @@ class ExtruderManager(QObject): # \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list. # If no extruder has the value, the list will contain the global value. @staticmethod - def getExtruderValues(key): + def getExtruderValues(key) -> List: global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() result = [] @@ -427,7 +427,7 @@ class ExtruderManager(QObject): # \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list. # If no extruder has the value, the list will contain the global value. @staticmethod - def getDefaultExtruderValues(key): + def getDefaultExtruderValues(key) -> List: global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() context = PropertyEvaluationContext(global_stack) context.context["evaluate_from_container_index"] = 1 # skip the user settings container @@ -471,7 +471,7 @@ class ExtruderManager(QObject): # # \return String representing the extruder values @pyqtSlot(str, result="QVariant") - def getInstanceExtruderValues(self, key): + def getInstanceExtruderValues(self, key) -> List: return ExtruderManager.getExtruderValues(key) ## Get the value for a setting from a specific extruder. @@ -484,7 +484,7 @@ class ExtruderManager(QObject): # \return The value of the setting for the specified extruder or for the # global stack if not found. @staticmethod - def getExtruderValue(extruder_index, key): + def getExtruderValue(extruder_index: int, key: str) -> Any: if extruder_index == -1: extruder_index = int(cura.CuraApplication.CuraApplication.getInstance().getMachineManager().defaultExtruderPosition) extruder = ExtruderManager.getInstance().getExtruderStack(extruder_index) @@ -509,7 +509,7 @@ class ExtruderManager(QObject): # \return The value of the setting for the specified extruder or for the # global stack if not found. @staticmethod - def getDefaultExtruderValue(extruder_index, key): + def getDefaultExtruderValue(extruder_index: int, key: str) -> Any: extruder = ExtruderManager.getInstance().getExtruderStack(extruder_index) context = PropertyEvaluationContext(extruder) context.context["evaluate_from_container_index"] = 1 # skip the user settings container @@ -536,7 +536,7 @@ class ExtruderManager(QObject): # # \return The effective value @staticmethod - def getResolveOrValue(key): + def getResolveOrValue(key: str) -> Any: global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() resolved_value = global_stack.getProperty(key, "value") @@ -550,7 +550,7 @@ class ExtruderManager(QObject): # # \return The effective value @staticmethod - def getDefaultResolveOrValue(key): + def getDefaultResolveOrValue(key: str) -> Any: global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() context = PropertyEvaluationContext(global_stack) context.context["evaluate_from_container_index"] = 1 # skip the user settings container From 5c6c299b27747e9ff0b17bfed546c210eacf4926 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 7 Sep 2018 17:06:18 +0200 Subject: [PATCH 07/10] Cleanup extruder manager Few more unused functions removed & simplified. It also fixes a few more typing issues that I encountered. --- cura/Settings/ExtruderManager.py | 40 +++++++++-------------------- cura/Settings/ExtrudersModel.py | 2 +- plugins/GCodeReader/FlavorParser.py | 2 +- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index 680461ccac..1003ab5c86 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -20,6 +20,7 @@ from typing import Optional, TYPE_CHECKING, Dict, List, Any if TYPE_CHECKING: from cura.Settings.ExtruderStack import ExtruderStack from cura.Settings.GlobalStack import GlobalStack + from UM.Scene.SceneNode import SceneNode ## Manages all existing extruder stacks. @@ -38,7 +39,7 @@ class ExtruderManager(QObject): self._application = cura.CuraApplication.CuraApplication.getInstance() # Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders. - self._extruder_trains = {} # type: Dict[str, List[ExtruderStack]] + self._extruder_trains = {} # type: Dict[str, Dict[str, ExtruderStack]] self._active_extruder_index = -1 # Indicates the index of the active extruder stack. -1 means no active extruder stack self._selected_object_extruders = [] # type: List[ExtruderStack] self._addCurrentMachineExtruders() @@ -119,7 +120,7 @@ class ExtruderManager(QObject): object_extruders = set() # First, build a list of the actual selected objects (including children of groups, excluding group nodes) - selected_nodes = [] + selected_nodes = [] # type: List["SceneNode"] for node in Selection.getAllSelectedObjects(): if node.callDecoration("isGroup"): for grouped_node in BreadthFirstIterator(node): #type: ignore #Ignore type error because iter() should get called automatically by Python syntax. @@ -131,14 +132,13 @@ class ExtruderManager(QObject): selected_nodes.append(node) # Then, figure out which nodes are used by those selected nodes. - global_stack = self._application.getGlobalContainerStack() - current_extruder_trains = self._extruder_trains.get(global_stack.getId()) + current_extruder_trains = self.getActiveExtruderStacks() for node in selected_nodes: extruder = node.callDecoration("getActiveExtruder") if extruder: object_extruders.add(extruder) elif current_extruder_trains: - object_extruders.add(current_extruder_trains["0"].getId()) + object_extruders.add(current_extruder_trains[0].getId()) self._selected_object_extruders = list(object_extruders) @@ -154,14 +154,7 @@ class ExtruderManager(QObject): @pyqtSlot(result = QObject) def getActiveExtruderStack(self) -> Optional["ExtruderStack"]: - global_container_stack = self._application.getGlobalContainerStack() - - if global_container_stack: - if global_container_stack.getId() in self._extruder_trains: - if str(self._active_extruder_index) in self._extruder_trains[global_container_stack.getId()]: - return self._extruder_trains[global_container_stack.getId()][str(self._active_extruder_index)] - - return None + return self.getExtruderStack(self._active_extruder_index) ## Get an extruder stack by index def getExtruderStack(self, index) -> Optional["ExtruderStack"]: @@ -172,15 +165,6 @@ class ExtruderManager(QObject): return self._extruder_trains[global_container_stack.getId()][str(index)] return None - ## Get all extruder stacks - def getExtruderStacks(self) -> List["ExtruderStack"]: - result = [] - for i in range(self.extruderCount): - stack = self.getExtruderStack(i) - if stack: - result.append(stack) - return result - def registerExtruder(self, extruder_train: "ExtruderStack", machine_id: str) -> None: changed = False @@ -207,13 +191,13 @@ class ExtruderManager(QObject): # \return \type{List} the list of results def getAllExtruderSettings(self, setting_key: str, prop: str) -> List: result = [] - for index in self.extruderIds: - extruder_stack_id = self.extruderIds[str(index)] - extruder_stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0] + + for extruder_stack in self.getActiveExtruderStacks(): result.append(extruder_stack.getProperty(setting_key, prop)) + return result - def extruderValueWithDefault(self, value): + def extruderValueWithDefault(self, value: str) -> str: machine_manager = self._application.getMachineManager() if value == "-1": return machine_manager.defaultExtruderPosition @@ -392,7 +376,7 @@ class ExtruderManager(QObject): # \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list. # If no extruder has the value, the list will contain the global value. @staticmethod - def getExtruderValues(key) -> List: + def getExtruderValues(key: str) -> List[Any]: global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() result = [] @@ -427,7 +411,7 @@ class ExtruderManager(QObject): # \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list. # If no extruder has the value, the list will contain the global value. @staticmethod - def getDefaultExtruderValues(key) -> List: + def getDefaultExtruderValues(key: str) -> List[Any]: global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() context = PropertyEvaluationContext(global_stack) context.context["evaluate_from_container_index"] = 1 # skip the user settings container diff --git a/cura/Settings/ExtrudersModel.py b/cura/Settings/ExtrudersModel.py index 37cb68af32..52fc502bfc 100644 --- a/cura/Settings/ExtrudersModel.py +++ b/cura/Settings/ExtrudersModel.py @@ -134,7 +134,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel): # Link to new extruders self._active_machine_extruders = [] extruder_manager = Application.getInstance().getExtruderManager() - for extruder in extruder_manager.getExtruderStacks(): + for extruder in extruder_manager.getActiveExtruderStacks(): if extruder is None: #This extruder wasn't loaded yet. This happens asynchronously while this model is constructed from QML. continue extruder.containersChanged.connect(self._onExtruderStackContainersChanged) diff --git a/plugins/GCodeReader/FlavorParser.py b/plugins/GCodeReader/FlavorParser.py index 10f841fc43..eb19853748 100644 --- a/plugins/GCodeReader/FlavorParser.py +++ b/plugins/GCodeReader/FlavorParser.py @@ -275,7 +275,7 @@ class FlavorParser: ## For showing correct x, y offsets for each extruder def _extruderOffsets(self) -> Dict[int, List[float]]: result = {} - for extruder in ExtruderManager.getInstance().getExtruderStacks(): + for extruder in ExtruderManager.getInstance().getActiveExtruderStacks(): result[int(extruder.getMetaData().get("position", "0"))] = [ extruder.getProperty("machine_nozzle_offset_x", "value"), extruder.getProperty("machine_nozzle_offset_y", "value")] From 2bc1e4b397aaf688232f0863119a9867b59eec56 Mon Sep 17 00:00:00 2001 From: Ian Paschal Date: Mon, 10 Sep 2018 09:27:59 +0200 Subject: [PATCH 08/10] Fix bug where disovery window does not appear --- plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py b/plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py index ece23507e5..be83e04585 100644 --- a/plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py +++ b/plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py @@ -24,7 +24,7 @@ class DiscoverUM3Action(MachineAction): def __init__(self) -> None: super().__init__("DiscoverUM3Action", catalog.i18nc("@action","Connect via Network")) - self._qml_url = "../resources/qml/DiscoverUM3Action.qml" + self._qml_url = "resources/qml/DiscoverUM3Action.qml" self._network_plugin = None #type: Optional[UM3OutputDevicePlugin] From 67bc45e37d2119252b7f8be5eaea210df65678db Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 10 Sep 2018 09:40:53 +0200 Subject: [PATCH 09/10] Added 3MF writer as required plugin --- cura/CuraApplication.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index dbc675a279..7e5e98adef 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -429,6 +429,7 @@ class CuraApplication(QtApplication): # Readers & Writers: "GCodeWriter", "STLReader", + "3MFWriter", # Tools: "CameraTool", From 5139e6147533c211d710d86bd98f251bb77420e7 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Sun, 9 Sep 2018 11:43:47 +0200 Subject: [PATCH 10/10] Found the dead line while reading some code --- plugins/Toolbox/src/PackagesModel.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/Toolbox/src/PackagesModel.py b/plugins/Toolbox/src/PackagesModel.py index 7892044d00..ae4cd7682d 100644 --- a/plugins/Toolbox/src/PackagesModel.py +++ b/plugins/Toolbox/src/PackagesModel.py @@ -76,7 +76,6 @@ class PackagesModel(ListModel): if "author_id" not in package["author"] or "display_name" not in package["author"]: package["author"]["author_id"] = "" package["author"]["display_name"] = "" - # raise Exception("Detected a package with malformed author data.") items.append({ "id": package["package_id"],