From 8dba85fe2f474465327d59168dd8879aac4cab88 Mon Sep 17 00:00:00 2001 From: amandaghassaei <amandaghassaei@gmail.com> Date: Wed, 18 Mar 2015 19:49:02 -0400 Subject: [PATCH] stock pos relative to origin --- css/main.css | 4 +-- js/cam/Assembler.js | 23 ++++++------- js/menus/CamMenuView.js | 64 ++++++++++++++++++++++++++++++------- js/menus/MenuWrapperView.js | 2 +- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/css/main.css b/css/main.css index 55dc09fa..ab529738 100644 --- a/css/main.css +++ b/css/main.css @@ -82,13 +82,13 @@ nav .btn { /*menus*/ #menuWrapper { - width: 400px; + width: 450px; height: 100%; z-index: 1; position: absolute; display: block; background-color: rgba(255,255,255,0.8); - right: -400px;/*initially hidden*/ + right: -450px;/*initially hidden*/ overflow:hidden; } diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index 8c00970e..f8fa89db 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -22,7 +22,8 @@ Assembler = Backbone.Model.extend({ origin: null, originPosition: new THREE.Vector3(20,0,0), stock: null, - stockPosition: new THREE.Vector3(20,0,0), + stockPosition: new THREE.Vector3(20,0,0),//in abs coordinates + stockPositionRelative: true, stockArraySize: {x:3, y:3}, stockSeparation: 2.78388, postStockNum: 0,//which piece of stock to pick up @@ -197,10 +198,10 @@ Assembler = Backbone.Model.extend({ var rapidHeight = this.get("rapidHeight"); var safeHeight = this.get("safeHeight"); - data += exporter.moveZ(rapidHeight); + var wcs = this.get("originPosition"); + data += exporter.moveZ(rapidHeight+wcs.z); data += "\n"; - var wcs = this.get("originPosition"); var stockPosition = this.get("stockPosition"); var self = this; dmaGlobals.lattice.rasterCells(this._getOrder(this.get("camStrategy")), function(cell){ @@ -210,7 +211,7 @@ Assembler = Backbone.Model.extend({ var stockArraySize = self.get("stockArraySize"); stockNumPosition.x += stockNum % stockArraySize.y * self.get("stockSeparation"); stockNumPosition.y -= Math.floor(stockNum / stockArraySize.y) * self.get("stockSeparation"); - data += self._grabStock(exporter, stockNumPosition, rapidHeight, safeHeight); + data += self._grabStock(exporter, stockNumPosition, rapidHeight, wcs, safeHeight); stockNum += 1; if (stockNum >= stockArraySize.x*stockArraySize.y) stockNum = 0; self.set("postStockNum", stockNum, {silent:true}); @@ -254,14 +255,14 @@ Assembler = Backbone.Model.extend({ return ""; }, - _grabStock: function(exporter, stockPosition, rapidHeight, safeHeight){ + _grabStock: function(exporter, stockPosition, rapidHeight, wcs, safeHeight){ var data = ""; - data += exporter.rapidXY(stockPosition.x, stockPosition.y); - data += exporter.rapidZ(stockPosition.z+safeHeight); - data += exporter.moveZ(stockPosition.z); + data += exporter.rapidXY(stockPosition.x-wcs.x, stockPosition.y-wcs.y); + data += exporter.rapidZ(stockPosition.z-wcs.z+safeHeight); + data += exporter.moveZ(stockPosition.z-wcs.z); data += exporter.addComment("get stock"); - data += exporter.moveZ(stockPosition.z+safeHeight); - data += exporter.rapidZ(rapidHeight); + data += exporter.moveZ(stockPosition.z-wcs.z+safeHeight); + data += exporter.rapidZ(rapidHeight+wcs.z); return data; }, @@ -273,7 +274,7 @@ Assembler = Backbone.Model.extend({ data += exporter.moveZ(cellPosition.z-wcs.z); data += exporter.addComment(JSON.stringify(cell.indices)); data += exporter.moveZ(cellPosition.z-wcs.z+safeHeight); - data += exporter.rapidZ(rapidHeight); + data += exporter.rapidZ(rapidHeight+wcs.z); return data; }, diff --git a/js/menus/CamMenuView.js b/js/menus/CamMenuView.js index 4f1d9d41..7442d585 100644 --- a/js/menus/CamMenuView.js +++ b/js/menus/CamMenuView.js @@ -10,7 +10,9 @@ CamMenuView = Backbone.View.extend({ events: { "click .camProcess": "_selectCamProcess", "click .units": "_changeUnits", - "click #saveCam": "_save" + "click #saveCam": "_save", + "change #stockPosRel": "_changeStockPositionRelative", + "focusout .numberInput": "render" }, @@ -38,8 +40,18 @@ CamMenuView = Backbone.View.extend({ _onKeyup: function(e){ if (this.model.get("currentTab") != "cam") return; + + if ($("input").is(":focus") && e.keyCode == 13) {//enter key + $(e.target).blur(); + this.render(); + return; + } + if ($(".wcs").is(":focus")) this._updateNumber(e, "originPosition"); - else if ($(".stockPosition").is(":focus")) this._updateNumber(e, "stockPosition"); + else if ($(".stockPosition").is(":focus")){ + if (!this.assembler.get("stockPositionRelative")) this._updateNumber(e, "stockPosition"); + else this._updateRelativeStockPosition(e); + } else if ($(".rapidSpeeds").is(":focus")) this._updateNumber(e, "rapidSpeeds"); else if ($(".feedRate").is(":focus")) this._updateNumber(e, "feedRate"); else if ($(".safeHeight").is(":focus")) this._updateNumber(e, "safeHeight"); @@ -50,15 +62,33 @@ CamMenuView = Backbone.View.extend({ e.preventDefault(); var newVal = parseFloat($(e.target).val()); if (isNaN(newVal)) return; - newVal = newVal.toFixed(4); + newVal = parseFloat(newVal.toFixed(4)); var object = this.assembler.get(property); if ($(e.target).data("type")) { object[$(e.target).data("type")] = newVal; - this.assembler.trigger("change:"+property); + this.assembler.trigger("change:" + property); + this.assembler.trigger("change"); } else this.assembler.set(property, newVal); }, + _updateRelativeStockPosition: function(e){ + e.preventDefault(); + var newVal = parseFloat($(e.target).val()); + if (isNaN(newVal)) return; + var dim = $(e.target).data("type"); + newVal = (newVal + this.assembler.get("originPosition")[dim]).toFixed(4); + this.assembler.get("stockPosition")[dim] = parseFloat(newVal); + this.assembler.trigger("change:stockPosition"); + this.assembler.trigger("change"); + }, + + _changeStockPositionRelative: function(e){ + e.preventDefault(); + $(e.target).blur(); + dmaGlobals.assembler.set("stockPositionRelative", !dmaGlobals.assembler.get("stockPositionRelative")); + }, + _save: function(e){ e.preventDefault(); this.assembler.save(); @@ -67,7 +97,15 @@ CamMenuView = Backbone.View.extend({ render: function(){ if (this.model.get("currentTab") != "cam") return; if ($("input").is(":focus")) return; - this.$el.html(this.template(_.extend(this.model.toJSON(), this.assembler.toJSON(), this.lattice.toJSON()))); + var data = _.extend(this.model.toJSON(), this.assembler.toJSON(), this.lattice.toJSON()); + if (this.assembler.get("stockPositionRelative")){ + var relStockPos = {}; + relStockPos.x = data.stockPosition.x - data.originPosition.x; + relStockPos.y = data.stockPosition.y - data.originPosition.y; + relStockPos.z = data.stockPosition.z - data.originPosition.z; + data.stockPosition = relStockPos; + } + this.$el.html(this.template(data)); }, template: _.template('\ @@ -90,12 +128,16 @@ CamMenuView = Backbone.View.extend({ <% }); %>\ </ul>\ </div><br/><br/>\ - 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/>\ + Zero (xyz): <input data-type="x" value="<%= originPosition.x.toFixed(4) %>" placeholder="X" class="form-control numberInput wcs" type="text">\ + <input data-type="y" value="<%= originPosition.y.toFixed(4) %>" placeholder="Y" class="form-control numberInput wcs" type="text">\ + <input data-type="z" value="<%= originPosition.z.toFixed(4) %>" placeholder="Z" class="form-control numberInput wcs" type="text"><br/><br/>\ + Stock (xyz): <input data-type="x" value="<%= stockPosition.x.toFixed(4) %>" placeholder="X" class="form-control numberInput stockPosition" type="text">\ + <input data-type="y" value="<%= stockPosition.y.toFixed(4) %>" placeholder="Y" class="form-control numberInput stockPosition" type="text">\ + <input data-type="z" value="<%= stockPosition.z.toFixed(4) %>" placeholder="Z" class="form-control numberInput stockPosition" type="text"><br/>\ + <label class="checkbox" for="stockPosRel">\ + <input id="stockPosRel" type="checkbox" <% if (stockPositionRelative){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="custom-checkbox">\ + <span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ + Stock position relative to Zero</label><br/>\ Clearance Height: <input value="<%= rapidHeight %>" placeholder="Z" class="form-control numberInput rapidHeight" type="text"><br/><br/>\ Approach Height: <input value="<%= safeHeight %>" placeholder="Z" class="form-control numberInput safeHeight" type="text"><br/><br/>\ Speeds (measured in <%= units %> per second):<br/><br/>\ diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 2f2cd7fa..0adcb0cc 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -111,7 +111,7 @@ MenuWrapper = Backbone.View.extend({ }, _hide: function(callback, suppressModelUpdate){ - this.$el.parent().animate({right: "-400"}, {done: callback}); + this.$el.parent().animate({right: "-450"}, {done: callback}); if (!suppressModelUpdate) this.model.set("menuIsVisible", false); }, -- GitLab