From 18c0e9b0812d7b910de07b8c926c58a7aec6782f Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 14 Aug 2015 13:09:07 -0400
Subject: [PATCH] parent child relationships

---
 js/cam/assemblers/Assembler.js | 14 ++++++++------
 js/cam/assemblers/Component.js |  4 ++--
 js/lattice/LatticeCAM.js       |  2 +-
 js/plists/CamPList.js          | 12 ++++++------
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js
index 1e331a0c..c1b96b9c 100644
--- a/js/cam/assemblers/Assembler.js
+++ b/js/cam/assemblers/Assembler.js
@@ -151,8 +151,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
                 data += self._postMoveXY(exporter, stockPosition.x-wcs.x, stockPosition.y-wcs.y);
                 data += self._postMoveToStock(exporter, thisStockPosition, rapidHeight, wcs, safeHeight);
             }
-            var cellPosition = cell.getPosition();//todo cell.getAbsolutePosition();
-            console.log(cellPosition);
+            var cellPosition = cell.getAbsolutePosition();
             data += self._postMoveXY(exporter, cellPosition.x-wcs.x, cellPosition.y-wcs.y);
             data += self._postReleaseStock(cellPosition, cell, exporter, rapidHeight, wcs, safeHeight);
             data += "\n";
@@ -182,7 +181,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
         var data = "";
         data += exporter.rapidZ(cellPosition.z-wcs.z+safeHeight);
         data += exporter.moveZ(cellPosition.z-wcs.z);
-        data += exporter.addComment(JSON.stringify(cell.index));
+        data += exporter.addComment(JSON.stringify(cell.getAbsoluteIndex()));
         data += exporter.moveZ(cellPosition.z-wcs.z+safeHeight);
         data += exporter.rapidZ(rapidHeight);
         return data;
@@ -212,8 +211,11 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
     };
     
     Assembler.prototype.releaseStock = function(index){
+        console.log(index);
         lattice.showCellAtIndex(JSON.parse(index));
-        this.stock.hide();
+        _.each(this.stock, function(stock){
+            stock.hide();
+        });
     };
     
     Assembler.prototype.pause = function(){
@@ -233,7 +235,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
             if (totalThreads > 0) return;
             callback();
         }
-        var startingPos = {x:this.components.xAxis.getPosition(), y:this.components.yAxis.getPosition(), z:this.components.zAxis.getPosition()};
+        var startingPos = {x:this.components.xAxis.getPosition().x, y:this.components.yAxis.getPosition().y, z:this.components.zAxis.getPosition().z};
         speed = this._normalizeSpeed(startingPos, x, y, this._reorganizeSpeed(speed));
         this.components.xAxis.moveTo(this._makeAxisVector(x, "x"), speed.x, sketchyCallback);
         this.components.yAxis.moveTo(this._makeAxisVector(y, "y"), speed.y, sketchyCallback);
@@ -255,7 +257,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
     
     Assembler.prototype._normalizeSpeed = function(startingPos, x, y, speed){//xy moves need speed normalization
         var normSpeed = {};
-        if (x == "" || y == "") return speed;
+        if (x == "" || y == "" || x === null || y === null) return speed;
         var deltaX = x-startingPos.x;
         var deltaY = y-startingPos.y;
         var totalDistance = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js
index 85b478bd..331fc3c6 100644
--- a/js/cam/assemblers/Component.js
+++ b/js/cam/assemblers/Component.js
@@ -81,7 +81,8 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
         var currentPosition = this.getPosition();
         var diff = _.clone(target);
         _.each(_.keys(target), function(key){
-            diff[key] -= currentPosition[key];
+            if (target[key] === null) diff[key] = 0;
+            else diff[key] -= currentPosition[key];
         });
 
         var diffLength = this._getLength(diff);
@@ -97,7 +98,6 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
         _.each(_.keys(incrementVector), function(key){
             incrementVector[key] *= increment/diffLength;
         });
-
         this._incrementalMove(incrementVector, target, callback);
     };
 
diff --git a/js/lattice/LatticeCAM.js b/js/lattice/LatticeCAM.js
index bc7a87f8..ea8a81b9 100644
--- a/js/lattice/LatticeCAM.js
+++ b/js/lattice/LatticeCAM.js
@@ -24,7 +24,7 @@ define(['lattice', 'three'], function(lattice, THREE){
                 firstLetter = order.charAt(0);
                 order = order.substr(1);
             }
-            if (!cells) cells = this.cells;//grab cells once at beginning and hold onto it in case changes are made while looping
+            if (!cells) cells = this.sparseCells;//grab cells once at beginning and hold onto it in case changes are made while looping
             var newVarOrder;
             var newVarDim;
             if (firstLetter == 'X'){
diff --git a/js/plists/CamPList.js b/js/plists/CamPList.js
index 95c92ccf..06a7e0fc 100644
--- a/js/plists/CamPList.js
+++ b/js/plists/CamPList.js
@@ -44,7 +44,7 @@ define([], function(){
                         axisOfMotion: null,
                         //minBound
                         //maxBound
-                        parent: "frame",
+                        parent: "yAxis",
                         children: ["zAxis"],
                         stl: {
                             filename: "assets/stls/stapler/xAxis.stl",
@@ -53,14 +53,14 @@ define([], function(){
                             rotation: {x:0,y:0,z:0}
                         }
                     },
-                    yAxis: {
+                    frame: {
                         name: "Y Axis",
                         isLinear: true,
                         axisOfMotion: null,
                         //minBound
                         //maxBound
                         parent: "substrate",
-                        children: ["frame"],
+                        children: ["yAxis"],
                         stl: {
                             filename: "assets/stls/stapler/yAxis.stl",
                             offset: {x:0,y:0,z:0},
@@ -83,13 +83,13 @@ define([], function(){
                             rotation: {x:0,y:0,z:0}
                         }
                     },
-                    frame: {
+                    yAxis: {
                         name: "Frame",
                         isLinear: true,
                         axisOfMotion: null,
                         //minBound
                         //maxBound
-                        parent: "yAxis",
+                        parent: "frame",
                         children: ["xAxis"],
                         stl: {
                             filename: "assets/stls/stapler/frame.stl",
@@ -105,7 +105,7 @@ define([], function(){
                         //minBound
                         //maxBound
                         parent: null,
-                        children: ["frame"],
+                        children: ["yAxis"],
                         stl: {
                             filename: "assets/stls/stapler/substrate.stl",
                             offset: {x:0,y:0,z:0},
-- 
GitLab