From 074b34f0475eb671d69b8920219703f25e75d828 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 25 Sep 2015 13:12:34 -0400 Subject: [PATCH] cleaning up lattice --- js/API/LatticeAPI.js | 53 ++++++++++++++++++++++++++++++---- js/lattice/Lattice.js | 10 +++---- js/lattice/LatticeBase.js | 24 ++++++--------- js/menus/CompositeMenuView.js | 2 +- js/menus/Ribbon.js | 12 +------- js/menus/templates/Ribbon.html | 3 +- js/models/AppState.js | 1 - js/models/FileSaver.js | 2 +- js/three/FillGeometry.js | 2 +- 9 files changed, 66 insertions(+), 43 deletions(-) diff --git a/js/API/LatticeAPI.js b/js/API/LatticeAPI.js index 931b71b3..7bed5afd 100644 --- a/js/API/LatticeAPI.js +++ b/js/API/LatticeAPI.js @@ -3,14 +3,19 @@ */ -define(['lattice'], function(lattice){ +define(['lattice', 'plist'], function(lattice, plist){ return { //getters getSize: function(){ + var bBox = lattice.calculateBoundingBox(); + return bBox.max.sub(bBox.min); + }, + getBoundingBox: function(){ + return lattice.calculateBoundingBox(); }, getAspectRatio: function(){ @@ -45,19 +50,47 @@ define(['lattice'], function(lattice){ }, setCellType: function(cellType){ - + if (plist.allLattices[cellType] === undefined){ + console.warn("no cell type " + cellType); + return; + } + return lattice.set("cellType", cellType); }, setConnectionType: function(connectionType){ - + var cellType = lattice.get("cellType"); + var plistCellData = plist.allLattices[cellType]; + if (plistCellData[connectionType] === undefined){ + console.warn("no connection type " + connectionType + " for cell type " + plistCellData.name); + return; + } + return lattice.set("connectionType", connectionType); }, setApplicationType: function(applicationType){ - + var cellType = lattice.get("cellType"); + var plistCellData = plist.allLattices[cellType]; + var connectionType = lattice.get("connectionType"); + var plistConnectionData = plistCellData[connectionType]; + if (plistConnectionData[applicationType] === undefined){ + console.warn("no application type " + applicationType + " for cell type " + plistCellData.name + " and connection type " + plistConnectionData.name); + return; + } + return lattice.set("latticeType", applicationType); }, setPartType: function(partType){ - + var cellType = lattice.get("cellType"); + var plistCellData = plist.allLattices[cellType]; + var connectionType = lattice.get("connectionType"); + var plistConnectionData = plistCellData[connectionType]; + var applicationType = lattice.get("latticeType"); + var plistAppData = plistConnectionData[applicationType]; + if (plistConnectionData[applicationType] === undefined){ + console.warn("no part type " + partType + " for cell type " + plistCellData.name + " and connection type " + plistConnectionData.name + " and application type " + plistAppData.name); + return; + } + return lattice.set("partType", partType); }, setLatticeType: function(cellType, connectionType, applicationType, partType){ @@ -72,11 +105,15 @@ define(['lattice'], function(lattice){ }, getSparseCells: function(){ + return lattice.sparseCells; + }, + setSparseCells: function(cells){ + lattice.reloadCells(cells); }, getCells: function(){ - + return lattice.cells; }, loopSparseCells: function(){ @@ -91,6 +128,10 @@ define(['lattice'], function(lattice){ }, + removeCell: function(cell){ + lattice.removeCell(cell); + }, + removeCellAtIndex: function(){ }, diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 4055942e..02c91353 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -33,18 +33,18 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis this.listenTo(this, "change:cellType", function(){ this._cellTypeChanged(); - this._reloadCells(); + this.reloadCells(); }); this.listenTo(this, "change:connectionType", function(){ this._connectionTypeChanged(); - this._reloadCells(); + this.reloadCells(); }); this.listenTo(this, "change:latticeType", function(){ this._latticeTypeChanged(); - this._reloadCells(); + this.reloadCells(); }); this.listenTo(this, "change:aspectRatio", function(){ - this._reloadCells(); + this.reloadCells(); }); this.listenTo(appState, "change:currentNav", this._navChanged); @@ -53,7 +53,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis }); this._latticeTypeChanged(); - this._reloadCells(); + this.reloadCells(); }, diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index e5a59ef9..91048b29 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -28,7 +28,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //bind events this.listenTo(appState, "change:cellMode", this._updateForMode); - this.listenTo(appState, "change:cellsVisible", this._setCellVisibility); if (this.__initialize) this.__initialize(options, callback); }, @@ -44,13 +43,13 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return plist.allLattices[this.get("cellType")].connection[this.get("connectionType")].type[this.get("latticeType")]; }, - _reloadCells: function(cells, subclass){ + reloadCells: function(cells, subclass){ if ((this.get("connectionType") == "gik" || this.previous("connectionType") == "gik") && !cells) this.clearCells(); if (!cells) cells = JSON.parse(JSON.stringify(this.sparseCells)); - if (this._setDefaultCellMode) this._setDefaultCellMode(); + if (this._setDefaultCellMode) this._setDefaultCellMode();//only on lattice var cellsMin = this.get("cellsMin"); var cellsMax = this.get("cellsMax"); @@ -63,7 +62,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre if (globals.highlighter) globals.highlighter.destroy(); } - if (cellsMax && cellsMin) this.checkForMatrixExpansion(this.sparseCells, cellsMax, cellsMin); + if (cellsMax && cellsMin) this._checkForMatrixExpansion(this.sparseCells, cellsMax, cellsMin); var self = this; require([subclass || this._getSubclassForLatticeType()], function(subclassObject){ _.extend(self, subclassObject); @@ -106,7 +105,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre addCellsInRange: function(range){//add a block of cells (extrude) - this.checkForMatrixExpansion(this.sparseCells, range.max, range.min); + this._checkForMatrixExpansion(this.sparseCells, range.max, range.min); var cellsMin = this.get("cellsMin"); var relativeMin = (new THREE.Vector3()).subVectors(range.min, cellsMin); @@ -134,14 +133,14 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre addCellAtIndex: function(index, noRender, noCheck){//no render no check from fill/load - if (!noCheck || noCheck === undefined) this.checkForMatrixExpansion(this.sparseCells, index, index); + if (!noCheck || noCheck === undefined) this._checkForMatrixExpansion(this.sparseCells, index, index); var relIndex = (new THREE.Vector3()).subVectors(index, this.get("cellsMin") || index); if (!noRender || noRender === undefined) three.setRenderFlag(); - this.addCellWithJson({index: index, materialName:appState.get("materialType")}, relIndex); + this._addCellWithJSON({index: index, materialName:appState.get("materialType")}, relIndex); }, - addCellWithJson: function(json, index){ + _addCellWithJSON: function(json, index){ var self = this; if (!this.sparseCells[index.x][index.y][index.z]) { this.makeCellForLatticeType(json, function(cell){ @@ -230,7 +229,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //cells array - checkForMatrixExpansion: function(cells, indicesMax, indicesMin){ + _checkForMatrixExpansion: function(cells, indicesMax, indicesMin){ if (!cells) { console.warn("no cells specified in matrix expansion"); @@ -457,11 +456,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }); }, - _setCellVisibility: function(){ - if (appState.get("cellsVisible")) this.showCells(); - else this.hideCells(); - }, - hideCells: function(whichArray){ if (!whichArray) whichArray = "sparseCells"; this._iterCells(this[whichArray], function(cell){ @@ -578,7 +572,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this._loopCells(sparseCells, function(cell, x, y, z, self){ if (cell) { var json = _.extend({index: (new THREE.Vector3(x, y, z)).add(cellsMin)}, cell); - self.addCellWithJson(json, new THREE.Vector3(x, y, z)); + self._addCellWithJSON(json, new THREE.Vector3(x, y, z)); } }); }, diff --git a/js/menus/CompositeMenuView.js b/js/menus/CompositeMenuView.js index 76fef640..a2f13cdb 100644 --- a/js/menus/CompositeMenuView.js +++ b/js/menus/CompositeMenuView.js @@ -52,7 +52,7 @@ define(['jquery', 'underscore', 'menuParent', 'compositeEditorLattice', 'materia var compositeLattice = new CompositeEditorLattice(_.extend({id:id}, _.omit(data, "sparseCells")), null, function(_composite){ var cells = null; if (data) cells = data.sparseCells; - _composite._reloadCells(cells, lattice._getSubclassForLatticeType()); + _composite.reloadCells(cells, lattice._getSubclassForLatticeType());//todo get rid of this }); lattice.setToCompositeMode(compositeLattice); diff --git a/js/menus/Ribbon.js b/js/menus/Ribbon.js index 0903f585..ec73dab5 100644 --- a/js/menus/Ribbon.js +++ b/js/menus/Ribbon.js @@ -12,7 +12,6 @@ define(['jquery', 'underscore', 'backbone', 'plist', 'lattice', 'appState', 'tex "click .ribbonCellMode": "_updateCellMode", "click .ribbonDeleteMode": "_updateDeleteMode", "click .highlightMode": "_updateHighlightMode", - "click .cellsVisible": "_updateCellVisibility", "click #ribbonAxesToggle": "_setAxesVis" }, @@ -25,7 +24,6 @@ define(['jquery', 'underscore', 'backbone', 'plist', 'lattice', 'appState', 'tex this.listenTo(this.model, "change:currentNav", this.render); this.listenTo(this.model, "change:deleteMode", this.render); this.listenTo(this.model, "change:highlightMode", this.render); - this.listenTo(this.model, "change:cellsVisible", this.render); this.listenTo(this.model, "change:axesAreVisible", this.render); this.listenTo(lattice, "change:cellType change:connectionType change:latticeType", this.render); this.render(); @@ -46,11 +44,6 @@ define(['jquery', 'underscore', 'backbone', 'plist', 'lattice', 'appState', 'tex this.model.set("highlightMode", !this.model.get("highlightMode")); }, - _updateCellVisibility: function(e){ - e.preventDefault(); - this.model.set("cellsVisible", !this.model.get("cellsVisible")); - }, - _changeVisibility: function(){ var state = this.model.get("ribbonIsVisible"); if (state) this.$el.show(); @@ -70,7 +63,4 @@ define(['jquery', 'underscore', 'backbone', 'plist', 'lattice', 'appState', 'tex }); return new Ribbon({model:appState}); -}); - -//<a class="btn btn-primary btn-ribbon highlightMode<% if (highlightMode){ %> ribbon-selected<% } %>" href="#"><img data-type="part" src="assets/imgs/cursor-light.png"></a>\ -//<a class="btn btn-primary btn-ribbon cellsVisible<% if (!cellsVisible){ %> ribbon-selected<% } %>" href="#"><img data-type="part" src="assets/imgs/hide.png"></a>\ +}); \ No newline at end of file diff --git a/js/menus/templates/Ribbon.html b/js/menus/templates/Ribbon.html index ae57ffba..0fee2414 100644 --- a/js/menus/templates/Ribbon.html +++ b/js/menus/templates/Ribbon.html @@ -8,7 +8,7 @@ <% } %> <!--<a data-type="beam" class="btn btn-primary btn-ribbon ribbonCellMode<% if (cellMode == "beam"){ %> ribbon-selected<% } %>" href="#">Beam</a>--> <% if (currentNav != "navDesign"){%> - <a data-type="hide" class="btn btn-primary btn-ribbon ribbonCellMode<% if (cellMode == "hide"){ %> ribbon-selected"<% } %>">Hide</a> + <a data-type="hide" class="btn btn-primary btn-ribbon ribbonCellMode<% if (cellMode == "hide"){ %> ribbon-selected"<% } %>"><img data-type="hide" src="assets/imgs/hide.png"></a> <% }else{ %> <a class="btn btn-primary btn-ribbon ribbonDeleteMode<% if (deleteMode){ %> ribbon-selected"<% } %>"><span class="fui-cross"></span></a> <% } %> @@ -16,4 +16,3 @@ </div> </div> <!--//<a class="btn btn-primary btn-ribbon highlightMode<% if (highlightMode){ %> ribbon-selected<% } %>" href="#"><img data-type="part" src="assets/imgs/cursor-light.png"></a>--> -<!--//<a class="btn btn-primary btn-ribbon cellsVisible<% if (!cellsVisible){ %> ribbon-selected<% } %>" href="#"><img data-type="part" src="assets/imgs/hide.png"></a>--> diff --git a/js/models/AppState.js b/js/models/AppState.js index d7341932..5ff1d306 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -34,7 +34,6 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], highlightMode: true, extrudeMode: false, cellMode: "cell",//supercell, cell, part, hide - cellsVisible: true, superCellIndex: new THREE.Vector3(0,0,0),//offset of superCell adds gikLength: 4,//this updates super cell range when using non-composite materials diff --git a/js/models/FileSaver.js b/js/models/FileSaver.js index 8529d4ca..8fe09e11 100644 --- a/js/models/FileSaver.js +++ b/js/models/FileSaver.js @@ -103,7 +103,7 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra lattice.clearCells(); var sparseCells = data.assembly.sparseCells; _setData(lattice, _.omit(data.assembly, "sparseCells")); - if (sparseCells) lattice._reloadCells(sparseCells); + if (sparseCells) lattice.reloadCells(sparseCells); ribbon.render(); menuWrapper.render(); } diff --git a/js/three/FillGeometry.js b/js/three/FillGeometry.js index fca1a71f..f2692cc8 100644 --- a/js/three/FillGeometry.js +++ b/js/three/FillGeometry.js @@ -52,7 +52,7 @@ define(['three', 'underscore', 'backbone', 'lattice', 'threeModel'], var maxIndex = lattice.getIndexForPosition(scaledMax); console.log(minIndex); console.log(maxIndex); - lattice.checkForMatrixExpansion(null, maxIndex, minIndex);//expand cells matrix before + lattice.checkForMatrixExpansion(null, maxIndex, minIndex);//todo put this somewhere else var raycaster = new THREE.Raycaster(); var direction = new THREE.Vector3(0,0,1); -- GitLab