Commit 5ef0906a authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

stock editing

parent 28a607be
......@@ -467,6 +467,15 @@ label {
left: 245px;
}
.assemblerTree>label{
padding-right: 10px;
width: 100%;
}
.assemblerTree{
margin-left: 30px;
}
\ No newline at end of file
display: inline-block;
width: 100%;
height: 35px;
background-color: #eee;
border: 1px solid #ddd;
}
......@@ -157,7 +157,9 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel
_tabChanged: function(){
this._setCAMVisibility();
if (appState.get("currentTab") != "animate") this.resetSimulation();
var currentTab = appState.get("currentTab");
if (currentTab == "assemblerSetup") this.get("assembler").buildComponentTree();
if (currentTab != "animate") this.resetSimulation();
else if (this.get("needsPostProcessing")) this.postProcess();
},
......
......@@ -105,7 +105,8 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
};
Assembler.prototype.highlight = function(componentId){
this.components[componentId].setTranslucent(false);
if (this.components[componentId]) this.components[componentId].setTranslucent(false);
else if (this.stock[componentId]) this.stock[componentId].show();
};
Assembler.prototype._setTranslucent = function(){
......@@ -115,10 +116,27 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
_.each(this.components, function(component){
component.setTranslucent(translucent);
});
this.hideStock();
};
Assembler.prototype.buildComponentTree = function(){
Assembler.prototype.buildComponentTree = function(index, parent, tree){
var self = this;
if (parent === undefined){
index = 0;
tree = {};
}
_.each(this.stock, function(thisStock, key){
if (thisStock.parent == parent) {
tree[key] = index;
}
});
_.each(this.components, function(component, key){
if (component.parent == parent) {
tree[key] = index;
self.buildComponentTree(index+1, key, tree);
}
});
this.tree = tree;
};
......@@ -230,6 +248,12 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
stock.updatePartType();
});
};
Assembler.prototype.hideStock = function(){
_.each(this.stock, function(stock){
stock.hide();
});
};
Assembler.prototype.pickUpStock = function(index, speed, settings, callback){
_.each(this.stock, function(stock){
......@@ -244,9 +268,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
Assembler.prototype.releaseStock = function(index, settings){
lattice.showCellAtIndex(index);
_.each(this.stock, function(stock){
stock.hide();
});
this.hideStock();
};
Assembler.prototype.pause = function(){
......@@ -328,7 +350,8 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
shouldPickUpStock: this.shouldPickUpStock,
relative: this.relative,
camProcesses: this.camProcesses,
numMaterials: this.numMaterials
numMaterials: this.numMaterials,
tree: this.tree || this.buildComponentTree()
}
};
......
......@@ -11,7 +11,8 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
this.object3D = new THREE.Object3D();
this.id = id || "id" + id++;
this.name = json.name || "";
this.parent = null;
this.parent = json.parent;
this.parentObject = null;
this.children = [];
}
......@@ -38,9 +39,9 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
};
Component.prototype.checkAncestry = function(component){//return true if this is a parent/grandparent/great-grandparent...
if (this.parent){
if (this.parent === component) return true;
else return this.parent.checkAncestry(component);
if (this.parentObject){
if (this.parentObject === component) return true;
else return this.parentObject.checkAncestry(component);
}
return false;
};
......@@ -55,11 +56,12 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
};
Component.prototype.addParent = function(parent){
if (this.parent) {
this.parent.removeChild(this);
this.parent = null;
if (this.parentObject) {
this.parentObject.removeChild(this);
this.parentObject = null;
}
this.parent = parent;
this.parentObject = parent;
this.parent = parent.id;
};
Component.prototype.getID = function(){
......@@ -174,7 +176,8 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
//helper
Component.prototype.destroy = function(){
if (this.parent) this.parent.removeChild(this);
if (this.parentObject) this.parentObject.removeChild(this);
this.parentObject = null;
this.parent = null;
var self = this;
_.each(this.children, function(child){
......@@ -191,13 +194,11 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
_.each(this.children, function(child){
childIDs.push(child.id);
});
var parentID = "";
if (this.parent) parentID = this.parent.id;
return {
id: this.id,
name: this.name,
children: childIDs,
parent: parentID,
parent: this.parent || "",
translation: this.object3D.position,
scale: this.object3D.scale.x,
rotation: this.object3D.rotation
......
......@@ -44,7 +44,7 @@ define(['underscore', 'cam', 'three', 'component', 'lattice'], function(_, cam,
};
StockComponent.prototype.hide = function(){
this.cell.hide();
if (this.cell) this.cell.hide();
};
StockComponent.prototype.setMode = function(){
......
Parent/Child Tree:<br/>
<% _.each(components, function(component){ %>
<label class="assemblerTree"><%= component.name %> <a data-id="<%= component.id %>" class="editMachineComponent" href="#">Edit</a></label><br/>
Parent/Child Tree:<br/><br/>
<% var treeLevel = 0; %>
<% _.each(tree, function(level, id){ %>
<% var component = components[id] || stock[id]; %>
<% treeLevel++; %>
<div class="assemblerTree" <% if (treeLevel%2 == 0){ %> style="background-color:#ddd"<% } %> ><label style="padding-left:<%= level*10 + 20 %>px"><%= component.name %>
<a data-id="<%= id %>" class="editMachineComponent pull-right" href="#">Edit</a></label></div><br/>
<% }); %><br/>
<a href="#" id="newMachineComponent" class=" btn btn-block btn-lg btn-default">+ New Machine Component</a><br/>
Stock:<br/>
<% _.each(stock, function(stockEl, id){ %>
<label class="assemblerTree"><%= stockEl.name %> <a data-id="<%= id %>" class="edit Stock" href="#">Edit</a></label><br/>
<% }); %><br/>
<a href="#" id="addStock" class=" btn btn-block btn-lg btn-default">+ New Stock</a><br/>
<a href="#" id="newMachineComponent" class=" btn halfWidth btn-lg btn-default">+ Component</a>
<a href="#" id="addStock" class=" btn halfWidth btn-lg btn-default pull-right">+ Stock</a><br/><br/>
Offset (xyz):&nbsp;&nbsp;
<input data-property="translation" data-key="x" value="<%= translation.x %>" placeholder="X" class="form-control floatInput assembler" type="text">&nbsp;
<input data-property="translation" data-key="y" value="<%= translation.y %>" placeholder="Y" class="form-control floatInput assembler" type="text">&nbsp;
......
Name: &nbsp;&nbsp;<input data-property="name" value="<%= components[editingComponent].name %>" placeholder="Enter Name" class="seventyFiveWidth form-control textInput component" type="text"><br/><br/>
Parent: &nbsp;&nbsp;
<div class="btn-group">
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= components[components[editingComponent].parent].name || "No Parent Selected" %><span class="caret"></span></button>
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><% if (components[editingComponent].parent){ %><%= components[components[editingComponent].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; %>
......@@ -19,9 +19,13 @@ Children: &nbsp;&nbsp;
<% }); %>
</ul>
</div><br/>
<% _.each(components[editingComponent].children, function(childID){ %>
<%= components[childID].name %> <a class="removeChild" data-id="<%= childID %>" href="#">Remove</a><br/>
<% if (components[childID]){ %>
<%= components[childID].name %> <a class="removeChild" data-id="<%= childID %>" href="#">Remove</a><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/>
Offset (xyz):&nbsp;&nbsp;
......
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