diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index 1b0b777327d926545ccc612dbe340667b6bfcb6d..b1b54507b1a3691e4d7653ab33e1c50bf7c3737e 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -90,5 +90,15 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'], CubeCell.prototype.propagateConductorGroupNum.call(this, num); }; + GIKCell.prototype.propagateStructuralGroupNum = function(num){ + if (num === undefined) num = this._eSimStructuralGroup; + var self = this; + this.superCell._loopCells(function(cell){ + if (cell == self) return; + if (cell) cell.setStructuralGroupNum(num); + }); + CubeCell.prototype.propagateStructuralGroupNum.call(this, num); + }; + return GIKCell; }); \ No newline at end of file diff --git a/js/menus/ESetupMenuView.js b/js/menus/ESetupMenuView.js index 0105bdf9639f7e20570b75382deb78051d80c943..8bc8a98256a47dbe5b57b14d03024f7daa9479a7 100644 --- a/js/menus/ESetupMenuView.js +++ b/js/menus/ESetupMenuView.js @@ -8,7 +8,8 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'materialsPlist', 'text!e return MenuParentView.extend({ events: { - "click #calcConnectivity": "_calcConnectivity", + "click #calcElectricalConnectivity": "_calcElectricalConnectivity", + "click #calcStructuralConnectivity": "_calcStructuralConnectivity", "click #showOverlappingCells": "_showOverlappingCells" }, @@ -27,11 +28,16 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'materialsPlist', 'text!e this.model.set("currentNav", materialClass + "NavSim"); }, - _calcConnectivity: function(e){ + _calcElectricalConnectivity: function(e){ e.preventDefault(); lattice.calculateConductorConnectivity(); }, + _calcStructuralConnectivity: function(e){ + e.preventDefault(); + lattice.calculateStructuralConnectivity(); + }, + _showOverlappingCells: function(e){ e.preventDefault(); lattice.highlightOverlappingCells(); diff --git a/js/menus/templates/ESetupMenuView.html b/js/menus/templates/ESetupMenuView.html index c102974e687108cbe5841a46b22c3fe0628ed50f..8dc6bdb73e20a161d34fe296c5adc35fbb230c63 100644 --- a/js/menus/templates/ESetupMenuView.html +++ b/js/menus/templates/ESetupMenuView.html @@ -12,7 +12,7 @@ Simulation Type: <% }); %> </ul> </div><br/><br/> -<a href="#" id="calcConnectivity" class="btn btn-block btn-lg btn-default"><% if(conductorGroups){ %>Re-<% } %>Calculate Connectivity</a><br/> +<a href="#" id="calcElectricalConnectivity" class="btn btn-block btn-lg btn-default"><% if(conductorGroups){ %>Re-<% } %>Calculate Electrical Connectivity</a><br/> <% if(conductorGroups){ %> Num Connected Conductors:  <%= _.keys(conductorGroups).length %><br/> <% if(_.keys(conductorGroups).length > 0){ %> @@ -31,4 +31,20 @@ Simulation Type: </label> <% }); %> <% } %> -<% } %> \ No newline at end of file +<% } %> +<a href="#" id="calcStructuralConnectivity" class="btn btn-block btn-lg btn-default"><% if(structuralGroups){ %>Re-<% } %>Calculate Structural Connectivity</a><br/> +<% if(structuralGroups){ %> + Num Separate Structures:  <%= _.keys(structuralGroups).length %><br/> + <% if(_.keys(structuralGroups).length > 0){ %> + <label class="radio"> + <input type="radio" <% if (visibleStructuralGroup == -1){ %>checked<% } %> name="visibleStructuralGroup" value="-1" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> + Show Everything + </label> + <% var index = 0; _.each(structuralGroups, function(groupData, id){ %> + <label class="radio"> + <input type="radio" <% if (id == visibleStructuralGroup){ %>checked<% } %> name="visibleStructuralGroup" value="<%= id %>" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> + Group <%= ++index %> + </label> + <% }); %> + <% } %> +<% } %> diff --git a/js/simulation/electronics/LatticeEsim.js b/js/simulation/electronics/LatticeEsim.js index 90c555bf1a4120d3d10775adb6209cdf2bdb0a58..12ba608586a25d594ec1c53c2e100c0448013e90 100644 --- a/js/simulation/electronics/LatticeEsim.js +++ b/js/simulation/electronics/LatticeEsim.js @@ -31,6 +31,47 @@ define(['lattice', 'appState', 'three', 'threeModel', 'numeric', 'eSim', 'eSimFi three.render(); }, + _showStructure: function(){ + var groupNum = eSim.get("visibleStructuralGroup"); + if (!eSim.get("structuralGroups") || _.keys(eSim.get("structuralGroups")).length == 0 || groupNum == -1){ + this.setOpaque(); + three.render(); + return; + } + var allVisible = groupNum == -1; + this._loopCells(this.sparseCells, function(cell){ + if (cell) cell.setTransparentByEval(function(evalCell){ + return !(allVisible || evalCell.structuralGroupVisible(groupNum)); + }); + }); + three.render(); + }, + + calculateStructuralConnectivity: function(){ + var num = 1; + this._loopCells(this.cells, function(cell){ + if (cell) cell.setStructuralGroupNum(num++, true); + }); + this._loopCells(this.cells, function(cell){ + if (cell) cell.propagateStructuralGroupNum(); + }); + this._calcNumberStructurallyConnectedComponents(); + this._showConductors(); + }, + + _calcNumberStructurallyConnectedComponents: function(){ + var groups = {}; + this._loopCells(this.cells, function(cell){ + if (!cell) return; + if (_.filter(groups, function(group){ + return group.id == cell.getStructuralGroupNum(); + }).length == 0) { + groups[cell.getStructuralGroupNum()] = {}; + } + }); + eSim.set("structuralGroups", groups); + }, + calculateConductorConnectivity: function(){ var num = 1; this._loopCells(this.cells, function(cell){ @@ -39,11 +80,11 @@ define(['lattice', 'appState', 'three', 'threeModel', 'numeric', 'eSim', 'eSimFi this._loopCells(this.cells, function(cell){ if (cell) cell.propagateConductorGroupNum(); }); - this._calcNumberConnectedComponents(); + this._calcNumberDCConnectedComponents(); this._showConductors(); }, - _calcNumberConnectedComponents: function(){ + _calcNumberDCConnectedComponents: function(){ var groups = {}; this._loopCells(this.cells, function(cell){ if (!cell) return; @@ -207,6 +248,7 @@ define(['lattice', 'appState', 'three', 'threeModel', 'numeric', 'eSim', 'eSimFi _.extend(lattice, eSimMethods); lattice.listenTo(appState, "change:currentTab", lattice._eSimTabChanged); lattice.listenTo(eSim, "change:visibleConductorGroup", lattice._showConductors); + lattice.listenTo(eSim, "change:visibleStructuralGroup", lattice._showStructure); lattice._showConductors(); diff --git a/js/simulation/electronics/cells/eSimCell.js b/js/simulation/electronics/cells/eSimCell.js index 1f0eef5d3055f9388d50d8b225a12f8529619d2b..b93eb8c10b7b6c7b3936d1a341b3a7d3733faee7 100644 --- a/js/simulation/electronics/cells/eSimCell.js +++ b/js/simulation/electronics/cells/eSimCell.js @@ -33,5 +33,28 @@ define(['cell', 'lattice'], function(DMACell, lattice){ return this.isConductive() && (allVisible || groupNum == this._eSimConductorGroup); }; + DMACell.prototype.setStructuralGroupNum = function(num, force){ + if (force) this._eSimStructuralGroup = num; + else if (this._eSimStructuralGroup>num){ + this._eSimStructuralGroup = num; + this.propagateStructuralGroupNum(num); + } + }; + + DMACell.prototype.propagateStructuralGroupNum = function(num){ + if (num === undefined) num = this._eSimStructuralGroup; + lattice.propagateToNeighbors(this.getAbsoluteIndex(), function(neighbor){ + if (neighbor) neighbor.setStructuralGroupNum(num); + }); + }; + + DMACell.prototype.getStructuralGroupNum = function(){ + return this._eSimStructuralGroup; + }; + + DMACell.prototype.structuralGroupVisible = function(groupNum){ + return groupNum == this._eSimStructuralGroup; + }; + }); \ No newline at end of file diff --git a/js/simulation/electronics/cells/eSimSuperCell.js b/js/simulation/electronics/cells/eSimSuperCell.js index 83b4e66a7318e719e877a2b77c263eca7f4404e4..9b2f78943f06eddef67b53ca9c178711db7e9ee7 100644 --- a/js/simulation/electronics/cells/eSimSuperCell.js +++ b/js/simulation/electronics/cells/eSimSuperCell.js @@ -17,5 +17,16 @@ define(['underscore', 'superCell'], function(_, DMASuperCell){ return false; }; + DMASuperCell.prototype.structuralGroupVisible = function(groupNum){ + for (var i=0;i<this.cells.length;i++){ + for (var j=0;j<this.cells[0].length;j++){ + for (var k=0;k<this.cells[0][0].length;k++){ + if (this.cells[i][j][k] && this.cells[i][j][k].structuralGroupVisible(groupNum)) return true; + } + } + } + return false; + }; + return DMASuperCell; }); \ No newline at end of file diff --git a/js/simulation/electronics/eSim.js b/js/simulation/electronics/eSim.js index 56508a8bff65e3376a6ba20a239f72866b6add85..fc3ba55d2ec3052e86a918d62396b955e98d3d10 100644 --- a/js/simulation/electronics/eSim.js +++ b/js/simulation/electronics/eSim.js @@ -8,8 +8,15 @@ define(['underscore', 'backbone', 'threeModel', 'appState'], function(_, Backbon var eSim = Backbone.Model.extend({ defaults:{ + + //electrical connections conductorGroups: null,//{{current:xx, voltage:xx}, ...} visibleConductorGroup: -1,//-2 = show everything, -1 = show all conductors + + //structural connections + structuralGroups: null, + visibleStructuralGroup: -1,//-1 = show everything + globalInductance: null, voltageUnits: "1", currentUnits: "0.001",