diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index cf56bbdccf559a74e524ff4463a25dfaaacea868..b1bc3057eb77616ae79b46c4478f71d7c28514f2 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -92,26 +92,40 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' Assembler.prototype._configureAssemblerMovementDependencies = function(json, components, newComponents, object3D){ if (json === undefined) return; + var self = this; _.each(json, function(componentJSON, id){ if (componentJSON.parent) components[componentJSON.parent].addChild(newComponents[id]); - else object3D.add(newComponents[id].getObject3D()); + else self.addChild(newComponents[id], object3D); }); }; Assembler.prototype.addChild = function(child, object3D){ child._addParent(this, null); - var object3D = object3D || this.object3D; + if (object3D === undefined) object3D = this.object3D; object3D.add(child.getObject3D()); }; Assembler.prototype._removeChild = function(child){ - if (this.object3D.children.indexOf(child.stl) == -1){ + if (this.object3D.children.indexOf(child.object3D) == -1){ console.warn("not a child"); return; } this.object3D.remove(child.getObject3D()); }; + Assembler.prototype.newComponent = function(){ + var component = new Component(null, {}); + var id = component.getID(); + this.components[id] = component; + this.addChild(component); + this.buildComponentTree(); + return id; + }; + + Assembler.prototype.checkAncestry = function(){ + return false; + }; + Assembler.prototype.setVisibility = function(visible){ this.object3D.visible = visible; this._setTranslucent(); @@ -139,7 +153,6 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' Assembler.prototype.buildComponentTree = function(){ var tree = this._recursiveTreeBuilding(0, null, {}); - console.log(tree); this.tree = tree; }; diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js index 6ef62e274247af7cde970c708573b428ac271dbf..7718c4bed1a1b5ebf729ceed9e3fddcee164ad29 100644 --- a/js/cam/assemblers/Component.js +++ b/js/cam/assemblers/Component.js @@ -5,12 +5,12 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ - var id = 0; + var idNum = 0; function Component(id, json){ this.object3D = new THREE.Object3D(); - this.id = id || "id" + id++; - this.name = json.name || "Component" + id; + this.id = id || ("id" + ++idNum); + this.name = json.name || "Component" + idNum; this.parent = null; if (json.parent) this.parent = json.parent; this.parentObject = null; diff --git a/js/menus/AssemblerSetupMenuView.js b/js/menus/AssemblerSetupMenuView.js index f3cad95565be46e49aacc4402c3b10241c0ee84a..d9b451c9c23d197b74ead5c163b24419368cda81 100644 --- a/js/menus/AssemblerSetupMenuView.js +++ b/js/menus/AssemblerSetupMenuView.js @@ -10,7 +10,8 @@ define(['jquery', 'underscore', 'menuParent', 'camPlist', 'cam', 'text!assembler events: { "click .editMachineComponent": "_editMachineComponent", - "click .editMachineCode": "_editMachineCode" + "click .editMachineCode": "_editMachineCode", + "click #newMachineComponent": "_newComponent" }, _initialize: function(){ @@ -33,6 +34,13 @@ define(['jquery', 'underscore', 'menuParent', 'camPlist', 'cam', 'text!assembler console.log("edit code"); }, + _newComponent: function(e){ + e.preventDefault(); + var id = cam.get("assembler").newComponent(); + cam.set("editingComponent", id); + this.model.set("currentNav", "navMachineComponent"); + }, + _makeTemplateJSON: function(){ return _.extend(this.model.toJSON(), cam.toJSON(), cam.get("assembler").toJSON()); }, diff --git a/js/menus/EditComponentMenuView.js b/js/menus/EditComponentMenuView.js index 2cfc5a1507101e6bbf7049e07f72d98a5b2f5154..92f473c5d8587bee0afccc7656d2df82977cbcd1 100644 --- a/js/menus/EditComponentMenuView.js +++ b/js/menus/EditComponentMenuView.js @@ -61,10 +61,10 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen _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"))); + var parent = assembler; + if (id) parent = assembler.getComponent(id); + parent.addChild(assembler.getComponent(cam.get("editingComponent"))); assembler.buildComponentTree(); this.render(); },