From 947c5c9f454de4bc9312fd69402181cb09d4c198 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 12 Mar 2015 16:51:38 -0400 Subject: [PATCH] wiring up controls --- js/cam/Assembler.js | 27 +++++++++++++++++++++------ js/cam/ShopbotExporter.js | 2 +- js/menus/CamMenuView.js | 29 +++++++++++++++++++---------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index e91e14ea..3ef8b113 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -17,9 +17,11 @@ Assembler = Backbone.Model.extend({ stockHeight: 3, origin: null, originPosition: new THREE.Vector3(0,0,0), + stock: null, + stockPosition: new THREE.Vector3(0,0,0), rapidSpeeds:{xy: 12, z: 4}, - feedRate:{xy: 12, z: 4}, + feedRate:{xy: 12, z: 4} }, initialize: function(){ @@ -27,9 +29,9 @@ Assembler = Backbone.Model.extend({ _.bindAll(this, "postProcess"); //bind events - this.listenTo(dmaGlobals.appState, "change:units", this._setNeedsPostProcessing); - this.listenTo(dmaGlobals.appState, "change:currentTab", this._setOriginVisibility); + this.listenTo(dmaGlobals.appState, "change:currentTab", this._setCAMVisibility); this.listenTo(this, "change:originPosition", this._moveOrigin); + this.listenTo(dmaGlobals.appState, "change:units", this._setNeedsPostProcessing); this.listenTo(this, "change:originPosition " + "change:feedRate " + @@ -37,19 +39,32 @@ Assembler = Backbone.Model.extend({ "change:camProcess " + "change:camStrategy", this._setNeedsPostProcessing); + this.listenTo(dmaGlobals.lattice, + "change:numCells " + + "change:scale " + + "change:cellType " + + "change:connectionType", + this._setNeedsPostProcessing); //init origin mesh - var origin = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4), new THREE.MeshBasicMaterial({color:0xff0000})); + var origin = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4), + new THREE.MeshBasicMaterial({color:0xff0000})); dmaGlobals.three.sceneAdd(origin); this.set("origin", origin); - this._setOriginVisibility(); + //init stock mesh + var stock = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4), + new THREE.MeshBasicMaterial({color:0xffff00})); + dmaGlobals.three.sceneAdd(origin); + this.set("stock", stock); + this._setCAMVisibility(); }, - _setOriginVisibility: function(){ + _setCAMVisibility: function(){ var visible = false; var currentTab = dmaGlobals.appState.get("currentTab"); if (currentTab == "cam" || currentTab == "animate" || currentTab == "send") visible = true; this.get("origin").visible = visible; + this.get("stock").visible = visible; dmaGlobals.three.render(); }, diff --git a/js/cam/ShopbotExporter.js b/js/cam/ShopbotExporter.js index a9cc0eb3..4b89f60b 100644 --- a/js/cam/ShopbotExporter.js +++ b/js/cam/ShopbotExporter.js @@ -8,8 +8,8 @@ function ShopbotExporter() { ShopbotExporter.prototype.makeHeader = function(){ var data = ""; data += this.addLine("FG", [], "single step mode"); - data += this.goHome(); data += this.addLine("SA", [], "absolute distances"); + data += this.goHome(); data += this.addLine("SM", [], "move/cut mode"); var rapidSpeeds = dmaGlobals.assembler.get("rapidSpeeds"); data += this.addLine("JS", [rapidSpeeds.xy, rapidSpeeds.z], "jog speed xy, z"); diff --git a/js/menus/CamMenuView.js b/js/menus/CamMenuView.js index d908e208..be447d49 100644 --- a/js/menus/CamMenuView.js +++ b/js/menus/CamMenuView.js @@ -20,11 +20,11 @@ CamMenuView = Backbone.View.extend({ this.assembler = options.assembler; _.bindAll(this, "render"); - _.bindAll(this, "_updateOrigin"); + _.bindAll(this, "_onKeyup"); //bind events this.listenTo(this.assembler, "change", this.render); this.listenTo(this.model, "change:units", this.render); - $(document).bind('keyup', {state:false}, this._updateOrigin); + $(document).bind('keyup', {state:false}, this._onKeyup); }, _selectCamProcess: function(e){ @@ -37,14 +37,20 @@ CamMenuView = Backbone.View.extend({ this.model.set("units", $(e.target).data("type")); }, - _updateOrigin: function(e){ - if (!$(".wcs").is(":focus")) return; + _onKeyup: function(e){ + if ($(".wcs").is(":focus")) this._updateNumber(e, "originPosition"); + else if ($(".stockPosition").is(":focus")) this._updateNumber(e, "stockPosition"); + else if ($(".rapidSpeeds").is(":focus")) this._updateNumber(e, "rapidSpeeds"); + else if ($(".feedRate").is(":focus")) this._updateNumber(e, "feedRate"); + }, + + _updateNumber: function(e, property){ e.preventDefault(); - var newPosition = parseFloat($(e.target).val()); - if (isNaN(newPosition)) return; - var origin = this.assembler.get("originPosition"); - origin[$(e.target).data("type")] = newPosition; - this.assembler.trigger("change:originPosition"); + var newVal = parseFloat($(e.target).val()); + if (isNaN(newVal)) return; + var object = this.assembler.get(property); + object[$(e.target).data("type")] = newVal; + this.assembler.trigger("change:"+property); }, _save: function(e){ @@ -54,7 +60,7 @@ CamMenuView = Backbone.View.extend({ render: function(){ if (this.model.get("currentTab") != "cam") return; - if ($(".wcs").is(":focus")) return; + if ($("input").is(":focus")) return; this.$el.html(this.template(_.extend(this.model.toJSON(), this.assembler.toJSON()))); }, @@ -81,6 +87,9 @@ CamMenuView = Backbone.View.extend({ Zero (xyz): <input data-type="x" value="<%= originPosition.x %>" placeholder="X" class="form-control numberInput wcs" type="text">\ <input data-type="y" value="<%= originPosition.y %>" placeholder="Y" class="form-control numberInput wcs" type="text">\ <input data-type="z" value="<%= originPosition.z %>" placeholder="Z" class="form-control numberInput wcs" type="text"><br/><br/>\ + Stock (xyz): <input data-type="x" value="<%= stockPosition.x %>" placeholder="X" class="form-control numberInput stockPosition" type="text">\ + <input data-type="y" value="<%= stockPosition.y %>" placeholder="Y" class="form-control numberInput stockPosition" type="text">\ + <input data-type="z" value="<%= stockPosition.z %>" placeholder="Z" class="form-control numberInput stockPosition" type="text"><br/><br/>\ Rapid Speeds (xy, z): <input data-type="xy" value="<%= rapidSpeeds.xy %>" placeholder="XY" class="form-control numberInput rapidSpeeds" type="text">\ <input data-type="z" value="<%= rapidSpeeds.z %>" placeholder="Z" class="form-control numberInput rapidSpeeds" type="text"><br/><br/>\ Feed Rate (xy, z): <input data-type="xy" value="<%= feedRate.xy %>" placeholder="XY" class="form-control numberInput feedRate" type="text">\ -- GitLab