Fixed mainaining state while deleting, removed time from config
This commit is contained in:
@@ -6,9 +6,9 @@ const cookie = require("./cookie")("bbctrl-");
|
||||
|
||||
module.exports = {
|
||||
template: "#control-view-template",
|
||||
props: [ "config", "template", "state" ],
|
||||
props: ["config", "template", "state"],
|
||||
|
||||
data: function() {
|
||||
data: function () {
|
||||
return {
|
||||
current_time: "",
|
||||
mach_units: this.$root.state.metric ? "METRIC" : "IMPERIAL",
|
||||
@@ -22,18 +22,18 @@ module.exports = {
|
||||
speed_override: 1,
|
||||
feed_override: 1,
|
||||
jog_incr_amounts: {
|
||||
"METRIC": {
|
||||
METRIC: {
|
||||
fine: 0.1,
|
||||
small: 1.0,
|
||||
medium: 10,
|
||||
large: 100,
|
||||
},
|
||||
"IMPERIAL": {
|
||||
IMPERIAL: {
|
||||
fine: 0.005,
|
||||
small: 0.05,
|
||||
medium: 0.5,
|
||||
large: 5,
|
||||
}
|
||||
},
|
||||
},
|
||||
jog_incr: localStorage.getItem("jog_incr") || "small",
|
||||
jog_step: cookie.get_bool("jog-step"),
|
||||
@@ -48,60 +48,58 @@ module.exports = {
|
||||
components: {
|
||||
"axis-control": require("./axis-control"),
|
||||
"path-viewer": require("./path-viewer"),
|
||||
"gcode-viewer": require("./gcode-viewer")
|
||||
"gcode-viewer": require("./gcode-viewer"),
|
||||
},
|
||||
|
||||
watch: {
|
||||
jog_incr: function(value) {
|
||||
jog_incr: function (value) {
|
||||
localStorage.setItem("jog_incr", value);
|
||||
},
|
||||
|
||||
"state.metric": {
|
||||
handler: function(metric) {
|
||||
this.mach_units = metric
|
||||
? "METRIC"
|
||||
: "IMPERIAL";
|
||||
handler: function (metric) {
|
||||
this.mach_units = metric ? "METRIC" : "IMPERIAL";
|
||||
},
|
||||
immediate: true
|
||||
immediate: true,
|
||||
},
|
||||
|
||||
"state.line": function() {
|
||||
"state.line": function () {
|
||||
if (this.mach_state != "HOMING") {
|
||||
this.$broadcast("gcode-line", this.state.line);
|
||||
}
|
||||
},
|
||||
|
||||
"state.selected_time": function() {
|
||||
"state.selected_time": function () {
|
||||
this.loadGCode();
|
||||
},
|
||||
|
||||
jog_step: function() {
|
||||
jog_step: function () {
|
||||
cookie.set_bool("jog-step", this.jog_step);
|
||||
},
|
||||
|
||||
jog_adjust: function() {
|
||||
jog_adjust: function () {
|
||||
cookie.set("jog-adjust", this.jog_adjust);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
computed: {
|
||||
display_units: {
|
||||
cache: false,
|
||||
get: function() {
|
||||
get: function () {
|
||||
return this.$root.display_units;
|
||||
},
|
||||
set: function(value) {
|
||||
set: function (value) {
|
||||
this.config.settings.units = value;
|
||||
this.$root.display_units = value;
|
||||
this.$dispatch("config-changed");
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
metric: function() {
|
||||
metric: function () {
|
||||
return this.display_units === "METRIC";
|
||||
},
|
||||
|
||||
mach_state: function() {
|
||||
mach_state: function () {
|
||||
const cycle = this.state.cycle;
|
||||
const state = this.state.xx;
|
||||
|
||||
@@ -112,46 +110,46 @@ module.exports = {
|
||||
return state || "";
|
||||
},
|
||||
|
||||
pause_reason: function() {
|
||||
pause_reason: function () {
|
||||
return this.state.pr;
|
||||
},
|
||||
|
||||
is_running: function() {
|
||||
is_running: function () {
|
||||
return this.mach_state == "RUNNING" || this.mach_state == "HOMING";
|
||||
},
|
||||
|
||||
is_stopping: function() {
|
||||
is_stopping: function () {
|
||||
return this.mach_state == "STOPPING";
|
||||
},
|
||||
|
||||
is_holding: function() {
|
||||
is_holding: function () {
|
||||
return this.mach_state == "HOLDING";
|
||||
},
|
||||
|
||||
is_ready: function() {
|
||||
is_ready: function () {
|
||||
return this.mach_state == "READY";
|
||||
},
|
||||
|
||||
is_idle: function() {
|
||||
is_idle: function () {
|
||||
return this.state.cycle == "idle";
|
||||
},
|
||||
|
||||
is_paused: function() {
|
||||
is_paused: function () {
|
||||
return this.is_holding && (this.pause_reason == "User pause" || this.pause_reason == "Program pause");
|
||||
},
|
||||
|
||||
can_mdi: function() {
|
||||
can_mdi: function () {
|
||||
return this.is_idle || this.state.cycle == "mdi";
|
||||
},
|
||||
|
||||
can_set_axis: function() {
|
||||
can_set_axis: function () {
|
||||
return this.is_idle;
|
||||
|
||||
// TODO allow setting axis position during pause
|
||||
// return this.is_idle || this.is_paused;
|
||||
},
|
||||
|
||||
message: function() {
|
||||
message: function () {
|
||||
if (this.mach_state == "ESTOPPED") {
|
||||
return this.state.er;
|
||||
}
|
||||
@@ -167,15 +165,15 @@ module.exports = {
|
||||
return "";
|
||||
},
|
||||
|
||||
highlight_state: function() {
|
||||
highlight_state: function () {
|
||||
return this.mach_state == "ESTOPPED" || this.mach_state == "HOLDING";
|
||||
},
|
||||
|
||||
plan_time: function() {
|
||||
plan_time: function () {
|
||||
return this.state.plan_time;
|
||||
},
|
||||
|
||||
plan_time_remaining: function() {
|
||||
plan_time_remaining: function () {
|
||||
if (!(this.is_stopping || this.is_running || this.is_holding)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -183,7 +181,7 @@ module.exports = {
|
||||
return this.toolpath.time - this.plan_time;
|
||||
},
|
||||
|
||||
eta: function() {
|
||||
eta: function () {
|
||||
if (this.mach_state != "RUNNING") {
|
||||
return "";
|
||||
}
|
||||
@@ -194,7 +192,7 @@ module.exports = {
|
||||
return d.toLocaleString();
|
||||
},
|
||||
|
||||
progress: function() {
|
||||
progress: function () {
|
||||
if (!this.toolpath.time || this.is_ready) {
|
||||
return 0;
|
||||
}
|
||||
@@ -203,28 +201,30 @@ module.exports = {
|
||||
return Math.min(1, p);
|
||||
},
|
||||
gcodeFiles: function () {
|
||||
const filesWithNoMacros=this.state.files.filter(item => !this.config.macrosList.some(compareItem => compareItem.gcode_file_name == item));
|
||||
console.log('filesWithNoMacros: ',filesWithNoMacros);
|
||||
console.log("this.state.GCodeList",this.state.GCodeList)
|
||||
const filesWithNoMacros = this.state.files.filter(
|
||||
item => !this.config.macrosList.some(compareItem => compareItem.gcode_file_name == item),
|
||||
);
|
||||
console.log("filesWithNoMacros: ", filesWithNoMacros);
|
||||
console.log("this.state.GCodeList", this.state.GCodeList);
|
||||
const unionSet = new Set([...filesWithNoMacros, ...this.state.GCodeList]);
|
||||
const files = [...unionSet];
|
||||
console.log("files: ",files);
|
||||
console.log("files: ", files);
|
||||
return files;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
events: {
|
||||
jog: function(axis, power) {
|
||||
jog: function (axis, power) {
|
||||
const data = { ts: new Date().getTime() };
|
||||
data[axis] = power;
|
||||
api.put("jog", data);
|
||||
},
|
||||
|
||||
back2zero: function(axis0, axis1) {
|
||||
back2zero: function (axis0, axis1) {
|
||||
this.send(`G0 ${axis0}0 ${axis1}0`);
|
||||
},
|
||||
|
||||
step: function(axis, value) {
|
||||
step: function (axis, value) {
|
||||
this.send(`
|
||||
M70
|
||||
G91
|
||||
@@ -234,7 +234,7 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
|
||||
ready: function() {
|
||||
ready: function () {
|
||||
this.loadGCode();
|
||||
|
||||
setInterval(() => {
|
||||
@@ -244,10 +244,10 @@ module.exports = {
|
||||
SvelteComponents.registerControllerMethods({
|
||||
stop: (...args) => this.stop(...args),
|
||||
send: (...args) => this.send(...args),
|
||||
isAxisHomed: (axis) => this[axis].homed,
|
||||
isAxisHomed: axis => this[axis].homed,
|
||||
unhome: (...args) => this.unhome(...args),
|
||||
set_position: (...args) => this.set_position(...args),
|
||||
set_home: (...args) => this.set_home(...args)
|
||||
set_home: (...args) => this.set_home(...args),
|
||||
});
|
||||
},
|
||||
|
||||
@@ -256,10 +256,10 @@ module.exports = {
|
||||
const weight = `font-weight:${this.jog_incr === value ? "bold" : "normal"}`;
|
||||
const color = this.jog_incr === value ? "color:#0078e7" : "";
|
||||
|
||||
return [ weight, color ].join(";");
|
||||
return [weight, color].join(";");
|
||||
},
|
||||
|
||||
jog_fn: function(x_jog, y_jog, z_jog, a_jog) {
|
||||
jog_fn: function (x_jog, y_jog, z_jog, a_jog) {
|
||||
const amount = this.jog_incr_amounts[this.display_units][this.jog_incr];
|
||||
|
||||
const xcmd = `X${x_jog * amount}`;
|
||||
@@ -274,18 +274,18 @@ module.exports = {
|
||||
`);
|
||||
},
|
||||
|
||||
send: function(msg) {
|
||||
send: function (msg) {
|
||||
this.$dispatch("send", msg);
|
||||
},
|
||||
|
||||
loadGCode: function() {
|
||||
loadGCode: function () {
|
||||
const file_time = this.state.selected_time;
|
||||
const file = this.state.selected;
|
||||
if (this.last_file == file && this.last_file_time == file_time) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("file: ",file," time: ",file_time);
|
||||
console.log("file: ", file, " time: ", file_time);
|
||||
|
||||
this.last_file = file;
|
||||
this.last_file_time = file_time;
|
||||
@@ -296,7 +296,7 @@ module.exports = {
|
||||
this.load_toolpath(file, file_time);
|
||||
},
|
||||
|
||||
load_toolpath: async function(file, file_time) {
|
||||
load_toolpath: async function (file, file_time) {
|
||||
this.toolpath = {};
|
||||
|
||||
if (!file || this.last_file_time != file_time) {
|
||||
@@ -327,7 +327,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
submit_mdi: function() {
|
||||
submit_mdi: function () {
|
||||
this.send(this.mdi);
|
||||
|
||||
if (!this.history.length || this.history[0] != this.mdi) {
|
||||
@@ -337,7 +337,7 @@ module.exports = {
|
||||
this.mdi = "";
|
||||
},
|
||||
|
||||
mdi_start_pause: function() {
|
||||
mdi_start_pause: function () {
|
||||
if (this.state.xx == "RUNNING") {
|
||||
this.pause();
|
||||
} else if (this.state.xx == "STOPPING" || this.state.xx == "HOLDING") {
|
||||
@@ -347,15 +347,15 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
load_history: function(index) {
|
||||
load_history: function (index) {
|
||||
this.mdi = this.history[index];
|
||||
},
|
||||
|
||||
open: function() {
|
||||
open: function () {
|
||||
utils.clickFileInput("gcode-file-input");
|
||||
},
|
||||
|
||||
uploadGCode: async function(e) {
|
||||
uploadGCode: async function (e) {
|
||||
const files = e.target.files || e.dataTransfer.files;
|
||||
if (!files.length) {
|
||||
return;
|
||||
@@ -375,9 +375,9 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
const isAlreadyPresent = this.state.GCodeList.find((element) => element == file.name);
|
||||
if(isAlreadyPresent == undefined){
|
||||
console.log('new gcode file');
|
||||
const isAlreadyPresent = this.state.GCodeList.find(element => element == file.name);
|
||||
if (isAlreadyPresent == undefined) {
|
||||
console.log("new gcode file");
|
||||
this.state.GCodeList.push(file.name);
|
||||
try {
|
||||
await api.put("config/save", this.config);
|
||||
@@ -386,12 +386,12 @@ module.exports = {
|
||||
console.error("Restore Failed: ", error);
|
||||
alert("Restore failed");
|
||||
}
|
||||
}else{
|
||||
console.log('Already exists');
|
||||
} else {
|
||||
console.log("Already exists");
|
||||
}
|
||||
|
||||
if(this.config.macrosList.some(obj => obj.gcode_file_name == file.name)){
|
||||
console.log("It is a macros, remove it from macrosList")
|
||||
if (this.config.macrosList.some(obj => obj.gcode_file_name == file.name)) {
|
||||
console.log("It is a macros, remove it from macrosList");
|
||||
// this.config.GCodeList.push(file.name);
|
||||
}
|
||||
|
||||
@@ -400,35 +400,35 @@ module.exports = {
|
||||
onComplete: () => {
|
||||
this.last_file_time = undefined; // Force reload
|
||||
this.$broadcast("gcode-reload", file.name);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
delete_current: function() {
|
||||
if(this.config.macrosList.find(item=>item.gcode_file_name==this.state.selected)==undefined){
|
||||
delete_current: function () {
|
||||
if (this.config.macrosList.find(item => item.gcode_file_name == this.state.selected) == undefined) {
|
||||
if (this.state.selected) {
|
||||
api.delete(`file/${this.state.selected}`);
|
||||
}
|
||||
}else{
|
||||
this.state.GCodeList.filter(item=>item!=this.state.selected);
|
||||
} else {
|
||||
this.state.GCodeList = this.state.GCodeList.filter(item => item != this.state.selected);
|
||||
}
|
||||
|
||||
this.deleteGCode = false;
|
||||
},
|
||||
|
||||
delete_all: function() {
|
||||
delete_all: function () {
|
||||
api.delete("file");
|
||||
this.deleteGCode = false;
|
||||
},
|
||||
|
||||
delete_all_except_macros: function() {
|
||||
const macrosList=this.config.macrosList.map(item=>item.gcode_file_name).toString();
|
||||
delete_all_except_macros: function () {
|
||||
const macrosList = this.config.macrosList.map(item => item.gcode_file_name).toString();
|
||||
api.delete(`file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${macrosList}`);
|
||||
this.state.GCodeList=[];
|
||||
this.state.GCodeList = [];
|
||||
this.deleteGCode = false;
|
||||
},
|
||||
|
||||
home: function(axis) {
|
||||
home: function (axis) {
|
||||
this.ask_home = false;
|
||||
|
||||
if (typeof axis == "undefined") {
|
||||
@@ -440,31 +440,31 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
set_home: function(axis, position) {
|
||||
set_home: function (axis, position) {
|
||||
api.put(`home/${axis}/set`, { position: parseFloat(position) });
|
||||
},
|
||||
|
||||
unhome: function(axis) {
|
||||
unhome: function (axis) {
|
||||
api.put(`home/${axis}/clear`);
|
||||
},
|
||||
|
||||
show_set_position: function(axis) {
|
||||
show_set_position: function (axis) {
|
||||
SvelteComponents.showDialog("SetAxisPosition", { axis });
|
||||
},
|
||||
|
||||
showMoveToZeroDialog: function(axes) {
|
||||
showMoveToZeroDialog: function (axes) {
|
||||
SvelteComponents.showDialog("MoveToZero", { axes });
|
||||
},
|
||||
|
||||
showToolpathMessageDialog: function(axis) {
|
||||
showToolpathMessageDialog: function (axis) {
|
||||
SvelteComponents.showDialog("Message", { title: this[axis].toolmsg });
|
||||
},
|
||||
|
||||
set_position: function(axis, position) {
|
||||
api.put(`position/${axis}`, { "position": parseFloat(position) });
|
||||
set_position: function (axis, position) {
|
||||
api.put(`position/${axis}`, { position: parseFloat(position) });
|
||||
},
|
||||
|
||||
zero_all: function() {
|
||||
zero_all: function () {
|
||||
for (const axis of "xyzabc") {
|
||||
if (this[axis].enabled) {
|
||||
this.zero(axis);
|
||||
@@ -472,7 +472,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
zero: function(axis) {
|
||||
zero: function (axis) {
|
||||
if (typeof axis == "undefined") {
|
||||
this.zero_all();
|
||||
} else {
|
||||
@@ -480,7 +480,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
start_pause: function() {
|
||||
start_pause: function () {
|
||||
if (this.state.xx == "RUNNING") {
|
||||
this.pause();
|
||||
} else if (this.state.xx == "STOPPING" || this.state.xx == "HOLDING") {
|
||||
@@ -490,39 +490,39 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
start: function() {
|
||||
start: function () {
|
||||
api.put("start");
|
||||
},
|
||||
|
||||
pause: function() {
|
||||
pause: function () {
|
||||
api.put("pause");
|
||||
},
|
||||
|
||||
unpause: function() {
|
||||
unpause: function () {
|
||||
api.put("unpause");
|
||||
},
|
||||
|
||||
optional_pause: function() {
|
||||
optional_pause: function () {
|
||||
api.put("pause/optional");
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
stop: function () {
|
||||
api.put("stop");
|
||||
},
|
||||
|
||||
step: function() {
|
||||
step: function () {
|
||||
api.put("step");
|
||||
},
|
||||
|
||||
override_feed: function() {
|
||||
override_feed: function () {
|
||||
api.put(`override/feed/${this.feed_override}`);
|
||||
},
|
||||
|
||||
override_speed: function() {
|
||||
override_speed: function () {
|
||||
api.put(`override/speed/${this.speed_override}`);
|
||||
},
|
||||
|
||||
current: function(axis, value) {
|
||||
current: function (axis, value) {
|
||||
const x = value / 32.0;
|
||||
if (this.state[`${axis}pl`] == x) {
|
||||
return;
|
||||
@@ -533,22 +533,25 @@ module.exports = {
|
||||
this.send(JSON.stringify(data));
|
||||
},
|
||||
|
||||
showProbeDialog: function(probeType) {
|
||||
showProbeDialog: function (probeType) {
|
||||
SvelteComponents.showDialog("Probe", { probeType });
|
||||
},
|
||||
runMacros : function(id){
|
||||
if( this.config.macros[id].gcode_file_name != this.state.selected || this.config.macros[id].gcode_file_time != this.state.selected_time ){
|
||||
this.state.selected=this.config.macros[id].gcode_file_name;
|
||||
this.state.selected_time=this.config.macros[id].gcode_file_time
|
||||
runMacros: function (id) {
|
||||
if (
|
||||
this.config.macros[id].gcode_file_name != this.state.selected ||
|
||||
this.config.macros[id].gcode_file_time != this.state.selected_time
|
||||
) {
|
||||
this.state.selected = this.config.macros[id].gcode_file_name;
|
||||
this.state.selected_time = this.config.macros[id].gcode_file_time;
|
||||
}
|
||||
try{
|
||||
try {
|
||||
this.loadGCode();
|
||||
this.start_pause();
|
||||
}catch(error){
|
||||
console.warn("Error running program: ",error);
|
||||
} catch (error) {
|
||||
console.warn("Error running program: ", error);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
mixins: [ require("./axis-vars") ]
|
||||
mixins: [require("./axis-vars")],
|
||||
};
|
||||
|
||||
@@ -145,9 +145,9 @@ module.exports = {
|
||||
file,
|
||||
onComplete: () => {
|
||||
this.last_file_time = undefined; // Force reload
|
||||
this.loadMacrosGcode();
|
||||
},
|
||||
});
|
||||
this.loadMacrosGcode();
|
||||
},
|
||||
uploadGCode: async function (filename, file) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
@@ -681,13 +681,7 @@
|
||||
"gcode_file_name": "TurnOffVac.ngc",
|
||||
"gcode_file_time": 1705008395.476232
|
||||
}
|
||||
],
|
||||
"template": {
|
||||
"gcode_file_time": {
|
||||
"type": "int",
|
||||
"default": 1705008395
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"admin": {
|
||||
|
||||
Reference in New Issue
Block a user