diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index 58e8899ed2b1914f367d92b4f0642fb32d961650..5b5b343165a1a6a657a35baf2659bb63ea660735 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -163,10 +163,21 @@ Assembler = Backbone.Model.extend({ _moveOrigin: function(){ var position = this.get("originPosition"); this.get("origin").position.set(position.x, position.y, position.z); + if (this.get("stockPositionRelative")) this._updateStockPosToOrigin(position); dmaGlobals.three.render(); if (this.get("machine").setMachinePosition) this.get("machine").setMachinePosition(); }, + _updateStockPosToOrigin: function(newOrigin){ + var lastOrigin = this.previous("originPosition"); + var newStockPosition = _.clone(this.get("stockPosition")); + _.each(_.keys(newStockPosition), function(key){ + newStockPosition[key] += newOrigin[key] - lastOrigin[key]; + newStockPosition[key] = parseFloat(newStockPosition[key].toFixed(4)); + }); + this.set("stockPosition", newStockPosition); + }, + _moveStock: function(){ var position = this.get("stockPosition"); this.get("stock").position.set(position.x, position.y, position.z); diff --git a/js/menus/CamMenuView.js b/js/menus/CamMenuView.js index d5cf92c8dcd553bf9799c303080f55526fbc8cee..d52545b0d5dae1782160bf8c1f3967d32c7cba53 100644 --- a/js/menus/CamMenuView.js +++ b/js/menus/CamMenuView.js @@ -65,29 +65,18 @@ CamMenuView = Backbone.View.extend({ else if ($(".stockSeparation").is(":focus")) this._updateNumber(e, "stockSeparation"); }, - _updateNumber: function(e, property){ - e.preventDefault(); + _getNumber: function(e, dontRound){ var newVal = parseFloat($(e.target).val()); - if (isNaN(newVal)) return; + if (isNaN(newVal)) return null; + if (dontRound) return newVal; 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"); - } - else this.assembler.set(property, newVal); + return newVal; }, - _updatePosNumber: function(e, property){ + _updateNumber: function(e, property){ e.preventDefault(); - var newVal = parseFloat($(e.target).val()); - if (isNaN(newVal)) return; - newVal = parseFloat(newVal.toFixed(4)); - if (newVal <= 0) { - console.warn("value must be positive"); - return; - } + var newVal = this._getNumber(e); + if (!newVal) return; var object = this.assembler.get(property); if ($(e.target).data("type")) { object[$(e.target).data("type")] = newVal; @@ -99,8 +88,8 @@ CamMenuView = Backbone.View.extend({ _updateRelativeStockPosition: function(e){ e.preventDefault(); - var newVal = parseFloat($(e.target).val()); - if (isNaN(newVal)) return; + var newVal = this._getNumber(e, true); + if (!newVal) return; var dim = $(e.target).data("type"); newVal = (newVal + this.assembler.get("originPosition")[dim]).toFixed(4); this.assembler.get("stockPosition")[dim] = parseFloat(newVal); @@ -110,8 +99,8 @@ CamMenuView = Backbone.View.extend({ _updateAbsoluteRapidHeight: function(e){ e.preventDefault(); - var newVal = parseFloat($(e.target).val()); - if (isNaN(newVal)) return; + var newVal = this._getNumber(e, true); + if (!newVal) return; newVal -= this.assembler.get("originPosition").z.toFixed(4);//always store relative to origin this.assembler.set("rapidHeight", parseFloat(newVal)); }, @@ -196,7 +185,7 @@ CamMenuView = Backbone.View.extend({ <input data-type="y" value="<%= stockArraySize.y %>" placeholder="Y" class="form-control numberInput stockArraySize" type="text"><br/><br/>\ Stock separation: <input value="<%= stockSeparation %>" placeholder="X" class="form-control numberInput stockSeparation" type="text"><br/><br/>\ <% } %>\ - Clearance Height: <input value="<%= rapidHeight %>" placeholder="Z" class="form-control numberInput rapidHeight" type="text"><br/>\ + Clearance Height: <input value="<%= rapidHeight.toFixed(4) %>" placeholder="Z" class="form-control numberInput rapidHeight" type="text"><br/>\ <label class="checkbox" for="rapidPosRel">\ <input id="rapidPosRel" data-property="rapidHeightRelative" type="checkbox" <% if (rapidHeightRelative){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="custom-checkbox">\ <span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 94f13021bd7bf5c184f8d7b212645abe5220c88f..736534a690a7c7284fb9ffc7fd99d553e8f3c70f 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -85,7 +85,14 @@ Highlighter = Backbone.View.extend({ /////////////////////////////////////////////////////////////////////////////////// getHighlightedObjectPosition: function(){ - if (this.highlightedObject instanceof DMACell) return this.highlightedObject.getPosition(); + if (this.highlightedObject instanceof DMACell) { + var position = this.highlightedObject.getPosition(); + return { + x:parseFloat(position.x.toFixed(4)), + y:parseFloat(position.y.toFixed(4)), + z:parseFloat(position.z.toFixed(4)) + }; + } return null; },