From ee4bc7a4c37dc0a233bf8e382c436049f57d668e Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sat, 24 Oct 2015 00:46:44 -0400 Subject: [PATCH] show overlapping cells --- js/cells/DMACell.js | 12 ++++++---- js/cells/GIKCell.js | 8 +++++++ js/cells/supercells/DMASuperCell.js | 23 ++++++++++++++----- js/lattice/Lattice.js | 2 +- js/lattice/LatticeBase.js | 28 +++++++++++++++++++----- js/lattice/LatticeCAM.js | 7 ------ js/menus/ESetupMenuView.js | 8 ++++++- js/menus/templates/ESetupMenuView.html | 6 +++-- js/simulation/electronics/LatticeEsim.js | 2 +- 9 files changed, 68 insertions(+), 28 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index e6650efc..f025137b 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -219,7 +219,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' DMACell.prototype.show = function(mode){ this.object3D.visible = true; - this._setTransparent(false); + this.setTransparent(false); this.setMode(mode); }; @@ -256,10 +256,14 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' this.object3D.children[1].visible = visible && this.object3D.children[1].name == mode; }; - DMACell.prototype.setTransparent = function(evalFunction){ + DMACell.prototype.setTransparentByEval = function(evalFunction){ this._setTransparent(evalFunction(this)) }; + DMACell.prototype.setTransparent = function(transparent){ + this._setTransparent(transparent); + }; + DMACell.prototype._setTransparent = function(transparent){ if (transparent == this.isTransparent) return; this.isTransparent = transparent; @@ -438,9 +442,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' //parse DMACell.prototype.addToDenseArray = function(cellsArray, min){ var index = this.getAbsoluteIndex().sub(min); - if (cellsArray[index.x][index.y][index.z]) return true; + if (cellsArray[index.x][index.y][index.z]) return [this, cellsArray[index.x][index.y][index.z]]; cellsArray[index.x][index.y][index.z] = this; - return false; + return null; }; DMACell.prototype.removeFromDenseArray = function(cellsArray, min){ diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index f4ef1444..1b0b7773 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -70,6 +70,14 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'], } }; + GIKCell.prototype.show = function(){ + this.superCell.show(); + }; + + GIKCell.prototype.setTransparent = function(){ + this.superCell.setTransparent(); + }; + //todo move this somewhere else GIKCell.prototype.propagateConductorGroupNum = function(num){ if (!this.isConductive()) return; diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 06b1eb0a..31f57556 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -102,10 +102,17 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell', 'mat }; - DMASuperCell.prototype.setTransparent = function(evalFunction){ - DMACell.prototype.setTransparent.call(this, evalFunction);//todo don't pass down to cells if no change + DMASuperCell.prototype.setTransparentByEval = function(evalFunction){ + DMACell.prototype.setTransparentByEval.call(this, evalFunction);//todo don't pass down to cells if no change this._loopCells(function(cell){ - if (cell) cell.setTransparent(evalFunction); + if (cell) cell.setTransparentByEval(evalFunction); + }) + }; + + DMASuperCell.prototype.setTransparent = function(transparent){ + this._setTransparent(transparent); + this._loopCells(function(cell){ + if (cell) cell._setTransparent(transparent); }) }; @@ -116,11 +123,15 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell', 'mat //parse DMASuperCell.prototype.addToDenseArray = function(cellsArray, min, forCAM){ if (forCAM && this._isBottomLayer()) return DMACell.prototype.addToDenseArray.call(this, cellsArray, min);//this gives back the bottom layer cell for assembly, not necessarily the lattice pitch - var overlap = false; + var overlap = []; this._loopCells(function(cell){ - if (cell) overlap |= cell.addToDenseArray(cellsArray, min, forCAM); + if (cell) { + var overlappingCells = cell.addToDenseArray(cellsArray, min, forCAM) + if (overlappingCells) overlap = overlap.concat(overlappingCells); + } }); - return overlap; + if (overlap.length>0) return overlap; + return null; }; diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 7c2d186a..8c3a095e 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -21,7 +21,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis aspectRatio: null, denseCellsMin: null, - overlapDetected: false, + overlappingCells: [], nodes: [] }), diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index 0107a95f..64fc6150 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -496,9 +496,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre setOpaque: function(){ this._loopCells(this.sparseCells, function(cell){ - if (cell) cell.setTransparent(function(){ - return false; - }); + if (cell) cell.setTransparent(false); }); three.render(); }, @@ -571,17 +569,35 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre } var min = this.get("cellsMin").sub(bounds.min); - var overlap = false; + var overlap = []; var forCAM = appState.get("currentNav") == "navAssemble"; this._loopCells(this.sparseCells, function(cell){ if (!cell) return; - overlap |= cell.addToDenseArray(cells, min, forCAM); + var overlappingCells = cell.addToDenseArray(cells, min, forCAM); + if (overlappingCells) overlap = overlap.concat(overlappingCells); }); - this.set("overlapDetected", overlap); + this.set("overlappingCells", overlap); this.cells = cells; }, + highlightOverlappingCells: function(){ + this._loopCells(this.sparseCells, function(cell){ + if (cell) cell.setTransparent(true); + }); + _.each(this.get("overlappingCells"), function(cell){ + cell.show(); + }); + three.render(); + }, + + showCellAtIndex: function(index){ + index = (new THREE.Vector3()).subVectors(index, this.get("cellsMin"));//index is probably a json object from gcode comment + var cell = this.cells[index.x][index.y][index.z]; + if (cell) cell.show(); + else console.warn("cell does not exist"); + }, + diff --git a/js/lattice/LatticeCAM.js b/js/lattice/LatticeCAM.js index bc7a87f8..0726e2a6 100644 --- a/js/lattice/LatticeCAM.js +++ b/js/lattice/LatticeCAM.js @@ -7,13 +7,6 @@ define(['lattice', 'three'], function(lattice, THREE){ var camMethods = { - showCellAtIndex: function(index){ - var latticeIndex = (new THREE.Vector3()).subVectors(index, this.get("cellsMin"));//index is probably a json object from gcode comment - var cell = this.cells[latticeIndex.x][latticeIndex.y][latticeIndex.z]; - if (cell) cell.show(); - else console.warn("placing a cell that does not exist"); - }, - rasterCells: function(order, callback, var1, var2, var3, cells){//used for CAM raster x/y/z in any order permutation //order is of form 'XYZ' var firstLetter = order.charAt(0); diff --git a/js/menus/ESetupMenuView.js b/js/menus/ESetupMenuView.js index 2363a529..0105bdf9 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 #calcConnectivity": "_calcConnectivity", + "click #showOverlappingCells": "_showOverlappingCells" }, _initialize: function(){ @@ -31,6 +32,11 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'materialsPlist', 'text!e lattice.calculateConductorConnectivity(); }, + _showOverlappingCells: function(e){ + e.preventDefault(); + lattice.highlightOverlappingCells(); + }, + _makeTemplateJSON: function(){ return _.extend(this.model.toJSON(), eSim.toJSON(), plist, materialsPlist, lattice.toJSON()); }, diff --git a/js/menus/templates/ESetupMenuView.html b/js/menus/templates/ESetupMenuView.html index 76f87236..c102974e 100644 --- a/js/menus/templates/ESetupMenuView.html +++ b/js/menus/templates/ESetupMenuView.html @@ -1,5 +1,7 @@ -<% if (overlapDetected) { %> - <div class="inlineWarning">Overlapping cells detected, check that hierarchical cells are not placed on top of one another. Simulation results may be inaccurate.</div> +<% if (overlappingCells.length>0) { %> + <div class="inlineWarning">Overlapping cells detected, check that hierarchical cells are not placed on top of one another. Simulation results may be inaccurate.<br/><br/> + <a href="#" id="showOverlappingCells" class="btn btn-block btn-lg btn-danger">Show Problem</a> + </div> <% } %> Simulation Type: <div class="btn-group"> diff --git a/js/simulation/electronics/LatticeEsim.js b/js/simulation/electronics/LatticeEsim.js index 73a88c12..90c555bf 100644 --- a/js/simulation/electronics/LatticeEsim.js +++ b/js/simulation/electronics/LatticeEsim.js @@ -24,7 +24,7 @@ define(['lattice', 'appState', 'three', 'threeModel', 'numeric', 'eSim', 'eSimFi } var allVisible = groupNum == -1; this._loopCells(this.sparseCells, function(cell){ - if (cell) cell.setTransparent(function(evalCell){ + if (cell) cell.setTransparentByEval(function(evalCell){ return !(evalCell.conductiveGroupVisible(allVisible, groupNum)); }); }); -- GitLab