Skip to content

Commit

Permalink
feat(spoolman): allow toggling individual sanity check warnings (#1186)
Browse files Browse the repository at this point in the history
Signed-off-by: Mathis Mensing <[email protected]>
  • Loading branch information
matmen authored Sep 23, 2023
1 parent 899c95c commit 2086c19
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 34 deletions.
46 changes: 46 additions & 0 deletions src/components/settings/SpoolmanSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@
/>
</app-setting>

<v-divider />
<app-setting
:title="$t('app.spoolman.setting.warn_on_not_enough_filament')"
>
<v-switch
v-model="warnOnNotEnoughFilament"
hide-details
class="mt-0 mb-4"
/>
</app-setting>

<v-divider />
<app-setting
:title="$t('app.spoolman.setting.warn_on_filament_type_mismatch')"
>
<v-switch
v-model="warnOnFilamentTypeMismatch"
hide-details
class="mt-0 mb-4"
/>
</app-setting>

<v-divider />
<app-setting :title="$t('app.setting.label.reset')">
<app-btn
Expand Down Expand Up @@ -135,6 +157,30 @@ export default class SpoolmanSettings extends Mixins(StateMixin) {
})
}
get warnOnNotEnoughFilament () {
return this.$store.state.config.uiSettings.spoolman.warnOnNotEnoughFilament
}
set warnOnNotEnoughFilament (value: boolean) {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.spoolman.warnOnNotEnoughFilament',
value,
server: true
})
}
get warnOnFilamentTypeMismatch () {
return this.$store.state.config.uiSettings.spoolman.warnOnFilamentTypeMismatch
}
set warnOnFilamentTypeMismatch (value: boolean) {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.spoolman.warnOnFilamentTypeMismatch',
value,
server: true
})
}
handleReset () {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.spoolman',
Expand Down
89 changes: 56 additions & 33 deletions src/components/widgets/spoolman/SpoolSelectionDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ export default class SpoolSelectionDialog extends Mixins(StateMixin, BrowserMixi
SocketActions.serverFilesMetadata(this.currentFileName)
}
if (this.hasDeviceCamera && this.$store.state.config.uiSettings.spoolman.preferDeviceCamera) {
if (this.hasDeviceCamera && this.preferDeviceCamera) {
this.$nextTick(() => (this.cameraScanSource = 'device'))
} else {
const autoOpenCameraId = this.$store.state.config.uiSettings.spoolman.autoOpenQRDetectionCamera
const autoOpenCameraId = this.autoOpenQRDetectionCamera
if (this.$store.getters['cameras/getCameraById'](autoOpenCameraId)) {
this.$nextTick(() => (this.cameraScanSource = autoOpenCameraId))
}
Expand Down Expand Up @@ -344,7 +344,7 @@ export default class SpoolSelectionDialog extends Mixins(StateMixin, BrowserMixi
this.search = ''
}
if (this.$store.state.config.uiSettings.spoolman.autoSelectSpoolOnMatch) {
if (this.autoSelectSpoolOnMatch) {
this.handleSelectSpool()
}
}
Expand All @@ -364,30 +364,25 @@ export default class SpoolSelectionDialog extends Mixins(StateMixin, BrowserMixi
}
const spool = this.availableSpools.find(spool => spool.id === this.selectedSpool)
if (spool && this.filename) {
// check for enough filament
if (spool && this.filename && (this.warnOnFilamentTypeMismatch || this.warnOnNotEnoughFilament)) {
let requiredLength = 0 // l[mm]
let remainingLength = spool.remaining_length
if (!remainingLength && spool.remaining_weight) {
// l[mm] = m[g]/D[g/cm³]/A[mm²]*(1000mm³/cm³)
remainingLength = spool.remaining_weight / spool.filament.density / (Math.PI * (spool.filament.diameter / 2) ** 2) * 1000
}
// l[mm]
let requiredLength = 0
if (this.currentFile) {
const fileMaterial = this.currentFile.filament_type?.toLowerCase()
const spoolMaterial = spool.filament.material?.toLowerCase()
if (spoolMaterial && fileMaterial && fileMaterial !== spoolMaterial) {
// filament materials don't match
const confirmation = await this.$confirm(
this.$tc('app.spoolman.msg.mismatched_filament'),
{ title: this.$tc('app.general.label.confirm'), color: 'card-heading', icon: '$warning' }
)
if (!confirmation) {
return
if (this.warnOnFilamentTypeMismatch) {
const fileMaterials = this.currentFile.filament_type?.toLowerCase()
.split(';').map((x: string) => x.replace(/"/g, ''))
const spoolMaterial = spool.filament.material?.toLowerCase()
if (spoolMaterial && fileMaterials && !fileMaterials.includes(spoolMaterial)) {
// filament materials don't match
const confirmation = await this.$confirm(
this.$tc('app.spoolman.msg.mismatched_filament'),
{ title: this.$tc('app.general.label.confirm'), color: 'card-heading', icon: '$warning' }
)
if (!confirmation) {
return
}
}
}
Expand All @@ -412,16 +407,24 @@ export default class SpoolSelectionDialog extends Mixins(StateMixin, BrowserMixi
}
}
if (typeof remainingLength === 'number' && requiredLength >= remainingLength) {
// not enough filament
if (this.warnOnNotEnoughFilament) {
let remainingLength = spool.remaining_length
if (!remainingLength && spool.remaining_weight) {
// l[mm] = m[g]/D[g/cm³]/A[mm²]*(1000mm³/cm³)
remainingLength = spool.remaining_weight / spool.filament.density / (Math.PI * (spool.filament.diameter / 2) ** 2) * 1000
}
const confirmation = await this.$confirm(
this.$tc('app.spoolman.msg.no_filament'),
{ title: this.$tc('app.general.label.confirm'), color: 'card-heading', icon: '$warning' }
)
if (typeof remainingLength === 'number' && requiredLength >= remainingLength) {
// not enough filament
if (!confirmation) {
return
const confirmation = await this.$confirm(
this.$tc('app.spoolman.msg.no_filament'),
{ title: this.$tc('app.general.label.confirm'), color: 'card-heading', icon: '$warning' }
)
if (!confirmation) {
return
}
}
}
}
Expand All @@ -446,6 +449,26 @@ export default class SpoolSelectionDialog extends Mixins(StateMixin, BrowserMixi
get spoolmanURL () {
return this.$store.state.server.config.spoolman?.server
}
get preferDeviceCamera () {
return this.$store.state.config.uiSettings.spoolman.preferDeviceCamera
}
get autoOpenQRDetectionCamera () {
return this.$store.state.config.uiSettings.spoolman.autoOpenQRDetectionCamera
}
get autoSelectSpoolOnMatch () {
return this.$store.state.config.uiSettings.spoolman.autoSelectSpoolOnMatch
}
get warnOnNotEnoughFilament () {
return this.$store.state.config.uiSettings.spoolman.warnOnNotEnoughFilament
}
get warnOnFilamentTypeMismatch (): boolean {
return this.$store.state.config.uiSettings.spoolman.warnOnFilamentTypeMismatch
}
}
</script>

Expand Down
4 changes: 4 additions & 0 deletions src/locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -754,3 +754,7 @@ app:
auto_select_spool_on_match: Spulenauswahl bei QR-Code- Übereinstimmung automatisch übernehmen
prefer_device_camera: Gerätekamera wenn verfügbar zur QR-Code- Erkennung verwenden
show_spool_selection_dialog_on_print_start: Spulenauswahl-Dialog automatisch bei Druckstart anzeigen
warn_on_not_enough_filament: >-
Warnung anzeigen, wenn die Spule nicht genug Filament verbleibend hat, um den Druck abzuschließen
warn_on_filament_type_mismatch: >-
Warnung anzeigen, wenn der Filamenttyp der Spule nicht mit dem im Slicer ausgewählten übereinstimmt
4 changes: 4 additions & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -821,3 +821,7 @@ app:
auto_select_spool_on_match: Automatically commit spool selection on QR code match
prefer_device_camera: Use device camera for QR code detection if available
show_spool_selection_dialog_on_print_start: Show spool selection dialog on print start
warn_on_not_enough_filament: >-
Show a warning when the selected spool doesn't have enough filament left on it to finish the print
warn_on_filament_type_mismatch: >-
Show a warning when the spool's filament type and the one selected in the slicer don't match
4 changes: 3 additions & 1 deletion src/store/config/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ export const defaultState = (): ConfigState => {
autoSpoolSelectionDialog: true,
autoOpenQRDetectionCamera: null,
autoSelectSpoolOnMatch: false,
preferDeviceCamera: false
preferDeviceCamera: false,
warnOnNotEnoughFilament: true,
warnOnFilamentTypeMismatch: 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 @@ -36,6 +36,8 @@ export interface SpoolmanConfig {
autoOpenQRDetectionCamera: string | null;
autoSelectSpoolOnMatch: boolean;
preferDeviceCamera: boolean;
warnOnNotEnoughFilament: boolean;
warnOnFilamentTypeMismatch: boolean;
}

export interface HostConfig {
Expand Down

0 comments on commit 2086c19

Please sign in to comment.