From 1370e52bc258663362528a6384ad356eeb32e0ec Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 25 May 2015 19:27:38 -0700
Subject: [PATCH] relative stock position working

---
 js/cam/Machine.js           |  6 +++---
 js/cam/MachineOneBit.js     |  4 ++--
 js/cam/cam.js               |  2 ++
 js/menus/MenuWrapperView.js | 10 ++++++----
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/js/cam/Machine.js b/js/cam/Machine.js
index 701f76cc..d5a098d6 100644
--- a/js/cam/Machine.js
+++ b/js/cam/Machine.js
@@ -28,7 +28,7 @@ Machine.prototype._setDefaults = function(){
     globals.cam.set("stockFixed", false);
     globals.cam.set("originPosition", {x:0,y:0,z:0});
     var boundingBox = globals.lattice.calculateBoundingBox();
-    var rapidHeight = (boundingBox.max.z + 2*globals.lattice.zScale()).toFixed(4);
+    var rapidHeight = parseFloat((boundingBox.max.z + 2*globals.lattice.zScale()).toFixed(4));
     globals.cam.set("rapidHeight", rapidHeight);
     globals.cam.set("stockPosition", {x:0,y:0,z:0});
     globals.cam.set("stockSeparation", globals.lattice.xScale());
@@ -269,7 +269,7 @@ Shopbot.prototype._setDefaults = function(){
     Machine.prototype._setDefaults.call(this);
     globals.cam.set("camProcess", "shopbot");
     var boundingBox = globals.lattice.calculateBoundingBox();
-    var yPos = (boundingBox.max.y + 3*globals.lattice.yScale()).toFixed(4);
+    var yPos = parseFloat((boundingBox.max.y + 3*globals.lattice.yScale()).toFixed(4));
     globals.cam.set("stockPosition", {x:0,y:yPos,z:0});
 };
 
@@ -309,7 +309,7 @@ God.prototype = Object.create(Machine.prototype);
 God.prototype._setDefaults = function(){
     Machine.prototype._setDefaults.call(this);
     var boundingBox = globals.lattice.calculateBoundingBox();
-    var zPos = (boundingBox.max.z + 5*globals.lattice.zScale()).toFixed(4);
+    var zPos = parseFloat((boundingBox.max.z + 5*globals.lattice.zScale()).toFixed(4));
     globals.cam.set("stockPosition", {x:0,y:0,z:zPos});
 };
 
diff --git a/js/cam/MachineOneBit.js b/js/cam/MachineOneBit.js
index cd30f185..56f5c76f 100644
--- a/js/cam/MachineOneBit.js
+++ b/js/cam/MachineOneBit.js
@@ -11,8 +11,8 @@ OneBitBot.prototype._setDefaults = function(){
     Machine.prototype._setDefaults.call(this);
     globals.cam.set("stockFixed", true);
     var scale = globals.lattice.get("scale");
-    var xPos = (1.11*scale).toFixed(4);
-    var zPos = (1.14*scale).toFixed(4);
+    var xPos = parseFloat((1.11*scale).toFixed(4));
+    var zPos = parseFloat((1.14*scale).toFixed(4));
     globals.cam.set("stockPosition", {x:xPos,y:0,z:zPos});
 };
 
diff --git a/js/cam/cam.js b/js/cam/cam.js
index ae113ac3..05a6f3c5 100644
--- a/js/cam/cam.js
+++ b/js/cam/cam.js
@@ -167,7 +167,9 @@ Cam = Backbone.Model.extend({
 
     _updateStockPosToOrigin: function(newOrigin, lastOrigin){
         var newStockPosition = _.clone(this.get("stockPosition"));
+        console.log(newStockPosition);
         _.each(_.keys(newStockPosition), function(key){
+            console.log(key);
             newStockPosition[key] += newOrigin[key] - lastOrigin[key];
             newStockPosition[key] = parseFloat(newStockPosition[key].toFixed(4));
         });
diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js
index 92cfd1c7..fb2c2d4b 100644
--- a/js/menus/MenuWrapperView.js
+++ b/js/menus/MenuWrapperView.js
@@ -85,11 +85,13 @@ MenuWrapper = Backbone.View.extend({
 
         if (key){
             if ($target.hasClass("lattice")) {
-                globals.lattice.get(property)[key] = newVal;
-                globals.lattice.trigger("change:"+property);
+                var value = _.clone(globals.lattice.get(property));
+                value[key] = newVal;
+                globals.lattice.set(property, value);
             } else if ($target.hasClass("assembler")) {
-                globals.cam.get(property)[key] = newVal;
-                globals.cam.trigger("change:"+property);
+                var value = _.clone(globals.cam.get(property));
+                value[key] = newVal;
+                globals.cam.set(property, value);
             }
             return;
         }
-- 
GitLab