From 4639dcab1c45914fe614e9a98032c352d8e54fd6 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sun, 16 Aug 2015 02:12:11 -0400 Subject: [PATCH] tree edits --- css/main.css | 14 +++++++ js/cam/assemblers/Assembler.js | 34 +++++++++++---- js/cam/assemblers/Component.js | 26 ++++++++---- js/menus/EditComponentMenuView.js | 15 ++++++- js/menus/MenuWrapperView.js | 5 ++- js/menus/templates/EditComponentMenuView.html | 42 +++++++++++++------ js/plists/CamPList.js | 10 ++--- todo | 9 ++-- 8 files changed, 115 insertions(+), 40 deletions(-) diff --git a/css/main.css b/css/main.css index cee86c43..4cff0d83 100644 --- a/css/main.css +++ b/css/main.css @@ -479,3 +479,17 @@ label { background-color: #eee; border: 1px solid #ddd; } + +.dropdown-menu>li>a{ + padding: 6px 9px; +} + +.navbar-inverse .navbar-nav > .dropdown > a .caret { + border-top-color: #ddd; + border-bottom-color: #ddd; +} + +.navbar-inverse .navbar-nav > .dropdown > a:hover .caret { + border-top-color: #aaa; + border-bottom-color: #aaa; +} \ No newline at end of file diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index c650b6db..cf56bbdc 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -98,6 +98,20 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' }); }; + Assembler.prototype.addChild = function(child, object3D){ + child._addParent(this, null); + var object3D = object3D || this.object3D; + object3D.add(child.getObject3D()); + }; + + Assembler.prototype._removeChild = function(child){ + if (this.object3D.children.indexOf(child.stl) == -1){ + console.warn("not a child"); + return; + } + this.object3D.remove(child.getObject3D()); + }; + Assembler.prototype.setVisibility = function(visible){ this.object3D.visible = visible; this._setTranslucent(); @@ -119,12 +133,18 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' this.hideStock(); }; - Assembler.prototype.buildComponentTree = function(index, parent, tree){ + Assembler.prototype.getComponent = function(id){ + return this.components[id] || this.stock[id]; + }; + + Assembler.prototype.buildComponentTree = function(){ + var tree = this._recursiveTreeBuilding(0, null, {}); + console.log(tree); + this.tree = tree; + }; + + Assembler.prototype._recursiveTreeBuilding = 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; @@ -133,10 +153,10 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' _.each(this.components, function(component, key){ if (component.parent == parent) { tree[key] = index; - self.buildComponentTree(index+1, key, tree); + self._recursiveTreeBuilding(index+1, key, tree); } }); - this.tree = tree; + return tree; }; diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js index d7a73f55..9d2f0d8b 100644 --- a/js/cam/assemblers/Component.js +++ b/js/cam/assemblers/Component.js @@ -11,9 +11,14 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ this.object3D = new THREE.Object3D(); this.id = id || "id" + id++; this.name = json.name || ""; - this.parent = json.parent; + this.parent = null; + if (json.parent) this.parent = json.parent; this.parentObject = null; this.children = []; + this.isStatic = json.isStatic; + this.rotary = json.rotary; + this.motionVector = new THREE.Vector3(); + if (json.motionVector) this.motionVector.set(json.motionVector.x, json.motionVector.y, json.motionVector.z); } //assembler setup @@ -34,7 +39,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ return; } this.children.push(child); - child.addParent(this); + child._addParent(this, this.id); this.object3D.add(child.getObject3D()); }; @@ -46,7 +51,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ return false; }; - Component.prototype.removeChild = function(child){ + Component.prototype._removeChild = function(child){ if (this.children.indexOf(child) == -1){ console.warn("not a child"); return; @@ -55,13 +60,13 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ this.object3D.remove(child.getObject3D()); }; - Component.prototype.addParent = function(parent){ + Component.prototype._addParent = function(parent, id){ if (this.parentObject) { - this.parentObject.removeChild(this); + this.parentObject._removeChild(this); this.parentObject = null; } this.parentObject = parent; - this.parent = parent.id; + this.parent = id; }; Component.prototype.getID = function(){ @@ -176,12 +181,12 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ //helper Component.prototype.destroy = function(){ - if (this.parentObject) this.parentObject.removeChild(this); + if (this.parentObject) this.parentObject._removeChild(this); this.parentObject = null; this.parent = null; var self = this; _.each(this.children, function(child){ - self.removeChild(child); + self._removeChild(child); }); this.children = null; this.name = null; @@ -201,7 +206,10 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ parent: this.parent || "", translation: this.object3D.position, scale: this.object3D.scale.x, - rotation: this.object3D.rotation + rotation: this.object3D.rotation, + isStatic: this.isStatic, + rotary: this.rotary, + motionVector: this.motionVector } }; diff --git a/js/menus/EditComponentMenuView.js b/js/menus/EditComponentMenuView.js index ddd2153b..5b1e1a09 100644 --- a/js/menus/EditComponentMenuView.js +++ b/js/menus/EditComponentMenuView.js @@ -18,6 +18,11 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen _initialize: function(){ }, + getPropertyOwner: function($target){ + if ($target.hasClass("component")) return cam.get("assembler").getComponent(cam.get("editingComponent")); + return null; + }, + _save: function(e){ e.preventDefault(); console.log("save component"); @@ -42,11 +47,17 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen _removeChild: function(e){ e.preventDefault(); - console.log("remove child"); + var id = $(e.target).data("id"); + var assembler = cam.get("assembler"); + assembler.addChild(assembler.getComponent(id));//add subtree to root + assembler.buildComponentTree(); + this.render(); }, _makeTemplateJSON: function(){ - return _.extend(this.model.toJSON(), cam.toJSON(), cam.get("assembler").toJSON()); + var assembler = cam.get("assembler"); + var component = assembler.getComponent(cam.get("editingComponent")); + return _.extend(this.model.toJSON(), cam.toJSON(), assembler.toJSON(), {thisComponent: component.toJSON()}); }, template: _.template(template) diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index a28159fa..42a47197 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -203,7 +203,10 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex _setOwnerProperty: function(owner, property, value){ if (owner instanceof Backbone.Model) owner.set(property, value); - else owner[property] = value; + else { + owner[property] = value; + this.menu.render(); + } }, diff --git a/js/menus/templates/EditComponentMenuView.html b/js/menus/templates/EditComponentMenuView.html index 7c95fcab..e5508099 100644 --- a/js/menus/templates/EditComponentMenuView.html +++ b/js/menus/templates/EditComponentMenuView.html @@ -1,4 +1,3 @@ -<% var thisComponent = components[editingComponent] || stock[editingComponent]; %> <% var isStock = stock[editingComponent]; %> Name: <input data-property="name" value="<%= thisComponent.name %>" placeholder="Enter Name" class="seventyFiveWidth form-control textInput component" type="text"><br/><br/> Parent: @@ -31,20 +30,37 @@ Parent: <% 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 %> - <% if(tree[editingComponent]+1 == level){ %><a data-id="<%= id %>" class="editMachineComponent pull-right" href="#">Remove</a><% } %></label></div><br/> + <% if(tree[editingComponent]+1 == level){ %><a data-id="<%= id %>" class="removeChild pull-right" href="#">Remove</a><% } %></label></div><br/> <% }); %><br/> - STL: STL Name<br/><br/> - <a id="uploadStl" href="#" class="btn btn-block btn-lg btn-default">Upload STL</a><br/> + + Motion:<label class="checkbox pull-right" for="isStatic"> + <input id="isStatic" data-property="isStatic" type="checkbox" <% if (thisComponent.isStatic){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="component custom-checkbox"> + <span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> + Is Static</label><br/> + <% if (!thisComponent.isStatic){ %> + <label class="checkbox" for="isRotary"> + <input id="isRotary" data-property="rotary" type="checkbox" <% if (thisComponent.rotary){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="component custom-checkbox"> + <span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> + Rotary Axis (default is Linear)</label> + Vector (xyz): + <input data-property="motionVector" data-key="x" value="<%= thisComponent.motionVector.x %>" placeholder="X" class="form-control floatInput component" type="text"> + <input data-property="motionVector" data-key="y" value="<%= thisComponent.motionVector.y %>" placeholder="Y" class="form-control floatInput component" type="text"> + <input data-property="motionVector" data-key="z" value="<%= thisComponent.motionVector.z %>" placeholder="Z" class="form-control floatInput component" type="text"><br/> + <!--Jog<br/>--> + <% } %> + <br/> + <!--STL: STL Name<br/><br/>--> + <!--<a id="uploadStl" href="#" class="btn btn-block btn-lg btn-default">Upload STL</a><br/>--> <% } %> -Offset (xyz): - <input data-property="translation" data-key="x" value="<%= translation.x %>" placeholder="X" class="form-control floatInput component" type="text"> - <input data-property="translation" data-key="y" value="<%= translation.y %>" placeholder="Y" class="form-control floatInput component" type="text"> - <input data-property="translation" data-key="z" value="<%= translation.z %>" placeholder="Z" class="form-control floatInput component" type="text"><br/><br/> -Rotation (xyz): - <input data-property="rotation" data-key="x" value="<%= rotation.x %>" placeholder="X" class="form-control floatInput component" type="text"> - <input data-property="rotation" data-key="y" value="<%= rotation.y %>" placeholder="Y" class="form-control floatInput component" type="text"> - <input data-property="rotation" data-key="z" value="<%= rotation.z %>" placeholder="Z" class="form-control floatInput component" type="text"><br/><br/> -<% if(!isStock){ %> Scale: <input data-property="scale" value="<%= scale %>" placeholder="Scale" class="form-control floatInput component" type="text"><br/><br/><% } %> +<!--Offset (xyz): --> + <!--<input data-property="translation" data-key="x" value="<%= translation.x %>" placeholder="X" class="form-control floatInput stl" type="text"> --> + <!--<input data-property="translation" data-key="y" value="<%= translation.y %>" placeholder="Y" class="form-control floatInput stl" type="text"> --> + <!--<input data-property="translation" data-key="z" value="<%= translation.z %>" placeholder="Z" class="form-control floatInput stl" type="text"><br/><br/>--> +<!--Rotation (xyz): --> + <!--<input data-property="rotation" data-key="x" value="<%= rotation.x %>" placeholder="X" class="form-control floatInput stl" type="text"> --> + <!--<input data-property="rotation" data-key="y" value="<%= rotation.y %>" placeholder="Y" class="form-control floatInput stl" type="text"> --> + <!--<input data-property="rotation" data-key="z" value="<%= rotation.z %>" placeholder="Z" class="form-control floatInput stl" type="text"><br/><br/>--> +<!--<% if(!isStock){ %> Scale: <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/> <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/> diff --git a/js/plists/CamPList.js b/js/plists/CamPList.js index 28107c8d..9a4259c2 100644 --- a/js/plists/CamPList.js +++ b/js/plists/CamPList.js @@ -45,7 +45,7 @@ define(['three'], function(THREE){ //minBound //maxBound parent: "yAxis", - children: ["zAxis"], + motionVector: {x:1, y:0, z:0}, stl: { filename: "assets/stls/stapler/xAxis.stl", offset: {x:0,y:0,z:0}, @@ -60,7 +60,7 @@ define(['three'], function(THREE){ //minBound //maxBound parent: "substrate", - children: ["yAxis"], + motionVector: {x:0, y:1, z:0}, stl: { filename: "assets/stls/stapler/yAxis.stl", offset: {x:0,y:0,z:0}, @@ -75,7 +75,7 @@ define(['three'], function(THREE){ //minBound //maxBound parent: "xAxis", - children: [],//stock + motionVector: {x:0, y:0, z:1}, stl: { filename: "assets/stls/stapler/zAxis.stl", offset: {x:0,y:0,z:0}, @@ -90,7 +90,7 @@ define(['three'], function(THREE){ //minBound //maxBound parent: "frame", - children: ["xAxis"], + isStatic: true, stl: { filename: "assets/stls/stapler/frame.stl", offset: {x:0,y:0,z:0}, @@ -106,7 +106,7 @@ define(['three'], function(THREE){ //minBound //maxBound parent: null, - children: ["yAxis"], + motionVector: {x:0, y:0, z:1}, stl: { filename: "assets/stls/stapler/substrate.stl", offset: {x:0,y:0,z:0}, diff --git a/todo b/todo index 2206ba8f..c68559e1 100644 --- a/todo +++ b/todo @@ -1,8 +1,8 @@ import - offset, scale, rotation -parse sparseCells -> cells + hierarchical - - gik dimensions + - single layer gik throwing error on parse - origin - rotation - load composite materials @@ -14,4 +14,7 @@ material transformations -> change material of a cell, change in bulk rendering callbacks -highligher - check mode, do not add cells except in design/composite/material modes \ No newline at end of file +highligher - check mode, do not add cells except in design/composite/material modes + +part stl import and orientation - settings to json +same for machine \ No newline at end of file -- GitLab