From fc444d538ee2565e0d698cef9e3e1dbbb762cab2 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 5 Jun 2015 18:23:48 -0700 Subject: [PATCH] material reorganization --- js/lattice/Lattice.js | 2 ++ js/menus/MaterialMenuView.js | 36 ++++++++++++++++++++++++++++++++---- js/menus/PartMenuView.js | 17 ----------------- js/models/AppState.js | 8 +++++--- js/models/Globals.js | 20 +++++++++++++++----- js/models/PList.js | 27 ++++++++++++++++----------- 6 files changed, 70 insertions(+), 40 deletions(-) diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 050a20fc..ec0ff0ec 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -371,6 +371,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _loadMaterialClass: function(){ var materialClass = this.get("materialClass"); + this.set("materialType", _.keys(plist.allMaterials[materialClass])[0], {silent:true});//set to default silently if (globals.materials[materialClass]) return;//already loaded require([materialClass + "Materials"], function(MaterialClass){ globals.materials[materialClass] = MaterialClass; @@ -454,6 +455,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre } var partType = _.keys(plist["allPartTypes"][newCellType][newConnectionType])[0]; this.set("partType", partType, {silent:true}); + this.set("materialClass", plist.allMaterialTypes[newCellType][newConnectionType], {silent:true}); }, _setDefaultCellMode: function(){//if no part associated with this lattice type diff --git a/js/menus/MaterialMenuView.js b/js/menus/MaterialMenuView.js index a6864247..46e5517f 100644 --- a/js/menus/MaterialMenuView.js +++ b/js/menus/MaterialMenuView.js @@ -2,7 +2,7 @@ * Created by aghassaei on 2/25/15. */ -define(['jquery', 'underscore', 'menuParent', 'plist'], function($, _, MenuParentView, plist){ +define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _, MenuParentView, plist, lattice){ return MenuParentView.extend({ @@ -10,16 +10,44 @@ define(['jquery', 'underscore', 'menuParent', 'plist'], function($, _, MenuParen }, _initialize: function(){ + //bind events + this.listenTo(lattice, "change", this.render); + this.listenTo(this.model, "change", this.render); }, _makeTemplateJSON: function(){ - return null; + return _.extend(lattice.toJSON(), this.model.toJSON(), plist); }, template: _.template('\ - create materials and assign them to parts in the model\ + Material Class: \ + <div class="btn-group">\ + <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allMaterialClasses[materialClass] %><span class="caret"></span></button>\ + <ul role="menu" class="dropdown-menu">\ + <% _.each(_.keys(allMaterialClasses), function(key){ %>\ + <li><a class="lattice dropdownSelector" data-property="materialClass" data-value="<%= key %>" href="#"><%= allMaterialClasses[key] %></a></li>\ + <% }); %>\ + </ul>\ + </div><br/><br/>\ + <% if (allMaterialTypes[cellType][connectionType]){ %> \ + Materials:<br/>\ + <% _.each(_.keys(allMaterials[materialClass]), 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){ %><%= allMaterials[materialClass][key].color %><% }else{ %><%= allMaterials[materialClass][key].altColor %><% } %>"></div>\ + <span><%= allMaterials[materialClass][key].name %></span></div>\ + </label>\ + <% }); %>\ + <br/>\ + <label class="checkbox" for="realisticColorScheme">\ + <input id="realisticColorScheme" data-property="realisticColorScheme" type="checkbox" <% if (realisticColorScheme){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="appState custom-checkbox">\ + <span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ + Use realistic color scheme</label>\ + <% } %>\ <br/><br/>\ - stiffness, elastic modulus\ + Composite Materials:<br/><br/>\ + <a href="#" class="btn btn-block btn-lg btn-default">+ Create New Composite Material</a><br/>\ ') }); diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index 83a674e0..7aeb4fca 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -32,23 +32,6 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ <!--Cell Separation (xy, z): <input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text">\ <input data-property="cellSeparation" data-key="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control floatInput lattice" type="text">\ <br/><br/>--><br/>\ - <% if (allMaterialTypes[cellType][connectionType]){ %> \ - Materials:<br/>\ - <% _.each(_.keys(allMaterials[allMaterialTypes[cellType][connectionType]]), 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){ %><%= allMaterials[allMaterialTypes[cellType][connectionType]][key].color %><% }else{ %><%= allMaterials[allMaterialTypes[cellType][connectionType]][key].altColor %><% } %>"></div>\ - <span><%= allMaterials[allMaterialTypes[cellType][connectionType]][key].name %></span></div>\ - </label>\ - <% }); %>\ - <br/>\ - <label class="checkbox" for="realisticColorScheme">\ - <input id="realisticColorScheme" data-property="realisticColorScheme" type="checkbox" <% if (realisticColorScheme){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="appState custom-checkbox">\ - <span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ - Use realistic color scheme</label>\ - <% } %>\ - <br/>\ ') }); diff --git a/js/models/AppState.js b/js/models/AppState.js index 14566526..5e9d6715 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -5,7 +5,7 @@ //a class to store global app state, model for navbar and menu wrapper //never deallocated -define(['underscore', 'backbone'], function(_, Backbone){ +define(['underscore', 'backbone', 'threeModel'], function(_, Backbone, three){ var AppState = Backbone.Model.extend({ @@ -111,8 +111,10 @@ define(['underscore', 'backbone'], function(_, Backbone){ }, _updateColorScheme: function(){ - changeGikMaterials(); - globals.three.render(); + require(['globals'], function(globals){ + globals.changeMaterialColorScheme(); + three.render(); + }); }, /////////////////////////////////////////////////////////////////////////////// diff --git a/js/models/Globals.js b/js/models/Globals.js index adf895ff..473797cd 100644 --- a/js/models/Globals.js +++ b/js/models/Globals.js @@ -4,12 +4,22 @@ //globals namespace, not sure if there's a way to get around this -define(['three'], function(THREE){ +define(['underscore', 'three'], function(_, THREE){ + + var materials = { + deleteMaterial: new THREE.MeshLambertMaterial({color:"#ff0000"}) + }; + + function changeMaterialColorScheme(){ + _.each(_.keys(materials), function(material){ + if (material.changeMaterials) material.changeMaterials(); + }); + } + return { baseplane: null, - highlighter: null, - materials: { - deleteMaterial: new THREE.MeshLambertMaterial({color:"#ff0000"}) - } + highlighter: null, + materials: materials, + changeMaterialColorScheme: changeMaterialColorScheme }; }); \ No newline at end of file diff --git a/js/models/PList.js b/js/models/PList.js index 2b02bf9b..2282c380 100644 --- a/js/models/PList.js +++ b/js/models/PList.js @@ -8,15 +8,15 @@ define(['three'], function(THREE){ allMenuTabs: { navDesign:{ lattice:"Lattice", -// import:"Import", - //sketch:"Sketch", - part:"Part", - script:"Script" +// import:"Import", + //sketch:"Sketch", + material:"Material", + part:"Part", + script:"Script" }, navSim:{ physics:"Physics", part:"Part", - material:"Material", optimize:"Optimize" }, navAssemble:{ @@ -88,6 +88,11 @@ define(['three'], function(THREE){ kelvin: {face: 'mechanical'} }, + allMaterialClasses:{ + electronic: "Electronic", + mechanical: "Structural" + }, + allMaterials:{ electronic:{ brass:{ @@ -109,12 +114,12 @@ define(['three'], function(THREE){ nType: { name: "Silicon N-Type", color: "#bcc6cc", - altColor: "#9CC9CB" + altColor: "#8391AC" }, nTypePlus: { name: "Silicon Heavily Doped N-Type (N+)", color: "#c6ccbc", - altColor: "#8391AC" + altColor: "#9CC9CB" }, pType: { name: "Silicon P-Type", @@ -133,13 +138,13 @@ define(['three'], function(THREE){ mechanical:{ rigid:{ name: "Rigid", - color: "#b5a642", - altColor: "#857B64" + color: "#8391AC", + altColor: "#8391AC" }, flexure: { name: "Flexure", - color: "#fef1b5", - altColor: "#ecf0f1" + color: "#666", + altColor: "#666" } } }, -- GitLab