From 2662e44484638aec52a9041c041b8a65f18da22d Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Mon, 10 Aug 2015 20:17:28 -0400 Subject: [PATCH] conductor groups stored as object --- js/menus/EStaticMenuView.js | 2 +- js/menus/templates/ESetupMenuView.html | 10 +++++----- js/menus/templates/EStaticMenuView.html | 8 ++++---- js/simulation/electronics/LatticeEsim.js | 6 +++--- js/simulation/electronics/eSim.js | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/js/menus/EStaticMenuView.js b/js/menus/EStaticMenuView.js index 6dff60af..b536655a 100644 --- a/js/menus/EStaticMenuView.js +++ b/js/menus/EStaticMenuView.js @@ -20,7 +20,7 @@ define(['jquery', 'underscore', 'menuParent', 'eSimPlist', 'text!eStaticMenuTemp getPropertyOwner: function($target){ if ($target.hasClass("eSim")) return eSim; - if ($target.hasClass("eSimGroup")) return eSim.get("conductorGroups")[$target.data("index")]; + if ($target.hasClass("eSimGroup")) return eSim.get("conductorGroups")[$target.data("id")]; return null; }, diff --git a/js/menus/templates/ESetupMenuView.html b/js/menus/templates/ESetupMenuView.html index 4fed4531..2c9e96ac 100644 --- a/js/menus/templates/ESetupMenuView.html +++ b/js/menus/templates/ESetupMenuView.html @@ -12,8 +12,8 @@ Simulation Type: </div><br/><br/> <a href="#" id="calcConnectivity" class="btn btn-block btn-lg btn-default"><% if(conductorGroups){ %>Re-<% } %>Calculate Connectivity</a><br/> <% if(conductorGroups){ %> - Num Connected Conductors:  <%= conductorGroups.length %><br/> - <% if(conductorGroups.length > 0){ %> + Num Connected Conductors:  <%= _.keys(conductorGroups).length %><br/> + <% if(_.keys(conductorGroups).length > 0){ %> <label class="radio"> <input type="radio" <% if (visibleConductorGroup == -2){ %>checked<% } %> name="visibleConductorGroup" value="-2" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> Show Everything @@ -22,10 +22,10 @@ Simulation Type: <input type="radio" <% if (visibleConductorGroup == -1){ %>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 Conducting Groups </label> - <% _.each(conductorGroups, function(groupData, index){ %> + <% var index = 0; _.each(conductorGroups, function(groupData, id){ %> <label class="radio"> - <input type="radio" <% if (groupData.id == visibleConductorGroup){ %>checked<% } %> name="visibleConductorGroup" value="<%= groupData.id %>" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> - Group <%= index + 1 %> + <input type="radio" <% if (id == visibleConductorGroup){ %>checked<% } %> name="visibleConductorGroup" 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/menus/templates/EStaticMenuView.html b/js/menus/templates/EStaticMenuView.html index c6da2f99..7d9239c7 100644 --- a/js/menus/templates/EStaticMenuView.html +++ b/js/menus/templates/EStaticMenuView.html @@ -1,4 +1,4 @@ -<% if(conductorGroups && conductorGroups.length > 0){ %> +<% if(conductorGroups && _.keys(conductorGroups).length > 0){ %> Simulation Resolution: <input data-property="simulationRes" value="<%= simulationRes %>" placeholder="Resolution" class="form-control intInput eSim voltageInput" type="text"><br/><br/> Dielectric Permittivity (k): <input data-property="dielectricPerm" value="<%= dielectricPerm %>" placeholder="k" class="form-control floatInput eSim voltageInput" type="text"><br/> <label class="radio"> @@ -9,10 +9,10 @@ <input type="radio" <% if (visibleConductorGroup == -1){ %>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 Conducting Groups </label> - <% _.each(conductorGroups, function(groupData, index){ %> + <% var index = 0; _.each(conductorGroups, function(groupData, id){ %> <label class="radio"> - <input type="radio" <% if (groupData.id == visibleConductorGroup){ %>checked<% } %> name="visibleConductorGroup" value="<%= groupData.id %>" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> - Group <%= index + 1 %> + <input type="radio" <% if (id == visibleConductorGroup){ %>checked<% } %> name="visibleConductorGroup" 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 %> <input data-property="voltage" data-index="<%= index %>" value="<%= groupData.voltage %>" placeholder="Voltage" class="form-control floatInput eSimGroup voltageInput" type="text"> <input data-property="current" data-index="<%= index %>" value="<%= groupData.current %>" placeholder="Current" class="form-control floatInput eSimGroup currentInput" type="text"> </label> diff --git a/js/simulation/electronics/LatticeEsim.js b/js/simulation/electronics/LatticeEsim.js index 3eb10101..0ea05346 100644 --- a/js/simulation/electronics/LatticeEsim.js +++ b/js/simulation/electronics/LatticeEsim.js @@ -17,7 +17,7 @@ define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimCell', 'eSimS _showConductors: function(){ var groupNum = eSim.get("visibleConductorGroup"); - if (!eSim.get("conductorGroups") || eSim.get("conductorGroups").length == 0 || groupNum == -2){ + if (!eSim.get("conductorGroups") || _.keys(eSim.get("conductorGroups")).length == 0 || groupNum == -2){ this.setOpaque(); three.render(); return; @@ -44,13 +44,13 @@ define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimCell', 'eSimS }, _calcNumberConnectedComponents: function(){ - var groups = []; + var groups = {}; this._loopCells(this.cells, function(cell){ if (!cell) return; if (_.filter(groups, function(group){ return group.id == cell.getConductorGroupNum(); }).length == 0 && cell.isConductive()) { - groups.push({id:cell.getConductorGroupNum(), current: null, voltage: null}); + groups[cell.getConductorGroupNum()] = {current: null, voltage: null}; } }); eSim.set("conductorGroups", groups); diff --git a/js/simulation/electronics/eSim.js b/js/simulation/electronics/eSim.js index 2f045d0d..ea9cf5cf 100644 --- a/js/simulation/electronics/eSim.js +++ b/js/simulation/electronics/eSim.js @@ -8,7 +8,7 @@ define(['underscore', 'backbone', 'threeModel'], function(_, Backbone, three){ var eSim = Backbone.Model.extend({ defaults:{ - conductorGroups: null,//[{id: xx, current:xx, voltage:xx}] + conductorGroups: null,//{{current:xx, voltage:xx}, ...} visibleConductorGroup: -1,//-2 = show everything, -1 = show all conductors globalInductance: null, voltageUnits: "1", -- GitLab