From 2c4797d0b0ada20e3c580359289c347b43f10c57 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 12 Mar 2015 03:01:42 -0400
Subject: [PATCH] more controls in cam, bugfixes

---
 js/cam/Assembler.js         | 23 +++++++++++++++++++----
 js/cam/GCodeExporter.js     |  3 ++-
 js/cam/ShopbotExporter.js   |  6 ++++--
 js/menus/CamMenuView.js     | 10 +++++++---
 js/menus/LatticeMenuView.js |  2 +-
 js/models/AppState.js       |  2 +-
 6 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js
index 96405d56..eb0d2e78 100644
--- a/js/cam/Assembler.js
+++ b/js/cam/Assembler.js
@@ -15,7 +15,10 @@ Assembler = Backbone.Model.extend({
         rapidHeight: 12,
         stockHeight: 3,
         origin: null,
-        originPosition: new THREE.Vector3(0,0,0)
+        originPosition: new THREE.Vector3(0,0,0),
+
+        rapidSpeeds:{xy: 12, z: 4},
+        feedRate:{xy: 12, z: 4},
     },
 
     initialize: function(){
@@ -23,10 +26,16 @@ Assembler = Backbone.Model.extend({
         _.bindAll(this, "postProcess");
 
         //bind events
-        this.listenTo(this, "change:camProcess", this._setNeedsPostProcessing);
         this.listenTo(dmaGlobals.appState, "change:units", this._setNeedsPostProcessing);
         this.listenTo(dmaGlobals.appState, "change:currentTab", this._setOriginVisibility);
         this.listenTo(this, "change:originPosition", this._moveOrigin);
+        this.listenTo(this,
+                "change:originPosition " +
+                "change:feedRate " +
+                "change:rapidSpeeds " +
+                "change:camProcess " +
+                "change:camStrategy",
+            this._setNeedsPostProcessing);
 
         //init origin mesh
         var origin = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4), new THREE.MeshBasicMaterial({color:0xff0000}));
@@ -89,7 +98,13 @@ Assembler = Backbone.Model.extend({
         var stockHeight = this.get("stockHeight");
         data += exporter.moveZ(rapidHeight);
         data += "\n";
-        dmaGlobals.lattice.rasterCells("XYZ", function(cell, x, y, z){
+        var wcs = this.get("originPosition");
+
+        var strategy = this.get("camStrategy");
+        var order;
+        if (strategy == "xRaster") order = "XYZ";
+        else if (strategy == "yRaster") order = "YXZ";
+        dmaGlobals.lattice.rasterCells(order, function(cell, x, y, z){
             if (!cell) return;
 
             data += exporter.rapidXY(0, 0);
@@ -97,7 +112,7 @@ Assembler = Backbone.Model.extend({
             data += exporter.moveZ(rapidHeight);
 
             var cellPosition = cell.getPosition();
-            data += exporter.rapidXY(cellPosition.x.toFixed(3), cellPosition.y.toFixed(3));
+            data += exporter.rapidXY((cellPosition.x-wcs.x).toFixed(3), (cellPosition.y-wcs.y).toFixed(3));
             data += exporter.moveZ(stockHeight);
             data += exporter.moveZ(rapidHeight);
 
diff --git a/js/cam/GCodeExporter.js b/js/cam/GCodeExporter.js
index 3ad33a5b..99c18b8a 100644
--- a/js/cam/GCodeExporter.js
+++ b/js/cam/GCodeExporter.js
@@ -18,6 +18,8 @@ GCodeExporter.prototype.makeHeader = function(){
     data += this.goHome();
 
     //set rapid and feed speeds
+    var rapidSpeeds = dmaGlobals.assembler.get("rapidSpeeds");
+    var feedRate = dmaGlobals.assembler.get("feedRate");
 
     return data;
 };
@@ -65,7 +67,6 @@ GCodeExporter.prototype.goHome = function(){
     return this.moveXYZ(0,0,dmaGlobals.assembler.get("rapidHeight"));
 };
 
-
 GCodeExporter.prototype.makeFooter = function(){
     var data = "";
     data += this.goHome();
diff --git a/js/cam/ShopbotExporter.js b/js/cam/ShopbotExporter.js
index 47989ca7..a9cc0eb3 100644
--- a/js/cam/ShopbotExporter.js
+++ b/js/cam/ShopbotExporter.js
@@ -11,8 +11,10 @@ ShopbotExporter.prototype.makeHeader = function(){
     data += this.goHome();
     data += this.addLine("SA", [], "absolute distances");
     data += this.addLine("SM", [], "move/cut mode");
-    data += this.addLine("JS", [4, 1], "jog speed xy, z");
-    data += this.addLine("MS", [2, 0.5], "move speed xy, z");
+    var rapidSpeeds = dmaGlobals.assembler.get("rapidSpeeds");
+    data += this.addLine("JS", [rapidSpeeds.xy, rapidSpeeds.z], "jog speed xy, z");
+    var feedRate = dmaGlobals.assembler.get("feedRate");
+    data += this.addLine("MS", [feedRate.xy, feedRate.z], "move speed xy, z");
     return data;
 };
 
diff --git a/js/menus/CamMenuView.js b/js/menus/CamMenuView.js
index 6337df5a..d908e208 100644
--- a/js/menus/CamMenuView.js
+++ b/js/menus/CamMenuView.js
@@ -78,9 +78,13 @@ CamMenuView = Backbone.View.extend({
                     <% }); %>\
                 </ul>\
             </div><br/><br/>\
-            Part Zero: &nbsp;&nbsp;<input data-type="x" value="<%= originPosition.x %>" placeholder="origin X" class="form-control numberInput wcs" type="text">\
-            &nbsp;<input data-type="y" value="<%= originPosition.y %>" placeholder="origin Y" class="form-control numberInput wcs" type="text">\
-            &nbsp;<input data-type="z" value="<%= originPosition.z %>" placeholder="origin Z" class="form-control numberInput wcs" type="text"><br/>\
+            Zero (xyz): &nbsp;&nbsp;<input data-type="x" value="<%= originPosition.x %>" placeholder="X" class="form-control numberInput wcs" type="text">\
+            &nbsp;<input data-type="y" value="<%= originPosition.y %>" placeholder="Y" class="form-control numberInput wcs" type="text">\
+            &nbsp;<input data-type="z" value="<%= originPosition.z %>" placeholder="Z" class="form-control numberInput wcs" type="text"><br/><br/>\
+            Rapid Speeds (xy, z): &nbsp;&nbsp;<input data-type="xy" value="<%= rapidSpeeds.xy %>" placeholder="XY" class="form-control numberInput rapidSpeeds" type="text">\
+            &nbsp;<input data-type="z" value="<%= rapidSpeeds.z %>" placeholder="Z" class="form-control numberInput rapidSpeeds" type="text"><br/><br/>\
+            Feed Rate (xy, z): &nbsp;&nbsp;<input data-type="xy" value="<%= feedRate.xy %>" placeholder="XY" class="form-control numberInput feedRate" type="text">\
+            &nbsp;<input data-type="z" value="<%= feedRate.z %>" placeholder="Z" class="form-control numberInput feedRate" type="text">\
         ')
 
 });
\ No newline at end of file
diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js
index e3421a62..6c254494 100644
--- a/js/menus/LatticeMenuView.js
+++ b/js/menus/LatticeMenuView.js
@@ -149,7 +149,7 @@ LatticeMenuView = Backbone.View.extend({
         <% } %>\
         <br/>\
         Scale:&nbsp;&nbsp;<input id="scaleSlider" data-slider-id="ex1Slider" type="text" data-slider-min="1" data-slider-max="100" data-slider-step="0.1" data-slider-value="<%= scale %>"/>\
-        <br/><input id="latticeScale" value="<%= scale %>" placeholder="enter scale" class="form-control" type="text"><br/>\
+        <br/><input id="latticeScale" value="<%= scale %>" placeholder="enter scale" class="form-control numberInput" type="text"><br/>\
         Units: &nbsp;&nbsp;\
             <div class="btn-group">\
                 <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allUnitTypes[units] %><span class="caret"></span></button>\
diff --git a/js/models/AppState.js b/js/models/AppState.js
index 182a8888..f29aa16f 100644
--- a/js/models/AppState.js
+++ b/js/models/AppState.js
@@ -237,7 +237,7 @@ AppState = Backbone.Model.extend({
                 this.set("shift", state);
                 break;
             case 68://d delete mode
-                if (this.get("cellMode") == "cell") this.set("deleteMode", state);//only for cell mode
+                if (dmaGlobals.lattice.get("cellMode") == "cell") this.set("deleteMode", state);//only for cell mode
                 else this.set("deleteMode", false);
                 break;
             case 69://e
-- 
GitLab