From a39eafd7377598457fab650c8439a3660174ecc1 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Wed, 25 Mar 2015 11:14:39 -0400
Subject: [PATCH] eod

---
 js/cam/Assembler.js     |  1 +
 js/cam/Machine.js       |  2 ++
 js/cam/MachineOneBit.js | 15 +++++++++++++++
 3 files changed, 18 insertions(+)

diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js
index 7a6e5622..780f7341 100644
--- a/js/cam/Assembler.js
+++ b/js/cam/Assembler.js
@@ -164,6 +164,7 @@ Assembler = Backbone.Model.extend({
         var position = this.get("originPosition");
         this.get("origin").position.set(position.x, position.y, position.z);
         dmaGlobals.three.render();
+        if (this.get("machine").setMachinePosition) this.get("machine").setMachinePosition();
     },
 
     _moveStock: function(){
diff --git a/js/cam/Machine.js b/js/cam/Machine.js
index f999f713..9b0096fc 100644
--- a/js/cam/Machine.js
+++ b/js/cam/Machine.js
@@ -15,6 +15,7 @@ function Machine() {
         _.each(_.values(meshes), function(mesh){
             dmaGlobals.three.sceneAdd(mesh);
         });
+        if (this.setMachinePosition) this.setMachinePosition();
         self.setVisibility();
     });
     this.setVisibility(false);
@@ -197,6 +198,7 @@ Machine.prototype.destroy = function(){
         mesh = null;
     });
     this.meshes = null;
+    this.position = null;
 };
 
 
diff --git a/js/cam/MachineOneBit.js b/js/cam/MachineOneBit.js
index 2e120f16..b1e27651 100644
--- a/js/cam/MachineOneBit.js
+++ b/js/cam/MachineOneBit.js
@@ -7,6 +7,18 @@ function OneBitBot(){
 }
 OneBitBot.prototype = Object.create(Machine.prototype);
 
+OneBitBot.prototype.setMachinePosition = function(){
+    if (!dmaGlobals.assembler) return;
+    this.position = dmaGlobals.assembler.get("originPosition");
+    var self = this;
+    _.each(_.values(this.meshes), function(mesh){
+        mesh.position.x += self.position.x;
+        mesh.position.y += self.position.y;
+        mesh.position.z += self.position.z;
+    });
+    dmaGlobals.three.render();
+};
+
 OneBitBot.prototype._buildMeshes = function(callback){
     var meshes = [];
     var numMeshes = 7;
@@ -66,6 +78,9 @@ OneBitBot.prototype._moveTo = function(x, y, z, speed, wcs, callback){
         if (totalThreads > 0) return;
         callback();
     }
+    x += this.position.x;
+    y += this.position.y;
+    z += this.position.z;
     var startingPos = this.meshes["zAxis"].position.clone();
     speed = this._normalizeSpeed(startingPos, x, y, this._reorganizeSpeed(speed));
     this._moveXAxis(startingPos.x, x, "x", speed.x, sketchyCallback);
-- 
GitLab