From 32e9705ccb1b929a395680d430e40bb4f2fdc094 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 11 Jun 2015 22:44:49 -0700 Subject: [PATCH] composite initing correctly --- js/lattice/CompositeEditorLattice.js | 2 +- js/lattice/Lattice.js | 52 ++++++---------------------- js/lattice/LatticeBase.js | 51 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 42 deletions(-) diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js index 344a416a..4d07850a 100644 --- a/js/lattice/CompositeEditorLattice.js +++ b/js/lattice/CompositeEditorLattice.js @@ -73,7 +73,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre color: this.get("color"), altColor: this.get("color"), numCells: this.get("numCells"), - cells: JSON.parse(JSON.stringify(this.sparseCells)), + sparseCells: JSON.parse(JSON.stringify(this.sparseCells)), cellsMin: this.get("cellsMin").clone(), cellsMax: this.get("cellsMax").clone(), dimensions: new THREE.Vector3().subVectors(this.get("cellsMax"), this.get("cellsMin")) diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 634a7632..0ea2d588 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -48,45 +48,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre - //lattice type - - _updateLatticeType: function(cells){//do not clear cells if loading from file (cells array contains important metadata) - - if (!cells) { - this._setToDefaultsSilently(); - cells = JSON.parse(JSON.stringify(this.sparseCells)); - } - - this._setDefaultCellMode(); - this._loadMaterialClass(); - - var cellsMin = this.get("cellsMin"); - var cellsMax = this.get("cellsMax"); - this._bindRenderToNumCells(this.get("numCells")); - this.clearCells(); - - if (this._undo) this._undo(); - if (globals.basePlane) globals.basePlane.destroy(); - if (globals.highlighter) globals.highlighter.destroy(); - - if (cellsMax && cellsMin) this.checkForMatrixExpansion(this.sparseCells, cellsMax, cellsMin); - var self = this; - require([this._getSubclassForLatticeType()], function(subclassObject){ - _.extend(self, subclassObject); - self._initLatticeType(); - if (self.get("cellsMin")) self.parseCellsJSON(cells); - }); - }, - - _bindRenderToNumCells: function(numCells){ - var self = this; - if (numCells > 0) this.listenTo(this, "change:numCells", function(){ - if (self.get("numCells") >= numCells){ - self.stopListening(self, "change:numCells"); - three.render(); - } - }); - }, + //latticeType _setToDefaultsSilently: function(){ var newCellType = this.get("cellType"); @@ -259,6 +221,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre + + //composite Cells _navChanged: function(){ @@ -274,8 +238,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre console.warn("composite editor already allocated"); self.compositeEditor.destroy(); } - self.compositeEditor = new CompositeEditorLattice(_.extend({id:id}, data), null, function(_self){ - _self.initLatticeSubclass(self._getSubclassForLatticeType()); + self.compositeEditor = new CompositeEditorLattice(_.extend({id:id}, _.omit(data, "sparseCells")), null, function(_self){ + var cells = null; + if (data) cells = data.sparseCells; + _self._updateLatticeType(cells, self._getSubclassForLatticeType()); appState.set("currentNav", "navComposite"); }); @@ -286,6 +252,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return appState.get("currentNav") == "navComposite" && this.compositeEditor; }, + _isSingltonLattice: function(){ + return true; + }, + exitCompositeEditing: function(){ if (this.compositeEditor) this.compositeEditor.destroy(); this.compositeEditor = null; diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index 1d33b1b3..b20f0ec5 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -39,6 +39,57 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre + + //lattice type + + _updateLatticeType: function(cells, subclass){//do not clear cells if loading from file (cells array contains important metadata) + + if (!cells) { + if (this._setToDefaultsSilently) this._setToDefaultsSilently(); + cells = JSON.parse(JSON.stringify(this.sparseCells)); + } + + if (this._setDefaultCellMode) this._setDefaultCellMode(); + if (this._loadMaterialClass) this._loadMaterialClass(); + + var cellsMin = this.get("cellsMin"); + var cellsMax = this.get("cellsMax"); + this._bindRenderToNumCells(this.get("numCells")); + this.clearCells(); + + if (this._undo) this._undo(); + if (this._isSingltonLattice()){ + if (globals.basePlane) globals.basePlane.destroy(); + if (globals.highlighter) globals.highlighter.destroy(); + } + + if (cellsMax && cellsMin) this.checkForMatrixExpansion(this.sparseCells, cellsMax, cellsMin); + var self = this; + require([subclass || this._getSubclassForLatticeType()], function(subclassObject){ + _.extend(self, subclassObject); + if (self._isSingltonLattice()) self._initLatticeType();//only do this for the lattice singleton + if (self.get("cellsMin")) self.parseCellsJSON(cells); + }); + }, + + _isSingltonLattice: function(){ + return false; + }, + + _bindRenderToNumCells: function(numCells){ + var self = this; + if (numCells > 0) this.listenTo(this, "change:numCells", function(){ + if (self.get("numCells") >= numCells){ + self.stopListening(self, "change:numCells"); + three.render(); + } + }); + }, + + + + + //add/remove cells addCellsInRange: function(range){//add a block of cells (extrude) -- GitLab