Skip to content

Commit

Permalink
feat: Extended G-Code viewer auto-actions (#738)
Browse files Browse the repository at this point in the history
Signed-off-by: Mathis Mensing <[email protected]>
  • Loading branch information
matmen authored Jul 4, 2022
1 parent 580a177 commit 79ec091
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
46 changes: 46 additions & 0 deletions src/components/settings/GcodePreviewSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@

<v-divider />

<app-setting :title="$t('app.setting.label.auto_load_on_print_start')">
<v-switch
v-model="autoLoadOnPrintStart"
hide-details
class="mb-5"
@click.native.stop
/>
</app-setting>

<v-divider />

<app-setting :title="$t('app.setting.label.auto_follow_on_file_load')">
<v-switch
v-model="autoFollowOnFileLoad"
hide-details
class="mb-5"
@click.native.stop
/>
</app-setting>

<v-divider />

<app-setting :title="$t('app.setting.label.reset')">
<app-btn
outlined
Expand Down Expand Up @@ -231,6 +253,30 @@ export default class GcodePreviewSettings extends Vue {
})
}
get autoLoadOnPrintStart () {
return this.$store.state.config.uiSettings.gcodePreview.autoLoadOnPrintStart
}
set autoLoadOnPrintStart (value: boolean) {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.gcodePreview.autoLoadOnPrintStart',
value,
server: true
})
}
get autoFollowOnFileLoad () {
return this.$store.state.config.uiSettings.gcodePreview.autoFollowOnFileLoad
}
set autoFollowOnFileLoad (value: boolean) {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.gcodePreview.autoFollowOnFileLoad',
value,
server: true
})
}
handleReset () {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.gcodePreview',
Expand Down
13 changes: 12 additions & 1 deletion src/components/widgets/gcode-preview/GcodePreviewCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ export default class GcodePreviewCard extends Mixins(StateMixin, FilesMixin) {
}
}
@Watch('printerFile')
onPrintFileChanged () {
if (this.autoLoadOnPrintStart && this.printerFile) {
this.loadCurrent()
}
}
get file (): AppFile | undefined {
return this.$store.getters['gcodePreview/getFile']
}
Expand Down Expand Up @@ -304,7 +311,7 @@ export default class GcodePreviewCard extends Mixins(StateMixin, FilesMixin) {
}
async loadCurrent () {
const file = this.$store.state.printer.printer.current_file as AppFile
const file = this.printerFile as AppFile
this.getGcode(file)
.then(response => response?.data)
.then((gcode: AxiosResponse) => {
Expand Down Expand Up @@ -339,5 +346,9 @@ export default class GcodePreviewCard extends Mixins(StateMixin, FilesMixin) {
return true
}
get autoLoadOnPrintStart () {
return this.$store.state.config.uiSettings.gcodePreview.autoLoadOnPrintStart
}
}
</script>
2 changes: 2 additions & 0 deletions src/locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ app:
all_off: Alle aus
all_on: Alle an
auto_edit_extensions: Erweiterungen, die automatisch im Bearbeitungsmodus geöffnet werden
auto_follow_on_file_load: Fortschritt beim Laden einer Datei automatisch folgen
auto_load_on_print_start: Datei bei Druckstart automatisch laden
camera_flip_x: Horizontal spiegeln
camera_flip_y: Vertikal spiegeln
camera_rotate_by: Rotieren um
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ app:
all_off: All off
all_on: All on
auto_edit_extensions: Extensions to automatically open in edit mode
auto_follow_on_file_load: Automatically follow progress on file load
auto_load_on_print_start: Automatically load file on print start
camera_flip_x: Flip horizontally
camera_flip_y: Flip vertically
camera_fullscreen_action:
Expand Down
2 changes: 2 additions & 0 deletions src/store/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export const defaultState = (): ConfigState => {
drawBackground: true,
showAnimations: true,
groupLowerLayers: false,
autoLoadOnPrintStart: true,
autoFollowOnFileLoad: true,
flip: {
horizontal: false,
vertical: true
Expand Down
2 changes: 2 additions & 0 deletions src/store/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export interface GcodePreviewConfig {
drawBackground: boolean;
showAnimations: boolean;
groupLowerLayers: boolean;
autoLoadOnPrintStart: boolean;
autoFollowOnFileLoad: boolean;
flip: {
horizontal: boolean;
vertical: boolean;
Expand Down
6 changes: 5 additions & 1 deletion src/store/gcodePreview/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const actions: ActionTree<GcodePreviewState, RootState> = {
}
},

async loadGcode ({ commit, getters, state }, payload: { file: AppFile; gcode: string }) {
async loadGcode ({ commit, getters, state, rootState }, payload: { file: AppFile; gcode: string }) {
const worker = await spawn(new Worker(new URL('@/workers/parseGcode.worker.ts', import.meta.url) as any))

commit('setParserWorker', worker)
Expand All @@ -46,6 +46,10 @@ export const actions: ActionTree<GcodePreviewState, RootState> = {
commit('setMoves', [])

commit('setFile', payload.file)
if (rootState.config?.uiSettings.gcodePreview.autoFollowOnFileLoad) {
// check if loaded file equals printed file is handled downstream
commit('setViewerState', { followProgress: true })
}

try {
commit('setMoves', await Promise.race([abort, worker.parse(payload.gcode)]))
Expand Down

0 comments on commit 79ec091

Please sign in to comment.