Skip to content

Commit

Permalink
feat: add option to switch print progress calculation (#1013)
Browse files Browse the repository at this point in the history
Co-authored-by: th33xitus <domwil1091+github@gmail.com>
  • Loading branch information
meteyou and dw-0 authored Aug 9, 2022
1 parent 8d7e4c1 commit f55b58a
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 15 deletions.
55 changes: 42 additions & 13 deletions src/components/settings/SettingsGeneralTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div>
<v-card flat>
<v-card-text>
<settings-row :title="$t('Settings.GeneralTab.PrinterName')">
<settings-row :title="$t('Settings.GeneralTab.PrinterName').toString()">
<v-text-field v-model="printerName" hide-details outlined dense></v-text-field>
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row :title="$t('Settings.GeneralTab.Language')">
<settings-row :title="$t('Settings.GeneralTab.Language').toString()">
<v-select
v-model="currentLanguage"
:items="availableLanguages"
Expand All @@ -17,8 +17,20 @@
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row
:title="$t('Settings.GeneralTab.CalcEstimateTime')"
:sub-title="$t('Settings.GeneralTab.CalcEstimateTimeDescription')">
:title="$t('Settings.GeneralTab.CalcPrintProgress').toString()"
:sub-title="$t('Settings.GeneralTab.CalcPrintProgressDescription').toString()">
<v-select
v-model="calcPrintProgress"
:items="calcPrintProgressItems"
hide-details
dense
outlined
attach></v-select>
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row
:title="$t('Settings.GeneralTab.CalcEstimateTime').toString()"
:sub-title="$t('Settings.GeneralTab.CalcEstimateTimeDescription').toString()">
<v-select
v-model="calcEstimateTime"
:items="calcEstimateItems"
Expand All @@ -30,8 +42,8 @@
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row
:title="$t('Settings.GeneralTab.CalcEtaTime')"
:sub-title="$t('Settings.GeneralTab.CalcEtaTimeDescription')">
:title="$t('Settings.GeneralTab.CalcEtaTime').toString()"
:sub-title="$t('Settings.GeneralTab.CalcEtaTimeDescription').toString()">
<v-select
v-model="calcEtaTime"
:items="calcEtaTimeItems"
Expand All @@ -42,7 +54,7 @@
attach></v-select>
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row :title="$t('Settings.GeneralTab.MoonrakerDb')" :dynamic-slot-width="true">
<settings-row :title="$t('Settings.GeneralTab.MoonrakerDb').toString()" :dynamic-slot-width="true">
<input
ref="uploadBackupFile"
type="file"
Expand All @@ -57,7 +69,7 @@
</v-btn>
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row :title="$t('Settings.GeneralTab.FactoryReset')" :dynamic-slot-width="true">
<settings-row :title="$t('Settings.GeneralTab.FactoryReset').toString()" :dynamic-slot-width="true">
<v-btn color="error" small @click="resetMainsail">
{{ $t('Settings.GeneralTab.FactoryReset') }}
</v-btn>
Expand All @@ -66,7 +78,7 @@
</v-card>
<v-dialog v-model="dialogBackupMainsail" persistent :width="360">
<panel
:title="$t('Settings.GeneralTab.Backup')"
:title="$t('Settings.GeneralTab.Backup').toString()"
card-class="mainsail-backup-dialog"
:margin-bottom="false"
:icon="mdiHelpCircle">
Expand Down Expand Up @@ -117,7 +129,7 @@
</v-dialog>
<v-dialog v-model="dialogResetMainsail" persistent :width="360">
<panel
:title="$t('Settings.GeneralTab.FactoryReset')"
:title="$t('Settings.GeneralTab.FactoryReset').toString()"
card-class="factory-reset-dialog"
:margin-bottom="false"
:icon="mdiHelpCircle">
Expand Down Expand Up @@ -183,7 +195,7 @@
</v-dialog>
<v-dialog v-model="dialogRestoreMainsail" persistent :width="360">
<panel
:title="$t('Settings.GeneralTab.Restore')"
:title="$t('Settings.GeneralTab.Restore').toString()"
card-class="factory-reset-dialog"
:margin-bottom="false"
:icon="mdiHelpCircle">
Expand Down Expand Up @@ -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') },
Expand Down Expand Up @@ -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 = []
Expand All @@ -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()
}
Expand Down
8 changes: 8 additions & 0 deletions src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 39 additions & 1 deletion src/store/farm/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,24 @@ export const getters: GetterTree<FarmPrinterState, any> = {
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 &&
Expand All @@ -84,6 +101,27 @@ export const getters: GetterTree<FarmPrinterState, any> = {
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('/')
Expand Down
1 change: 1 addition & 0 deletions src/store/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const getDefaultState = (): GuiState => {
general: {
printername: '',
language: 'en',
calcPrintProgress: 'file-relative',
calcEstimateTime: ['file', 'filament'],
calcEtaTime: ['file', 'filament', 'slicer'],
},
Expand Down
1 change: 1 addition & 0 deletions src/store/gui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
40 changes: 39 additions & 1 deletion src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,24 @@ import {
} from '@mdi/js'

export const getters: GetterTree<PrinterState, RootState> = {
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 &&
Expand All @@ -55,6 +72,27 @@ export const getters: GetterTree<PrinterState, RootState> = {
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 ?? {}
Expand Down

0 comments on commit f55b58a

Please sign in to comment.