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

moving origin

parent a293e65c
No related branches found
No related tags found
No related merge requests found
......@@ -160,3 +160,8 @@ hr {
#gcodeEditor:focus {
outline-width: 0;
}
input.numberInput{
width:22%;
display: inline;
}
......@@ -14,6 +14,8 @@ Assembler = Backbone.Model.extend({
rapidHeight: 12,
stockHeight: 3,
origin: null,
originPosition: new THREE.Vector3(0,0,0)
},
initialize: function(){
......@@ -23,7 +25,28 @@ Assembler = Backbone.Model.extend({
//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);
//init origin mesh
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();
},
_setOriginVisibility: function(){
var visible = false;
var currentTab = dmaGlobals.appState.get("currentTab");
if (currentTab == "cam" || currentTab == "animate" || currentTab == "send") visible = true;
this.get("origin").visible = visible;
dmaGlobals.three.render();
},
_moveOrigin: function(){
var position = this.get("originPosition");
this.get("origin").position.set(position.x, position.y, position.z);
dmaGlobals.three.render();
},
_setNeedsPostProcessing: function(){
......
......@@ -20,8 +20,11 @@ CamMenuView = Backbone.View.extend({
this.assembler = options.assembler;
_.bindAll(this, "render");
_.bindAll(this, "_updateOrigin");
//bind events
this.listenTo(this.assembler, "change", this.render);
this.listenTo(this.model, "change:units", this.render);
$(document).bind('keyup', {state:false}, this._updateOrigin);
},
_selectCamProcess: function(e){
......@@ -34,6 +37,16 @@ CamMenuView = Backbone.View.extend({
this.model.set("units", $(e.target).data("type"));
},
_updateOrigin: function(e){
if (!$(".wcs").is(":focus")) return;
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");
},
_save: function(e){
e.preventDefault();
this.assembler.save();
......@@ -41,6 +54,7 @@ CamMenuView = Backbone.View.extend({
render: function(){
if (this.model.get("currentTab") != "cam") return;
if ($(".wcs").is(":focus")) return;
this.$el.html(this.template(_.extend(this.model.toJSON(), this.assembler.toJSON())));
},
......@@ -54,6 +68,7 @@ CamMenuView = Backbone.View.extend({
<% }); %>\
</ul>\
</div><br/><br/>\
<a href="#" id="saveCam" class=" btn btn-block btn-lg btn-default">Process and Save</a><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>\
......@@ -63,7 +78,9 @@ CamMenuView = Backbone.View.extend({
<% }); %>\
</ul>\
</div><br/><br/>\
<a href="#" id="saveCam" class=" btn btn-block btn-lg btn-default">Process and Save</a><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/>\
')
});
\ No newline at end of file
......@@ -92,6 +92,7 @@ MenuWrapper = Backbone.View.extend({
var self = this;
this._hide(function(){
self._populateAndShow();
self.model.trigger("change:currentTab");//this was updated silently before
}, true);
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment