diff --git a/js/cam/Cam.js b/js/cam/Cam.js index 4c1aacc0bc910566dbdfcbbc7ec66ee8fde74392..61c422aae4cabd61b4c3de1f35096b583aa16fc2 100644 --- a/js/cam/Cam.js +++ b/js/cam/Cam.js @@ -157,6 +157,7 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel _tabChanged: function(){ this._setCAMVisibility(); if (appState.get("currentTab") != "animate") this.resetSimulation(); + else if (this.get("needsPostProcessing")) this.postProcess(); }, _setCAMVisibility: function(){ @@ -262,8 +263,16 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel var allLines = this.get("dataOut").split("\n"); if(currentLine<allLines.length){ var self = this; + + var scale = lattice.get("scale"); + var scaledSettings = { + scale: scale, + originPosition: this.get("originPosition").clone().divideScalar(scale), + stockPosition: this.get("stockPosition").clone().divideScalar(scale), + }; + this.get("exporter").simulate(allLines[currentLine], this.get("assembler"), - this.get("originPosition"), function(){ + scaledSettings, function(){ currentLine++; self.set("simLineNumber", currentLine); self._stockSimulation(); @@ -294,10 +303,12 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel //post processing _setNeedsPostProcessing: function(){ + console.log("hi"); this.set("needsPostProcessing", true); }, postProcess: function(){ + console.log("process"); this.set("needsPostProcessing", false); var scale = lattice.get("scale"); diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index 2bef70f9484b2e0073c06be7173496f3e4c4fa95..cf41d039ac5298ade2bc86c1c96785df6996ffd5 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -197,13 +197,13 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' }); }; - Assembler.prototype.pickUpStock = function(){ + Assembler.prototype.pickUpStock = function(settings){ _.each(this.stock, function(stock){ stock.show(); }); }; - Assembler.prototype.releaseStock = function(index){ + Assembler.prototype.releaseStock = function(index, settings){ console.log(index); lattice.showCellAtIndex(JSON.parse(index)); _.each(this.stock, function(stock){ @@ -214,14 +214,14 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' Assembler.prototype.pause = function(){ }; - Assembler.prototype.moveTo = function(x, y, z, speed, wcs, callback){ - x = this._makeAbsPosition(x, wcs.x); - y = this._makeAbsPosition(y, wcs.y); - z = this._makeAbsPosition(z, wcs.z); - this._moveTo(x, y, z, speed, wcs, callback); + Assembler.prototype.moveTo = function(x, y, z, speed, settings, callback){ + x = this._makeAbsPosition(x, settings.originPosition.x); + y = this._makeAbsPosition(y, settings.originPosition.y); + z = this._makeAbsPosition(z, settings.originPosition.z); + this._moveTo(x, y, z, speed, callback); }; - Assembler.prototype._moveTo = function(x, y, z, speed, wcs, callback){ + Assembler.prototype._moveTo = function(x, y, z, speed, callback){ var totalThreads = 3; function sketchyCallback(){ totalThreads -= 1; @@ -235,9 +235,9 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' this.components.zAxis.moveTo(this._makeAxisVector(z, "z"), speed.z, sketchyCallback); }; - Assembler.prototype._makeAbsPosition = function(target, wcs){ + Assembler.prototype._makeAbsPosition = function(target, origin){ if (target == "" || target == null || target === undefined) return null; - return parseFloat(target)+wcs; + return parseFloat(target)+origin; }; Assembler.prototype._reorganizeSpeed = function(speed){ diff --git a/js/cam/processes/GCodeExporter.js b/js/cam/processes/GCodeExporter.js index b14e42d35ad566a8ddbe84251c6ba845ae26dfb2..aa57830f05ed9e0954bae7af4cea5fdf54fdd07b 100644 --- a/js/cam/processes/GCodeExporter.js +++ b/js/cam/processes/GCodeExporter.js @@ -96,41 +96,41 @@ define(['underscore', 'cam', 'lattice'], function(_, cam, lattice){ saveAs(blob, "GCodeExport" + ".nc"); }; - GCodeExporter.prototype.simulate = function(line, machine, wcs, callback){ + GCodeExporter.prototype.simulate = function(line, machine, settings, callback){ if (line == "(get stock)"){ - machine.pickUpStock(); + machine.pickUpStock(settings); return callback(); } if (line.substr(0,2) == "({"){ - machine.releaseStock(line.substr(1,line.length-2)); + machine.releaseStock(line.substr(1,line.length-2), settings); return callback(); } if (line[0] == "F"){//speed - this.animationSpeed = line.split("F")[1]; + this.animationSpeed = line.split("F")[1] / settings.scale; return callback(); } if (line == "" || line[0] == "(" || line.substr(0,3) != "G01"){ return callback(); } if (line.substr(0,3) == "G01"){ - return this._simulateGetPosition(line, {xy:this.animationSpeed, z:this.animationSpeed}, machine, wcs, callback); + return this._simulateGetPosition(line, {xy:this.animationSpeed, z:this.animationSpeed}, machine, settings, callback); } else { console.warn("problem parsing gcode: " + line); return callback(); } }; - GCodeExporter.prototype._simulateGetPosition = function(line, speed, machine, wcs, callback){ + GCodeExporter.prototype._simulateGetPosition = function(line, speed, machine, settings, 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); + if (item[0] == "X") position.x = item.substr(1) / settings.scale; + if (item[0] == "Y") position.y = item.substr(1) / settings.scale; + if (item[0] == "Z") position.z = item.substr(1) / settings.scale; } - machine.moveTo(position.x, position.y, position.z, speed, wcs, callback); + machine.moveTo(position.x, position.y, position.z, speed, settings, callback); }; return GCodeExporter;