diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 14eecd552e085343f34d4562a862482092a9f4b0..44d2d8c80f0b32306eb74d81904648946b4dc324 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -13,6 +13,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' if (json.index) this.index = new THREE.Vector3(json.index.x, json.index.y, json.index.z); if (superCell) this.superCell = superCell; this.materialName = json.materialName || appState.get("materialType"); + this.isTransparent = false; //object 3d is parent to all 3d elements owned by cell: cell mesh and wireframe, parts, beams, nodes, etc this.object3D = this._buildObject3D(); @@ -167,7 +168,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' if (part) part.setMaterial(material); }); } - this.object3D.children[0].material = material; + this.setMaterial(material); three.render(); }; @@ -236,10 +237,18 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' console.warn("no three material object found for type "+ this.materialName); return null; } + if (this.isTransparent) return materials.list[this.materialName].transparentMaterial; return materials.list[this.materialName].threeMaterial; }; - DMACell.prototype.setOpacity = function(opacity){ + DMACell.prototype.setMaterial = function(material){ + this.object3D.children[0].material = material; + }; + + DMACell.prototype.setTransparent = function(transparent){ + if (transparent == this.isTransparent) return; + this.isTransparent = transparent; + this.setMaterial(this.getMaterial(true)); }; DMACell.prototype.setMode = function(mode, callback){ diff --git a/js/lattice/LatticeEsim.js b/js/lattice/LatticeEsim.js index 04e21b59e8cc25a0cb28289d2af81379a4120f89..438e40422478bf07917af2ddff63cc9fed0e3b15 100644 --- a/js/lattice/LatticeEsim.js +++ b/js/lattice/LatticeEsim.js @@ -6,24 +6,24 @@ define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){ var eSimMethods = { - calculateConnectivity: function(){ + calculateConductorConnectivity: function(){ var num = 1; this._loopCells(this.cells, function(cell){ - if (cell) cell.setConnectivityGroupNum(num++); + if (cell) cell.setConductorGroupNum(num++, true); }); this._loopCells(this.cells, function(cell){ - if (cell) cell.propagateConnectivityGroupNum(); + if (cell) cell.propagateConductorGroupNum(); }); this._calcNumberConnectedComponents(); }, _calcNumberConnectedComponents: function(){ - var groups = {}; + var groups = []; this._loopCells(this.cells, function(cell){ if (!cell) return; - if (!groups[cell.getConnectivityGroupNum()] && cell.getMaterialName() == "brass") groups[cell.getConnectivityGroupNum()] = cell.getMaterialName(); + if (groups.indexOf(cell.getConductorGroupNum()) < 0 && cell.isConductive()) groups.push(cell.getConductorGroupNum()); }); - eSim.set("numConnectedComponents", _.keys(groups).length); + eSim.set("conductorGroups", _.keys(groups)); }, propagateToNeighbors: function(index, callback){ diff --git a/js/materials/DMAMaterials.js b/js/materials/DMAMaterials.js index debed48fd2fb829b002eae54bc7a4e4467814ff5..71fd2f0105ccef83acd0198a04b5f83ee2e0f574 100644 --- a/js/materials/DMAMaterials.js +++ b/js/materials/DMAMaterials.js @@ -39,7 +39,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu else materialsList[id][key] = data[key]; }); - if (materialsList[id].threeMaterial || oldColor != materialsList[id].color) changeSingleMaterialColorScheme(id); + if (!materialsList[id].threeMaterial || oldColor != materialsList[id].color) changeSingleMaterialColorScheme(id); if (edited){ var allChangedMaterialsList = getAllParentComposites(id); allChangedMaterialsList.push(id); @@ -183,6 +183,8 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu var color = getMaterialColorForState(state, materialInfo, name); if (materialInfo.threeMaterial) materialInfo.threeMaterial.color = new THREE.Color(color); else materialInfo.threeMaterial = makeMaterialObject(color); + if (materialInfo.transparentMaterial) materialInfo.transparentMaterial.color = new THREE.Color(color); + else materialInfo.transparentMaterial = makeMaterialObject(color, true); } function getMaterialColorForState(state, definition, key){ @@ -192,7 +194,8 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu return color; } - function makeMaterialObject(color){ + function makeMaterialObject(color, transparent){ + if (transparent) return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading, transparent: true, opacity:0.4}); return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading}); } diff --git a/js/menus/ESetupMenuView.js b/js/menus/ESetupMenuView.js index e2a4d086dbc08b8563ee0a87fd2ff708c05a4c27..361820c25f551b8f9a7cbd0f55e8cf8f1780cf33 100644 --- a/js/menus/ESetupMenuView.js +++ b/js/menus/ESetupMenuView.js @@ -16,6 +16,11 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'text!eSetupMenuTemplate' this.listenTo(this.model, "change:materialClass", this._changeSimNav); }, + getPropertyOwner: function($target){ + if ($target.hasClass("eSim")) return eSim; + return null; + }, + _changeSimNav: function(){ var materialClass = this.model.get("materialClass"); this.model.set("currentNav", materialClass + "NavSim"); @@ -23,7 +28,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'text!eSetupMenuTemplate' _calcConnectivity: function(e){ e.preventDefault(); - lattice.calculateConnectivity(); + lattice.calculateConductorConnectivity(); }, _makeTemplateJSON: function(){ diff --git a/js/menus/SetupCommMenuView.js b/js/menus/SetupCommMenuView.js index 3c594ffc8748d33a00f5909764ca8fadb9cbd08a..d88cfff14b6b87bcdd664ab924c3d2e42a88e5f6 100644 --- a/js/menus/SetupCommMenuView.js +++ b/js/menus/SetupCommMenuView.js @@ -30,7 +30,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'serialComm', 'text!setup getPropertyOwner: function($target){ if ($target.hasClass("serialComm")) return serialComm; - return null + return null; }, _sendTestMessage: function(e){ diff --git a/js/menus/templates/ESetupMenuView.html b/js/menus/templates/ESetupMenuView.html index e1607e72a3238d76753e9c7bf3dd3e8b0e04a914..e5ae5f517a283bd0538eb255faaf6418026305ad 100644 --- a/js/menus/templates/ESetupMenuView.html +++ b/js/menus/templates/ESetupMenuView.html @@ -8,8 +8,18 @@ Simulation Type: </ul> </div><br/><br/> <a href="#" id="calcConnectivity" class="btn btn-block btn-lg btn-default">Calculate Connectivity</a><br/> -<% if(numConnectedComponents){ %>Num Connected Conductors:  <%= numConnectedComponents %><br/><br/> -Show Conductors: +<% if(conductorGroups){ %> + Num Connected Conductors:  <%= conductorGroups.length %><br/> + <label class="radio"> + <input type="radio" <% if (visibleConductorGroup < 0){ %>checked<% } %> name="visibleConductorGroup" value="-1" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> + Show All + </label> + <% _.each(conductorGroups, function(groupNum, index){ %> + <label class="radio"> + <input type="radio" <% if (groupNum == visibleConductorGroup){ %>checked<% } %> name="visibleConductorGroup" value="<%= groupNum %>" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> + Group Num <%= index + 1 %> + </label> + <% }); %> <% } %> \ No newline at end of file diff --git a/js/models/FileSaver.js b/js/models/FileSaver.js index e4cbaf9c149a2da4711762a5cee400ca064b5967..3ae25dfeca8f0d07b6d5599d30399cecd8190a14 100644 --- a/js/models/FileSaver.js +++ b/js/models/FileSaver.js @@ -68,7 +68,7 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra } function _getMaterialDataToSave(id){ - return _.omit(materials.list[id], "threeMaterial"); + return _.omit(materials.list[id], "threeMaterial", "transparentMaterial"); } function loadFile(data){//parsed json todo make this better - load composite diff --git a/js/plists/PList.js b/js/plists/PList.js index 5fe339eb4ae518270e9aa6573397f8a1f97deed7..06c9a73a0d19236031680e9e6aba3f14944e2450 100644 --- a/js/plists/PList.js +++ b/js/plists/PList.js @@ -123,38 +123,47 @@ define(['three'], function(THREE){ brass:{ name: "Brass", color: "#b5a642", - altColor: "#857B64" + altColor: "#857B64", + properties:{ + conductive: true + } }, fiberGlass: { name: "Fiberglass", color: "#fef1b5", // opacity: "0.9", - altColor: "#ecf0f1" + altColor: "#ecf0f1", + properties:{} }, carbon: { name: "Carbon Composite", color: "#222", - altColor: "#000" + altColor: "#000", + properties:{} }, nType: { name: "Silicon N-Type", color: "#bcc6cc", - altColor: "#8391AC" + altColor: "#8391AC", + properties:{} }, nTypePlus: { name: "Silicon Heavily Doped N-Type (N+)", color: "#c6ccbc", - altColor: "#9CC9CB" + altColor: "#9CC9CB", + properties:{} }, pType: { name: "Silicon P-Type", color: "#ccbcc6", - altColor: "#F5447B" + altColor: "#F5447B", + properties:{} }, pTypePlus: { name: "Silicon Heavily Doped P-Type (P+)", color: "#ccc2bc", - altColor: "#F99987" + altColor: "#F99987", + properties:{} } //857B64 //FDE2D9 @@ -164,12 +173,14 @@ define(['three'], function(THREE){ rigid:{ name: "Rigid", color: "#aaa", - altColor: "#666" + altColor: "#666", + properties:{} }, flexure: { name: "Flexure", color: "#aaa", - altColor: "#8391AC" + altColor: "#8391AC", + properties:{} } }, space:{ @@ -177,37 +188,46 @@ define(['three'], function(THREE){ name: "Glass Filled Nylon", color: "#fef1b5", // opacity: "0.9", - altColor: "#ecf0f1" + altColor: "#ecf0f1", + properties:{} }, carbon: { name: "Carbon Composite", color: "#222", - altColor: "#000" + altColor: "#000", + properties:{} }, nType: { name: "Aluminum", color: "#bcc6cc", - altColor: "#8391AC" + altColor: "#8391AC", + properties:{} }, brass:{ name: "Brass", color: "#b5a642", - altColor: "#857B64" + altColor: "#857B64", + properties:{ + conductive: true + } }, nTypePlus: { name: "Power Storage", color: "#c6ccbc", - altColor: "#9CC9CB" + altColor: "#9CC9CB", + properties:{} }, pType: { name: "Logic", color: "#ccbcc6", - altColor: "#F5447B" + altColor: "#F5447B", + properties:{} }, pTypePlus: { name: "Solar Panel", color: "#ccc2bc", - altColor: "#F99987" + altColor: "#F99987", + properties:{} } //857B64 //FDE2D9 diff --git a/js/simulation/electronics/eSim.js b/js/simulation/electronics/eSim.js index 3059d4f4326b75fa682ccdfd4134720d2f4292d8..60f59d8686355eafcc71b2dbbad6a026f9b69154 100644 --- a/js/simulation/electronics/eSim.js +++ b/js/simulation/electronics/eSim.js @@ -8,7 +8,8 @@ define(['underscore', 'backbone'], function(_, Backbone){ var eSim = Backbone.Model.extend({ defaults:{ - numConnectedComponents: null + conductorGroups: null, + visibleConductorGroup: -1 } diff --git a/js/simulation/electronics/eSimCell.js b/js/simulation/electronics/eSimCell.js index 90fb49e238c61f845128ad9c91683426a1b8fe98..f2d18e64dd983dd60678a29076368c29b17b0426 100644 --- a/js/simulation/electronics/eSimCell.js +++ b/js/simulation/electronics/eSimCell.js @@ -5,25 +5,30 @@ //assume latticeESim has loaded? define(['cell', 'lattice'], function(DMACell, lattice){ - DMACell.prototype.setConnectivityGroupNum = function(num, materialName){ - if (!materialName) this._eSimConnectivityGroup = num; - else if (this._eSimConnectivityGroup>num){ - this._eSimConnectivityGroup = num; - this.propagateConnectivityGroupNum(num, materialName); + DMACell.prototype.isConductive = function(){ + return this.getMaterial().properties.conductive; + }; + + DMACell.prototype.setConductorGroupNum = function(num, force){ + if (force) this._eSimConductorGroup = num; + else if (this._eSimConductorGroup>num){ + this._eSimConductorGroup = num; + this.propagateConductorGroupNum(num); } }; - DMACell.prototype.getConnectivityGroupNum = function(){ - return this._eSimConnectivityGroup; + DMACell.prototype.getConductorGroupNum = function(){ + return this._eSimConductorGroup; }; - DMACell.prototype.propagateConnectivityGroupNum = function(num, materialName){ - if (materialName === undefined) materialName = this.materialName; - if (materialName != "brass") return; - if (num === undefined) num = this._eSimConnectivityGroup; + DMACell.prototype.propagateConductorGroupNum = function(num){ + if (!this.isConductive()) return; + if (num === undefined) num = this._eSimConductorGroup; lattice.propagateToNeighbors(this.getAbsoluteIndex(), function(neighbor){ - if (neighbor) neighbor.setConnectivityGroupNum(num, materialName); + if (neighbor) neighbor.setConductorGroupNum(num); }); }; + + }); \ No newline at end of file