Commit 22cc7f31 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

eod

parent 28c74e78
......@@ -10,7 +10,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
function Component(id, json){
this.object3D = new THREE.Object3D();
this.id = id || "id" + id++;
this.name = json.name || "";
this.name = json.name || "Component" + id;
this.parent = null;
if (json.parent) this.parent = json.parent;
this.parentObject = null;
......@@ -51,6 +51,12 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
return false;
};
Component.prototype.getAncestry = function(ancestors){
if (this.parent === null) return ancestors;
ancestors.push(this.parent);
return this.parentObject.getAncestry(ancestors);
};
Component.prototype._removeChild = function(child){
if (this.children.indexOf(child) == -1){
console.warn("not a child");
......
......@@ -10,9 +10,10 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen
events: {
"click #finishComponent": "_save",
"click #cancelComponent": "_cancel",
"click #deleteComponent": "_delete",
"click .removeChild": "_removeChild"
"click .removeChild": "_removeChild",
"click .addChild": "_addChild",
"click .changeParent": "_changeParent"
},
_initialize: function(){
......@@ -24,12 +25,6 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen
},
_save: function(e){
e.preventDefault();
console.log("save component");
this._stopEditing();
},
_cancel: function(e){
e.preventDefault();
this._stopEditing();
},
......@@ -54,10 +49,41 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen
this.render();
},
_addChild: function(e){
e.preventDefault();
var id = $(e.target).data("id");
var assembler = cam.get("assembler");
assembler.getComponent(cam.get("editingComponent")).addChild(assembler.getComponent(id));
assembler.buildComponentTree();
this.render();
},
_changeParent: function(e){
e.preventDefault();
var id = $(e.target).data("id");
console.log(id);
if (!id) id = null;
var assembler = cam.get("assembler");
assembler.getComponent(id).addChild(assembler.getComponent(cam.get("editingComponent")));
assembler.buildComponentTree();
this.render();
},
_makeTemplateJSON: function(){
var assembler = cam.get("assembler");
var component = assembler.getComponent(cam.get("editingComponent"));
return _.extend(this.model.toJSON(), cam.toJSON(), assembler.toJSON(), {thisComponent: component.toJSON()});
var editingComponent = cam.get("editingComponent");
var component = assembler.getComponent(editingComponent);
var allDescendants = [];
var allAncestors = component.getAncestry([]);
var correctBranch = false;
_.each(assembler.tree, function(level, id){
if(correctBranch && level <= assembler.tree[editingComponent]) correctBranch = false;
if(id == editingComponent) correctBranch = true;
if (!correctBranch || assembler.tree[editingComponent] >= level) return;
allDescendants.push(id);
});
return _.extend(this.model.toJSON(), cam.toJSON(), assembler.toJSON(),
{thisComponent: component.toJSON(), ancestors:allAncestors, descendants:allDescendants});
},
template: _.template(template)
......
......@@ -202,6 +202,7 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex
},
_setOwnerProperty: function(owner, property, value){
console.log(value);
if (owner instanceof Backbone.Model) owner.set(property, value);
else {
owner[property] = value;
......
......@@ -5,9 +5,10 @@ Parent: &nbsp;&nbsp;
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><% if (thisComponent.parent){ %><%= components[thisComponent.parent].name %><% }else{ %>No Parent Selected<% } %><span class="caret"></span></button>
<ul role="menu" class="dropdown-menu">
<% _.each(components, function(component){ %>
<% if (component.id == editingComponent) return; %>
<li><a class="component dropdownSelector" data-property="parent" data-value="<%= component.id %>" href="#"><%= component.name %></a></li>
<% if (component.id == editingComponent || descendants.indexOf(component.id)>=0) return; %>
<li><a class="changeParent dropdownSelector" data-id="<%= component.id %>" href="#"><%= component.name %></a></li>
<% }); %>
<li><a class="changeParent dropdownSelector" href="#">None</a></li>
</ul>
</div><br/><br/>
<% if(!isStock){ %>
......@@ -16,20 +17,18 @@ Parent: &nbsp;&nbsp;
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button">+ Add Child<span class="caret"></span></button>
<ul role="menu" class="dropdown-menu">
<% _.each(components, function(component, id){ %>
<% if (component.id == editingComponent || component.id == thisComponent.parent) return; %>
<li><a class="component dropdownSelector" data-property="newChild" data-value="<%= id %>" href="#"><%= component.name %></a></li>
<% if (component.id == editingComponent || ancestors.indexOf(component.id)>=0 || thisComponent.children.indexOf(component.id)>=0) return; %>
<li><a class="addChild dropdownSelector" data-id="<%= id %>" href="#"><%= component.name %></a></li>
<% }); %>
<% _.each(stock, function(thisStock, id){ %>
<li><a class="component dropdownSelector" data-property="newChild" data-value="<%= id %>" href="#"><%= thisStock.name %></a></li>
<% if (thisStock.id == editingComponent || ancestors.indexOf(thisStock.id)>=0 || thisComponent.children.indexOf(thisStock.id)>=0) return; %>
<li><a class="addChild dropdownSelector" data-id="<%= id %>" href="#"><%= thisStock.name %></a></li>
<% }); %>
</ul>
</div><br/><br/>
<% var treeLevel = 0; %>
<% var correctBranch = false; %>
<% _.each(tree, function(level, id){ %>
<% if(correctBranch && level <= tree[editingComponent]) correctBranch = false; %>
<% if(id == editingComponent) correctBranch = true; %>
<% if (!correctBranch || tree[editingComponent] >= level) return; %>
<% if (descendants.indexOf(id)<0) return; %>
<% var component = components[id] || stock[id]; %>
<% treeLevel++; %>
<div class="assemblerTree" <% if (treeLevel%2 == 0){ %> style="background-color:#ddd"<% } %> ><label style="padding-left:<%= (level-tree[editingComponent]-1)*10 + 20 %>px"><%= component.name %>
......@@ -52,18 +51,17 @@ Parent: &nbsp;&nbsp;
<!--Jog<br/>-->
<% } %>
<br/>
<!--STL: &nbsp;&nbsp;STL Name<br/><br/>-->
<!--<a id="uploadStl" href="#" class="btn btn-block btn-lg btn-default">Upload STL</a><br/>-->
<a id="uploadStl" href="#" class="btn btn-block btn-lg btn-default">Upload STL</a><br/>
STL: &nbsp;&nbsp;STL Name<br/><br/>
<% } %>
<!--Offset (xyz):&nbsp;&nbsp;-->
<!--<input data-property="translation" data-key="x" value="<%= translation.x %>" placeholder="X" class="form-control floatInput stl" type="text">&nbsp;-->
<!--<input data-property="translation" data-key="y" value="<%= translation.y %>" placeholder="Y" class="form-control floatInput stl" type="text">&nbsp;-->
<!--<input data-property="translation" data-key="z" value="<%= translation.z %>" placeholder="Z" class="form-control floatInput stl" type="text"><br/><br/>-->
<!--Rotation (xyz):&nbsp;&nbsp;-->
<!--<input data-property="rotation" data-key="x" value="<%= rotation.x %>" placeholder="X" class="form-control floatInput stl" type="text">&nbsp;-->
<!--<input data-property="rotation" data-key="y" value="<%= rotation.y %>" placeholder="Y" class="form-control floatInput stl" type="text">&nbsp;-->
<!--<input data-property="rotation" data-key="z" value="<%= rotation.z %>" placeholder="Z" class="form-control floatInput stl" type="text"><br/><br/>-->
<!--<% if(!isStock){ %> Scale: &nbsp;&nbsp;<input data-property="scale" value="<%= scale %>" placeholder="Scale" class="form-control floatInput stl" type="text"><br/><br/><% } %>-->
<a id="finishComponent" href="#" class="btn btn-block btn-lg btn-success">Save <% if(isStock){ %>Stock<% }else{ %>Component<% } %></a><br/>
Offset (xyz):&nbsp;&nbsp;
<input data-property="translation" data-key="x" value="<%= translation.x %>" placeholder="X" class="form-control floatInput stl" type="text">&nbsp;
<input data-property="translation" data-key="y" value="<%= translation.y %>" placeholder="Y" class="form-control floatInput stl" type="text">&nbsp;
<input data-property="translation" data-key="z" value="<%= translation.z %>" placeholder="Z" class="form-control floatInput stl" type="text"><br/><br/>
Rotation (xyz):&nbsp;&nbsp;
<input data-property="rotation" data-key="x" value="<%= rotation.x %>" placeholder="X" class="form-control floatInput stl" type="text">&nbsp;
<input data-property="rotation" data-key="y" value="<%= rotation.y %>" placeholder="Y" class="form-control floatInput stl" type="text">&nbsp;
<input data-property="rotation" data-key="z" value="<%= rotation.z %>" placeholder="Z" class="form-control floatInput stl" type="text"><br/><br/>
<% if(!isStock){ %> Scale: &nbsp;&nbsp;<input data-property="scale" value="<%= scale %>" placeholder="Scale" class="form-control floatInput stl" type="text"><br/><br/><% } %>
<a id="deleteComponent" href="#" class="btn btn-halfWidth btn-lg btn-default"><span class="fui-trash"></span> Delete</a>
<a id="cancelComponent" href="#" class="btn btn-halfWidth pull-right btn-lg btn-default">Cancel / Exit</a><br/><br/>
<a id="finishComponent" href="#" class="btn btn-halfWidth pull-right btn-lg btn-success">Save <% if(isStock){ %>Stock<% }else{ %>Component<% } %></a><br/><br/>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment