Skip to content

Commit

Permalink
feat: improve support for adaptive bedmeshes (#1328)
Browse files Browse the repository at this point in the history
Signed-off-by: Mathis Mensing <github@matmen.dev>
Co-authored-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
matmen and pedrolamas committed Jan 29, 2024
1 parent 1a273dd commit 447a340
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 25 deletions.
20 changes: 15 additions & 5 deletions src/components/widgets/bedmesh/BedMeshControls.vue
Expand Up @@ -84,6 +84,7 @@
fab
text
x-small
:disabled="item.adaptive"
@click="removeProfile(item.name)"
v-on="on"
>
Expand Down Expand Up @@ -265,6 +266,7 @@
v-if="saveDialogState.open"
v-model="saveDialogState.open"
:existing-name="saveDialogState.existingName"
:adaptive="saveDialogState.adaptive"
@save="handleMeshSave"
/>

Expand All @@ -280,7 +282,12 @@ import { Component, Mixins, Watch } from 'vue-property-decorator'
import SaveMeshDialog from './SaveMeshDialog.vue'
import StateMixin from '@/mixins/state'
import ToolheadMixin from '@/mixins/toolhead'
import type { MeshState, BedMeshProfile, KlipperBedMesh, MatrixType } from '@/store/mesh/types'
import type {
MeshState,
KlipperBedMesh,
MatrixType,
BedMeshProfileListEntry
} from '@/store/mesh/types'
@Component({
components: {
Expand All @@ -295,7 +302,8 @@ export default class BedMesh extends Mixins(StateMixin, ToolheadMixin) {
saveDialogState = {
open: false,
existingName: 'default'
existingName: 'default',
adaptive: false
}
get matrix () {
Expand Down Expand Up @@ -343,8 +351,8 @@ export default class BedMesh extends Mixins(StateMixin, ToolheadMixin) {
}
// The available meshes.
get bedMeshProfiles () {
return this.$store.getters['mesh/getBedMeshProfiles'] as BedMeshProfile[]
get bedMeshProfiles (): BedMeshProfileListEntry[] {
return this.$store.getters['mesh/getBedMeshProfiles']
}
// The current mesh, unprocessed.
Expand Down Expand Up @@ -408,9 +416,11 @@ export default class BedMesh extends Mixins(StateMixin, ToolheadMixin) {
}
handleOpenSaveDialog () {
const profile = this.bedMeshProfiles.find(mesh => mesh.name === this.currentMesh.profile_name)
this.saveDialogState = {
open: true,
existingName: this.currentMesh.profile_name
existingName: this.currentMesh.profile_name,
adaptive: profile?.adaptive ?? false
}
}
Expand Down
25 changes: 15 additions & 10 deletions src/components/widgets/bedmesh/SaveMeshDialog.vue
Expand Up @@ -19,17 +19,19 @@
:label="$t('app.bedmesh.label.profile_name')"
/>

<v-checkbox
v-model="removeDefault"
:label="$t('app.bedmesh.label.remove_profile', { name: existingName })"
hide-details="auto"
class="mb-4"
:disabled="name === existingName"
/>
<template v-if="!adaptive">
<v-checkbox
v-model="removeDefault"
:label="$t('app.bedmesh.label.remove_profile', { name: existingName })"
hide-details="auto"
class="mb-4"
:disabled="name === existingName"
/>

<span>
{{ $t('app.bedmesh.msg.hint', { name: existingName }) }}
</span>
<span>
{{ $t('app.bedmesh.msg.hint', { name: existingName }) }}
</span>
</template>
</v-card-text>
</app-dialog>
</template>
Expand All @@ -47,6 +49,9 @@ export default class SaveMeshDialog extends Mixins(StateMixin, ToolheadMixin) {
@Prop({ type: String })
readonly existingName!: string
@Prop({ type: Boolean })
readonly adaptive!: boolean
mounted () {
this.name = 'default'
this.removeDefault = false
Expand Down
31 changes: 24 additions & 7 deletions src/store/mesh/getters.ts
@@ -1,5 +1,12 @@
import type { GetterTree } from 'vuex'
import type { BedMeshProfile, MeshState, AppMeshes, KlipperBedMesh, KlipperBedMeshProfile, LegacyKlipperBedMeshProfile } from './types'
import type {
MeshState,
AppMeshes,
KlipperBedMesh,
KlipperBedMeshProfile,
LegacyKlipperBedMeshProfile,
BedMeshProfileListEntry
} from './types'
import type { RootState } from '../types'
import { transformMesh } from '@/util/transform-mesh'

Expand Down Expand Up @@ -47,8 +54,8 @@ export const getters: GetterTree<MeshState, RootState> = {
return klipperProfiles
},

getBedMeshProfiles: (state, getters, rootState) => {
const profiles: BedMeshProfile[] = []
getBedMeshProfiles: (state, getters, rootState): BedMeshProfileListEntry[] => {
const profiles: BedMeshProfileListEntry[] = []
const bedMesh = rootState.printer.printer.bed_mesh as KlipperBedMesh

const klipperProfiles = bedMesh.profiles ?? getters.getLegacyBedMeshProfiles as Record<string, KlipperBedMeshProfile>
Expand All @@ -61,10 +68,20 @@ export const getters: GetterTree<MeshState, RootState> = {
profiles.push({
name,
active: name === bedMesh.profile_name,
min,
max,
range: Math.abs(min - max),
...profile
adaptive: false,
range: Math.abs(min - max)
})
}

if (bedMesh.profile_name && !(bedMesh.profile_name in klipperProfiles)) {
const min = Math.min(...(bedMesh.mesh_matrix?.flat() ?? [0]))
const max = Math.max(...(bedMesh.mesh_matrix?.flat() ?? [0]))

profiles.push({
name: bedMesh.profile_name,
active: true,
adaptive: true,
range: max - min
})
}

Expand Down
5 changes: 2 additions & 3 deletions src/store/mesh/types.ts
Expand Up @@ -51,11 +51,10 @@ export interface KlipperBedMeshProfileMeshParams {
y_count: number;
}

export interface BedMeshProfile extends KlipperBedMeshProfile {
export interface BedMeshProfileListEntry {
name: string;
active: boolean;
min: number;
max: number,
adaptive: boolean;
range: number;
}

Expand Down

0 comments on commit 447a340

Please sign in to comment.