From 29fedafce627548f148452315b79fcd57e214504 Mon Sep 17 00:00:00 2001 From: David Carley Date: Sat, 23 Jul 2022 21:30:10 -0700 Subject: [PATCH] Rebuilt the "Set Position" and "Manually Home" dialogs in Svelte --- src/js/control-view.js | 31 ++------- src/pug/templates/control-view.pug | 48 +------------- .../src/dialogs/DialogHost.svelte | 34 ++++++++++ .../src/dialogs/HomeMachineDialog.svelte | 1 + .../src/dialogs/ManualHomeAxisDialog.svelte | 46 +++++++++++++ .../src/dialogs/SetAxisPositionDialog.svelte | 64 +++++++++++++++++++ .../src/lib/RegisterControllerMethods.ts | 4 ++ 7 files changed, 159 insertions(+), 69 deletions(-) create mode 100644 src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte create mode 100644 src/svelte-components/src/dialogs/SetAxisPositionDialog.svelte diff --git a/src/js/control-view.js b/src/js/control-view.js index 00a1af9..47bf907 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -20,22 +20,6 @@ module.exports = { history: [], speed_override: 1, feed_override: 1, - manual_home: { - x: false, - y: false, - z: false, - a: false, - b: false, - c: false - }, - position_msg: { - x: false, - y: false, - z: false, - a: false, - b: false, - c: false - }, jog_incr_amounts: { "METRIC": { fine: 0.1, @@ -50,7 +34,6 @@ module.exports = { large: 5, } }, - axis_position: 0, jog_incr: localStorage.getItem("jog_incr") || 'small', jog_step: cookie.get_bool('jog-step'), jog_adjust: parseInt(cookie.get('jog-adjust', 2)), @@ -261,7 +244,11 @@ module.exports = { SvelteComponents.registerControllerMethods({ stop: (...args) => this.stop(...args), send: (...args) => this.send(...args), - goto_zero: (...args) => this.goto_zero(...args) + goto_zero: (...args) => this.goto_zero(...args), + isAxisHomed: (axis) => this[axis].homed, + unhome: (...args) => this.unhome(...args), + set_position: (...args) => this.set_position(...args), + set_home: (...args) => this.set_home(...args) }); }, @@ -433,23 +420,20 @@ module.exports = { } else if (this[axis].homingMode != 'manual') { api.put('home/' + axis); } else { - this.manual_home[axis] = true; + SvelteComponents.showDialog("ManualHomeAxis", { axis }); } }, set_home: function (axis, position) { - this.manual_home[axis] = false; api.put('home/' + axis + '/set', { position: parseFloat(position) }); }, unhome: function (axis) { - this.position_msg[axis] = false; api.put('home/' + axis + '/clear'); }, show_set_position: function (axis) { - this.axis_position = 0; - this.position_msg[axis] = true; + SvelteComponents.showDialog("SetAxisPosition", { axis }); }, show_toolpath_msg: function (axis) { @@ -457,7 +441,6 @@ module.exports = { }, set_position: function (axis, position) { - this.position_msg[axis] = false; api.put('position/' + axis, { 'position': parseFloat(position) }); }, diff --git a/src/pug/templates/control-view.pug b/src/pug/templates/control-view.pug index 21b2228..83845b9 100644 --- a/src/pug/templates/control-view.pug +++ b/src/pug/templates/control-view.pug @@ -150,60 +150,18 @@ script#control-view-template(type="text/x-template") th.actions button.pure-button(:disabled="!can_set_axis", title=`Set {{'${axis}' | upper}} axis position.`, - @click=`show_set_position('${axis}')`,style="height:60px;width:60px") + @click=`show_set_position('${axis}')`, style="height:60px;width:60px") .fa.fa-cog button.pure-button(:disabled="!can_set_axis", title=`Zero {{'${axis}' | upper}} axis offset.`, - @click=`zero('${axis}')`,style="height:60px;width:60px") + @click=`zero('${axis}')`, style="height:60px;width:60px") .fa.fa-map-marker button.pure-button(:disabled="!is_idle", @click=`home('${axis}')`, - title=`Home {{'${axis}' | upper}} axis.`,style="height:60px;width:60px") + title=`Home {{'${axis}' | upper}} axis.`, style="height:60px;width:60px") .fa.fa-home - message(:show.sync=`position_msg['${axis}']`) - h3(slot="header") Set {{'#{axis}' | upper}} axis position - - div(slot="body") - .pure-form - .pure-control-group - label Position - input(v-model="axis_position", - @keyup.enter=`set_position('${axis}', axis_position)`) - p - - div(slot="footer") - button.pure-button(@click=`position_msg['${axis}'] = false`) - | Cancel - - button.pure-button(v-if=`${axis}.homed`, - @click=`unhome('${axis}')`) Unhome - - button.pure-button.button-success( - @click=`set_position('${axis}', axis_position)`) Set - - message(:show.sync=`manual_home['${axis}']`) - h3(slot="header") Manually home {{'#{axis}' | upper}} axis - - div(slot="body") - p Set axis absolute position. - - .pure-form - .pure-control-group - label Absolute - input(v-model="axis_position", - @keyup.enter=`set_home('${axis}', axis_position)`) - - p - - div(slot="footer") - button.pure-button(@click=`manual_home['${axis}'] = false`) - | Cancel - - button.pure-button.button-success( - title=`Home {{'${axis}' | upper}} axis.`, - @click=`set_home('${axis}', axis_position)`) Set tr(style="vertical-align: top;") td diff --git a/src/svelte-components/src/dialogs/DialogHost.svelte b/src/svelte-components/src/dialogs/DialogHost.svelte index db1f8ed..a8765ec 100644 --- a/src/svelte-components/src/dialogs/DialogHost.svelte +++ b/src/svelte-components/src/dialogs/DialogHost.svelte @@ -5,6 +5,8 @@ import ScreenRotationDialog from "$dialogs/ScreenRotationDialog.svelte"; import UploadDialog from "$dialogs/UploadDialog.svelte"; import SetTimeDialog from "./SetTimeDialog.svelte"; + import ManualHomeAxisDialog from "./ManualHomeAxisDialog.svelte"; + import SetAxisPositionDialog from "./SetAxisPositionDialog.svelte"; const HomeMachineDialogProps = writable(); type HomeMachineDialogPropsType = { @@ -35,6 +37,18 @@ open: boolean; }; + const ManualHomeAxisDialogProps = writable(); + type ManualHomeAxisDialogPropsType = { + open: boolean; + axis: string; + }; + + const SetAxisPositionDialogProps = writable(); + type SetAxisPositionDialogPropsType = { + open: boolean; + axis: string; + }; + export function showDialog( dialog: "HomeMachine", props: Omit @@ -60,6 +74,16 @@ props: Omit ); + export function showDialog( + dialog: "ManualHomeAxis", + props: Omit + ); + + export function showDialog( + dialog: "SetAxisPosition", + props: Omit + ); + export function showDialog(dialog: string, props: any) { switch (dialog) { case "HomeMachine": @@ -82,6 +106,14 @@ SetTimeDialogProps.set({ ...props, open: true }); break; + case "ManualHomeAxis": + ManualHomeAxisDialogProps.set({ ...props, open: true }); + break; + + case "SetAxisPosition": + SetAxisPositionDialogProps.set({ ...props, open: true }); + break; + default: throw new Error(`Unknown dialog '${dialog}`); } @@ -93,3 +125,5 @@ + + diff --git a/src/svelte-components/src/dialogs/HomeMachineDialog.svelte b/src/svelte-components/src/dialogs/HomeMachineDialog.svelte index d4c1f3e..a5d36d8 100644 --- a/src/svelte-components/src/dialogs/HomeMachineDialog.svelte +++ b/src/svelte-components/src/dialogs/HomeMachineDialog.svelte @@ -8,6 +8,7 @@ diff --git a/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte b/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte new file mode 100644 index 0000000..eb08d36 --- /dev/null +++ b/src/svelte-components/src/dialogs/ManualHomeAxisDialog.svelte @@ -0,0 +1,46 @@ + + + + Manually Home {axis.toUpperCase()} Axis + +

Set axis absolute position

+ + +
+ + + + + +
diff --git a/src/svelte-components/src/dialogs/SetAxisPositionDialog.svelte b/src/svelte-components/src/dialogs/SetAxisPositionDialog.svelte new file mode 100644 index 0000000..8f49c26 --- /dev/null +++ b/src/svelte-components/src/dialogs/SetAxisPositionDialog.svelte @@ -0,0 +1,64 @@ + + + + Set {axis.toUpperCase()} Axis Position + + + + + + + {#if homed} + + {/if} + + + diff --git a/src/svelte-components/src/lib/RegisterControllerMethods.ts b/src/svelte-components/src/lib/RegisterControllerMethods.ts index e5975c7..f0b47d9 100644 --- a/src/svelte-components/src/lib/RegisterControllerMethods.ts +++ b/src/svelte-components/src/lib/RegisterControllerMethods.ts @@ -3,6 +3,10 @@ type ControllerMethods = { send: (gcode: string) => void; goto_zero: (x: number, y: number, z: number, a: number) => void; dispatch: (event: string, ...args: any[]) => void; + isAxisHomed: (axis: string) => boolean; + unhome: (axis: string) => void; + set_position: (axis: string, value: number) => void; + set_home: (axis: string, value: number) => void; } export let ControllerMethods: ControllerMethods;