added reset macros button, trying gcode-viewer,

This commit is contained in:
sanjayk03-dev
2024-01-04 20:15:58 +05:30
parent f92feaac95
commit 83d69030ac
3 changed files with 189 additions and 162 deletions

View File

@@ -4,152 +4,155 @@ const api = require("./api");
const utils = require("./utils"); const utils = require("./utils");
module.exports = { module.exports = {
template: "#macros-template", template: "#macros-template",
props: [ "config", "template", "state" ], props: ["config", "template", "state"],
data: function (){ data: function () {
return { return {
tab: "1", tab: "1",
} };
},
components: {
"axis-control": require("./axis-control"),
"path-viewer": require("./path-viewer"),
"gcode-viewer": require("./gcode-viewer"),
},
computed: {
mach_state: function () {
const cycle = this.state.cycle;
const state = this.state.xx;
if (state != "ESTOPPED" && (cycle == "jogging" || cycle == "homing")) {
return cycle.toUpperCase();
}
return state || "";
}, },
components: { is_ready: function () {
"axis-control": require("./axis-control"), return this.mach_state == "READY";
"path-viewer": require("./path-viewer"),
"gcode-viewer": require("./gcode-viewer")
}, },
computed:{ },
mach_state: function() { methods: {
const cycle = this.state.cycle; open: function () {
const state = this.state.xx; utils.clickFileInput("gcode-file-input");
if (state != "ESTOPPED" && (cycle == "jogging" || cycle == "homing")) {
return cycle.toUpperCase();
}
return state || "";
},
is_ready: function() {
return this.mach_state == "READY";
},
}, },
methods:{ load: function () {
open: function() { const file_time = this.state.selected_time;
utils.clickFileInput("gcode-file-input"); console.log("file_time", file_time);
const file = this.state.selected;
console.log("file: ", file);
console.log("last_file: ",this.last_file);
console.log("last_file_time: ",this.last_file_time);
// if (this.last_file == file && this.last_file_time == file_time) {
// return;
// }
// this.last_file = file;
// this.last_file_time = file_time;
// this.$broadcast("gcode-load", file);
// this.$broadcast("gcode-line", this.state.line);
// this.toolpath_progress = 0;
// this.load_toolpath(file, file_time);
},
upload: function (e) {
const files = e.target.files || e.dataTransfer.files;
if (!files.length) {
return;
}
const file = files[0];
const extension = file.name.split(".").pop();
switch (extension.toLowerCase()) {
case "nc":
case "ngc":
case "gcode":
case "gc":
break;
default:
alert(`Unsupported file type: ${extension}`);
return;
}
SvelteComponents.showDialog("Upload", {
file,
onComplete: () => {
this.last_file_time = undefined; // Force reload
this.$broadcast("gcode-reload", file.name);
}, },
load: function() { });
const file_time = this.state.selected_time; },
console.log('file_time',file_time); saveMacros: async function (id) {
const file = this.state.selected; var macrosName = document.getElementById(`macros-name-${id}`).value;
console.log("file: ",file); var macrosColor = document.getElementById(`macros-color-${id}`).value;
// if (this.last_file == file && this.last_file_time == file_time) {
// return;
// }
// this.last_file = file; this.config.macros[id].name = macrosName;
// this.last_file_time = file_time; this.config.macros[id].color = macrosColor;
this.config.macros[id].gcode_file_name = this.state.selected;
this.config.macros[id].gcode_file_time = this.state.selected_time;
// this.$broadcast("gcode-load", file); console.log(this.config.macros);
// this.$broadcast("gcode-line", this.state.line); try {
// this.toolpath_progress = 0; await api.put("config/save", this.config);
// this.load_toolpath(file, file_time); console.log("Successfully saved");
this.$dispatch("update");
} catch (error) {
console.error("Restore Failed: ", error);
alert("Restore failed");
}
},
cancelMacros: function (id) {
document.getElementById(`macros-name-${id}`).value = '';
document.getElementById(`macros-color-${id}`).value = '';
},
resetConfig: async function () {
this.config.macros = [
{
name: " ",
color: "#efefef",
gcode_file_name: " ",
gcode_file_time: 0,
}, },
upload: function(e) { {
const files = e.target.files || e.dataTransfer.files; name: " ",
if (!files.length) { color: "#efefef",
return; gcode_file_name: " ",
} gcode_file_time: 0,
const file = files[0];
const extension = file.name.split(".").pop();
switch (extension.toLowerCase()) {
case "nc":
case "ngc":
case "gcode":
case "gc":
break;
default:
alert(`Unsupported file type: ${extension}`);
return;
}
SvelteComponents.showDialog("Upload", {
file,
onComplete: () => {
this.last_file_time = undefined; // Force reload
this.$broadcast("gcode-reload", file.name);
}
});
}, },
saveMacros: async function(id){ {
var macrosName = document.getElementById(`macros-name-${id}`).value; name: " ",
var macrosColor = document.getElementById(`macros-color-${id}`).value; color: "#efefef",
gcode_file_name: " ",
this.config.macros[id].name=macrosName; gcode_file_time: 0,
this.config.macros[id].color=macrosColor;
this.config.macros[id].gcode_file_name=this.state.selected;
this.config.macros[id].gcode_file_time=this.state.selected_time;
console.log(this.config.macros);
try {
await api.put("config/save",this.config);
console.log("Successfully saved");
this.$dispatch("update");
} catch (error) {
console.error("Restore Failed: ",error);
alert("Restore failed");
}
}, },
printConfig: function(){ {
console.log(this.config); name: " ",
color: "#efefef",
gcode_file_name: " ",
gcode_file_time: 0,
}, },
flushConfig: async function(){ {
this.config.macros=[ name: " ",
{ color: "#efefef",
name:"Macros 1", gcode_file_name: " ",
color: "#efefef", gcode_file_time: 0,
gcode_file_name: " ", },
gcode_file_time: 0 {
}, name: " ",
{ color: "#efefef",
name:"Macros 2", gcode_file_name: " ",
color: "#efefef", gcode_file_time: 0,
gcode_file_name: " ", },
gcode_file_time: 0 ];
}, try {
{ await api.put("config/save", this.config);
name:"Macros 3", console.log("Successfully flushed");
color: "#efefef", this.$dispatch("update");
gcode_file_name: " ", } catch (error) {
gcode_file_time: 0 console.error("Restore Failed: ", error);
}, alert("Restore failed");
{ }
name:"Macros 4", },
color: "#efefef", },
gcode_file_name: " ", };
gcode_file_time: 0
},
{
name:"Macros 5",
color: "#efefef",
gcode_file_name: " ",
gcode_file_time: 0
},
{
name:"Macros 6",
color: "#efefef",
gcode_file_name: " ",
gcode_file_time: 0
},
]
try {
await api.put("config/save",this.config);
console.log("Successfully flushed");
this.$dispatch("update");
} catch (error) {
console.error("Restore Failed: ",error);
alert("Restore failed");
}
}
}
}

View File

@@ -1,6 +1,12 @@
script#macros-template(type="text/x-template") script#macros-template(type="text/x-template")
#macros #macros
h1 Macros Configuration h1 Macros Configuration
button.pure-button(title="Print config.", @click="resetConfig",
style="height:50px;width:120px;font-weight:normal;padding-vertical:5px;background-color:#5a9ad7") Reset Macros
.warning-box
p
u Note:
| Reset the macros to default macros recommended by Onefinity CNC.
.tabs .tabs
input#tab1(type="radio", name="tabs",checked="" @click="tab = '1'") input#tab1(type="radio", name="tabs",checked="" @click="tab = '1'")
label(for="tab1",style="height:50px;width:100px") Macros 1 label(for="tab1",style="height:50px;width:100px") Macros 1
@@ -22,11 +28,11 @@ script#macros-template(type="text/x-template")
section#content1.tab-content section#content1.tab-content
.macros-form .macros-form
p.title Enter Macros Name p.title Name
.input-container .input-container
input.input-color(type="color",id="macros-color-0",value="#ffffff") input.input-color(type="color",id="macros-color-0",value="#ffffff")
input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-0") input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-0")
p.title Select/Upload G-Code p.title G-Code
select(title="Select previously uploaded GCode programs.", select(title="Select previously uploaded GCode programs.",
v-model="state.selected", @change="load", :disabled="!is_ready", v-model="state.selected", @change="load", :disabled="!is_ready",
style="max-width:100%;height:40px;border-radius:5px") style="max-width:100%;height:40px;border-radius:5px")
@@ -39,16 +45,19 @@ script#macros-template(type="text/x-template")
input(type="file", @change="upload", :disabled="!is_ready", input(type="file", @change="upload", :disabled="!is_ready",
accept=".nc,.ngc,.gcode,.gc") accept=".nc,.ngc,.gcode,.gc")
br br
gcode-viewer
button.submit-macros(title="Save Macros",@click="saveMacros(0)", button.submit-macros(title="Save Macros",@click="saveMacros(0)",
style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save Macros style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save
button.submit-macros(title="Save Macros",@click="cancelMacros(0)",
style="height:50px;width:140px;font-weight:normal;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel
section#content2.tab-content section#content2.tab-content
.macros-form .macros-form
p.title Enter Macros Name p.title Name
.input-container .input-container
input.input-color(type="color",id="macros-color-1",value="#ffffff") input.input-color(type="color",id="macros-color-1",value="#ffffff")
input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-1") input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-1")
p.title Select/Upload G-Code p.title G-Code
select(title="Select previously uploaded GCode programs.", select(title="Select previously uploaded GCode programs.",
v-model="state.selected", @change="load", :disabled="!is_ready", v-model="state.selected", @change="load", :disabled="!is_ready",
style="max-width:100%;height:40px;border-radius:5px") style="max-width:100%;height:40px;border-radius:5px")
@@ -61,16 +70,19 @@ script#macros-template(type="text/x-template")
input(type="file", @change="upload", :disabled="!is_ready", input(type="file", @change="upload", :disabled="!is_ready",
accept=".nc,.ngc,.gcode,.gc") accept=".nc,.ngc,.gcode,.gc")
br br
gcode-viewer
button.submit-macros(title="Save Macros",@click="saveMacros(1)", button.submit-macros(title="Save Macros",@click="saveMacros(1)",
style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save Macros style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save
button.submit-macros(title="Save Macros",@click="cancelMacros(1)",
style="height:50px;width:140px;font-weight:normal;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel
section#content3.tab-content section#content3.tab-content
.macros-form .macros-form
p.title Enter Macros Name p.title Name
.input-container .input-container
input.input-color(type="color",id="macros-color-2",value="#ffffff") input.input-color(type="color",id="macros-color-2",value="#ffffff")
input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-2") input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-2")
p.title Select/Upload G-Code p.title G-Code
select(title="Select previously uploaded GCode programs.", select(title="Select previously uploaded GCode programs.",
v-model="state.selected", @change="load", :disabled="!is_ready", v-model="state.selected", @change="load", :disabled="!is_ready",
style="max-width:100%;height:40px;border-radius:5px") style="max-width:100%;height:40px;border-radius:5px")
@@ -83,16 +95,19 @@ script#macros-template(type="text/x-template")
input(type="file", @change="upload", :disabled="!is_ready", input(type="file", @change="upload", :disabled="!is_ready",
accept=".nc,.ngc,.gcode,.gc") accept=".nc,.ngc,.gcode,.gc")
br br
gcode-viewer
button.submit-macros(title="Save Macros",@click="saveMacros(2)", button.submit-macros(title="Save Macros",@click="saveMacros(2)",
style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save Macros style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save
button.submit-macros(title="Save Macros",@click="cancelMacros(2)",
style="height:50px;width:140px;font-weight:normal;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel
section#content4.tab-content section#content4.tab-content
.macros-form .macros-form
p.title Enter Macros Name p.title Name
.input-container .input-container
input.input-color(type="color",id="macros-color-3",value="#ffffff") input.input-color(type="color",id="macros-color-3",value="#ffffff")
input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-3") input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-3")
p.title Select/Upload G-Code p.title G-Code
select(title="Select previously uploaded GCode programs.", select(title="Select previously uploaded GCode programs.",
v-model="state.selected", @change="load", :disabled="!is_ready", v-model="state.selected", @change="load", :disabled="!is_ready",
style="max-width:100%;height:40px;border-radius:5px") style="max-width:100%;height:40px;border-radius:5px")
@@ -105,16 +120,19 @@ script#macros-template(type="text/x-template")
input(type="file", @change="upload", :disabled="!is_ready", input(type="file", @change="upload", :disabled="!is_ready",
accept=".nc,.ngc,.gcode,.gc") accept=".nc,.ngc,.gcode,.gc")
br br
gcode-viewer
button.submit-macros(title="Save Macros",@click="saveMacros(3)", button.submit-macros(title="Save Macros",@click="saveMacros(3)",
style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save Macros style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save
button.submit-macros(title="Save Macros",@click="cancelMacros(3)",
style="height:50px;width:140px;font-weight:normal;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel
section#content5.tab-content section#content5.tab-content
.macros-form .macros-form
p.title Enter Macros Name p.title Name
.input-container .input-container
input.input-color(type="color",id="macros-color-4",value="#ffffff") input.input-color(type="color",id="macros-color-4",value="#ffffff")
input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-4") input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-4")
p.title Select/Upload G-Code p.title G-Code
select(title="Select previously uploaded GCode programs.", select(title="Select previously uploaded GCode programs.",
v-model="state.selected", @change="load", :disabled="!is_ready", v-model="state.selected", @change="load", :disabled="!is_ready",
style="max-width:100%;height:40px;border-radius:5px") style="max-width:100%;height:40px;border-radius:5px")
@@ -127,16 +145,19 @@ script#macros-template(type="text/x-template")
input(type="file", @change="upload", :disabled="!is_ready", input(type="file", @change="upload", :disabled="!is_ready",
accept=".nc,.ngc,.gcode,.gc") accept=".nc,.ngc,.gcode,.gc")
br br
gcode-viewer
button.submit-macros(title="Save Macros",@click="saveMacros(4)", button.submit-macros(title="Save Macros",@click="saveMacros(4)",
style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save Macros style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save
button.submit-macros(title="Save Macros",@click="cancelMacros(4)",
style="height:50px;width:140px;font-weight:normal;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel
section#content6.tab-content section#content6.tab-content
.macros-form .macros-form
p.title Enter Macros Name p.title Name
.input-container .input-container
input.input-color(type="color",id="macros-color-5",value="#ffffff") input.input-color(type="color",id="macros-color-5",value="#ffffff")
input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-5") input.input-name(type="text",minlength='1',maxlength='15',id="macros-name-5")
p.title Select/Upload G-Code p.title G-Code
select(title="Select previously uploaded GCode programs.", select(title="Select previously uploaded GCode programs.",
v-model="state.selected", @change="load", :disabled="!is_ready", v-model="state.selected", @change="load", :disabled="!is_ready",
style="max-width:100%;height:40px;border-radius:5px") style="max-width:100%;height:40px;border-radius:5px")
@@ -149,11 +170,8 @@ script#macros-template(type="text/x-template")
input(type="file", @change="upload", :disabled="!is_ready", input(type="file", @change="upload", :disabled="!is_ready",
accept=".nc,.ngc,.gcode,.gc") accept=".nc,.ngc,.gcode,.gc")
br br
gcode-viewer
button.submit-macros(title="Save Macros",@click="saveMacros(5)", button.submit-macros(title="Save Macros",@click="saveMacros(5)",
style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save Macros style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save
button.submit-macros(title="Save Macros",@click="cancelMacros(5)",
//- button.pure-button(title="Print config.", @click="printConfig", style="height:50px;width:140px;font-weight:normal;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel
//- style="height:50px;width:120px;font-weight:normal;padding-top:5px") print Config
//- button.pure-button(title="Print config.", @click="flushConfig",
//- style="height:50px;width:120px;font-weight:normal;padding-top:5px") Flush Config

View File

@@ -631,6 +631,12 @@ span.unit
.macros .macros
width 90% width 90%
.warning-box
background-color #f9ff17
border-radius 10px
border 0
padding 4px
.tabs .tabs
margin-top 5px margin-top 5px