From 64d6ec70069f28d3300243c38c211bf7ddc67d41 Mon Sep 17 00:00:00 2001
From: amandaghassaei <amandaghassaei@gmail.com>
Date: Sat, 14 Mar 2015 05:00:14 -0400
Subject: [PATCH] moving stuff around

---
 js/cam/Assembler.js           | 12 ++++++------
 js/main.js                    | 10 +++++-----
 js/menus/AnimationMenuView.js | 16 ++++++++++++++--
 js/models/AppState.js         |  9 +++++----
 js/models/Lattice.js          |  7 +++++--
 js/models/LatticeOcta.js      | 12 ------------
 js/models/LatticeOther.js     |  9 ---------
 7 files changed, 35 insertions(+), 40 deletions(-)

diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js
index a0329a55..4306ef05 100644
--- a/js/cam/Assembler.js
+++ b/js/cam/Assembler.js
@@ -24,12 +24,12 @@ Assembler = Backbone.Model.extend({
         feedRate:{xy: 12, z: 4}
     },
 
-    initialize: function(){
+    initialize: function(options){
 
         _.bindAll(this, "postProcess");
 
         //bind events
-        this.listenTo(dmaGlobals.appState, "change:currentTab", this._setCAMVisibility);
+        this.listenTo(options.appState, "change:currentTab", this._setCAMVisibility);
         this.listenTo(this, "change:originPosition", this._moveOrigin);
         this.listenTo(this, "change:stockPosition", this._moveStock);
         this.listenTo(this,
@@ -40,7 +40,7 @@ Assembler = Backbone.Model.extend({
                 "change:camProcess " +
                 "change:camStrategy",
             this._setNeedsPostProcessing);
-        this.listenTo(dmaGlobals.lattice,
+        this.listenTo(options.lattice,
                 "change:numCells " +
                 "change:units " +
                 "change:scale " +
@@ -49,13 +49,13 @@ Assembler = Backbone.Model.extend({
             this._setNeedsPostProcessing);
 
         //init origin mesh
-        var scale = dmaGlobals.lattice.get("scale");
-        var origin = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4),
+        var scale = options.lattice.get("scale");
+        var origin = new THREE.Mesh(new THREE.SphereGeometry(scale/4),
             new THREE.MeshBasicMaterial({color:0xff0000}));
         dmaGlobals.three.sceneAdd(origin);
         this.set("origin", origin);
         //init stock mesh
-        var stock = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4),
+        var stock = new THREE.Mesh(new THREE.SphereGeometry(scale/4),
             new THREE.MeshBasicMaterial({color:0xff00ff}));
         dmaGlobals.three.sceneAdd(stock);
         this.set("stock", stock);
diff --git a/js/main.js b/js/main.js
index 8288646a..09de1c03 100644
--- a/js/main.js
+++ b/js/main.js
@@ -11,13 +11,13 @@ $(function(){
     //init web workers
     window.workers = persistentWorkers(8);
 
-    //init threeJS and geometry models
+    //init global singletons
     dmaGlobals.three = new ThreeModel();
-
     dmaGlobals.appState = new AppState();
-    dmaGlobals.lattice = new Lattice();
-    dmaGlobals.lattice._updateLatticeType();//todo get rid of this
-    dmaGlobals.assembler = new Assembler();
+    dmaGlobals.lattice = new Lattice({appState: dmaGlobals.appState});
+    dmaGlobals.assembler = new Assembler({appState: dmaGlobals.appState, lattice:dmaGlobals.lattice});
+
+    dmaGlobals.lattice.delayedInit();
     dmaGlobals.appState.delayedInit();
 
 
diff --git a/js/menus/AnimationMenuView.js b/js/menus/AnimationMenuView.js
index 730458f2..2e59860a 100644
--- a/js/menus/AnimationMenuView.js
+++ b/js/menus/AnimationMenuView.js
@@ -8,7 +8,8 @@ AnimationMenuView = Backbone.View.extend({
     el: "#menuContent",
 
     events: {
-        "click .sceneType":                         "_changeScene"
+        "click #playStockSim":                          "_playStockSim",
+        "click #pauseStockSim":                         "_pauseStockSim"
     },
 
     initialize: function(options){
@@ -19,6 +20,16 @@ AnimationMenuView = Backbone.View.extend({
         this.listenTo(this.model, "change:currentScene", this.render);
     },
 
+    _playStockSim: function(e){
+        e.preventDefault();
+        dmaGlobals.appState.set("stockSimulationPlaying", true);
+    },
+
+    _pauseStockSim: function(e){
+        e.preventDefault();
+        dmaGlobals.appState.set("stockSimulationPlaying", false);
+    },
+
     _changeScene: function(e){
         e.preventDefault();
         this.model.set("currentScene", $(e.target).data("type"));
@@ -30,7 +41,8 @@ AnimationMenuView = Backbone.View.extend({
     },
 
     template: _.template('\
-        animation settings\
+        <a href="#" id="playStockSim" class=" btn btn-block btn-lg btn-default">Play</a><br/>\
+        <a href="#" id="pauseStockSim" class=" btn btn-block btn-lg btn-default">Pause</a><br/>\
         ')
 
 });
diff --git a/js/models/AppState.js b/js/models/AppState.js
index fbfcd98b..f57e20b5 100644
--- a/js/models/AppState.js
+++ b/js/models/AppState.js
@@ -147,13 +147,12 @@ AppState = Backbone.Model.extend({
         shift: false,
         deleteMode: false,
         extrudeMode: false,
-        cellMode: "cell"//show cells vs parts
-    },
+        cellMode: "cell",//show cells vs parts
 
-    initialize: function(){
+        stockSimulationPlaying: false
     },
 
-    delayedInit: function(){
+    initialize: function(){
 
          _.bindAll(this, "_handleKeyStroke");
 
@@ -168,7 +167,9 @@ AppState = Backbone.Model.extend({
         this.downKeys = {};//track keypresses to prevent repeat keystrokeson hold
 
         if (this.isMobile()) this.set("menuIsVisible", false);
+    },
 
+    delayedInit: function(){
         this.set("menuWrapper", new MenuWrapper({model: this}));
     },
 
diff --git a/js/models/Lattice.js b/js/models/Lattice.js
index 3738be2d..36e4fb43 100644
--- a/js/models/Lattice.js
+++ b/js/models/Lattice.js
@@ -31,17 +31,20 @@ Lattice = Backbone.Model.extend({
 
     //pass in fillGeometry
 
-    initialize: function(){
+    initialize: function(options){
 
         _.extend(this, OctaLatticeSubclasses, OtherLatticeSubclasses);
 
         //bind events
         this.listenTo(this, "change:scale", this._scaleDidChange);
-        this.listenTo(dmaGlobals.appState, "change:cellMode", this._updateForMode);
+        this.listenTo(options.appState, "change:cellMode", this._updateForMode);
         this.listenTo(this, "change:partType", this._updateForMode);
         this.listenTo(this, "change:cellType change:connectionType", this._updateLatticeType);
         this.listenTo(this, "change:cellSeparation", this._updateCellSeparation);
+    },
 
+    delayedInit: function(){
+        this._updateLatticeType();
     },
 
     ////////////////////////////////////////////////////////////////////////////////////
diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js
index 232f9084..ff3c5bec 100644
--- a/js/models/LatticeOcta.js
+++ b/js/models/LatticeOcta.js
@@ -73,9 +73,6 @@ OctaLatticeSubclasses = {
     OctaFreeFormFaceLattice: {
 
         _initLatticeType: function(){
-
-            //bind events
-
             this.set("basePlane", new OctaBasePlane({scale:this.get("scale")}));
             this.set("highlighter", new OctaFreeFormHighlighter({scale:this.get("scale")}));
 
@@ -154,9 +151,6 @@ OctaLatticeSubclasses = {
     OctaEdgeLattice: {
 
         _initLatticeType: function(){
-
-            //bind events
-
             this.set("basePlane", new OctaBasePlane({scale:this.get("scale")}));
             this.set("highlighter", new OctaEdgeHighlighter({scale:this.get("scale")}));
 
@@ -216,9 +210,6 @@ OctaLatticeSubclasses = {
     OctaRotEdgeLattice: {
 
         _initLatticeType: function(){
-
-            //bind events
-
             this.set("basePlane", new RotEdgeOctaBasePlane({scale:this.get("scale")}));
             this.set("highlighter", new OctaVertexHighlighter({scale:this.get("scale")}));
         },
@@ -282,9 +273,6 @@ OctaLatticeSubclasses = {
     OctaVertexLattice: {
 
         _initLatticeType: function(){
-
-            //bind events
-
             this.set("basePlane", new SquareBasePlane({scale:this.get("scale")}));
             this.set("highlighter", new OctaVertexHighlighter({scale:this.get("scale")}));
         },
diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js
index cf3e6b3e..11213081 100644
--- a/js/models/LatticeOther.js
+++ b/js/models/LatticeOther.js
@@ -12,9 +12,6 @@ OtherLatticeSubclasses = {
     CubeLattice: {
 
         _initLatticeType: function(){
-
-            //bind events
-
             this.set("basePlane", new SquareBasePlane({scale:this.get("scale")}));
             this.set("highlighter", new CubeHighlighter({scale:this.get("scale")}));
         },
@@ -60,9 +57,6 @@ OtherLatticeSubclasses = {
     TruncatedCubeLattice: {
 
         _initLatticeType: function(){
-
-            //bind events
-
             this.set("basePlane", new SquareBasePlane({scale:this.get("scale")}));
             this.set("highlighter", new TruncatedCubeHighlighter({scale:this.get("scale")}));
         },
@@ -110,9 +104,6 @@ OtherLatticeSubclasses = {
     KelvinLattice: {
 
         _initLatticeType: function(){
-
-            //bind events
-
             this.set("basePlane", new SquareBasePlane({scale:this.get("scale")}));
             this.set("highlighter", new TruncatedCubeHighlighter({scale:this.get("scale")}));
         },
-- 
GitLab