diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index c19814c0ae47be174ba6f5bf446a4e9727dd338c..a8daf39013e0d1a563cf71ea5abb8a1b74c71235 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -131,6 +131,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _parseSparseCell: function(){ + console.log("parse cells"); + if (this.get("numCells") == 0) { console.warn("no cells in assembly"); this.cells = [[[null]]]; diff --git a/js/lattice/LatticeEsim.js b/js/lattice/LatticeEsim.js new file mode 100644 index 0000000000000000000000000000000000000000..66ed1caaa358b11e40ccd3002f53105ba8edcc4b --- /dev/null +++ b/js/lattice/LatticeEsim.js @@ -0,0 +1,46 @@ +/** + * Created by aghassaei on 6/30/15. + */ + +define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){ + + var eSimMethods = { + + calculateConnectivity: function(){ + var num = 1; + this._loopCells(this.cells, function(cell){ + if (cell) cell.setConnectivityGroupNum(num++, true); + }); + this._loopCells(this.cells, function(cell){ + if (cell) cell.propagateConnectivityGroupNum(); + }); + this._calcNumberConnectedComponents(); + }, + + _calcNumberConnectedComponents: function(){ + var groups = []; + this._loopCells(this.cells, function(cell){ + if (!cell) return; + if (groups.indexOf(cell.getConnectivityGroupNum())<0) groups.push(cell.getConnectivityGroupNum()); + }); + eSim.set("numConnectedComponents", groups.length); + }, + + propagateToNeighbors: function(index, callback){ + index.sub(this.get("cellsMin"));//todo wrong + var xLength = this.cells.length; + var yLength = this.cells[0].length; + var zLength = this.cells[0][0].length; + if (index.x+1 < xLength) callback(this.cells[index.x+1][index.y][index.z]); + if (index.x-1 >= 0) callback(this.cells[index.x-1][index.y][index.z]); + if (index.y+1 < yLength) callback(this.cells[index.x][index.y+1][index.z]); + if (index.y-1 >= 0) callback(this.cells[index.x][index.y-1][index.z]); + if (index.z+1 < zLength) callback(this.cells[index.x][index.y][index.z+1]); + if (index.z-1 >= 0) callback(this.cells[index.x][index.y][index.z-1]); + } + + }; + + _.extend(lattice, eSimMethods); + return lattice; +}); diff --git a/js/main.js b/js/main.js index 7dedc7c1ddd9c16ccc17dd3f62c07730d4791c53..a88f8bf1586aecfba56f8da89f4fa9ea3c65bab0 100644 --- a/js/main.js +++ b/js/main.js @@ -151,6 +151,12 @@ require.config({ mStaticMenuTemplate: 'menus/templates/MStaticMenuView.html', mDynamicMenuTemplate: 'menus/templates/MDynamicMenuView.html', + //electronic sim + eSim: 'simulation/electronics/eSim', + latticeESim: 'lattice/latticeESim', + eSimCell: 'simulation/electronics/eSimCell', + + //cam cam: 'cam/cam', diff --git a/js/menus/ESetupMenuView.js b/js/menus/ESetupMenuView.js index 5967c3072b2c834b61dbf3f8cf4cac50463dd45d..e2a4d086dbc08b8563ee0a87fd2ff708c05a4c27 100644 --- a/js/menus/ESetupMenuView.js +++ b/js/menus/ESetupMenuView.js @@ -2,18 +2,32 @@ * Created by aghassaei on 2/25/15. */ -define(['jquery', 'underscore', 'menuParent', 'plist', 'text!eSetupMenuTemplate'], function($, _, MenuParentView, plist, template){ +define(['jquery', 'underscore', 'menuParent', 'plist', 'text!eSetupMenuTemplate', 'latticeESim', 'eSim'], + function($, _, MenuParentView, plist, template, lattice, eSim){ return MenuParentView.extend({ events: { + "click #calcConnectivity": "_calcConnectivity" }, _initialize: function(){ + this.listenTo(eSim, "change", this.render); + this.listenTo(this.model, "change:materialClass", this._changeSimNav); + }, + + _changeSimNav: function(){ + var materialClass = this.model.get("materialClass"); + this.model.set("currentNav", materialClass + "NavSim"); + }, + + _calcConnectivity: function(e){ + e.preventDefault(); + lattice.calculateConnectivity(); }, _makeTemplateJSON: function(){ - return null; + return _.extend(this.model.toJSON(), eSim.toJSON(), plist); }, template: _.template(template) diff --git a/js/menus/templates/ESetupMenuView.html b/js/menus/templates/ESetupMenuView.html index c14ccd9ceaa2f8236914251793bb62fd58887508..a6bd5cb166103963f8a042c7bada2dab830753e8 100644 --- a/js/menus/templates/ESetupMenuView.html +++ b/js/menus/templates/ESetupMenuView.html @@ -1 +1,11 @@ -boundaries \ No newline at end of file +Simulation Type: + <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="appState dropdownSelector" data-property="materialClass" data-value="<%= key %>" href="#"><%= allMaterialClasses[key] %></a></li> + <% }); %> + </ul> + </div><br/><br/> +<a href="#" id="calcConnectivity" class="btn btn-block btn-lg btn-default">Calculate Connectivity</a><br/> +<% if(numConnectedComponents){ %>Num Connected Components:  <%= numConnectedComponents %> <% } %> \ No newline at end of file diff --git a/js/simulation/electronics/eCell.js b/js/simulation/electronics/eCell.js deleted file mode 100644 index 9ae6b0d7c7513df9fa93e4abd8b5c65248447935..0000000000000000000000000000000000000000 --- a/js/simulation/electronics/eCell.js +++ /dev/null @@ -1,3 +0,0 @@ -/** - * Created by aghassaei on 6/29/15. - */ diff --git a/js/simulation/electronics/eSim.js b/js/simulation/electronics/eSim.js index 9ae6b0d7c7513df9fa93e4abd8b5c65248447935..3059d4f4326b75fa682ccdfd4134720d2f4292d8 100644 --- a/js/simulation/electronics/eSim.js +++ b/js/simulation/electronics/eSim.js @@ -1,3 +1,18 @@ /** * Created by aghassaei on 6/29/15. */ + + +define(['underscore', 'backbone'], function(_, Backbone){ + + var eSim = Backbone.Model.extend({ + + defaults:{ + numConnectedComponents: null + } + + + }); + + return new eSim(); +}); \ No newline at end of file diff --git a/js/simulation/electronics/eSimCell.js b/js/simulation/electronics/eSimCell.js new file mode 100644 index 0000000000000000000000000000000000000000..58527050da473e538583a597c5274feab2acce22 --- /dev/null +++ b/js/simulation/electronics/eSimCell.js @@ -0,0 +1,27 @@ +/** + * Created by aghassaei on 6/29/15. + */ + +//assume latticeESim has loaded? +define(['cell', 'lattice'], function(DMACell, lattice){ + + DMACell.prototype.setConnectivityGroupNum = function(num, force){ + if (force) this._eSimConnectivityGroup = num; + else if (this._eSimConnectivityGroup>num){ + this._eSimConnectivityGroup = num; + this.propagateConnectivityGroupNum(num); + } + }; + + DMACell.prototype.getConnectivityGroupNum = function(){ + return this._eSimConnectivityGroup; + }; + + DMACell.prototype.propagateConnectivityGroupNum = function(num){ + if (num===undefined) num = this._eSimConnectivityGroup; + lattice.propagateToNeighbors(this.getAbsoluteIndex(), function(neighbor){ + if (neighbor) neighbor.setConnectivityGroupNum(num); + }); + }; + +}); \ No newline at end of file