From 72e9dc93a123ed52886efc4b754d6a9cdce63ba2 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 14 Aug 2015 14:38:16 -0400 Subject: [PATCH] simulation scaled --- js/cam/Cam.js | 13 ++++++++++++- js/cam/assemblers/Assembler.js | 20 ++++++++++---------- js/cam/processes/GCodeExporter.js | 20 ++++++++++---------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/js/cam/Cam.js b/js/cam/Cam.js index 4c1aacc0..61c422aa 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 2bef70f9..cf41d039 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 b14e42d3..aa57830f 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; -- GitLab