diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index e6650efcc2be4f15da1c94623658e47b51aad156..f025137b933d2726582ffdae36b9d7cba097a78d 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 f4ef144423612d26fe608eb431237861a3e1fdec..1b0b777327d926545ccc612dbe340667b6bfcb6d 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 06b1eb0a30c21f42d39aa28bc2d746a7e0b7aa12..31f575565f119f386251ac09ef86ad60316ede1d 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 7c2d186ac9cd3566dab8267ac27967c8f8983b46..8c3a095ea9e2ded04dbcab7e8bcade43a77f73d6 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 0107a95f2d8482e6b3f4cafd633df6c6f8ac80c4..64fc615090e89c30964ca6f3dd0468bfcde74227 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 bc7a87f8d0d810714365e6aa49d5a2ed42aa9e0b..0726e2a6207eb16e8545afe5957fa919539f0543 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 2363a529cd16fd5529c281e275e66ff5e9b8f942..0105bdf9639f7e20570b75382deb78051d80c943 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 76f87236a9813ee2174f758ea3e8f41146e4c3a3..c102974e687108cbe5841a46b22c3fe0628ed50f 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 73a88c12b6c9b91f0dbaad764c5cf44a06758a76..90c555bf1a4120d3d10775adb6209cdf2bdb0a58 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)); }); });