Skip to content

Commit

Permalink
Catch unconfigured toolpaths error to console
Browse files Browse the repository at this point in the history
  • Loading branch information
petervanderwalt committed Jul 8, 2024
1 parent d52f019 commit 7996030
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 53 deletions.
100 changes: 53 additions & 47 deletions js/advanced-cam-gcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,61 +48,67 @@ function makeGcodeExec() {
// console.log(toolpathsInScene[j].userData.visible)
if (toolpathsInScene[j].userData.visible) {

// todo: Settings params
var rapidSpeed = 1000;
var toolon = "";
var tooloff = "";
// toolpath settings is applied to the parent Toolpath. Each child in the "toolpath" is processed with the same settings
if (toolpathsInScene[j].userData.camOperation.indexOf('Drill') == 0) {
// for Drilling, feed at Plunge Rate for the entire drill feed
var Feedrate = toolpathsInScene[j].userData.camPlungerate;
if (toolpathsInScene[j].userData.camOperation == undefined) {
console.log(`Toolpath Error: Toolpath-` + j + ` has not been configured! Please configure the toolpath before creating GCODE`)
} else {
var Feedrate = toolpathsInScene[j].userData.camFeedrate;
}
var Plungerate = toolpathsInScene[j].userData.camPlungerate;
var LaserPower = toolpathsInScene[j].userData.camLaserPower;
var SpindleRPM = toolpathsInScene[j].userData.camSpindleRpm;
var ZClearance = toolpathsInScene[j].userData.camZClearance;
var PlasmaIHS = toolpathsInScene[j].userData.camPlasmaIHS;
var rampplunge = toolpathsInScene[j].userData.tRampPlunge == "Yes" ? true : false;
var Passes = toolpathsInScene[j].userData.camPasses;

if (toolpathsInScene[j].userData.camOperation.indexOf('Pen') == 0) {
toolon = "M3S" + toolpathsInScene[j].userData.camPenDown + "\nG4 P0.5";
tooloff = "M3S" + toolpathsInScene[j].userData.camPenUp + "\nG4 P0.5";
ZClearance = 0;
}
// todo: Settings params
var rapidSpeed = 1000;
var toolon = "";
var tooloff = "";
// toolpath settings is applied to the parent Toolpath. Each child in the "toolpath" is processed with the same settings
if (toolpathsInScene[j].userData.camOperation.indexOf('Drill') == 0) {
// for Drilling, feed at Plunge Rate for the entire drill feed
var Feedrate = toolpathsInScene[j].userData.camPlungerate;
} else {
var Feedrate = toolpathsInScene[j].userData.camFeedrate;
}
var Plungerate = toolpathsInScene[j].userData.camPlungerate;
var LaserPower = toolpathsInScene[j].userData.camLaserPower;
var SpindleRPM = toolpathsInScene[j].userData.camSpindleRpm;
var ZClearance = toolpathsInScene[j].userData.camZClearance;
var PlasmaIHS = toolpathsInScene[j].userData.camPlasmaIHS;
var rampplunge = toolpathsInScene[j].userData.tRampPlunge == "Yes" ? true : false;
var Passes = toolpathsInScene[j].userData.camPasses;

if (toolpathsInScene[j].userData.camOperation.indexOf('Plasma') == 0) {
toolon = "M3S" + $("#scommandscale").val();
tooloff = "M5";
}
if (toolpathsInScene[j].userData.camOperation.indexOf('Pen') == 0) {
toolon = "M3S" + toolpathsInScene[j].userData.camPenDown + "\nG4 P0.5";
tooloff = "M3S" + toolpathsInScene[j].userData.camPenUp + "\nG4 P0.5";
ZClearance = 0;
}

if (parseInt(Passes) && toolpathsInScene[j].userData.camOperation.indexOf('Laser') == 0) {
var g = ""
var gcode = generateGcode(j, toolpathsInScene[j].userData.inflated, Feedrate, Plungerate, SpindleRPM, LaserPower, rapidSpeed, toolon, tooloff, ZClearance, false, PlasmaIHS, rampplunge);
for (k = 0; k < Passes; k++) {
g += '; Pass ' + k + "\n"
g += gcode
if (toolpathsInScene[j].userData.camOperation.indexOf('Plasma') == 0) {
toolon = "M3S" + $("#scommandscale").val();
tooloff = "M5";
}

if (parseInt(Passes) && toolpathsInScene[j].userData.camOperation.indexOf('Laser') == 0) {
var g = ""
var gcode = generateGcode(j, toolpathsInScene[j].userData.inflated, Feedrate, Plungerate, SpindleRPM, LaserPower, rapidSpeed, toolon, tooloff, ZClearance, false, PlasmaIHS, rampplunge);
for (k = 0; k < Passes; k++) {
g += '; Pass ' + k + "\n"
g += gcode
}
toolpathsInScene[j].userData.gcode = g;
} else {
toolpathsInScene[j].userData.gcode = generateGcode(j, toolpathsInScene[j].userData.inflated, Feedrate, Plungerate, SpindleRPM, LaserPower, rapidSpeed, toolon, tooloff, ZClearance, false, PlasmaIHS, rampplunge);
}
toolpathsInScene[j].userData.gcode = g;
} else {
toolpathsInScene[j].userData.gcode = generateGcode(j, toolpathsInScene[j].userData.inflated, Feedrate, Plungerate, SpindleRPM, LaserPower, rapidSpeed, toolon, tooloff, ZClearance, false, PlasmaIHS, rampplunge);
}



$("#savetpgcode").removeClass("disabled");
$("#exportGcodeMenu").removeClass("disabled");
$("#savetpgcode").removeClass("disabled");
$("#exportGcodeMenu").removeClass("disabled");

// var template = `
// <form class="form-horizontal">
// <label for="gcode` + i + `" class="control-label">` + toolpathsInScene[j].name + `</label>
// <textarea id="gcode` + i + `" spellcheck="false" style="width: 100%; height: 80px;" placeholder="processing..." disabled></textarea>
// </form>`
// $('#gcodejobs').append(template);
$('#gcode' + i).val(toolpathsInScene[j].userData.gcode);
// var template = `
// <form class="form-horizontal">
// <label for="gcode` + i + `" class="control-label">` + toolpathsInScene[j].name + `</label>
// <textarea id="gcode` + i + `" spellcheck="false" style="width: 100%; height: 80px;" placeholder="processing..." disabled></textarea>
// </form>`
// $('#gcodejobs').append(template);
$('#gcode' + i).val(toolpathsInScene[j].userData.gcode);
}
}


}

var startgcode = document.getElementById('startgcode').value;
Expand Down Expand Up @@ -162,7 +168,7 @@ function generateGcode(index, toolpathGrp, cutSpeed, plungeSpeed, spindleRpm, la
var IHScommand = document.getElementById('ihsgcode').value; // or "G0 " + clearanceHeight + "\nG38.2 Z-30 F100\nG10 P2 L1 Z0" // Plasma IHS

if (!toolpathGrp) {
var message = `Toolpath Error: One or more of your toolpaths is not configured. You need to configure the toolpaths, before generating GCODE`
var message = `Toolpath Error: One or more of your toolpaths is not configured. You need to configure the toolpaths (toolpath-` + index + `), before generating GCODE`
Metro.toast.create(message, null, 4000, 'bg-red');
$("#generatetpgcode").html("<i class='fa fa-cubes' aria-hidden='true'></i> Generate G-Code");
$("#generatetpgcode").prop('disabled', false);
Expand Down
4 changes: 2 additions & 2 deletions js/advanced-cam-workspace-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function initExportworkspace() {
}

function readWorkspace(evt) {
console.log(evt)
//console.log(evt)
var files = evt.target.files || evt.dataTransfer.files;
for (var i = 0; i < files.length; i++) {
loadWorkspace(files[i]);
Expand All @@ -214,7 +214,7 @@ function loadWorkspace(f) {
r.readAsText(f);
r.onload = function(event) {
parseLoadWorkspace(this.result)
console.log(this.result)
//console.log(this.result)
};
$('.workspaceTitle').html(' - ' + f.name)
} else {
Expand Down
8 changes: 4 additions & 4 deletions workers/toolpath/worker/toolpathworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ if (typeof window == "undefined") { // Only run as worker


function workerGetInflatePath(paths, delta, joinType) {
console.log(JSON.stringify(paths));
//console.log(JSON.stringify(paths));
var scale = 10000;
ClipperLib.JS.Clean(paths, 2);
ClipperLib.JS.ScaleUpPaths(paths, scale);
Expand Down Expand Up @@ -567,11 +567,11 @@ if (typeof window == "undefined") { // Only run as worker

if (config.leadInPaths.length == config.paths.length) {
var pointIndex = 0
console.log(config.leadInPaths[i][0])
//console.log(config.leadInPaths[i][0])
config.leadInPaths[i].sort(function(a, b) {
return distanceFormula(a.X, config.paths[i][0].X, a.Y, config.paths[i][0].Y) - distanceFormula(b.X, config.paths[i][0].X, b.Y, config.paths[i][0].Y)
})
console.log(config.leadInPaths[i][0])
//console.log(config.leadInPaths[i][0])


lineUnionGeo.vertices.push(new THREE.Vector3(config.leadInPaths[i][pointIndex].X, config.leadInPaths[i][pointIndex].Y, config.z));
Expand Down Expand Up @@ -759,7 +759,7 @@ if (typeof window == "undefined") { // Only run as worker
if (config.name) {
lineUnion.name = config.name;
}
console.log(lineUnionGeo)
//console.log(lineUnionGeo)
group.add(lineUnion);
clipperPaths.push(clipperArr);
clipperTabsPaths.push(clipperTabsArr);
Expand Down

0 comments on commit 7996030

Please sign in to comment.