From 57b785d8c25bec0ff61a3ca36b75b65247a027be Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 11 Jun 2015 00:42:55 -0700 Subject: [PATCH] eidt composites --- js/lattice/CompositeEditorLattice.js | 14 ++++++++------ js/lattice/Lattice.js | 6 +++--- js/menus/CompositeMenu.js | 3 ++- js/menus/MaterialMenuView.js | 24 +++++++++++++++++------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js index de70a7ab..f5c470a8 100644 --- a/js/lattice/CompositeEditorLattice.js +++ b/js/lattice/CompositeEditorLattice.js @@ -17,10 +17,13 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th _initCompositeEditor: function(id, data){ + if (!id) id = "composite" + ++compositeId;//todo real unique id here + this.set("compositeId", id, {silent:true}); + _.extend(defaults, { - compositeId: "composite"+compositeId++,//todo real unique id + compositeName: "", compositeColor: makeRandomColor(), - numCompositeCells:2, + compositeNumCells:2, compositeCellsMin: new THREE.Vector3(0,0,0),//null, compositeCellsMax: new THREE.Vector3(2,4,5)//null }); @@ -33,10 +36,9 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th if (data){ _.each(_.keys(data), function(key){ - self.set(key, defaults[key], {silent:true}); + self.set("composite" + key.charAt(0).toUpperCase() + key.slice(1), data[key]); }); this.compositeCells = data.cells;//todo parse cells - this.set("compositeId", id, {silent:true}); } }, @@ -49,6 +51,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th console.warn("no cells in this composite"); return; } + if (name == "") name = "Composite Material " + compositeId; var id = this.get("compositeId"); var data = { name: name, @@ -61,7 +64,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th dimensions: new THREE.Vector3().subVectors(this.get("compositeCellsMax"), this.get("compositeCellsMin")) }; globals.materials.compositeMaterials[id] = data;//todo trigger change on all instances - console.log(data); }, _undoCompositeEditor: function(){ @@ -73,7 +75,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th self.unset(key, {silent:true}); }); this.compositeCells = null; - } + }, }; return CompositeEditorLattice; diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 2f35c19c..6db3e6a7 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -329,12 +329,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //composite Cells - setToCompositeMode: function(callback){ + setToCompositeMode: function(id, data){ var self = this; require(['compositeEditorLattice'], function(CompositeEditorLattice){ _.extend(self, CompositeEditorLattice); - self._initCompositeEditor(); - if (callback) callback(); + self._initCompositeEditor(id, data); + appState.set("currentNav", "navComposite"); }); }, diff --git a/js/menus/CompositeMenu.js b/js/menus/CompositeMenu.js index 1ca1b9aa..9ad79a81 100644 --- a/js/menus/CompositeMenu.js +++ b/js/menus/CompositeMenu.js @@ -47,13 +47,14 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ }, _makeTemplateJSON: function(){ + console.log("render"); return _.extend(lattice.toJSON()); }, template: _.template('\ <a href="#" class="btn btn-halfWidth btn-lg btn-default importJSON">Load Composite</a>\ <a id="saveComposite" href="#" class="btn btn-halfWidth btn-lg pull-right btn-default">Save Composite</a><br/><br/>\ - Name: <input id="compositeName" value="" placeholder="Enter Name" class="halfWidth form-control" type="text"><br/><br/>\ + Name: <input id="compositeName" value="<%= compositeName %>" placeholder="Enter Name" class="halfWidth form-control" type="text"><br/><br/>\ Bounding Box: ()<br/><br/>\ Display Color: \ <input style="border-color: <%= compositeColor %> ;" value="<%= compositeColor %>" placeholder="Enter HEX" class="halfWidth form-control" type="text"><br/><br/>\ diff --git a/js/menus/MaterialMenuView.js b/js/menus/MaterialMenuView.js index f70c47ed..db6df9f5 100644 --- a/js/menus/MaterialMenuView.js +++ b/js/menus/MaterialMenuView.js @@ -7,7 +7,9 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals'], fu return MenuParentView.extend({ events: { - "click #navToCompositeMenu": "_navToCompositeMenu" + "click #navToCompositeMenu": "_navToCompositeMenu", + "click #compositeFromLattice": "_latticeToComposite", + "click .editComposite": "_editComposite" }, _initialize: function(){ @@ -18,11 +20,18 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals'], fu _navToCompositeMenu: function(e){ e.preventDefault(); - var self = this; - lattice.setToCompositeMode(function(){ - self.model.set("currentNav", "navComposite"); - }); + lattice.setToCompositeMode(); + }, + + _editComposite: function(e){ + e.stopPropagation(); + e.preventDefault(); + var id = $(e.target).data("id"); + lattice.setToCompositeMode(id, globals.materials.compositeMaterials[id]); + }, + _latticeToComposite: function(e){ + e.preventDefault(); }, _makeTemplateJSON: function(){ @@ -55,17 +64,18 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals'], fu <span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ Use realistic color scheme</label>\ <% } %>\ - <br/><br/>\ + <br/>\ Composite Materials:<br/>\ <% _.each(_.keys(materials.compositeMaterials), function(key){ %>\ <label class="radio colorSwatches">\ <input type="radio" <%if (key == materialType){ %>checked<%}%> name="materialType" value="<%= key %>" data-toggle="radio" class="custom-radio lattice"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ <div class="materialColorSwatch">\ <div style="background-color:<% if(realisticColorScheme){ %><%= materials.compositeMaterials[key].color %><% }else{ %><%= materials.compositeMaterials[key].altColor %><% } %>"></div>\ - <span><%= materials.compositeMaterials[key].name %></span></div>\ + <span><%= materials.compositeMaterials[key].name %><a data-id="<%= key %>" class="editComposite">Edit</a></span></div>\ </label>\ <% }); %><br/>\ <a id="navToCompositeMenu" href="#" class="btn btn-block btn-lg btn-default">+ Create New Composite Material</a><br/>\ + <a id="compositeFromLattice" href="#" class="btn btn-block btn-lg btn-default">New Composite From Current Assembly</a><br/>\ ') }); -- GitLab