From 7899179fb2574b3429ea5b480e28e532b8b078ce Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Wed, 11 Mar 2015 00:21:51 -0400
Subject: [PATCH] asembler class

---
 js/cam/Assembler.js           | 21 +++++++++++++++++++++
 js/cam/ShopbotExporter.js     | 11 +++++++++++
 js/main.js                    |  4 +++-
 js/menus/AnimationMenuView.js |  2 +-
 js/menus/AssemblerMenuView.js | 30 +++++++++++++++++++++---------
 js/menus/CamMenuView.js       |  7 ++++---
 js/menus/ImportMenuView.js    |  2 +-
 js/menus/LatticeMenuView.js   |  2 +-
 js/menus/MenuWrapperView.js   |  4 ++--
 js/menus/PartMenuView.js      |  2 +-
 js/menus/SketchMenuView.js    |  2 +-
 js/models/AppState.js         | 22 ++++++++++++----------
 main.html                     |  2 ++
 13 files changed, 81 insertions(+), 30 deletions(-)
 create mode 100644 js/cam/Assembler.js
 create mode 100644 js/cam/ShopbotExporter.js

diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js
new file mode 100644
index 00000000..44964c5a
--- /dev/null
+++ b/js/cam/Assembler.js
@@ -0,0 +1,21 @@
+/**
+ * Created by aghassaei on 3/10/15.
+ */
+
+Assembler = Backbone.Model.extend({
+
+    defaults: {
+        camStrategy: "xRaster",
+        camProcess: "shopbot"
+    },
+
+    initialize: function(){
+
+        //bind events
+
+    },
+
+    destroy: function(){
+    }
+
+});
\ No newline at end of file
diff --git a/js/cam/ShopbotExporter.js b/js/cam/ShopbotExporter.js
new file mode 100644
index 00000000..f25bf3a3
--- /dev/null
+++ b/js/cam/ShopbotExporter.js
@@ -0,0 +1,11 @@
+/**
+ * Created by aghassaei on 3/10/15.
+ */
+
+function ShopbotExporter() {
+
+}
+
+ShopbotExporter.prototype.exportAndSave = function(){
+
+};
diff --git a/js/main.js b/js/main.js
index 2b6fdd33..dad9fc39 100644
--- a/js/main.js
+++ b/js/main.js
@@ -16,7 +16,9 @@ $(function(){
 
     dmaGlobals.lattice = new Lattice();
     dmaGlobals.lattice._updateLatticeType();//todo get rid of this
-    dmaGlobals.appState = new AppState({lattice:dmaGlobals.lattice});
+    dmaGlobals.assembler = new Assembler();
+    dmaGlobals.appState = new AppState();
+
 
     //ui
     new NavBar({model:dmaGlobals.appState});
diff --git a/js/menus/AnimationMenuView.js b/js/menus/AnimationMenuView.js
index 362f06af..730458f2 100644
--- a/js/menus/AnimationMenuView.js
+++ b/js/menus/AnimationMenuView.js
@@ -26,7 +26,7 @@ AnimationMenuView = Backbone.View.extend({
 
     render: function(){
         if (this.appState.get("currentTab") != "animate") return;
-        this.$el.html(this.template(this.model.attributes));
+        this.$el.html(this.template(this.model.toJSON()));
     },
 
     template: _.template('\
diff --git a/js/menus/AssemblerMenuView.js b/js/menus/AssemblerMenuView.js
index aa1a23aa..a56c4e1e 100644
--- a/js/menus/AssemblerMenuView.js
+++ b/js/menus/AssemblerMenuView.js
@@ -8,24 +8,36 @@ AssemblerMenuView = Backbone.View.extend({
     el: "#menuContent",
 
     events: {
+        "click .camStrategy":                            "_selectCamStrategy"
     },
 
     initialize: function(options){
 
+        this.assembler = options.assembler;
+
         _.bindAll(this, "render");
+        this.listenTo(this.assembler, "change", this.render);
+    },
+
+    _selectCamStrategy: function(e){
+        e.preventDefault();
+        this.assembler.set("camStrategy", $(e.target).data("type"));
     },
 
     render: function(){
         if (this.model.get("currentTab") != "assembler") return;
-        this.$el.html(this.template());
+        this.$el.html(this.template(_.extend(this.model.toJSON(), this.assembler.toJSON())));
     },
 
-    template: _.template("\
-        <a href='https://www.youtube.com/watch?v=1Cv7qaz63nQ'>Kiva simulation</a><br/><br/>\
-        <a href='http://fab.cba.mit.edu/classes/865.15/people/will.langford/2_replicating/index.html'>will's demo</a><br/><br/>\
-        <a href='http://www.eecs.harvard.edu/ssr/papers/iros11wksp-werfel.pdf'>asynchronous, multi-agent assembly algorithms</a> (doesn't necessarily have to be swarm-based)\
-        <a href='https://www.youtube.com/watch?v=XNoNpjYQN4s'>video</a>\
-        <br/><br/>\
-        ")
-
+    template: _.template('\
+        Strategy: &nbsp;&nbsp;\
+            <div class="btn-group">\
+                <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allAssemblyStrategies[camStrategy] %><span class="caret"></span></button>\
+                <ul role="menu" class="dropdown-menu">\
+                    <% _.each(_.keys(allAssemblyStrategies), function(key){ %>\
+                        <li><a class="camStrategy" data-type="<%= key %>" href="#"><%= allAssemblyStrategies[key] %></a></li>\
+                    <% }); %>\
+                </ul>\
+            </div><br/><br/>\
+        ')
 });
\ No newline at end of file
diff --git a/js/menus/CamMenuView.js b/js/menus/CamMenuView.js
index 5c9c933c..d08343d0 100644
--- a/js/menus/CamMenuView.js
+++ b/js/menus/CamMenuView.js
@@ -15,19 +15,20 @@ CamMenuView = Backbone.View.extend({
     initialize: function(options){
 
         this.lattice = options.lattice;
+        this.assembler = options.assembler;
 
         _.bindAll(this, "render");
-        this.listenTo(this.model, "change:camProcess", this.render);
+        this.listenTo(this.assembler, "change", this.render);
     },
 
     _selectCamProcess: function(e){
         e.preventDefault();
-        this.model.set("camProcess", $(e.target).data("type"));
+        this.assembler.set("camProcess", $(e.target).data("type"));
     },
 
     render: function(){
         if (this.model.get("currentTab") != "cam") return;
-        this.$el.html(this.template(_.extend(this.model.attributes)));
+        this.$el.html(this.template(_.extend(this.model.toJSON(), this.assembler.toJSON())));
     },
 
     template: _.template('\
diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js
index a4c111c6..a8ac6483 100644
--- a/js/menus/ImportMenuView.js
+++ b/js/menus/ImportMenuView.js
@@ -88,7 +88,7 @@ ImportMenuView = Backbone.View.extend({
 
     render: function(){
         if (this.appState.get("currentTab") != "import") return;
-        this.$el.html(this.template(this.model.attributes));
+        this.$el.html(this.template(this.model.toJSON()));
     },
 
 //    makeDimensionString: function(){
diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js
index 7dfe0600..0caee853 100644
--- a/js/menus/LatticeMenuView.js
+++ b/js/menus/LatticeMenuView.js
@@ -97,7 +97,7 @@ LatticeMenuView = Backbone.View.extend({
 
     render: function(){
         if (this.model.get("currentTab") != "lattice") return;
-        this.$el.html(this.template(_.extend(this.model.attributes, this.lattice.attributes)));
+        this.$el.html(this.template(_.extend(this.model.toJSON(), this.lattice.toJSON())));
 
         $('#scaleSlider').slider({
             formatter: function(value) {
diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js
index 40d64b35..248deb41 100644
--- a/js/menus/MenuWrapperView.js
+++ b/js/menus/MenuWrapperView.js
@@ -26,9 +26,9 @@ MenuWrapper = Backbone.View.extend({
         this.physicsMenu = new PhysicsMenuView({model:this.model});
         this.materialMenu = new MaterialMenuView({model:this.model});
         this.optimizeMenu = new OptimizationMenuView({model:this.model});
-        this.assemblerMenu = new AssemblerMenuView({model:this.model});
+        this.assemblerMenu = new AssemblerMenuView({model:this.model, assembler: dmaGlobals.assembler});
         this.animationMenu = new AnimationMenuView({model:lattice.get("basePlane"), appState:this.model});
-        this.camMenu = new CamMenuView({model:this.model, lattice:lattice});
+        this.camMenu = new CamMenuView({model:this.model, lattice:lattice, assembler:dmaGlobals.assembler});
 
         //data names and titles
         this.designMenuTabs = {lattice:"Lattice", import:"Import", sketch:"Sketch", part:"Part", script:"Script"};
diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js
index 18f1b009..c9ad5049 100644
--- a/js/menus/PartMenuView.js
+++ b/js/menus/PartMenuView.js
@@ -31,7 +31,7 @@ PartMenuView = Backbone.View.extend({
 
     render: function(){
         if (this.model.get("currentTab") != "part") return;
-        this.$el.html(this.template(_.extend(this.model.attributes, this.lattice.attributes)));
+        this.$el.html(this.template(_.extend(this.model.toJSON(), this.lattice.toJSON())));
 
         $('#columnSepSlider').slider({
             formatter: function(value) {
diff --git a/js/menus/SketchMenuView.js b/js/menus/SketchMenuView.js
index 0b69b789..6d7df911 100644
--- a/js/menus/SketchMenuView.js
+++ b/js/menus/SketchMenuView.js
@@ -25,7 +25,7 @@ SketchMenuView = Backbone.View.extend({
 
     render: function(){
         if (this.appState.get("currentTab") != "sketch") return;
-        this.$el.html(this.template(this.model.get("basePlane").attributes));
+        this.$el.html(this.template(this.model.get("basePlane").toJSON()));
 
         $('#zHeightSlider').slider({
             formatter: function(value) {
diff --git a/js/models/AppState.js b/js/models/AppState.js
index 62d18488..7755818e 100644
--- a/js/models/AppState.js
+++ b/js/models/AppState.js
@@ -48,11 +48,14 @@ AppState = Backbone.Model.extend({
             }
         },
 
+        allAssemblyStrategies: {
+            xRaster: "X Raster",
+            yRaster: "Y Raster"
+        },
         allCamProcesses: {
             shopbot: "Shopbot (sbp)",
             gcode: "G-Code"
         },
-        camProcess: "shopbot",
 
         menuIsVisible: true,
 
@@ -62,7 +65,7 @@ AppState = Backbone.Model.extend({
         extrudeMode: false
     },
 
-    initialize: function(options){
+    initialize: function(){
 
         _.bindAll(this, "_handleKeyStroke");
 
@@ -74,7 +77,6 @@ AppState = Backbone.Model.extend({
         this.listenTo(this, "change:currentNav", this._updateCurrentTabForNav);
         this.listenTo(this, "change:currentTab", this._updateCellMode);
 
-        this.lattice = options.lattice;//this doesn't need to be tracked for changes
         this.downKeys = {};//track keypresses to prevent repeat keystrokeson hold
 
         if (this.isMobile()) this.set("menuIsVisible", false);
@@ -105,10 +107,10 @@ AppState = Backbone.Model.extend({
 
     _updateCellMode: function(){
         var currentTab = this.get("currentTab");
-        if (currentTab == "lattice") this.lattice.set("cellMode", "cell");
-        else if (currentTab == "import") this.lattice.set("cellMode", "cell");
-        else if (currentTab == "sketch") this.lattice.set("cellMode", "cell");
-        else if (currentTab == "part") this.lattice.set("cellMode", "part");
+        if (currentTab == "lattice") dmaGlobals.lattice.set("cellMode", "cell");
+        else if (currentTab == "import") dmaGlobals.lattice.set("cellMode", "cell");
+        else if (currentTab == "sketch") dmaGlobals.lattice.set("cellMode", "cell");
+        else if (currentTab == "part") dmaGlobals.lattice.set("cellMode", "part");
     },
 
     //update to last tab open in that section
@@ -155,9 +157,9 @@ AppState = Backbone.Model.extend({
                 this.set("extrudeMode", state);
                 break;
             case 80://p part mode
-                var cellMode = this.lattice.get("cellMode");
-                if (cellMode == "part") this.lattice.set("cellMode", "cell");
-                else if (cellMode == "cell") this.lattice.set("cellMode", "part");
+                var cellMode = dmaGlobals.lattice.get("cellMode");
+                if (cellMode == "part") dmaGlobals.lattice.set("cellMode", "cell");
+                else if (cellMode == "cell") dmaGlobals.lattice.set("cellMode", "part");
                 break;
             case 83://s save
                 if (e.ctrlKey || e.metaKey){//command
diff --git a/main.html b/main.html
index 97964b37..132c5860 100644
--- a/main.html
+++ b/main.html
@@ -63,6 +63,8 @@
     <script src="js/models/BasePlane.js"></script>
     <script src="js/models/extrudeVisualizer.js"></script>
     <script src="js/models/AppState.js"></script>
+    <script src="js/cam/Assembler.js"></script>
+    <script src="js/cam/ShopbotExporter.js"></script>
 
     <!--views-->
     <script src="js/menus/MenuWrapperView.js"></script>
-- 
GitLab