From a1e4f65cf0ee0ef48b6a980f3d836e525d0be6d3 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 24 Mar 2015 17:06:58 -0400
Subject: [PATCH] cleaning up postProcess func

---
 js/cam/Assembler.js       | 20 +++++---------------
 js/cam/GCodeExporter.js   |  1 -
 js/cam/Machine.js         |  3 ++-
 js/cam/ShopbotExporter.js |  2 +-
 4 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js
index 49412e6d..2091e02c 100644
--- a/js/cam/Assembler.js
+++ b/js/cam/Assembler.js
@@ -28,7 +28,6 @@ Assembler = Backbone.Model.extend({
         multipleStockPositions: false,
         stockArraySize: {x:4, y:4},
         stockSeparation: 2.78388,
-        postStockNum: 0,//which piece of stock to pick up
 
         rapidSpeeds:{xy: 3, z: 2},//rapids at clearance height
         feedRate:{xy: 0.1, z: 0.1},//speed when heading towards assembly
@@ -180,7 +179,6 @@ Assembler = Backbone.Model.extend({
         dmaGlobals.appState.set("stockSimulationPlaying", false);
         dmaGlobals.three.stopAnimationLoop();
         this.set("simStockNum", 0);
-        this.set("postStockNum", 0);
         dmaGlobals.lattice.showCells();
     },
 
@@ -234,31 +232,23 @@ Assembler = Backbone.Model.extend({
         data += "\n";
 
         var stockPosition = this.get("stockPosition");
+        var stockNum = 0;//position of stock in stock array
         var multStockPositions = this.get("multipleStockPositions");
         var self = this;
         dmaGlobals.lattice.rasterCells(this._getOrder(this.get("camStrategy")), function(cell){
             if (!cell) return;
-            var stockNum = self.get("postStockNum");
-            var stockNumPosition = {x:stockPosition.x, y:stockPosition.y, z:stockPosition.z};
+            var thisStockPosition = _.clone(stockPosition);
             if (multStockPositions) {
                 var stockArraySize = self.get("stockArraySize");
-                stockNumPosition.x += stockNum % stockArraySize.y * self.get("stockSeparation");
-                stockNumPosition.y -= Math.floor(stockNum / stockArraySize.y) * self.get("stockSeparation");
-            }
-            data += self._grabStock(exporter, stockNumPosition, rapidHeight, wcs, safeHeight);
-            if (multStockPositions) {
+                thisStockPosition.x += stockNum % stockArraySize.y * self.get("stockSeparation");
+                thisStockPosition.y -= Math.floor(stockNum / stockArraySize.y) * self.get("stockSeparation");
                 stockNum += 1;
                 if (stockNum >= stockArraySize.x * stockArraySize.y) stockNum = 0;
-                self.set("postStockNum", stockNum, {silent: true});
-                data += exporter.rapidXY(stockPosition.x-wcs.x, stockPosition.y-wcs.y);//move to stock origin
             }
+            data += self._grabStock(exporter, thisStockPosition, rapidHeight, wcs, safeHeight);
             data += self._placeCell(cell, exporter, rapidHeight, wcs, safeHeight);
-            if (multStockPositions) {
-                data += exporter.rapidXY(stockPosition.x-wcs.x, stockPosition.y-wcs.y);//move to stock origin
-            }
             data += "\n";
         });
-        data += exporter.rapidXY(0, 0);
 
         data += "\n\n";
         data += exporter.addComment("end program");
diff --git a/js/cam/GCodeExporter.js b/js/cam/GCodeExporter.js
index ceba96c6..dec78ede 100644
--- a/js/cam/GCodeExporter.js
+++ b/js/cam/GCodeExporter.js
@@ -73,7 +73,6 @@ GCodeExporter.prototype.goHome = function(){
 
 GCodeExporter.prototype.makeFooter = function(){
     var data = "";
-    data += this.goHome();
     data += this.addLine("M30", [], "program stop");
 
     return data;
diff --git a/js/cam/Machine.js b/js/cam/Machine.js
index b394008e..11dd0ab8 100644
--- a/js/cam/Machine.js
+++ b/js/cam/Machine.js
@@ -14,6 +14,7 @@ function Machine() {
         _.each(_.values(meshes), function(mesh){
             dmaGlobals.three.sceneAdd(mesh);
         });
+        self.setVisibility();
     });
     this.cell = this._makeStockCell();
     this.setVisibility(false);
@@ -135,7 +136,6 @@ Machine.prototype.destroy = function(){
 };
 
 
-
 ///////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////SHOPBOT///////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////
@@ -181,6 +181,7 @@ Shopbot.prototype._moveAxis = function(startingPos, target, axis, speed, callbac
     this._animateObjects([this.meshes.endEffector, this.cell], axis, speed, startingPos, target, callback);
 };
 
+
 ///////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////ONE BIT///////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/js/cam/ShopbotExporter.js b/js/cam/ShopbotExporter.js
index d96101e0..1ab7a520 100644
--- a/js/cam/ShopbotExporter.js
+++ b/js/cam/ShopbotExporter.js
@@ -70,7 +70,7 @@ ShopbotExporter.prototype.goHome = function(){
 };
 
 ShopbotExporter.prototype.makeFooter = function(){
-    return this.goHome();
+    return "";
 };
 
 ShopbotExporter.prototype.save = function(data){
-- 
GitLab