From 57bb268ea04dac3438543709008676cf4f72f4a1 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 8 Oct 2022 18:37:25 +0200 Subject: [PATCH] feat: add SET_PRINT_STATS_INFO command support (#1034) --- .../panels/Status/PrintstatusPrinting.vue | 27 +----------- src/store/printer/getters.ts | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/components/panels/Status/PrintstatusPrinting.vue b/src/components/panels/Status/PrintstatusPrinting.vue index a23eda5b3..c98880333 100644 --- a/src/components/panels/Status/PrintstatusPrinting.vue +++ b/src/components/panels/Status/PrintstatusPrinting.vue @@ -189,34 +189,11 @@ export default class StatusPanelPrintstatusPrinting extends Mixins(BaseMixin) { } get max_layers() { - if ( - 'first_layer_height' in this.current_file && - 'layer_height' in this.current_file && - 'object_height' in this.current_file - ) { - const max = Math.ceil( - (this.current_file.object_height - this.current_file.first_layer_height) / - this.current_file.layer_height + - 1 - ) - return max > 0 ? max : 0 - } - - return 0 + return this.$store.getters['printer/getPrintMaxLayers'] ?? 0 } get current_layer() { - if (this.print_time > 0 && 'first_layer_height' in this.current_file && 'layer_height' in this.current_file) { - const gcodePositionZ = this.$store.state.printer.gcode_move?.gcode_position[2] ?? 0 - let current_layer = Math.ceil( - (gcodePositionZ - this.current_file.first_layer_height) / this.current_file.layer_height + 1 - ) - current_layer = current_layer <= this.max_layers ? current_layer : this.max_layers - - return current_layer > 0 ? current_layer : 0 - } - - return 0 + return this.$store.getters['printer/getPrintCurrentLayer'] ?? 0 } get estimated_time_file() { diff --git a/src/store/printer/getters.ts b/src/store/printer/getters.ts index a882f9df7..0686c076d 100644 --- a/src/store/printer/getters.ts +++ b/src/store/printer/getters.ts @@ -96,6 +96,48 @@ export const getters: GetterTree = { return state.virtual_sdcard?.progress ?? 0 }, + getPrintMaxLayers: (state) => { + if (state.print_stats?.info?.total_layer !== null) { + return state.print_stats.info.total_layer + } else if (state.current_file?.layer_count) { + return state.current_file.layer_count + } else if ( + 'current_file' in state && + 'first_layer_height' in state.current_file && + 'layer_height' in state.current_file && + 'object_height' in state.current_file + ) { + const max = Math.ceil( + (state.current_file.object_height - state.current_file.first_layer_height) / + state.current_file.layer_height + + 1 + ) + return max > 0 ? max : 0 + } + + return 0 + }, + + getPrintCurrentLayer: (state, getters) => { + if (state.print_stats?.info?.current_layer !== null) { + return state.print_stats.info.current_layer + } else if ( + state.print_stats?.print_duration > 0 && + 'first_layer_height' in state.current_file && + 'layer_height' in state.current_file + ) { + const gcodePositionZ = state.gcode_move?.gcode_position[2] ?? 0 + const current_layer = Math.ceil( + (gcodePositionZ - state.current_file.first_layer_height) / state.current_file.layer_height + 1 + ) + + if (current_layer > getters.getPrintMaxLayers) return getters.getPrintMaxLayers + if (current_layer > 0) return current_layer + } + + return 0 + }, + getMacros: (state) => { const array: PrinterStateMacro[] = [] const config = state.configfile?.config ?? {}