Skip to content
Snippets Groups Projects
Commit 797471dc authored by amandaghassaei's avatar amandaghassaei
Browse files

support for gcode sim

parent d3391493
No related branches found
No related tags found
No related merge requests found
......@@ -29,11 +29,7 @@ GCodeExporter.prototype.addLine = function(command, params, comment){
data += command + " ";
_.each(params, function(param){
if (!param) return;
if (isNaN(parseFloat(param))) {
data += param + " ";
return;
}
data += param.toFixed(3) + " ";
data += param + " ";
});
if (comment) data += "(" + comment + ")";
data += "\n";
......@@ -57,9 +53,9 @@ GCodeExporter.prototype.rapidZ = function(z){
};
GCodeExporter.prototype.moveXYZ = function(x, y, z){
if (x !== null) x = "X"+x;
if (y !== null) y = "Y"+y;
if (z !== null) z = "Z"+z;
if (x !== null) x = "X"+parseFloat(x).toFixed(3);
if (y !== null) y = "Y"+parseFloat(y).toFixed(3);
if (z !== null) z = "Z"+parseFloat(z).toFixed(3);
return this.addLine("G01", [x,y,z]);
};
......@@ -87,3 +83,37 @@ GCodeExporter.prototype.save = function(data){
var blob = new Blob([data], {type: "text/plain;charset=utf-8"});
saveAs(blob, "GCodeExport" + ".g");
};
GCodeExporter.prototype.simulate = function(line, machine, wcs, callback){
if (line == "(get stock)"){
machine.pickUpStock();
return callback();
}
if (line.substr(0,2) == "({"){
machine.releaseStock(line.substr(1,line.length-2));
return callback();
}
if (line == "" || line[0] == "(" || line.substr(0,3) != "G01"){
return callback();
}
if (line.substr(0,3) == "G01"){
//return this._simulateGetPosition(line, dmaGlobals.assembler.get("feedRate"), machine, wcs, callback);
return this._simulateGetPosition(line, dmaGlobals.assembler.get("rapidSpeeds"), machine, wcs, callback);
} else {
console.warn("problem parsing gcode: " + line);
return callback();
}
};
GCodeExporter.prototype._simulateGetPosition = function(line, speed, machine, wcs, callback){
var data = line.split(" ");
var position = {x:"",y:"",z:""};
if (data.length<2) console.warn("problem parsing gcode " + line);
for (var i=1;i<data.length;i++){
var item = data[i];
if (item[0] == "X") position.x = item.substr(1);
if (item[0] == "Y") position.y = item.substr(1);
if (item[0] == "Z") position.z = item.substr(1);
}
machine.moveTo(position.x, position.y, position.z, speed, wcs, callback);
};
......@@ -100,7 +100,7 @@ ShopbotExporter.prototype.simulate = function(line, machine, wcs, callback){
} else if (line[0] == "M"){
return this._simulateGetPosition(line, dmaGlobals.assembler.get("feedRate"), machine, wcs, callback);
} else {
console.warn("problem parsing sbp");
console.warn("problem parsing sbp " + line);
return callback();
}
};
......@@ -121,7 +121,7 @@ ShopbotExporter.prototype._simulateGetPosition = function(line, speed, machine,
} else if (line[1] == "S"){
return callback();
} else {
console.warn("problem parsing sbp");
console.warn("problem parsing sbp " + line);
return callback();
}
};
......@@ -78,14 +78,16 @@ AnimationMenuView = Backbone.View.extend({
var newText = code.join("\n");
var $editor = $('#gcodeEditor');
$editor.html(newText);
var highlighterHeight = $("#gcodeHighlighter").position().top - $editor.position().top;
var $highlighter = $("#gcodeHighlighter");
if (!$editor.position() || !$highlighter.position()) return;//todo weird bug
var highlighterHeight = $highlighter.position().top - $editor.position().top;
var desiredHeight = $editor.height()/2;
if (highlighterHeight > desiredHeight) $editor.scrollTop($editor.scrollTop()+highlighterHeight-desiredHeight);
},
_setEditorHeight: function(){
var $editor = $('#gcodeEditor');
var height = this.$el.height()-$editor.position().top-50
var height = this.$el.height()-$editor.position().top-50;
height = Math.max(height, 250);
$editor.css({height:height +"px"});
},
......@@ -94,9 +96,8 @@ AnimationMenuView = Backbone.View.extend({
if (this.model.get("currentTab") != "animate") return;
if (dmaGlobals.assembler.get("needsPostProcessing") && !dmaGlobals.assembler.get("editsMadeToProgram")) dmaGlobals.assembler.postProcess();
this.$el.html(this.template(_.extend(this.model.toJSON(), dmaGlobals.assembler.toJSON())));
if (!dmaGlobals.appState.get("stockSimulationPlaying")) this._drawGcodeHighlighter();//in case of code pause
this._setEditorHeight();
this._drawGcodeHighlighter();//in case of code pause
$('#speedSlider').slider({
formatter: function(value) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment