Skip to content
Snippets Groups Projects
Commit 947c5c9f authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

wiring up controls

parent 9340a255
Branches
No related tags found
No related merge requests found
......@@ -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();
},
......
......@@ -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");
......
......@@ -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): &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/>\
Stock (xyz): &nbsp;&nbsp;<input data-type="x" value="<%= stockPosition.x %>" placeholder="X" class="form-control numberInput stockPosition" type="text">\
&nbsp;<input data-type="y" value="<%= stockPosition.y %>" placeholder="Y" class="form-control numberInput stockPosition" type="text">\
&nbsp;<input data-type="z" value="<%= stockPosition.z %>" placeholder="Z" class="form-control numberInput stockPosition" 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">\
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment