From eeb57a2b3ba5cb83e8c82769d9f8c9727fc7b633 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sun, 24 May 2015 22:09:46 -0700 Subject: [PATCH] baseplane and highlighter are globals now --- js/main.js | 6 +++--- js/models/AppState.js | 10 +++------- js/models/Lattice.js | 26 ++++++++++++-------------- js/models/LatticeOcta.js | 20 ++++++++++---------- js/models/LatticeOther.js | 16 ++++++++-------- js/threeViews/ThreeView.js | 2 +- 6 files changed, 37 insertions(+), 43 deletions(-) diff --git a/js/main.js b/js/main.js index 1db6b107..94f2fb61 100644 --- a/js/main.js +++ b/js/main.js @@ -15,12 +15,12 @@ $(function(){ globals.plist = buildAppPList(); globals.three = new ThreeModel(); globals.appState = new AppState(); - globals.lattice = new Lattice({appState: globals.appState}); - globals.lattice.delayedInit(); + globals.lattice = new Lattice(); + globals.lattice.delayedInit();//todo need this? globals.assembler = new Assembler({appState: globals.appState, lattice:globals.lattice}); - globals.appState.delayedInit(); //ui + new MenuWrapper({model: globals.appState}); new NavBar({model:globals.appState}); new Ribbon({model:globals.appState}); diff --git a/js/models/AppState.js b/js/models/AppState.js index 2b0d0c6d..e3f5609a 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -7,7 +7,7 @@ AppState = Backbone.Model.extend({ - defaults: { + defaults: {//menu and view/render/interaction states currentNav:"navDesign",// design, sim, assemble currentTab:"lattice", @@ -17,7 +17,6 @@ AppState = Backbone.Model.extend({ lastSimulationTab: "physics", lastAssembleTab: "assembler", - menuWrapper: null, menuIsVisible: true, //key bindings @@ -27,7 +26,8 @@ AppState = Backbone.Model.extend({ extrudeMode: false, cellMode: "cell",//show cells vs part cellsVisible: true, - superCellIndex: 0, + + superCellIndex: 0,//offset of superCell adds todo lattice? stockSimulationPlaying: false, manualSelectOrigin: false//mode that allows user ot select origin from existing cell @@ -51,10 +51,6 @@ AppState = Backbone.Model.extend({ if (this.isMobile()) this.set("menuIsVisible", false); }, - delayedInit: function(){ - this.set("menuWrapper", new MenuWrapper({model: this})); - }, - isMobile: function() { // var check = false; // (function(a,b){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera); diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 513eaabb..4d069f2b 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -15,9 +15,7 @@ Lattice = Backbone.Model.extend({ cellsMax: {x:0, y:0, z:0},//max position of cells matrix numCells: 0, - basePlane: null,//plane to build from scale: 20, - highlighter: null,//highlights build-able surfaces //spacing for connectors/joints cellSeparation: {xy:0, z:0}, @@ -31,19 +29,19 @@ Lattice = Backbone.Model.extend({ //pass in fillGeometry - initialize: function(options){ + initialize: function(){ _.extend(this, OctaLatticeSubclasses, OtherLatticeSubclasses); //bind events this.listenTo(this, "change:scale", this._scaleDidChange); this.listenTo(this, "change:gikLength", this._gikLengthDidChange); - this.listenTo(options.appState, "change:superCellIndex", this._gikLengthDidChange); - this.listenTo(options.appState, "change:cellMode", this._updateForMode); + this.listenTo(globals.appState, "change:superCellIndex", this._gikLengthDidChange); + this.listenTo(globals.appState, "change:cellMode", this._updateForMode); this.listenTo(this, "change:partType", this._updatePartType); this.listenTo(this, "change:cellType change:connectionType", this._updateLatticeType); this.listenTo(this, "change:cellSeparation", this._updateCellSeparation); - this.listenTo(options.appState, "change:cellsVisible", this._setCellVisibility); + this.listenTo(globals.appState, "change:cellsVisible", this._setCellVisibility); }, delayedInit: function(){ @@ -145,7 +143,7 @@ Lattice = Backbone.Model.extend({ this.set("cellsMin", {x:0, y:0, z:0}); this.set("nodes", []); this.set("numCells", 0); - if (this.get("basePlane")) this.get("basePlane").set("zIndex", 0); + if (globals.basePlane) globals.basePlane.set("zIndex", 0); globals.three.render(); }, @@ -351,7 +349,7 @@ Lattice = Backbone.Model.extend({ _updateCellSeparation: function(){ var cellSep = this.get("cellSeparation"); - this.get("basePlane").updateXYSeparation(cellSep.xy); + globals.basePlane.updateXYSeparation(cellSep.xy); var scale = this.get("scale"); var cellMode = globals.appState.get("cellMode"); @@ -364,8 +362,8 @@ Lattice = Backbone.Model.extend({ _scaleDidChange: function(){ var scale = this.get("scale"); - this.get("basePlane").updateScale(scale); - this.get("highlighter").updateScale(scale); + globals.basePlane.updateScale(scale); + globals.highlighter.updateScale(scale); var cellMode = globals.appState.get("cellMode"); var partType = this.get("partType"); @@ -377,11 +375,11 @@ Lattice = Backbone.Model.extend({ }, _gikLengthDidChange: function(){ - if (this.get("highlighter").updateGikLength) this.get("highlighter").updateGikLength(this.get("scale")); + if (globals.highlighter.updateGikLength) globals.highlighter.updateGikLength(this.get("scale")); }, previewScaleChange: function(scale){ - this.get("basePlane").updateScale(scale); + globals.basePlane.updateScale(scale); }, _setCellVisibility: function(){//todo maybe leave wireframes? @@ -432,8 +430,8 @@ Lattice = Backbone.Model.extend({ var cellType = this.get("cellType"); var connectionType = this.get("connectionType"); if (this._undo) this._undo(); - if (this.get("basePlane")) this.get("basePlane").destroy(); - if (this.get("highlighter")) this.get("highlighter").destroy(); + if (globals.basePlane) globals.basePlane.destroy(); + if (globals.highlighter) globals.highlighter.destroy(); if (cellType == "octa"){ if (connectionType == "face"){ _.extend(this, this.OctaFaceLattice); diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js index a9b98afd..6ecfd29b 100644 --- a/js/models/LatticeOcta.js +++ b/js/models/LatticeOcta.js @@ -12,8 +12,8 @@ OctaLatticeSubclasses = { OctaFaceLattice: { _initLatticeType: function(){ - this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); - this.set("highlighter", new OctaFaceHighlighter({scale:this.get("scale")})); + globals.basePlane = new OctaBasePlane({scale:this.get("scale")}); + globals.highlighter = new OctaFaceHighlighter({scale:this.get("scale")}); }, getIndexForPosition: function(absPosition){ @@ -73,8 +73,8 @@ OctaLatticeSubclasses = { OctaFreeFormFaceLattice: { _initLatticeType: function(){ - this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); - this.set("highlighter", new OctaFreeFormHighlighter({scale:this.get("scale")})); + globals.basePlane = new OctaBasePlane({scale:this.get("scale")}); + globals.highlighter = new OctaFreeFormHighlighter({scale:this.get("scale")}); this.set("freeformCellType", "octa"); @@ -151,8 +151,8 @@ OctaLatticeSubclasses = { OctaEdgeLattice: { _initLatticeType: function(){ - this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); - this.set("highlighter", new OctaEdgeHighlighter({scale:this.get("scale")})); + globals.basePlane = new OctaBasePlane({scale:this.get("scale")}); + globals.highlighter = new OctaEdgeHighlighter({scale:this.get("scale")}); }, @@ -210,8 +210,8 @@ OctaLatticeSubclasses = { OctaRotEdgeLattice: { _initLatticeType: function(){ - this.set("basePlane", new RotEdgeOctaBasePlane({scale:this.get("scale")})); - this.set("highlighter", new OctaVertexHighlighter({scale:this.get("scale")})); + globals.basePlane = new RotEdgeOctaBasePlane({scale:this.get("scale")}); + globals.highlighter = new OctaVertexHighlighter({scale:this.get("scale")}); }, getIndexForPosition: function(absPosition){ @@ -273,8 +273,8 @@ OctaLatticeSubclasses = { OctaVertexLattice: { _initLatticeType: function(){ - this.set("basePlane", new SquareBasePlane({scale:this.get("scale")})); - this.set("highlighter", new OctaVertexHighlighter({scale:this.get("scale")})); + globals.basePlane = new SquareBasePlane({scale:this.get("scale")}); + globals.highlighter = new OctaVertexHighlighter({scale:this.get("scale")}); }, getIndexForPosition: function(absPosition){ diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index 91c6ddd8..f1500d42 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -12,8 +12,8 @@ OtherLatticeSubclasses = { CubeLattice: { _initLatticeType: function(){ - this.set("basePlane", new SquareBasePlane({scale:this.get("scale")})); - this.set("highlighter", new CubeHighlighter({scale:this.get("scale")})); + globals.basePlane = new SquareBasePlane({scale:this.get("scale")}); + globals.highlighter = new CubeHighlighter({scale:this.get("scale")}); }, getIndexForPosition: function(absPosition){ @@ -57,8 +57,8 @@ OtherLatticeSubclasses = { GIKLattice: { _initLatticeType: function(){ - this.set("basePlane", new SquareBasePlane({scale:this.get("scale")})); - this.set("highlighter", new GIKHighlighter({scale:this.get("scale")})); + globals.basePlane = new SquareBasePlane({scale:this.get("scale")}); + globals.highlighter = new GIKHighlighter({scale:this.get("scale")}); }, getIndexForPosition: function(absPosition){ @@ -160,8 +160,8 @@ OtherLatticeSubclasses = { TruncatedCubeLattice: { _initLatticeType: function(){ - this.set("basePlane", new SquareBasePlane({scale:this.get("scale")})); - this.set("highlighter", new TruncatedCubeHighlighter({scale:this.get("scale")})); + globals.basePlane = new SquareBasePlane({scale:this.get("scale")}); + globals.highlighter = new TruncatedCubeHighlighter({scale:this.get("scale")}); }, getIndexForPosition: function(absPosition){ @@ -207,8 +207,8 @@ OtherLatticeSubclasses = { KelvinLattice: { _initLatticeType: function(){ - this.set("basePlane", new SquareBasePlane({scale:this.get("scale")})); - this.set("highlighter", new TruncatedCubeHighlighter({scale:this.get("scale")})); + globals.basePlane = new SquareBasePlane({scale:this.get("scale")}); + globals.highlighter = new TruncatedCubeHighlighter({scale:this.get("scale")}); }, getIndexForPosition: function(absPosition){ diff --git a/js/threeViews/ThreeView.js b/js/threeViews/ThreeView.js index b1fa867d..43259eda 100644 --- a/js/threeViews/ThreeView.js +++ b/js/threeViews/ThreeView.js @@ -134,7 +134,7 @@ ThreeView = Backbone.View.extend({ //////////////////////////////////////////////////////////////////////////////// _saveHighlighter: function(){ - this.highlighter = globals.lattice.get("highlighter"); + this.highlighter = globals.highlighter; }, _setNoPartIntersections: function(){ -- GitLab