Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: copy bed mesh into clipboard as image #1272

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 50 additions & 6 deletions src/components/widgets/bedmesh/BedMeshCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
:collapsable="!fullscreen"
layout-path="dashboard.bed-mesh-card"
>
<template
v-if="!fullscreen"
#menu
>
<template #menu>
<app-btn
v-if="!fullscreen"
small
class="ms-1 my-1"
:loading="hasWait($waits.onMeshCalibrate)"
Expand All @@ -21,11 +19,35 @@
{{ $t('app.general.btn.calibrate') }}
</app-btn>

<v-tooltip
v-if="canCopyImage"
bottom
>
<template #activator="{ on, attrs }">
<app-btn
v-bind="attrs"
color=""
fab
x-small
text
class="ms-1 my-1"
:disabled="!hasMeshLoaded"
v-on="on"
@click="copyImage()"
>
<v-icon>$screenshot</v-icon>
</app-btn>
</template>
<span>{{ $t('app.bedmesh.tooltip.copy_image') }}</span>
</v-tooltip>

<app-btn
v-if="!fullscreen"
color=""
fab
x-small
text
class="ms-1 my-1"
@click="$filters.routeTo($router, '/tune')"
>
<v-icon>$fullScreen</v-icon>
Expand All @@ -34,7 +56,7 @@

<v-card-text>
<bed-mesh-chart
v-if="mesh && mesh[matrix] && mesh[matrix].coordinates && mesh[matrix].coordinates.length > 0"
v-if="hasMeshLoaded"
ref="chart"
:options="options"
:data="series"
Expand All @@ -48,7 +70,7 @@
</template>

<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator'
import { Component, Mixins, Prop, Ref } from 'vue-property-decorator'
import BedMeshChart from './BedMeshChart.vue'
import StateMixin from '@/mixins/state'
import ToolheadMixin from '@/mixins/toolhead'
Expand All @@ -64,6 +86,16 @@ export default class BedMeshCard extends Mixins(StateMixin, ToolheadMixin, Brows
@Prop({ type: Boolean })
readonly fullscreen?: boolean

@Ref('chart')
readonly bedMeshChart!: BedMeshChart

get hasMeshLoaded () {
const mesh = this.mesh
const matrix = this.matrix

return mesh && mesh[matrix] && mesh[matrix].coordinates && mesh[matrix].coordinates.length > 0
}

get options () {
const map_scale = this.scale / 2
const box_scale = this.boxScale / 2
Expand Down Expand Up @@ -199,5 +231,17 @@ export default class BedMeshCard extends Mixins(StateMixin, ToolheadMixin, Brows
get mesh (): AppMeshes {
return this.$store.getters['mesh/getCurrentMeshData'] as AppMeshes
}

get canCopyImage () {
return (
typeof navigator.clipboard === 'object' &&
typeof navigator.clipboard.write === 'function' &&
typeof ClipboardItem === 'function'
)
}

copyImage () {
this.bedMeshChart.copyImage()
}
}
</script>
12 changes: 12 additions & 0 deletions src/components/widgets/bedmesh/BedMeshChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ export default class BedMeshChart extends Mixins(BrowserMixin) {
}
return text
}

async copyImage () {
const image = await fetch(this.chart.getDataURL({ type: 'png', backgroundColor: '#262629' }))

const blob = await image.blob()

const data = [
new ClipboardItem({ 'image/png': blob })
]

await navigator.clipboard.write(data)
}
}
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import {
mdiArchiveLock,
mdiFileImage,
mdiGauge,
mdiMonitorScreenshot,
mdiRotateLeft,
mdiRotateRight,
mdiToothbrush
Expand Down Expand Up @@ -403,6 +404,7 @@ export const Icons = Object.freeze({
jobQueue: mdiTrayFull,
enqueueJob: mdiTrayPlus,
sensors: mdiGauge,
screenshot: mdiMonitorScreenshot,
zRotateClockwise: mdiRotateRight,
zRotateCounterclockwise: mdiRotateLeft
})
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ app:
delete: Delete Profile
load: Load Profile
save: Commits calibrated profile to printer.cfg
copy_image: Copy bed mesh image
chart:
label:
current: Actual
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ app:
delete: Supprime le profil
load: Charger le profil
save: Enregistrer le profil calibré dans 'printer.cfg'
copy_image: Copier l'image du bed mesh
chart:
label:
current: Courant
Expand Down