Skip to content

Commit

Permalink
feat: display gcodeviewer always and store klipper settings in moonra…
Browse files Browse the repository at this point in the history
…ker DB as a fallback (#725)

* refactor: save necessary klipper settings in database

Signed-off-by: Stefan Dej <[email protected]>

* refactor: use klipper cache data as fallback for the gcode viewer

Signed-off-by: Stefan Dej <[email protected]>

* fix: update gcodeviewer klipper cache action

Signed-off-by: Stefan Dej <[email protected]>

* feat: display gcodeviewer always in the navi

Signed-off-by: Stefan Dej <[email protected]>

* fix: typo in klipper cache fallback in gcodeviewer

Signed-off-by: Stefan Dej <[email protected]>

* refactor: remove debug output

Co-authored-by: pataar <[email protected]>

* style: fix code format

Signed-off-by: Stefan Dej <[email protected]>

Co-authored-by: pataar <[email protected]>
  • Loading branch information
meteyou and pataar authored Mar 21, 2022
1 parent cde0156 commit 94ce369
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
30 changes: 21 additions & 9 deletions src/components/gcodeviewer/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,27 @@ export default class Viewer extends Mixins(BaseMixin) {
}
get kinematics() {
return this.$store.state.printer.configfile?.settings?.printer?.kinematics ?? ''
return (
this.$store.state.printer.configfile?.settings?.printer?.kinematics ??
this.$store.state.gui?.gcodeViewer?.klipperCache?.kinematics ??
''
)
}
get bedMaxSize() {
return (
this.$store.state.printer.toolhead?.axis_maximum ??
this.$store.state.gui?.gcodeViewer?.klipperCache?.axis_maximum ??
null
)
}
get bedMinSize() {
return (
this.$store.state.printer.toolhead?.axis_minimum ??
this.$store.state.gui?.gcodeViewer?.klipperCache?.axis_minimum ??
null
)
}
@Watch('kinematics')
Expand All @@ -946,10 +966,6 @@ export default class Viewer extends Mixins(BaseMixin) {
}
}
get bedMinSize() {
return this.$store.state.printer.toolhead?.axis_minimum ?? null
}
@Watch('bedMinSize', { deep: true })
bedMinSizeChanged(newVal: number[] | null) {
if (viewer && newVal) {
Expand All @@ -959,10 +975,6 @@ export default class Viewer extends Mixins(BaseMixin) {
}
}
get bedMaxSize() {
return this.$store.state.printer.toolhead?.axis_maximum ?? null
}
@Watch('bedMaxSize', { deep: true })
bedMaxSizeChanged(newVal: number[] | null) {
if (newVal && viewer) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const routes: AppRoute[] = [
path: '/viewer',
icon: mdiVideo3d,
component: () => import('../pages/Viewer.vue'),
alwaysShow: false,
alwaysShow: true,
showInNavi: true,
},
{
Expand Down
12 changes: 12 additions & 0 deletions src/store/gui/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,16 @@ export const actions: ActionTree<GuiState, RootState> = {
value: newVal,
})
},

updateGcodeviewerCache({ dispatch, state }, payload) {
const klipperCache = (state.gcodeViewer.klipperCache as { [key: string]: any }) ?? {}

Object.keys(payload).forEach((key) => {
const value = payload[key]
const oldValue = key in klipperCache ? klipperCache[key] : null

if (JSON.stringify(value) !== JSON.stringify(oldValue))
dispatch('saveSetting', { name: `gcodeViewer.klipperCache.${key}`, value })
})
},
}
5 changes: 5 additions & 0 deletions src/store/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export const getDefaultState = (): GuiState => {
voxelWidth: 1,
voxelHeight: 1,
specularLighting: false,
klipperCache: {
kinematics: null,
axis_minimum: null,
axis_maximum: null,
},
},
uiSettings: {
logo: defaultLogoColor,
Expand Down
5 changes: 5 additions & 0 deletions src/store/gui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export interface GuiState {
voxelWidth: number
voxelHeight: number
specularLighting: boolean
klipperCache: {
kinematics: string | null
axis_minimum: number[] | null
axis_maximum: number[] | null
}
}
macros?: GuiMacrosState
presets?: GuiPresetsState
Expand Down
34 changes: 32 additions & 2 deletions src/store/printer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const actions: ActionTree<PrinterState, RootState> = {
Vue.$socket.emit('server.temperature_store', {}, { action: 'printer/tempHistory/init' })
},

getData({ commit, state }, payload) {
getData({ commit, dispatch, state }, payload) {
if ('status' in payload) payload = payload.status
if ('requestParams' in payload) delete payload.requestParams

Expand All @@ -73,7 +73,37 @@ export const actions: ActionTree<PrinterState, RootState> = {
if ('bed_mesh' in state && 'bed_mesh' in payload && 'profiles' in payload.bed_mesh) {
commit('setBedMeshProfiles', payload.bed_mesh.profiles)

delete payload.bed_mesh.profiles
delete payload.bed_mesh['profiles']
}

if (payload.configfile?.settings?.printer?.kinematics) {
dispatch(
'gui/updateGcodeviewerCache',
{
kinematics: payload.configfile?.settings?.printer?.kinematics,
},
{ root: true }
)
}

if (payload.toolhead?.axis_maximum) {
dispatch(
'gui/updateGcodeviewerCache',
{
axis_maximum: payload.toolhead?.axis_maximum,
},
{ root: true }
)
}

if (payload.toolhead?.axis_minimum) {
dispatch(
'gui/updateGcodeviewerCache',
{
axis_minimum: payload.toolhead?.axis_minimum,
},
{ root: true }
)
}

commit('setData', payload)
Expand Down

0 comments on commit 94ce369

Please sign in to comment.