From a0f003c9eb961fdd603e177796996181eb24de56 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 1 Dec 2024 20:46:54 +0100 Subject: [PATCH] feat(spoolman): add multi tool support (#1946) --- .../dialogs/SpoolmanChangeSpoolDialog.vue | 30 +++++++++ .../ExtruderControlPanelToolsItem.vue | 15 +++++ .../panels/Spoolman/SpoolmanToolsDropdown.vue | 37 +++++++++++ .../Spoolman/SpoolmanToolsDropdownItem.vue | 66 +++++++++++++++++++ src/components/panels/SpoolmanPanel.vue | 13 +++- src/locales/en.json | 2 + 6 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 src/components/panels/Spoolman/SpoolmanToolsDropdown.vue create mode 100644 src/components/panels/Spoolman/SpoolmanToolsDropdownItem.vue diff --git a/src/components/dialogs/SpoolmanChangeSpoolDialog.vue b/src/components/dialogs/SpoolmanChangeSpoolDialog.vue index 26abd8951..cfd200186 100644 --- a/src/components/dialogs/SpoolmanChangeSpoolDialog.vue +++ b/src/components/dialogs/SpoolmanChangeSpoolDialog.vue @@ -84,6 +84,7 @@ export default class SpoolmanChangeSpoolDialog extends Mixins(BaseMixin) { mdiRefresh = mdiRefresh @Prop({ required: true }) declare readonly showDialog: boolean + @Prop({ required: false, default: null }) declare readonly tool?: string search = '' @@ -135,6 +136,12 @@ export default class SpoolmanChangeSpoolDialog extends Mixins(BaseMixin) { return this.$store.state.server.config.config?.spoolman?.server ?? null } + get existsSaveVariables() { + const settings = this.$store.state.printer.configfile?.settings ?? {} + + return 'save_variables' in settings + } + openSpoolManager() { window.open(this.spoolManagerUrl, '_blank') } @@ -182,6 +189,29 @@ export default class SpoolmanChangeSpoolDialog extends Mixins(BaseMixin) { setSpool(spool: ServerSpoolmanStateSpool) { this.$store.dispatch('server/spoolman/setActiveSpool', spool.id) + + // Close the dialog if no tool is selected + if (!this.tool) { + this.close() + return + } + + // Set spool_id for tool + const gcode = `SET_GCODE_VARIABLE MACRO=${this.tool} VARIABLE=spool_id VALUE=${spool.id}` + this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' }) + this.$socket.emit('printer.gcode.script', { script: gcode }) + + // Close dialog if save_variables is not enabled + if (!this.existsSaveVariables) { + this.close() + return + } + + // Set spool_id to save_variable + const gcode2 = `SAVE_VARIABLE VARIABLE=${this.tool.toUpperCase()}__SPOOL_ID VALUE=${spool.id}` + this.$store.dispatch('server/addEvent', { message: gcode2, type: 'command' }) + this.$socket.emit('printer.gcode.script', { script: gcode2 }) + this.close() } diff --git a/src/components/panels/Extruder/ExtruderControlPanelToolsItem.vue b/src/components/panels/Extruder/ExtruderControlPanelToolsItem.vue index 707a2cd68..0818d7e3a 100644 --- a/src/components/panels/Extruder/ExtruderControlPanelToolsItem.vue +++ b/src/components/panels/Extruder/ExtruderControlPanelToolsItem.vue @@ -15,6 +15,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator' import { PrinterStateMacro } from '@/store/printer/types' import BaseMixin from '@/components/mixins/base' import ControlMixin from '@/components/mixins/control' +import { ServerSpoolmanStateSpool } from '@/store/server/spoolman/types' @Component({ components: {}, @@ -27,12 +28,26 @@ export default class ExtruderControlPanel extends Mixins(BaseMixin, ControlMixin } get color() { + if (this.spool) { + return this.spool.filament?.color_hex ?? '000000' + } + const color = this.macro.variables.color ?? this.macro.variables.colour ?? null if (color === '' || color === 'undefined') return null return color } + get spoolId() { + return this.macro.variables.spool_id ?? null + } + + get spool() { + const spools = this.$store.state.server.spoolman.spools ?? [] + + return spools.find((spool: ServerSpoolmanStateSpool) => spool.id === this.spoolId) ?? null + } + get primaryColor(): string { return this.$store.state.gui.uiSettings.primary } diff --git a/src/components/panels/Spoolman/SpoolmanToolsDropdown.vue b/src/components/panels/Spoolman/SpoolmanToolsDropdown.vue new file mode 100644 index 000000000..fb91b339f --- /dev/null +++ b/src/components/panels/Spoolman/SpoolmanToolsDropdown.vue @@ -0,0 +1,37 @@ + + + diff --git a/src/components/panels/Spoolman/SpoolmanToolsDropdownItem.vue b/src/components/panels/Spoolman/SpoolmanToolsDropdownItem.vue new file mode 100644 index 000000000..594adccd1 --- /dev/null +++ b/src/components/panels/Spoolman/SpoolmanToolsDropdownItem.vue @@ -0,0 +1,66 @@ + + + + + diff --git a/src/components/panels/SpoolmanPanel.vue b/src/components/panels/SpoolmanPanel.vue index 054a8786d..1d3ff304d 100644 --- a/src/components/panels/SpoolmanPanel.vue +++ b/src/components/panels/SpoolmanPanel.vue @@ -2,7 +2,8 @@