From f55b58a2a93d92acd24410ca1f1b5a0eecd2ba46 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Tue, 9 Aug 2022 19:38:04 +0200 Subject: [PATCH] feat: add option to switch print progress calculation (#1013) Co-authored-by: th33xitus --- .../settings/SettingsGeneralTab.vue | 55 ++++++++++++++----- src/locales/de.json | 8 +++ src/locales/en.json | 8 +++ src/store/farm/printer/getters.ts | 40 +++++++++++++- src/store/gui/index.ts | 1 + src/store/gui/types.ts | 1 + src/store/printer/getters.ts | 40 +++++++++++++- 7 files changed, 138 insertions(+), 15 deletions(-) diff --git a/src/components/settings/SettingsGeneralTab.vue b/src/components/settings/SettingsGeneralTab.vue index b3127da7..b9def89e 100644 --- a/src/components/settings/SettingsGeneralTab.vue +++ b/src/components/settings/SettingsGeneralTab.vue @@ -2,11 +2,11 @@
- + - + + :title="$t('Settings.GeneralTab.CalcPrintProgress').toString()" + :sub-title="$t('Settings.GeneralTab.CalcPrintProgressDescription').toString()"> + + + + + :title="$t('Settings.GeneralTab.CalcEtaTime').toString()" + :sub-title="$t('Settings.GeneralTab.CalcEtaTimeDescription').toString()"> - + - + {{ $t('Settings.GeneralTab.FactoryReset') }} @@ -66,7 +78,7 @@ @@ -117,7 +129,7 @@ @@ -183,7 +195,7 @@ @@ -348,6 +360,23 @@ export default class SettingsGeneralTab extends Mixins(BaseMixin) { return languages } + get calcPrintProgressItems() { + return [ + { value: 'file-relative', text: this.$t('Settings.GeneralTab.CalcPrintProgressItems.FileRelative') }, + { value: 'file-absolute', text: this.$t('Settings.GeneralTab.CalcPrintProgressItems.FileAbsolute') }, + { value: 'slicer', text: this.$t('Settings.GeneralTab.CalcPrintProgressItems.Slicer') }, + { value: 'filament', text: this.$t('Settings.GeneralTab.CalcPrintProgressItems.Filament') }, + ] + } + + get calcPrintProgress() { + return this.$store.state.gui.general.calcPrintProgress ?? 'file-relative' + } + + set calcPrintProgress(newVal) { + this.$store.dispatch('gui/saveSetting', { name: 'general.calcPrintProgress', value: newVal }) + } + get calcEstimateItems() { return [ { value: 'file', text: this.$t('Settings.GeneralTab.EstimateValues.File') }, @@ -452,7 +481,7 @@ export default class SettingsGeneralTab extends Mixins(BaseMixin) { } async backupDb() { - this.$store.dispatch('socket/addLoading', 'backupDbButton') + await this.$store.dispatch('socket/addLoading', 'backupDbButton') await this.refreshNamespaces() if (this.availableNamespaces.includes('mainsail')) await this.refreshMainsailKeys() else this.mainsailKeys = [] @@ -469,7 +498,7 @@ export default class SettingsGeneralTab extends Mixins(BaseMixin) { } async restoreDb() { - this.$store.dispatch('socket/addLoading', 'restoreUploadButton') + await this.$store.dispatch('socket/addLoading', 'restoreUploadButton') this.$refs?.uploadBackupFile?.click() } diff --git a/src/locales/de.json b/src/locales/de.json index 110f3273..792a9124 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -753,6 +753,14 @@ "CalcEstimateTimeDescription": "Bei Mehrfachauswahl wird ein Durchschnitt berechnet", "CalcEtaTime": "ETA Berechnung", "CalcEtaTimeDescription": "Bei Mehrfachauswahl wird ein Durchschnitt berechnet", + "CalcPrintProgress": "Berechnung des Druckfortschritts", + "CalcPrintProgressDescription": "Methode zur Berechnung des Druckfortschritts.", + "CalcPrintProgressItems": { + "Filament": "Filament", + "FileRelative": "Dateiposition (relativ)", + "FileAbsolute": "Dateiposition (absolut)", + "Slicer": "Slicer (M73)" + }, "CannotReadJson": "Sicherungsdatei kann nicht gelesen/analysiert werden.", "DbConsoleHistory": "Verlauf der Konsole", "DbHistoryJobs": "Historie Druckvorgänge", diff --git a/src/locales/en.json b/src/locales/en.json index d82aa3c2..07b186f7 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -753,6 +753,14 @@ "CalcEstimateTimeDescription": "If multiple are selected, an average will be calculated", "CalcEtaTime": "ETA calculation", "CalcEtaTimeDescription": "If multiple are selected, an average will be calculated", + "CalcPrintProgress": "Print progress calculation", + "CalcPrintProgressDescription": "Method for calculating the print progress.", + "CalcPrintProgressItems": { + "Filament": "Filament", + "FileRelative": "File position (relative)", + "FileAbsolute": "File position (absolute)", + "Slicer": "Slicer (M73)" + }, "CannotReadJson": "Cannot read/parse backup file.", "DbConsoleHistory": "Console History", "DbHistoryJobs": "History Jobs", diff --git a/src/store/farm/printer/getters.ts b/src/store/farm/printer/getters.ts index 6331fdc3..41406c14 100644 --- a/src/store/farm/printer/getters.ts +++ b/src/store/farm/printer/getters.ts @@ -65,7 +65,24 @@ export const getters: GetterTree = { return state.data.print_stats?.filename ?? '' }, - getPrintPercent: (state) => { + getPrintPercent: (state, getters) => { + const type = state.data.gui?.general?.calcPrintProgress ?? 'file-relative' + switch (type) { + case 'file-relative': + return getters['getPrintPercentByFilepositionRelative'] + case 'file-absolute': + return getters['getPrintPercentByFilepositionAbsolute'] + case 'slicer': + return getters['getPrintPercentBySlicer'] + case 'filament': + return getters['getPrintPercentByFilament'] + + default: + return getters['getPrintPercentByFilepositionRelative'] + } + }, + + getPrintPercentByFilepositionRelative: (state) => { if ( state.current_file?.filename && state.current_file?.gcode_start_byte && @@ -84,6 +101,27 @@ export const getters: GetterTree = { return state.data.virtual_sdcard?.progress ?? 0 }, + getPrintPercentByFilepositionAbsolute: (state) => { + return state.data.virtual_sdcard?.progress ?? 0 + }, + + getPrintPercentBySlicer: (state) => { + return state.data.display_status?.progress ?? 0 + }, + + getPrintPercentByFilament: (state) => { + const filament_used = state.data.print_stats?.filament_used ?? null + const filament_total = state.current_file?.filament_total ?? null + + if (filament_used !== null && filament_total !== null) { + if (filament_total == 0) return 0 + + return filament_used / filament_total + } + + return state.data.virtual_sdcard?.progress ?? 0 + }, + getImage: (state) => { if (state.current_file.filename && state.current_file.thumbnails?.length) { const indexLastDir = state.current_file.filename.lastIndexOf('/') diff --git a/src/store/gui/index.ts b/src/store/gui/index.ts index a971b445..c92d765f 100644 --- a/src/store/gui/index.ts +++ b/src/store/gui/index.ts @@ -19,6 +19,7 @@ export const getDefaultState = (): GuiState => { general: { printername: '', language: 'en', + calcPrintProgress: 'file-relative', calcEstimateTime: ['file', 'filament'], calcEtaTime: ['file', 'filament', 'slicer'], }, diff --git a/src/store/gui/types.ts b/src/store/gui/types.ts index fdafe2c8..aeaf58c9 100644 --- a/src/store/gui/types.ts +++ b/src/store/gui/types.ts @@ -10,6 +10,7 @@ export interface GuiState { general: { printername: string language: string + calcPrintProgress: 'file-relative' | 'file-absolute' | 'slicer' | 'filament' calcEstimateTime: string[] // file, filament are possible values calcEtaTime: string[] // file, filament, slicer are possible values } diff --git a/src/store/printer/getters.ts b/src/store/printer/getters.ts index 3af07d3e..8fb562e8 100644 --- a/src/store/printer/getters.ts +++ b/src/store/printer/getters.ts @@ -36,7 +36,24 @@ import { } from '@mdi/js' export const getters: GetterTree = { - getPrintPercent: (state) => { + getPrintPercent: (state, getters, rootState) => { + const type = rootState?.gui?.general?.calcPrintProgress ?? 'file-relative' + switch (type) { + case 'file-relative': + return getters['getPrintPercentByFilepositionRelative'] + case 'file-absolute': + return getters['getPrintPercentByFilepositionAbsolute'] + case 'slicer': + return getters['getPrintPercentBySlicer'] + case 'filament': + return getters['getPrintPercentByFilament'] + + default: + return getters['getPrintPercentByFilepositionRelative'] + } + }, + + getPrintPercentByFilepositionRelative: (state) => { if ( state.current_file?.filename && state.current_file?.gcode_start_byte && @@ -55,6 +72,27 @@ export const getters: GetterTree = { return state.virtual_sdcard?.progress ?? 0 }, + getPrintPercentByFilepositionAbsolute: (state) => { + return state.virtual_sdcard?.progress ?? 0 + }, + + getPrintPercentBySlicer: (state) => { + return state.display_status?.progress ?? 0 + }, + + getPrintPercentByFilament: (state) => { + const filament_used = state.print_stats?.filament_used ?? null + const filament_total = state.current_file?.filament_total ?? null + + if (filament_used !== null && filament_total !== null) { + if (filament_total == 0) return 0 + + return filament_used / filament_total + } + + return state.virtual_sdcard?.progress ?? 0 + }, + getMacros: (state) => { const array: PrinterStateMacro[] = [] const config = state.configfile?.config ?? {}