diff --git a/index.html b/index.html index 28ac011c379293bb54c41ad870a8152ce5570a46..79164e39d8e842ccd9879f969d7b9deaf9196646 100644 --- a/index.html +++ b/index.html @@ -59,6 +59,7 @@ <script src="js/models/FillGeometry.js"></script> <script src="js/models/BasePlane.js"></script> <script src="js/models/extrudeVisualizer.js"></script> + <script src="js/models/AllAppPLists.js"></script> <script src="js/models/AppState.js"></script> <script src="js/cam/Machine.js"></script> <script src="js/cam/MachineOneBit.js"></script> diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index 12dcd83731e4aa8a50e6886ee93c8f1b38d73768..67bf02f98152e3bfa977bc4b622058cea452251b 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -68,7 +68,7 @@ Assembler = Backbone.Model.extend({ "change:connectionType", this._setNeedsPostProcessing); this.listenTo(options.lattice, "change:scale", this._setCAMScale); - this.listenTo(dmaGlobals.appState, "change:stockSimulationPlaying", this._stockSimulation); + this.listenTo(globals.appState, "change:stockSimulationPlaying", this._stockSimulation); this.listenTo(options.lattice, "change:partType", this._updatePartType); this.listenTo(options.lattice, "change:cellType change:connectionType", this._updateCellType); @@ -101,7 +101,7 @@ Assembler = Backbone.Model.extend({ /////////////////////////////////////////////////////////////////////////////////////////////// isVisible: function(){ - var currentTab = dmaGlobals.appState.get("currentTab"); + var currentTab = globals.appState.get("currentTab"); return (currentTab == "cam" || currentTab == "animate" || currentTab == "send"); }, @@ -117,11 +117,11 @@ Assembler = Backbone.Model.extend({ _updateCellMode: function(){ if (this.get("machine")) this.get("machine").setVisibility(this.isVisible()); - dmaGlobals.three.render(); + globals.three.render(); }, _setCAMScale: function(){ - var scale = dmaGlobals.lattice.get("scale"); + var scale = globals.lattice.get("scale"); this.get("origin").scale.set(scale/8, scale/8, scale/8); this.get("stock").scale.set(scale/8, scale/8, scale/8); if (this.get("machine")) this.get("machine").setScale(scale); @@ -129,7 +129,7 @@ Assembler = Backbone.Model.extend({ _tabChanged: function(){ this._setCAMVisibility(); - if (dmaGlobals.appState.get("currentTab") != "animate") this.resetSimulation(); + if (globals.appState.get("currentTab") != "animate") this.resetSimulation(); }, _setCAMVisibility: function(){ @@ -138,19 +138,19 @@ Assembler = Backbone.Model.extend({ this.get("stock").visible = visible; if (visible && !this.get("machine")) this.selectMachine(); if (this.get("machine")) this.get("machine").setVisibility(visible); - dmaGlobals.three.render(); + globals.three.render(); }, _initOriginAndStock: function(){//todo this is ugly var origin = new THREE.Mesh(new THREE.SphereGeometry(1), new THREE.MeshBasicMaterial({color:0xff0000})); - dmaGlobals.three.sceneAdd(origin); + globals.three.sceneAdd(origin); this.set("origin", origin); this._moveOrigin(); //init stock mesh var stock = new THREE.Mesh(new THREE.SphereGeometry(1), new THREE.MeshBasicMaterial({color:0xff00ff})); - dmaGlobals.three.sceneAdd(stock); + globals.three.sceneAdd(stock); this.set("stock", stock); this._moveStock(); this._setCAMScale(); @@ -161,7 +161,7 @@ Assembler = Backbone.Model.extend({ var position = this.get("originPosition"); this.get("origin").position.set(position.x, position.y, position.z); if (this.get("stockFixed")) this._updateStockPosToOrigin(position, this.previous("originPosition")); - dmaGlobals.three.render(); + globals.three.render(); if (this.get("machine") && this.get("machine").setMachinePosition) this.get("machine").setMachinePosition(); }, @@ -177,7 +177,7 @@ Assembler = Backbone.Model.extend({ _moveStock: function(){ var position = this.get("stockPosition"); this.get("stock").position.set(position.x, position.y, position.z); - dmaGlobals.three.render(); + globals.three.render(); }, /////////////////////////////////////////////////////////////////////////////////////////////// @@ -186,16 +186,16 @@ Assembler = Backbone.Model.extend({ resetSimulation: function(){ this.set("simLineNumber", 0, {silent:true}); - dmaGlobals.appState.set("stockSimulationPlaying", false); - dmaGlobals.three.stopAnimationLoop(); - dmaGlobals.lattice.showCells(); + globals.appState.set("stockSimulationPlaying", false); + globals.three.stopAnimationLoop(); + globals.lattice.showCells(); }, _stockSimulation: function(){ - if (dmaGlobals.appState.get("stockSimulationPlaying")){ - dmaGlobals.three.startAnimationLoop(); + if (globals.appState.get("stockSimulationPlaying")){ + globals.three.startAnimationLoop(); var currentLine = this.get("simLineNumber"); - if (currentLine == 0) dmaGlobals.lattice.hideCells(); + if (currentLine == 0) globals.lattice.hideCells(); var allLines = this.get("dataOut").split("\n"); if(currentLine<allLines.length){ var self = this; @@ -210,7 +210,7 @@ Assembler = Backbone.Model.extend({ this.resetSimulation(); } } else { - dmaGlobals.three.stopAnimationLoop(); + globals.three.stopAnimationLoop(); this.get("machine").pause(); } @@ -244,7 +244,7 @@ Assembler = Backbone.Model.extend({ this.set("dataOut", data); this.set("editsMadeToProgram", false); this.set("exporter", exporter); - if (!dmaGlobals.appState.get("stockSimulationPlaying")) this.resetSimulation(); + if (!globals.appState.get("stockSimulationPlaying")) this.resetSimulation(); return {data:data, exporter:exporter}; }, diff --git a/js/cam/GCodeExporter.js b/js/cam/GCodeExporter.js index 90d513574eca73897df8ab1e3b550df82eec0486..7b33f3cf8a205fad2ab51d17c6a178c5d0a4d4df 100644 --- a/js/cam/GCodeExporter.js +++ b/js/cam/GCodeExporter.js @@ -10,7 +10,7 @@ function GCodeExporter() { GCodeExporter.prototype.makeHeader = function(){ var data = ""; - if (dmaGlobals.lattice.get("units") == "inches") data += this.addLine("G20", [], "units inches"); + if (globals.lattice.get("units") == "inches") data += this.addLine("G20", [], "units inches"); else data += this.addLine("G21", [], "units mm"); // data += this.addLine("G90", [], "absolute positioning"); // data += this.addLine("G54", [], "work offset"); @@ -49,13 +49,13 @@ GCodeExporter.prototype._setSpeed = function(speed){ GCodeExporter.prototype.rapidXY = function(x, y){ var data = ""; - if (this.postSpeed != dmaGlobals.assembler.get("rapidSpeeds").xy) data += this._setSpeed(dmaGlobals.assembler.get("rapidSpeeds").xy); + if (this.postSpeed != globals.assembler.get("rapidSpeeds").xy) data += this._setSpeed(globals.assembler.get("rapidSpeeds").xy); return data + this._goXYZ(x, y, null); }; GCodeExporter.prototype.rapidZ = function(z){ var data = ""; - if (this.postSpeed != dmaGlobals.assembler.get("rapidSpeeds").z) data += this._setSpeed(dmaGlobals.assembler.get("rapidSpeeds").z); + if (this.postSpeed != globals.assembler.get("rapidSpeeds").z) data += this._setSpeed(globals.assembler.get("rapidSpeeds").z); return data + this._goXYZ(null, null, z); }; @@ -68,19 +68,19 @@ GCodeExporter.prototype._goXYZ = function(x, y, z){ GCodeExporter.prototype.moveXY = function(x, y){ var data = ""; - if (this.postSpeed != dmaGlobals.assembler.get("feedRate").xy) data += this._setSpeed(dmaGlobals.assembler.get("feedRate").xy); + if (this.postSpeed != globals.assembler.get("feedRate").xy) data += this._setSpeed(globals.assembler.get("feedRate").xy); return data + this._goXYZ(x, y, null); }; GCodeExporter.prototype.moveZ = function(z){ var data = ""; - if (this.postSpeed != dmaGlobals.assembler.get("feedRate").z) data += this._setSpeed(dmaGlobals.assembler.get("feedRate").z); + if (this.postSpeed != globals.assembler.get("feedRate").z) data += this._setSpeed(globals.assembler.get("feedRate").z); return data + this._goXYZ(null, null, z); }; GCodeExporter.prototype.goHome = function(){ - var data = this._setSpeed(dmaGlobals.assembler.get("rapidSpeeds").z); - return data + this._goXYZ(0,0,dmaGlobals.assembler.get("rapidHeight")); + var data = this._setSpeed(globals.assembler.get("rapidSpeeds").z); + return data + this._goXYZ(0,0,globals.assembler.get("rapidHeight")); }; GCodeExporter.prototype.makeFooter = function(){ diff --git a/js/cam/Machine.js b/js/cam/Machine.js index 78bc3df97168df8686aebd02dfeece92fbb804d3..92b4b7171ee5599c97fbb736f34bbd4d3ce0404d 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -15,7 +15,7 @@ function Machine() { this._buildMeshes(function(meshes){ self.meshes = meshes; _.each(_.values(meshes), function(mesh){ - dmaGlobals.three.sceneAdd(mesh); + globals.three.sceneAdd(mesh); }); if (self.setMachinePosition) self.setMachinePosition(); self.setVisibility(); @@ -24,30 +24,30 @@ function Machine() { } Machine.prototype._setDefaults = function(){ - dmaGlobals.assembler.set("camProcess", "gcode"); - dmaGlobals.assembler.set("stockFixed", false); - dmaGlobals.assembler.set("originPosition", {x:0,y:0,z:0}); - var boundingBox = dmaGlobals.lattice.calculateBoundingBox(); - dmaGlobals.assembler.set("rapidHeight", boundingBox.max.z + 2*dmaGlobals.lattice.zScale()); - dmaGlobals.assembler.set("stockPosition", {x:0,y:0,z:0}); - dmaGlobals.assembler.set("stockSeparation", dmaGlobals.lattice.xScale()); + globals.assembler.set("camProcess", "gcode"); + globals.assembler.set("stockFixed", false); + globals.assembler.set("originPosition", {x:0,y:0,z:0}); + var boundingBox = globals.lattice.calculateBoundingBox(); + globals.assembler.set("rapidHeight", boundingBox.max.z + 2*globals.lattice.zScale()); + globals.assembler.set("stockPosition", {x:0,y:0,z:0}); + globals.assembler.set("stockSeparation", globals.lattice.xScale()); }; Machine.prototype.setVisibility = function(visible){ if (visible == null || visible === undefined) { - if (dmaGlobals.assembler) visible = dmaGlobals.assembler.isVisible(); + if (globals.assembler) visible = globals.assembler.isVisible(); else visible = false; } if (visible && this.hasStock) this.cell.draw(); else this.cell.hide(); this._setAlpha(); this._setMeshesVisiblity(visible); - dmaGlobals.three.render(); + globals.three.render(); }; Machine.prototype._setAlpha = function(){ //todo make stock transparent - if (dmaGlobals.appState.get("currentTab") == "cam"){ + if (globals.appState.get("currentTab") == "cam"){ this.material.opacity = 0.5; } else { this.material.opacity = 1; @@ -58,7 +58,7 @@ Machine.prototype._setMeshesVisiblity = function(visible){ _.each(_.values(this.meshes), function(mesh){ mesh.visible = visible; }); - if (visible) this.setScale(dmaGlobals.lattice.get("scale")); + if (visible) this.setScale(globals.lattice.get("scale")); }; Machine.prototype.setScale = function(scale){ @@ -68,8 +68,8 @@ Machine.prototype.setScale = function(scale){ } Machine.prototype._makeStockCell = function(){ - if (dmaGlobals.lattice.makeSuperCell) return dmaGlobals.lattice.makeSuperCell(); - return dmaGlobals.lattice.makeCellForLatticeType(null, dmaGlobals.lattice.get("scale")); + if (globals.lattice.makeSuperCell) return globals.lattice.makeSuperCell(); + return globals.lattice.makeCellForLatticeType(null, globals.lattice.get("scale")); }; Machine.prototype.updateCellType = function(){ @@ -91,7 +91,7 @@ Machine.prototype.pickUpStock = function(){ Machine.prototype.releaseStock = function(index){ this.hasStock = false; - dmaGlobals.lattice.showCellAtIndex(JSON.parse(index)); + globals.lattice.showCellAtIndex(JSON.parse(index)); this.cell.hide(); }; @@ -146,7 +146,7 @@ Machine.prototype._normalizeSpeed = function(startingPos, x, y, speed){//xy move }; Machine.prototype._animateObjects = function(objects, axis, speed, startingPos, target, callback){ - var increment = speed/25*dmaGlobals.assembler.get("simSpeed"); + var increment = speed/25*globals.assembler.get("simSpeed"); if (increment == 0) { if (callback) callback(); return; @@ -184,18 +184,18 @@ Machine.prototype._setPosition = function(objects, nextPos, axis){ Machine.prototype.postProcess = function(data, exporter){//override in subclasses - var rapidHeight = dmaGlobals.assembler.get("rapidHeight"); - var safeHeight = dmaGlobals.assembler.get("safeHeight"); - var wcs = dmaGlobals.assembler.get("originPosition"); + var rapidHeight = globals.assembler.get("rapidHeight"); + var safeHeight = globals.assembler.get("safeHeight"); + var wcs = globals.assembler.get("originPosition"); - var stockPosition = dmaGlobals.assembler.get("stockPosition"); + var stockPosition = globals.assembler.get("stockPosition"); var stockNum = 0;//position of stock in stock array - var multStockPositions = dmaGlobals.assembler.get("multipleStockPositions"); - var stockSeparation = dmaGlobals.assembler.get("stockSeparation"); - var stockArraySize = dmaGlobals.assembler.get("stockArraySize"); + var multStockPositions = globals.assembler.get("multipleStockPositions"); + var stockSeparation = globals.assembler.get("stockSeparation"); + var stockArraySize = globals.assembler.get("stockArraySize"); var self = this; - dmaGlobals.lattice.rasterCells(dmaGlobals.assembler._getOrder(dmaGlobals.assembler.get("camStrategy")), function(cell){ + globals.lattice.rasterCells(globals.assembler._getOrder(globals.assembler.get("camStrategy")), function(cell){ if (!cell) return; var thisStockPosition = _.clone(stockPosition); if (multStockPositions) { @@ -246,7 +246,7 @@ Machine.prototype._postReleaseStock = function(cellPosition, cell, exporter, rap Machine.prototype.destroy = function(){ this.cell.destroy(); _.each(_.values(this.meshes), function(mesh){ - dmaGlobals.three.sceneRemove(mesh); + globals.three.sceneRemove(mesh); mesh = null; }); this.meshes = null; @@ -266,9 +266,9 @@ Shopbot.prototype = Object.create(Machine.prototype); Shopbot.prototype._setDefaults = function(){ Machine.prototype._setDefaults.call(this); - dmaGlobals.assembler.set("camProcess", "shopbot"); - var boundingBox = dmaGlobals.lattice.calculateBoundingBox(); - dmaGlobals.assembler.set("stockPosition", {x:0,y:boundingBox.max.y + 3*dmaGlobals.lattice.yScale(),z:0}); + globals.assembler.set("camProcess", "shopbot"); + var boundingBox = globals.lattice.calculateBoundingBox(); + globals.assembler.set("stockPosition", {x:0,y:boundingBox.max.y + 3*globals.lattice.yScale(),z:0}); }; Shopbot.prototype._buildMeshes = function(callback){ @@ -306,8 +306,8 @@ God.prototype = Object.create(Machine.prototype); God.prototype._setDefaults = function(){ Machine.prototype._setDefaults.call(this); - var boundingBox = dmaGlobals.lattice.calculateBoundingBox(); - dmaGlobals.assembler.set("stockPosition", {x:0,y:0,z:boundingBox.max.z + 5*dmaGlobals.lattice.zScale()}); + var boundingBox = globals.lattice.calculateBoundingBox(); + globals.assembler.set("stockPosition", {x:0,y:0,z:boundingBox.max.z + 5*globals.lattice.zScale()}); }; God.prototype._buildMeshes = function(callback){ diff --git a/js/cam/MachineOneBit.js b/js/cam/MachineOneBit.js index ac364428322136cbc6b0d4ef2bcb4deac2a39d95..80cd6729a77fccd1bb59e9a9d85ef4576330e4c0 100644 --- a/js/cam/MachineOneBit.js +++ b/js/cam/MachineOneBit.js @@ -9,24 +9,24 @@ OneBitBot.prototype = Object.create(Machine.prototype); OneBitBot.prototype._setDefaults = function(){ Machine.prototype._setDefaults.call(this); - dmaGlobals.assembler.set("stockFixed", true); - var scale = dmaGlobals.lattice.get("scale"); - dmaGlobals.assembler.set("stockPosition", {x:1.11*scale,y:0,z:1.14*scale}); - dmaGlobals.assembler.set("rapidHeight", 2*scale); + globals.assembler.set("stockFixed", true); + var scale = globals.lattice.get("scale"); + globals.assembler.set("stockPosition", {x:1.11*scale,y:0,z:1.14*scale}); + globals.assembler.set("rapidHeight", 2*scale); }; OneBitBot.prototype.setMachinePosition = function(){ - if (!dmaGlobals.assembler) return; - this.position = dmaGlobals.assembler.get("originPosition"); + if (!globals.assembler) return; + this.position = globals.assembler.get("originPosition"); var self = this; _.each(_.values(this.meshes), function(mesh){//todo add cell? mesh.position.set(self.position.x, self.position.y, self.position.z); }); - var stockPosition = dmaGlobals.assembler.get("stockPosition"); + var stockPosition = globals.assembler.get("stockPosition"); this.cell.moveTo(stockPosition.x, "x"); this.cell.moveTo(stockPosition.y, "y"); this.cell.moveTo(stockPosition.z, "z"); - dmaGlobals.three.render(); + globals.three.render(); }; OneBitBot.prototype._buildMeshes = function(callback){ diff --git a/js/cam/ShopbotExporter.js b/js/cam/ShopbotExporter.js index 0d7401d529bfbc70db41181cd30d01d8dd1459b8..85de5caccbecbdb9f9f1a511d57266c1a3bd9066 100644 --- a/js/cam/ShopbotExporter.js +++ b/js/cam/ShopbotExporter.js @@ -10,9 +10,9 @@ ShopbotExporter.prototype.makeHeader = function(){ //data += this.addLine("FG", [], "single step mode"); data += this.addLine("SA", [], "absolute distances"); data += this.addLine("SM", [], "move/cut mode"); - var rapidSpeeds = dmaGlobals.assembler.get("rapidSpeeds"); + var rapidSpeeds = globals.assembler.get("rapidSpeeds"); data += this.addLine("JS", [rapidSpeeds.xy, rapidSpeeds.z], "jog speed xy, z"); - var feedRate = dmaGlobals.assembler.get("feedRate"); + var feedRate = globals.assembler.get("feedRate"); data += this.addLine("MS", [feedRate.xy, feedRate.z], "move speed xy, z"); data += this.goHome(); return data; @@ -27,7 +27,7 @@ ShopbotExporter.prototype.addLine = function(command, params, comment){ data += param + ", "; return; } - if (dmaGlobals.lattice.get("units") == "mm") param = self.convertToInches(param);//all shopbot stuff must be in inches + if (globals.lattice.get("units") == "mm") param = self.convertToInches(param);//all shopbot stuff must be in inches data += parseFloat(param).toFixed(3) + ", "; }); if (comment) data += "'" +comment; @@ -64,7 +64,7 @@ ShopbotExporter.prototype.moveZ = function(z){ }; ShopbotExporter.prototype.goHome = function(){ - var data = this.rapidZ(dmaGlobals.assembler.get("rapidHeight")); + var data = this.rapidZ(globals.assembler.get("rapidHeight")); data += this.rapidXY(0,0); return data; }; @@ -100,9 +100,9 @@ ShopbotExporter.prototype.simulate = function(line, machine, wcs, callback){ return callback(); } if (line[0] == "J"){ - return this._simulateGetPosition(line, dmaGlobals.assembler.get("rapidSpeeds"), machine, wcs, callback); + return this._simulateGetPosition(line, globals.assembler.get("rapidSpeeds"), machine, wcs, callback); } else if (line[0] == "M"){ - return this._simulateGetPosition(line, dmaGlobals.assembler.get("feedRate"), machine, wcs, callback); + return this._simulateGetPosition(line, globals.assembler.get("feedRate"), machine, wcs, callback); } else { console.warn("problem parsing sbp " + line); return callback(); @@ -118,10 +118,10 @@ ShopbotExporter.prototype._simulateGetPosition = function(line, speed, machine, if (item[item.length-1] == ",") data[i] = item.substring(0, item.length - 1) } if (line[1] == 3){ - if (dmaGlobals.lattice.get("units") == "inches") machine.moveTo(data[1], data[2], data[3], speed, wcs, callback); + if (globals.lattice.get("units") == "inches") machine.moveTo(data[1], data[2], data[3], speed, wcs, callback); else machine.moveTo(this.convertToMM(data[1]), this.convertToMM(data[2]), this.convertToMM(data[3]), speed, wcs, callback); } else { - if (dmaGlobals.lattice.get("units") == "inches") machine.moveTo(data[1], data[2], "", speed, wcs, callback); + if (globals.lattice.get("units") == "inches") machine.moveTo(data[1], data[2], "", speed, wcs, callback); else machine.moveTo(this.convertToMM(data[1]), this.convertToMM(data[2]), "", speed, wcs, callback); } } else if (line[1] == "S"){ diff --git a/js/cam/TinyGExporter.js b/js/cam/TinyGExporter.js index b00378d5a57dd8965e6418a145959c8214beecd9..0f4d75a3eb2106f90fc02938f2df708012d6aac6 100644 --- a/js/cam/TinyGExporter.js +++ b/js/cam/TinyGExporter.js @@ -48,13 +48,13 @@ TinyGExporter.prototype.engageZAxis = function(type, cellPosition, cell, wcs){ }; TinyGExporter.prototype.simulate = function(line, machine, wcs, callback){ - var rapidSpeed = dmaGlobals.assembler.get("rapidSpeeds"); - var rapidHeight = dmaGlobals.assembler.get("rapidHeight"); + var rapidSpeed = globals.assembler.get("rapidSpeeds"); + var rapidHeight = globals.assembler.get("rapidHeight"); if (line == "(home)"){ return machine.moveTo("", "", rapidHeight, rapidSpeed, wcs, callback); } else if (line[0]=="M"){ if (line == "M3 M5 M4 M5 M3 M5"){//get stock - var stockPosition = dmaGlobals.assembler.get("stockPosition"); + var stockPosition = globals.assembler.get("stockPosition"); return this.simulateZ(machine, rapidSpeed, wcs, rapidHeight, stockPosition.z-wcs.z, function(){ machine.pickUpStock(); }, callback); @@ -64,7 +64,7 @@ TinyGExporter.prototype.simulate = function(line, machine, wcs, callback){ machine.releaseStock(line.substr(4, line.length-5)); }, callback); } else if (line == "M3 M5 M3 M5 M4 M5"){//higher height - return this.simulateZ(machine, rapidSpeed, wcs, rapidHeight, wcs.z+dmaGlobals.lattice.zScale(), function(){ + return this.simulateZ(machine, rapidSpeed, wcs, rapidHeight, wcs.z+globals.lattice.zScale(), function(){ machine.releaseStock(line.substr(4, line.length-5)); }, callback); } else if (line.substr(0,3) == "M5 ") return callback(); @@ -75,8 +75,8 @@ TinyGExporter.prototype.simulate = function(line, machine, wcs, callback){ }; TinyGExporter.prototype.simulateZ = function(machine, rapidSpeed, wcs, rapidHeight, height, action, callback){ - var feedRate = dmaGlobals.assembler.get("feedRate"); - var safeHeight = dmaGlobals.assembler.get("safeHeight"); + var feedRate = globals.assembler.get("feedRate"); + var safeHeight = globals.assembler.get("safeHeight"); return machine.moveTo("", "", height+safeHeight, rapidSpeed, wcs, function(){ machine.moveTo("", "", height, feedRate, wcs, function(){ action(); diff --git a/js/fea/DMACellFreeform.js b/js/fea/DMACellFreeform.js index 828587aa4321de6790b3f447a6846fc91cd75c50..d240876faf6109f1dbd0bd7d6c98026a86ac046c 100644 --- a/js/fea/DMACellFreeform.js +++ b/js/fea/DMACellFreeform.js @@ -19,7 +19,7 @@ DMAFreeFormCell.prototype = Object.create(DMACell.prototype); DMAFreeFormCell.prototype._calcPosition = function(){//todo this might not be necessary - put in lattice var position = {}; - var zScale = dmaGlobals.lattice.zScale(); + var zScale = globals.lattice.zScale(); position.x = this.parentPos.x+this.parentDirection.x*zScale/2; position.y = this.parentPos.y+this.parentDirection.y*zScale/2; position.z = this.parentPos.z+this.parentDirection.z*zScale/2; diff --git a/js/fea/DMASuperCell.js b/js/fea/DMASuperCell.js index 085fb8c14dcdf424c9216f8855f4706ffcddfaf5..d4ea4fd69d7dd24c167baee931a7494ce6516955 100644 --- a/js/fea/DMASuperCell.js +++ b/js/fea/DMASuperCell.js @@ -8,13 +8,13 @@ var cellFiberGlassMaterial = new THREE.MeshLambertMaterial({color:"#fff68f"}); DMASuperCell = function(length, range, cells){ if (range) var shouldRotate = range.max.x == range.min.x; - this.material = dmaGlobals.lattice.get("materialType"); + this.material = globals.lattice.get("materialType"); this.mesh = this._buildSuperCellMesh(length, shouldRotate); - this.setVisibility(dmaGlobals.appState.get("cellMode")=="cell"); + this.setVisibility(globals.appState.get("cellMode")=="cell"); if (range) this.indices = _.clone(range.max); this.cells = cells; this.setScale(); - dmaGlobals.three.sceneAdd(this.mesh); + globals.three.sceneAdd(this.mesh); }; DMASuperCell.prototype._buildSuperCellMesh = function(length, shouldRotate){ @@ -37,12 +37,12 @@ DMASuperCell.prototype.getMaterialType = function(){ DMASuperCell.prototype._setPosition = function(index){ if (!index) return; - var position = dmaGlobals.lattice.getPositionForIndex(index); + var position = globals.lattice.getPositionForIndex(index); this.mesh.position.set(position.x, position.y, position.z); }; DMASuperCell.prototype.setScale = function(scale){ - if (!scale) scale = dmaGlobals.lattice.get("scale"); + if (!scale) scale = globals.lattice.get("scale"); this.mesh.scale.set(scale, scale, scale); this._setPosition(this.indices); }; @@ -64,7 +64,7 @@ DMASuperCell.prototype.hide = function(){//only used in the context of stock sim DMASuperCell.prototype.draw = function(scale, cellMode, partType){ if (this.hideForStockSimulation) return; - if (!scale) scale = dmaGlobals.lattice.get("scale"); + if (!scale) scale = globals.lattice.get("scale"); var partMode = cellMode == "part"; // this.updateForScale(scale, cellMode, partType); @@ -90,9 +90,9 @@ DMASuperCell.prototype.moveTo = function(position, axis){//used for stock simula DMASuperCell.prototype.destroy = function(){ if (this.destroyStarted) return;//prevents loop destroy from cells this.destroyStarted = true; - dmaGlobals.three.sceneRemove(this.mesh); + globals.three.sceneRemove(this.mesh); _.each(this.cells, function(cell){ - if (cell && !cell.destroyStarted) dmaGlobals.lattice.removeCell(cell); + if (cell && !cell.destroyStarted) globals.lattice.removeCell(cell); }); this.cells = null; this.mesh = null; diff --git a/js/fea/DmaBeam.js b/js/fea/DmaBeam.js index a94ba87bba3cb00fbcddbe890d93eea9cce5bf6b..d054e2cd2e090fef980ae4d5c57f1485b49e4c4c 100644 --- a/js/fea/DmaBeam.js +++ b/js/fea/DmaBeam.js @@ -35,7 +35,7 @@ DmaBeam.prototype._buildBeamMesh = function(){ var eulerRot = new THREE.Euler().setFromQuaternion(quaternion); mesh.rotation.set(eulerRot.x, eulerRot.y, eulerRot.z); - dmaGlobals.three.sceneAdd(mesh);//todo make a type for this + globals.three.sceneAdd(mesh);//todo make a type for this return mesh; }; @@ -58,7 +58,7 @@ DmaBeam.prototype.setVisibility = function(visible){ }; DmaBeam.prototype.destroy = function(){ - dmaGlobals.three.sceneRemove(this.mesh, "part"); + globals.three.sceneRemove(this.mesh, "part"); this.mesh = null; var self = this; _.each(this.nodes, function(node){ diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 201af4061c1675821a1f4bcff497b79629b5e99a..fada48f7cd3fb8d316a870c3a36f245af1080e0d 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -15,7 +15,7 @@ function DMACell(indices, scale, cellMode, partType) { this.cellMesh = this._buildCellMesh(); this._doMeshTransformations(this.cellMesh);//some cell types require transformations - dmaGlobals.three.sceneAdd(this.cellMesh,this._sceneType(indices)); + globals.three.sceneAdd(this.cellMesh,this._sceneType(indices)); this.draw(scale, cellMode, partType); @@ -29,9 +29,9 @@ DMACell.prototype._sceneType = function(indices){ DMACell.prototype.draw = function(scale, cellMode, partType){ if (this.hideForStockSimulation) return; - if (!scale) scale = dmaGlobals.lattice.get("scale"); - if (!cellMode) cellMode = dmaGlobals.appState.get("cellMode"); - if (!partType) partType = dmaGlobals.lattice.get("partType"); + if (!scale) scale = globals.lattice.get("scale"); + if (!cellMode) cellMode = globals.appState.get("cellMode"); + if (!partType) partType = globals.lattice.get("partType"); //var beamMode = partType == "beam"; var beamMode = false; var partMode = cellMode == "part"; @@ -71,7 +71,7 @@ DMACell.prototype.hide = function(){//only used in the context of stock simulati /////////////////////////////////////////////////////////////////////////////////////////////// DMACell.prototype.updateForScale = function(scale, cellMode, partType){ - if (!scale) scale = dmaGlobals.lattice.get("scale"); + if (!scale) scale = globals.lattice.get("scale"); var position = this._calcPosition(); this._setMeshPosition(this.cellMesh, position); this.cellMesh.scale.set(scale, scale, scale);//must do this so highlighting works properly in part mode @@ -79,8 +79,8 @@ DMACell.prototype.updateForScale = function(scale, cellMode, partType){ if (this.superCell && this.superCellIndex == 0) this.superCell.setScale(scale); //only update visible object to scale - if (!cellMode) cellMode = dmaGlobals.appState.get("cellMode"); - if (!partType) partType = dmaGlobals.lattice.get("partType"); + if (!cellMode) cellMode = globals.appState.get("cellMode"); + if (!partType) partType = globals.lattice.get("partType"); if (cellMode == "part"){ if (partType == "beam"){ _.each(this.beams, function(beam){ @@ -102,7 +102,7 @@ DMACell.prototype._setMeshPosition = function(mesh, position){ DMACell.prototype.moveTo = function(position, axis){//used for stock simulations this.cellMesh.position[axis] = position; - if (dmaGlobals.appState.get("cellMode") == "part"){ + if (globals.appState.get("cellMode") == "part"){ _.each(this.parts, function(part){ if (part) part.moveTo(position, axis); }); @@ -114,7 +114,7 @@ DMACell.prototype.getType = function(){ }; DMACell.prototype.getScale = function(){//need for part relay - return dmaGlobals.lattice.get("scale"); + return globals.lattice.get("scale"); }; DMACell.prototype.getPosition = function(){ @@ -130,7 +130,7 @@ DMACell.prototype.getEulerRotation = function(){ }; DMACell.prototype._calcPosition = function(){//need for part relay - if (this.indices) return dmaGlobals.lattice.getPositionForIndex(this.indices); + if (this.indices) return globals.lattice.getPositionForIndex(this.indices); return this.cellMesh.position;//used for cam simulation }; @@ -139,15 +139,15 @@ DMACell.prototype._setCellMeshVisibility = function(visibility){ }; DMACell.prototype.xScale = function(scale){ - return dmaGlobals.lattice.xScale(scale); + return globals.lattice.xScale(scale); }; DMACell.prototype.yScale = function(scale){ - return dmaGlobals.lattice.yScale(scale); + return globals.lattice.yScale(scale); }; DMACell.prototype.zScale = function(scale){ - return dmaGlobals.lattice.zScale(scale); + return globals.lattice.zScale(scale); }; @@ -180,7 +180,7 @@ DMACell.prototype.removePart = function(index){ _.each(this.parts, function(part){ if (part) hasAnyParts = true; }); - if (!hasAnyParts) dmaGlobals.lattice.removeCell(this);//if all parts are gone, remove cell + if (!hasAnyParts) globals.lattice.removeCell(this);//if all parts are gone, remove cell }; DMACell.prototype.destroyParts = function(){ @@ -243,7 +243,7 @@ DMACell.prototype.destroy = function(){ if (this.destroyStarted) return; this.destroyStarted = true; if (this.cellMesh) { - dmaGlobals.three.sceneRemove(this.cellMesh, this._sceneType(this.indices)); + globals.three.sceneRemove(this.cellMesh, this._sceneType(this.indices)); this.cellMesh.myParent = null; // this.cellMesh.dispose(); // geometry.dispose(); diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index 817b20e30470709a8d2624a0a6e5f05521f970ab..9172a3ced48cf7a1f73f50d85073964a98bbf2a0 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -91,7 +91,7 @@ function DMARotatedEdgeCell(indices, scale, cellMode, partType){ DMARotatedEdgeCell.prototype = Object.create(DMACell.prototype); DMARotatedEdgeCell.prototype._initParts = function(){ - return this.changePartType(dmaGlobals.lattice.get("partType")); + return this.changePartType(globals.lattice.get("partType")); }; DMARotatedEdgeCell.prototype.changePartType = function(type){ diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index 4cddf23db4b67fc3b935533e7636b74ee78c0fb5..c1ca36828867ee235e640e1f7b48ecdf9d4c8293 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -86,7 +86,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; this.superCell = superCell; this.superCellIndex = index; if (this.superCellIndex == this.superCell.getLength()) this.cellMesh.rotateZ(Math.PI); - if (dmaGlobals.appState.get("cellMode")=="part") { + if (globals.appState.get("cellMode")=="part") { this.parts = this.__initParts(); this.draw(); } @@ -100,7 +100,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; if (!this.superCell) return []; var parts = []; var isEnd = this.superCellIndex == 0 || this.superCellIndex == this.superCell.getLength(); - if (dmaGlobals.lattice.get("partType") == "lego") { + if (globals.lattice.get("partType") == "lego") { if (isEnd) parts.push(new DMAGIKEndPart(0, this)); else parts.push(new DMAGIKPart(0, this)); } diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js index 914ebb6e6f23ac9dcbfab74213299184faea7fc2..7069dfb530651729f24cb07aa3246c90aee5baba 100644 --- a/js/fea/DmaPart.js +++ b/js/fea/DmaPart.js @@ -19,7 +19,7 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE var rotation = this.parentCell.getEulerRotation(); this.mesh.rotation.set(rotation.x, rotation.y, rotation.z); this.updateForScale(this.parentCell.getScale(), this.parentCell.getPosition()); - dmaGlobals.three.sceneAdd(this.mesh, "part"); + globals.three.sceneAdd(this.mesh, "part"); }; DMAPart.prototype.updateForScale = function(scale, position){ @@ -65,13 +65,13 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE DMAPart.prototype.removeFromCell = function(){//send message back to parent cell to destroy this if (this.parentCell) { this.parentCell.removePart(this.type); - dmaGlobals.three.render(); + globals.three.render(); } else console.warn("part has no parent cell"); }; DMAPart.prototype.destroy = function(){ if (this.mesh) { - dmaGlobals.three.sceneRemove(this.mesh, "part"); + globals.three.sceneRemove(this.mesh, "part"); this.mesh.myPart = null; // this.mesh.dispose(); // geometry.dispose(); diff --git a/js/main.js b/js/main.js index fd52e31d80ac1de9038a6e2db0a22bcb0d74aca4..1db6b107bb10a064c113a608460b1b5cb65d1a8c 100644 --- a/js/main.js +++ b/js/main.js @@ -3,7 +3,7 @@ */ //setup persistent global variables -if (typeof dmaGlobals === "undefined") dmaGlobals = {}; +if (typeof globals === "undefined") globals = {}; $(function(){ @@ -12,19 +12,20 @@ $(function(){ // window.workers = persistentWorkers(8); //init global singletons - dmaGlobals.three = new ThreeModel(); - dmaGlobals.appState = new AppState(); - dmaGlobals.lattice = new Lattice({appState: dmaGlobals.appState}); - dmaGlobals.lattice.delayedInit(); - dmaGlobals.assembler = new Assembler({appState: dmaGlobals.appState, lattice:dmaGlobals.lattice}); - dmaGlobals.appState.delayedInit(); + globals.plist = buildAppPList(); + globals.three = new ThreeModel(); + globals.appState = new AppState(); + globals.lattice = new Lattice({appState: globals.appState}); + globals.lattice.delayedInit(); + globals.assembler = new Assembler({appState: globals.appState, lattice:globals.lattice}); + globals.appState.delayedInit(); //ui - new NavBar({model:dmaGlobals.appState}); - new Ribbon({model:dmaGlobals.appState}); + new NavBar({model:globals.appState}); + new Ribbon({model:globals.appState}); //threeJS View - new ThreeView({model:dmaGlobals.three, appState:dmaGlobals.appState}); + new ThreeView({model:globals.three, appState:globals.appState}); - if (dmaGlobals.lattice.get("connectionType") != "gik") dmaGlobals.lattice.addCellAtIndex({x:0,y:0,z:0});//add a cell + if (globals.lattice.get("connectionType") != "gik") globals.lattice.addCellAtIndex({x:0,y:0,z:0});//add a cell }); diff --git a/js/menus/AnimationMenuView.js b/js/menus/AnimationMenuView.js index d618161d53b2d6404906b13addaf20763c47970b..35e20b6fb0c389fa0b8959a78738b06e00f5fbee 100644 --- a/js/menus/AnimationMenuView.js +++ b/js/menus/AnimationMenuView.js @@ -23,31 +23,31 @@ AnimationMenuView = Backbone.View.extend({ //bind events this.listenTo(this.model, "change:stockSimulationPlaying", this.render); var self = this; - this.listenTo(dmaGlobals.assembler, "change", function(){ + this.listenTo(globals.assembler, "change", function(){ //ignore simLineNumber for render calls - if (_.isEqual(_.keys(dmaGlobals.assembler.changedAttributes()), ["simLineNumber"])) return; + if (_.isEqual(_.keys(globals.assembler.changedAttributes()), ["simLineNumber"])) return; self.render(); }); - this.listenTo(dmaGlobals.assembler, "change:simLineNumber", this._drawGcodeHighlighter); + this.listenTo(globals.assembler, "change:simLineNumber", this._drawGcodeHighlighter); $(document).bind('keyup', {state:false}, this._codeEdit); //this.$el.bind('resize', this._setEditorHeight); }, _save: function(e){ e.preventDefault(); - dmaGlobals.assembler.save(); + globals.assembler.save(); }, _postProcess: function(e){ e.preventDefault(); - dmaGlobals.assembler.postProcess(); + globals.assembler.postProcess(); }, _codeEdit: function(e){ var editor = $("#gcodeEditor"); if (!editor.is(":focus")) return; e.preventDefault(); - dmaGlobals.assembler.makeProgramEdits(editor.text()); + globals.assembler.makeProgramEdits(editor.text()); }, _playStockSim: function(e){ @@ -62,19 +62,19 @@ AnimationMenuView = Backbone.View.extend({ _resetStockSim: function(e){ e.preventDefault(); - dmaGlobals.assembler.resetSimulation(); + globals.assembler.resetSimulation(); this.render(); }, _changeSpeedSlider: function(e){ e.preventDefault(); - dmaGlobals.assembler.set("simSpeed", Math.pow(2,$(e.target)[0].value)); + globals.assembler.set("simSpeed", Math.pow(2,$(e.target)[0].value)); }, _drawGcodeHighlighter: function(){ - var lineNum = dmaGlobals.assembler.get("simLineNumber"); + var lineNum = globals.assembler.get("simLineNumber"); if (lineNum == 0) return; - var code = dmaGlobals.assembler.get("dataOut").split("\n"); + var code = globals.assembler.get("dataOut").split("\n"); code[lineNum] = "<span id='gcodeHighlighter'>" + code[lineNum] + " </span>"; var newText = code.join("\n"); var $editor = $('#gcodeEditor'); @@ -96,8 +96,8 @@ AnimationMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "animate") return; - if (dmaGlobals.assembler.get("needsPostProcessing") && !dmaGlobals.assembler.get("editsMadeToProgram")) dmaGlobals.assembler.postProcess(); - this.$el.html(this.template(_.extend(this.model.toJSON(), dmaGlobals.assembler.toJSON()))); + if (globals.assembler.get("needsPostProcessing") && !globals.assembler.get("editsMadeToProgram")) globals.assembler.postProcess(); + this.$el.html(this.template(_.extend(this.model.toJSON(), globals.assembler.toJSON()))); this._setEditorHeight(); this._drawGcodeHighlighter();//in case of code pause diff --git a/js/menus/AssemblerMenuView.js b/js/menus/AssemblerMenuView.js index bc00644f9651db7b6a8133e3e2f85023c62b6d5c..5e20cc3140e8a338d5db75fc4e672e91bc612926 100644 --- a/js/menus/AssemblerMenuView.js +++ b/js/menus/AssemblerMenuView.js @@ -55,7 +55,7 @@ AssemblerMenuView = Backbone.View.extend({ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "assembler") return; if ($("input").is(":focus")) return; - this.$el.html(this.template(_.extend(this.model.toJSON(), this.assembler.toJSON(), dmaGlobals.lattice.toJSON()))); + this.$el.html(this.template(_.extend(this.model.toJSON(), this.assembler.toJSON(), globals.lattice.toJSON()))); }, template: _.template('\ diff --git a/js/menus/CamMenuView.js b/js/menus/CamMenuView.js index bcdd795d0effb46feece73ceff07590983a9804f..1681162aebeefd1648a234725b459bd83cc29fb4 100644 --- a/js/menus/CamMenuView.js +++ b/js/menus/CamMenuView.js @@ -109,12 +109,12 @@ CamMenuView = Backbone.View.extend({ var $object = $(e.target); $object.blur(); var property = $object.data("property"); - dmaGlobals.assembler.set(property, !dmaGlobals.assembler.get(property)); + globals.assembler.set(property, !globals.assembler.get(property)); }, _selectOrigin: function(e){ e.preventDefault(); - dmaGlobals.appState.set("manualSelectOrigin", !dmaGlobals.appState.get("manualSelectOrigin")); + globals.appState.set("manualSelectOrigin", !globals.appState.get("manualSelectOrigin")); }, _save: function(e){ diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index 9a2a59f2dcbbf74ac6e2211638e6abdfe887a463..131e5222744011fa8317d9c2bfa2c4a4eefd354f 100644 --- a/js/menus/ImportMenuView.js +++ b/js/menus/ImportMenuView.js @@ -34,7 +34,7 @@ ImportMenuView = Backbone.View.extend({ _buildWall: function(e){ e.preventDefault(); - dmaGlobals.lattice.addCellsInRange({min:{x:-5,y:-5,z:0}, max:{x:5,y:5,z:3}}); + globals.lattice.addCellsInRange({min:{x:-5,y:-5,z:0}, max:{x:5,y:5,z:3}}); }, _uploadMesh: function(e){//select a mesh to upload @@ -84,7 +84,7 @@ ImportMenuView = Backbone.View.extend({ _clearCells: function(e){ e.preventDefault(); - dmaGlobals.lattice.clearCells(); + globals.lattice.clearCells(); }, render: function(){ diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index bbe0e55d42faff495ad65d3b976d43720d7b4e5b..24df6bb1e00b73964abbe6344fd44a52a68b4852 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -56,7 +56,7 @@ LatticeMenuView = Backbone.View.extend({ e.preventDefault(); var newVal = parseInt($(e.target).val()); if (isNaN(newVal)) return; - dmaGlobals.lattice.set("gikLength", newVal); + globals.lattice.set("gikLength", newVal); }, _clearCells: function(e){ @@ -80,7 +80,7 @@ LatticeMenuView = Backbone.View.extend({ var scale = $(e.target)[0].value; this.lattice.previewScaleChange(scale);//does not trigger lattice change event - no rerendering of ui $("#latticeScale").val(scale); - dmaGlobals.three.render(); + globals.three.render(); }, _changeScaleSlider: function(e){ @@ -109,10 +109,10 @@ LatticeMenuView = Backbone.View.extend({ _setAppStateToDefaultsSilently: function(newCellType, newConnectionType){ if (!newConnectionType){ - newConnectionType = _.keys(dmaGlobals.appState.get("allConnectionTypes")[newCellType])[0]; + newConnectionType = _.keys(globals.appState.get("allConnectionTypes")[newCellType])[0]; this.lattice.set("connectionType", newConnectionType, {silent:true}); } - var partType = _.keys(dmaGlobals.appState.get("allPartTypes")[newCellType][newConnectionType])[0]; + var partType = _.keys(globals.appState.get("allPartTypes")[newCellType][newConnectionType])[0]; this.lattice.set("partType", partType, {silent:true}); }, @@ -130,7 +130,7 @@ LatticeMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "lattice") return; - this.$el.html(this.template(_.extend(this.model.toJSON(), this.lattice.toJSON()))); + this.$el.html(this.template(_.extend(this.model.toJSON(), this.lattice.toJSON(), globals.plist))); $('#scaleSlider').slider({ formatter: function(value) { diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index eb10c2933c1357d9b73ff0cdda424be3df3c90ac..be08ad143e2f2beded966f3ebba402658373a23d 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -15,7 +15,7 @@ MenuWrapper = Backbone.View.extend({ _.bindAll(this, "render", "_updateCurrentTab", "_setVisibility", "_hide", "_show"); - var lattice = dmaGlobals.lattice; + var lattice = globals.lattice; //init all tab view controllers this.latticeMenu = new LatticeMenuView({model:this.model, lattice:lattice}); @@ -26,9 +26,9 @@ MenuWrapper = Backbone.View.extend({ this.physicsMenu = new PhysicsMenuView({model:this.model}); this.materialMenu = new MaterialMenuView({model:this.model}); this.optimizeMenu = new OptimizationMenuView({model:this.model}); - this.assemblerMenu = new AssemblerMenuView({model:this.model, assembler: dmaGlobals.assembler}); + this.assemblerMenu = new AssemblerMenuView({model:this.model, assembler: globals.assembler}); this.animationMenu = new AnimationMenuView({model:this.model}); - this.camMenu = new CamMenuView({model:this.model, lattice:lattice, assembler:dmaGlobals.assembler}); + this.camMenu = new CamMenuView({model:this.model, lattice:lattice, assembler:globals.assembler}); this.sendMenu = new SendMenuView({model:this.model}); //bind events @@ -97,7 +97,7 @@ MenuWrapper = Backbone.View.extend({ }, _populateAndShow: function(){ - this.$el.html(this.template(_.extend(this.model.toJSON(), dmaGlobals.lattice.toJSON()))); + this.$el.html(this.template(_.extend(this.model.toJSON(), globals.lattice.toJSON(), globals.plist))); this._updateCurrentTab(); this._show(); }, diff --git a/js/menus/Navbar.js b/js/menus/Navbar.js index 0cd1717e054b84d6c998a37e135f856e88d1100e..2087386749591c77dd0bbd8416925868fa60a5c9 100644 --- a/js/menus/Navbar.js +++ b/js/menus/Navbar.js @@ -95,9 +95,9 @@ NavBar = Backbone.View.extend({ return function(e) { var extension = filename.substr(filename.length - 5); if (extension == ".json"){ - dmaGlobals.appState.loadLatticeFromJSON(JSON.parse(e.target.result)); + globals.appState.loadLatticeFromJSON(JSON.parse(e.target.result)); } else if (extension == ".user"){ - dmaGlobals.appState.loadUser(e.target.result); + globals.appState.loadUser(e.target.result); } else console.warn("file type not recognized"); } })(); @@ -105,20 +105,20 @@ NavBar = Backbone.View.extend({ _save: function(e){ e.preventDefault(); - dmaGlobals.appState.saveJSON(); + globals.appState.saveJSON(); }, _saveAs: function(e){ e.preventDefault(); var fileName = $("#saveAsFileName").val(); - dmaGlobals.appState.saveJSON(fileName); + globals.appState.saveJSON(fileName); $('#saveAsModel').modal('hide'); }, _saveUserSettings: function(e){ e.preventDefault(); var fileName = $("#userSettingsFilename").val(); - dmaGlobals.appState.saveUser(fileName); + globals.appState.saveUser(fileName); $('#saveUserModel').modal('hide'); }, @@ -126,7 +126,7 @@ NavBar = Backbone.View.extend({ e.preventDefault(); var url = "data/users/" + $(e.target).data("file"); $.getJSON( url, function(data) { - dmaGlobals.appState.loadUser(data, true); + globals.appState.loadUser(data, true); }); }, @@ -134,7 +134,7 @@ NavBar = Backbone.View.extend({ e.preventDefault(); var url = "data/demos/" + $(e.target).data("file"); $.getJSON( url, function(data) { - dmaGlobals.appState.loadLatticeFromJSON(data); + globals.appState.loadLatticeFromJSON(data); }); }, diff --git a/js/menus/Ribbon.js b/js/menus/Ribbon.js index 6d77491d27a25b2ce56a2891bdcaad798828fa78..9e1ea57dc71cf62191e188bde8085ffde18c0509 100644 --- a/js/menus/Ribbon.js +++ b/js/menus/Ribbon.js @@ -22,32 +22,32 @@ Ribbon = Backbone.View.extend({ 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(dmaGlobals.lattice, "change:cellType change:connectionType", this.render); + this.listenTo(globals.lattice, "change:cellType change:connectionType", this.render); this.render(); }, _updateCellMode: function(e){ e.preventDefault(); - dmaGlobals.appState.set("cellMode", $(e.target).data("type")); + globals.appState.set("cellMode", $(e.target).data("type")); }, _updateDeleteMode: function(e){ e.preventDefault(); - dmaGlobals.appState.set("deleteMode", !dmaGlobals.appState.get("deleteMode")); + globals.appState.set("deleteMode", !globals.appState.get("deleteMode")); }, _updateHighlightMode: function(e){ e.preventDefault(); - dmaGlobals.appState.set("highlightMode", !dmaGlobals.appState.get("highlightMode")); + globals.appState.set("highlightMode", !globals.appState.get("highlightMode")); }, _updateVisibility: function(e){ e.preventDefault(); - dmaGlobals.appState.set("cellsVisible", !dmaGlobals.appState.get("cellsVisible")); + globals.appState.set("cellsVisible", !globals.appState.get("cellsVisible")); }, render: function(){ - this.$el.html(this.template(_.extend(dmaGlobals.lattice.toJSON(), this.model.toJSON()))); + this.$el.html(this.template(_.extend(globals.lattice.toJSON(), this.model.toJSON(), globals.plist))); }, template: _.template('\ diff --git a/js/models/AllAppPLists.js b/js/models/AllAppPLists.js new file mode 100644 index 0000000000000000000000000000000000000000..b667c09abb09d92c1ea77449667046bd8d5cbd36 --- /dev/null +++ b/js/models/AllAppPLists.js @@ -0,0 +1,157 @@ +//all property lists for the app, these are "static" variables + +function buildAppPList(){ + return { + + + allMenuTabs: { + navDesign:{ + lattice:"Lattice", + import:"Import", + //sketch:"Sketch", + part:"Part", + script:"Script" + }, + navSim:{ + physics:"Physics", + part:"Part", + material:"Material", + optimize:"Optimize" + }, + navAssemble:{ + assembler:"Assembler", + cam: "Process", + animate:"Preview", + send: "Send" + } + }, + + allCellTypes: { + octa:"Octahedron", + tetra: "Tetrahedron (Coming Soon)", + cube:"Cube", + truncatedCube:"Cuboctahedron", + kelvin:"Truncated Octahedron" + }, + allConnectionTypes: { + octa: {face:"Face", freeformFace:"Freeform Face", edgeRot:"Edge", vertex:"Vertex"},//edge:"Edge", + tetra: {vertex: "Vertex"}, + cube: {face:"Face", gik: "GIK"}, + truncatedCube: {face:"Face"}, + kelvin: {face: "Face"} + }, + allPartTypes:{ + octa:{ + face: { + triangle:"Triangle" + //beam:"Beam", + //truss:"Truss" + }, + freeformFace: { + trox:"Troxes" + //beam:"Beam" + }, + edge: null, + edgeRot: { + vox: "Snap Voxel (high res)", + voxLowPoly: "Snap Voxel (low res)" + //beam:"Beam" + }, + vertex: null//{ + //beam:"Beam", +// square:"Square", +// xShape:"X" +// } + }, + tetra: {vertex: null}, + cube: {face: null, + gik: { + lego: "Micro LEGO (high res)", + legoLowPoly: "Micro LEGO (low res)" + } + }, + truncatedCube: {face: null}, + kelvin: {face: null} + }, + + allMaterialTypes:{ + octa:{ + face: null, + freeformFace: null, + edge: null, + edgeRot: null, + vertex: null//{ + //beam:"Beam", +// square:"Square", +// xShape:"X" +// } + }, + tetra: {vertex: null}, + cube: {face: null, + gik: { + brass:{ + name: "Brass", + color: "#b5a642" + }, + fiberGlass: { + name: "Fiberglass", + color: "#fef1b5" + } + } + }, + truncatedCube: {face: null}, + kelvin: {face: null} + }, + + allMachineTypes:{ + octa:{ + face: {handOfGod: "Hand of God"}, + freeformFace: {handOfGod: "Hand of God"}, + edgeRot: { + shopbot: "Shopbot", + oneBitBot: "One Bit Bot", + oneBitBotLegs: "One Bit Bot with Legs", + handOfGod: "Hand of God" + }, + vertex: {handOfGod: "Hand of God"} + }, + tetra: { + vertex:{handOfGod: "Hand of God"} + }, + cube:{ + face:{handOfGod: "Hand of God"}, + gik: {handOfGod: "Hand of God"} + }, + truncatedCube:{ + face:{handOfGod: "Hand of God"} + }, + kelvin:{ + face:{handOfGod: "Hand of God"} + } + }, + allAssemblyStrategies: { + raster: "Raster" + }, + allCamProcesses: { + shopbot:{ + shopbot: "Shopbot (sbp)", + gcode: "G-Code" + }, + handOfGod:{gcode: "G-Code"}, + oneBitBot:{ + gcode: "G-Code", + tinyG: "TinyG" + } + }, + + allScripts: { + loadFile: "Load From File..." + }, + + allUnitTypes: { + inches: "Inches", + mm: "mm", + //um: "micron" + } + +}} \ No newline at end of file diff --git a/js/models/AppState.js b/js/models/AppState.js index 1bcc364a726b03bc86c9c101ca15807a82ba4696..2b0d0c6d1ad9249402c9ac24ececa68ba9434dc5 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -20,156 +20,6 @@ AppState = Backbone.Model.extend({ menuWrapper: null, menuIsVisible: true, - allMenuTabs: { - navDesign:{ - lattice:"Lattice", - import:"Import", - //sketch:"Sketch", - part:"Part", - script:"Script" - }, - navSim:{ - physics:"Physics", - part:"Part", - material:"Material", - optimize:"Optimize" - }, - navAssemble:{ - assembler:"Assembler", - cam: "Process", - animate:"Preview", - send: "Send" - } - }, - - allCellTypes: { - octa:"Octahedron", - tetra: "Tetrahedron (Coming Soon)", - cube:"Cube", - truncatedCube:"Cuboctahedron", - kelvin:"Truncated Octahedron" - }, - allConnectionTypes: { - octa: {face:"Face", freeformFace:"Freeform Face", edgeRot:"Edge", vertex:"Vertex"},//edge:"Edge", - tetra: {vertex: "Vertex"}, - cube: {face:"Face", gik: "GIK"}, - truncatedCube: {face:"Face"}, - kelvin: {face: "Face"} - }, - allPartTypes:{ - octa:{ - face: { - triangle:"Triangle" - //beam:"Beam", - //truss:"Truss" - }, - freeformFace: { - trox:"Troxes" - //beam:"Beam" - }, - edge: null, - edgeRot: { - vox: "Snap Voxel (high res)", - voxLowPoly: "Snap Voxel (low res)" - //beam:"Beam" - }, - vertex: null//{ - //beam:"Beam", -// square:"Square", -// xShape:"X" -// } - }, - tetra: {vertex: null}, - cube: {face: null, - gik: { - lego: "Micro LEGO (high res)", - legoLowPoly: "Micro LEGO (low res)" - } - }, - truncatedCube: {face: null}, - kelvin: {face: null} - }, - - allMaterialTypes:{ - octa:{ - face: null, - freeformFace: null, - edge: null, - edgeRot: null, - vertex: null//{ - //beam:"Beam", -// square:"Square", -// xShape:"X" -// } - }, - tetra: {vertex: null}, - cube: {face: null, - gik: { - brass:{ - name: "Brass", - color: "#b5a642" - }, - fiberGlass: { - name: "Fiberglass", - color: "#fef1b5" - } - } - }, - truncatedCube: {face: null}, - kelvin: {face: null} - }, - - allMachineTypes:{ - octa:{ - face: {handOfGod: "Hand of God"}, - freeformFace: {handOfGod: "Hand of God"}, - edgeRot: { - shopbot: "Shopbot", - oneBitBot: "One Bit Bot", - oneBitBotLegs: "One Bit Bot with Legs", - handOfGod: "Hand of God" - }, - vertex: {handOfGod: "Hand of God"} - }, - tetra: { - vertex:{handOfGod: "Hand of God"} - }, - cube:{ - face:{handOfGod: "Hand of God"}, - gik: {handOfGod: "Hand of God"} - }, - truncatedCube:{ - face:{handOfGod: "Hand of God"} - }, - kelvin:{ - face:{handOfGod: "Hand of God"} - } - }, - allAssemblyStrategies: { - raster: "Raster" - }, - allCamProcesses: { - shopbot:{ - shopbot: "Shopbot (sbp)", - gcode: "G-Code" - }, - handOfGod:{gcode: "G-Code"}, - oneBitBot:{ - gcode: "G-Code", - tinyG: "TinyG" - } - }, - - allScripts: { - loadFile: "Load From File..." - }, - - allUnitTypes: { - inches: "Inches", - mm: "mm", - //um: "micron" - }, - //key bindings shift: false, deleteMode: false, @@ -222,7 +72,7 @@ AppState = Backbone.Model.extend({ var currentTab = this.get("currentTab"); if (currentTab != "animate") this.set("stockSimulationPlaying", false); if (currentTab != "cam") this.set("manualSelectOrigin", false); - if (currentTab == "import" && dmaGlobals.lattice.get("connectionType") == "edgeRot") dmaGlobals.lattice.set("partType", "voxLowPoly"); + if (currentTab == "import" && globals.lattice.get("connectionType") == "edgeRot") globals.lattice.set("partType", "voxLowPoly"); this._storeTab(this.get("currentNav"), currentTab); }, @@ -299,7 +149,7 @@ AppState = Backbone.Model.extend({ this.set("shift", false); $("#saveAsModel").modal("show"); } else { - dmaGlobals.appState.saveJSON(); + globals.appState.saveJSON(); } } break; @@ -321,20 +171,20 @@ AppState = Backbone.Model.extend({ case 55: case 56: case 57: - if (dmaGlobals.lattice.get("connectionType") != "gik") break; - if (state) dmaGlobals.lattice.set("gikLength", e.keyCode-48); + if (globals.lattice.get("connectionType") != "gik") break; + if (state) globals.lattice.set("gikLength", e.keyCode-48); break; case 81://q - increase supercell index if (state) { var index = this.get("superCellIndex")+1; - if (index > dmaGlobals.lattice.get("gikLength")-1) index = 0; + if (index > globals.lattice.get("gikLength")-1) index = 0; this.set("superCellIndex", index); } break; case 65://a - decrease supercell index if (state) { var index = this.get("superCellIndex")-1; - if (index < 0) index = dmaGlobals.lattice.get("gikLength")-1; + if (index < 0) index = globals.lattice.get("gikLength")-1; this.set("superCellIndex", index); } break; @@ -366,20 +216,20 @@ AppState = Backbone.Model.extend({ }, _getAssemblerDataToSave: function(){ - var assemblerData = _.omit(dmaGlobals.assembler.toJSON(), ["origin", "stock", "exporter", "appState", "lattice", "machine", "simLineNumber"]); - if (!dmaGlobals.assembler.get("editsMadeToProgram")) assemblerData.dataOut = ""; + var assemblerData = _.omit(globals.assembler.toJSON(), ["origin", "stock", "exporter", "appState", "lattice", "machine", "simLineNumber"]); + if (!globals.assembler.get("editsMadeToProgram")) assemblerData.dataOut = ""; return assemblerData; }, _getLatticeDataToSave: function(){ - return _.omit(dmaGlobals.lattice.toJSONFull(), ["highlighter", "basePlane", "nodes", "appState"]); + return _.omit(globals.lattice.toJSONFull(), ["highlighter", "basePlane", "nodes", "appState"]); }, loadLatticeFromJSON: function(data){ - dmaGlobals.lattice.clearCells(); + globals.lattice.clearCells(); this._setData(data, false); - dmaGlobals.lattice._updateLatticeType(null, null, null, true); - dmaGlobals.lattice.trigger("change:scale");//todo make this better + globals.lattice._updateLatticeType(null, null, null, true); + globals.lattice.trigger("change:scale");//todo make this better }, saveUser: function(name){ @@ -399,10 +249,10 @@ AppState = Backbone.Model.extend({ _setData: function(data, silent){ _.each(_.keys(data.lattice), function(key){ - dmaGlobals.lattice.set(key, data.lattice[key], {silent:silent}); + globals.lattice.set(key, data.lattice[key], {silent:silent}); }); _.each(_.keys(data.assembler), function(key){ - dmaGlobals.assembler.set(key, data.assembler[key]); + globals.assembler.set(key, data.assembler[key]); }); } diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index 7afbb7125af22702ff7b272de245202ac2da38f9..1e2f6d9b19c308f5878fdc7439053133ca40f405 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -27,9 +27,9 @@ BasePlane = Backbone.Model.extend({ var self = this; _.each(this.get("mesh"), function(mesh){ - dmaGlobals.three.sceneAdd(mesh, self._checkIsHighlightable(mesh)); + globals.three.sceneAdd(mesh, self._checkIsHighlightable(mesh)); }); - dmaGlobals.three.render(); + globals.three.render(); }, @@ -71,9 +71,9 @@ BasePlane = Backbone.Model.extend({ var self = this; _.each(this.get("mesh"), function(mesh){ if (mesh.myParent) mesh.myParent = null; - dmaGlobals.three.sceneRemove(mesh, self._checkIsHighlightable(mesh)); + globals.three.sceneRemove(mesh, self._checkIsHighlightable(mesh)); }); - dmaGlobals.three.render(); + globals.three.render(); }, destroy: function(){ @@ -131,24 +131,24 @@ OctaBasePlane = BasePlane.extend({ _renderZIndexChange: function(){ var zIndex = this.get("zIndex"); - var scale = dmaGlobals.lattice.get("scale"); - var xScale = dmaGlobals.lattice.xScale(scale); - var yScale = dmaGlobals.lattice.yScale(scale); - var zScale = dmaGlobals.lattice.zScale(scale); + var scale = globals.lattice.get("scale"); + var xScale = globals.lattice.xScale(scale); + var yScale = globals.lattice.yScale(scale); + var zScale = globals.lattice.zScale(scale); _.each(this.get("mesh"), function(mesh){ mesh.position.set(xScale*(zIndex%2)/2, -yScale/3*(zIndex%2), zIndex*zScale); mesh.rotation.set(Math.PI*(zIndex%2),0,0) }); - dmaGlobals.three.render(); + globals.three.render(); }, _calcOctaFaceVertices: function(xySep){ var vertices = []; - var xScale = dmaGlobals.lattice.xScale(1); - var yScale = dmaGlobals.lattice.yScale(1); + var xScale = globals.lattice.xScale(1); + var yScale = globals.lattice.yScale(1); var dimX = this.get("dimX"); var dimY = this.get("dimY"); @@ -183,11 +183,11 @@ OctaBasePlane = BasePlane.extend({ calcHighlighterPosition: function(face, position){ - var index = dmaGlobals.lattice.getIndexForPosition(position); + var index = globals.lattice.getIndexForPosition(position); if (index.z%2 != 0) index.x -= 1; index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane - var position = dmaGlobals.lattice.getPositionForIndex(index); - position.z += dmaGlobals.lattice.zScale()/2; + var position = globals.lattice.getPositionForIndex(index); + position.z += globals.lattice.zScale()/2; return {index: index, direction: new THREE.Vector3(0,0,1), position:position}; } @@ -202,7 +202,7 @@ SquareBasePlane = BasePlane.extend({ _makeBasePlaneMesh: function(){ - var scale = dmaGlobals.lattice.xScale(1); + var scale = globals.lattice.xScale(1); var dimX = this.get("dimX")*scale; var dimY = this.get("dimY")*scale; @@ -232,18 +232,18 @@ SquareBasePlane = BasePlane.extend({ _renderZIndexChange: function(){ var zIndex = this.get("zIndex"); - var zScale = dmaGlobals.lattice.zScale(); + var zScale = globals.lattice.zScale(); _.each(this.get("mesh"), function(mesh){ mesh.position.set(0, 0, zIndex*zScale); }); - dmaGlobals.three.render(); + globals.three.render(); }, calcHighlighterPosition: function(face, position){ - var index = dmaGlobals.lattice.getIndexForPosition(position); + var index = globals.lattice.getIndexForPosition(position); index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane - var latticePosition = dmaGlobals.lattice.getPositionForIndex(index); - latticePosition.z += dmaGlobals.lattice.zScale()/2; + var latticePosition = globals.lattice.getPositionForIndex(index); + latticePosition.z += globals.lattice.zScale()/2; return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition}; } @@ -258,11 +258,11 @@ SquareBasePlane = BasePlane.extend({ RotEdgeOctaBasePlane = SquareBasePlane.extend({ calcHighlighterPosition: function(face, position){ - var index = dmaGlobals.lattice.getIndexForPosition(position); + var index = globals.lattice.getIndexForPosition(position); index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane - var latticePosition = dmaGlobals.lattice.getPositionForIndex(index); - latticePosition.x -= dmaGlobals.lattice.xScale()/2; - latticePosition.y -= dmaGlobals.lattice.yScale()/2; + var latticePosition = globals.lattice.getPositionForIndex(index); + latticePosition.x -= globals.lattice.xScale()/2; + latticePosition.y -= globals.lattice.yScale()/2; return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition}; } }); \ No newline at end of file diff --git a/js/models/FillGeometry.js b/js/models/FillGeometry.js index c60123faebb62d84296b24150f6f26b00e09541b..976a33f127311a2c553bb33a886ad3327664ba86 100644 --- a/js/models/FillGeometry.js +++ b/js/models/FillGeometry.js @@ -32,8 +32,8 @@ FillGeometry = Backbone.Model.extend({ side:THREE.DoubleSide})); this.makeBoundingBox(mesh); this.set({mesh: mesh}); - dmaGlobals.three.sceneAdd(mesh, null); - dmaGlobals.three.render(); + globals.three.sceneAdd(mesh, null); + globals.three.render(); }, makeBoundingBox: function(mesh){ @@ -42,7 +42,7 @@ FillGeometry = Backbone.Model.extend({ box.material.opacity = 0.4; box.material.transparent = true; this.set("boundingBox", box); -// dmaGlobals.three.sceneAdd(box); +// globals.three.sceneAdd(box); }, fillGeo: function(){ @@ -50,11 +50,11 @@ FillGeometry = Backbone.Model.extend({ boundingBox.geometry.computeBoundingBox(); var bounds = boundingBox.geometry.boundingBox; - var scale = dmaGlobals.lattice.get("scale"); + var scale = globals.lattice.get("scale"); - var minIndex = dmaGlobals.lattice.getIndexForPosition(bounds.min); - var maxIndex = dmaGlobals.lattice.getIndexForPosition(bounds.max); - dmaGlobals.lattice.checkForMatrixExpansion(null, maxIndex, minIndex);//expand cells matrix before + var minIndex = globals.lattice.getIndexForPosition(bounds.min); + var maxIndex = globals.lattice.getIndexForPosition(bounds.max); + globals.lattice.checkForMatrixExpansion(null, maxIndex, minIndex);//expand cells matrix before var raycaster = new THREE.Raycaster(); var direction = new THREE.Vector3(0,0,1); @@ -63,7 +63,7 @@ FillGeometry = Backbone.Model.extend({ raycaster.far = bounds.max-bounds.min+2;//add some padding just in case for (var x=minIndex.x;x<=maxIndex.x;x++){ for (var y=minIndex.y;y<=maxIndex.y;y++){ - var origin = dmaGlobals.lattice.getPositionForIndex({x:x, y:y, z:minIndex.z}); + var origin = globals.lattice.getPositionForIndex({x:x, y:y, z:minIndex.z}); origin.z = bounds.min.z-1;//more padding raycaster.set(origin, direction); var intersections = raycaster.intersectObject(mesh); @@ -73,16 +73,16 @@ FillGeometry = Backbone.Model.extend({ var nextIntersection = intersections[nextIntersectionIndex].distance; for (var z=minIndex.z;z<=maxIndex.z;z++){ var index = {x:x,y:y,z:z}; - var position = dmaGlobals.lattice.getPositionForIndex(index); + var position = globals.lattice.getPositionForIndex(index); if (!inside){ if (position.z<nextIntersection) continue; else { inside = true; - dmaGlobals.lattice.addCellAtIndex(index, true, true); + globals.lattice.addCellAtIndex(index, true, true); } } else { if (position.z<nextIntersection) { - dmaGlobals.lattice.addCellAtIndex(index, true, true); + globals.lattice.addCellAtIndex(index, true, true); continue; } else inside = false; @@ -95,7 +95,7 @@ FillGeometry = Backbone.Model.extend({ } } } - dmaGlobals.three.render(); + globals.three.render(); }, _getNextIntersection: function(position, intersections, nextIntersectionIndex, inside){ @@ -109,17 +109,17 @@ FillGeometry = Backbone.Model.extend({ }, subtractGeo: function(){ - dmaGlobals.lattice.subtractMesh(this.get("mesh")); + globals.lattice.subtractMesh(this.get("mesh")); }, removeMesh: function(){ if (!this.get("mesh")) return; - dmaGlobals.three.sceneRemove(this.get("mesh")); - dmaGlobals.three.sceneRemove(this.get("boundingBox")); + globals.three.sceneRemove(this.get("mesh")); + globals.three.sceneRemove(this.get("boundingBox")); this.set("mesh", null); this.set("boundingBox", null); this.set("filename", this.defaults.filename); - dmaGlobals.three.render(); + globals.three.render(); }, scale: function(scale){ diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 638f747d2f86f72d41ab985807ecd96651a303fc..513eaabba7bbda7e77c532f9197eaf406ca5c8fc 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -76,7 +76,7 @@ Lattice = Backbone.Model.extend({ } } } - dmaGlobals.three.render(); + globals.three.render(); return newCells; }, @@ -90,7 +90,7 @@ Lattice = Backbone.Model.extend({ if (!cells[index.x][index.y][index.z]) { cells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices, scale); this.set("numCells", this.get("numCells")+1); - if (!noRender) dmaGlobals.three.render(); + if (!noRender) globals.three.render(); } else console.warn("already a cell there"); }, @@ -132,7 +132,7 @@ Lattice = Backbone.Model.extend({ //todo shrink cells matrix if needed this.set("numCells", this.get("numCells")-1); - dmaGlobals.three.render(); + globals.three.render(); }, //todo send clear all to three and destroy without sceneRemove to cell @@ -146,7 +146,7 @@ Lattice = Backbone.Model.extend({ this.set("nodes", []); this.set("numCells", 0); if (this.get("basePlane")) this.get("basePlane").set("zIndex", 0); - dmaGlobals.three.render(); + globals.three.render(); }, calculateBoundingBox: function(){ @@ -208,7 +208,7 @@ Lattice = Backbone.Model.extend({ } } - dmaGlobals.three.render(); + globals.three.render(); }, _findIntersectionsInWindow: function(windowX, windowY, origin, allVertexPos){ @@ -340,13 +340,13 @@ Lattice = Backbone.Model.extend({ }, _updateForMode: function(){ - var cellMode = dmaGlobals.appState.get("cellMode"); + var cellMode = globals.appState.get("cellMode"); var partType = this.get("partType"); var scale = this.get("scale"); this._iterCells(this.get("cells"), function(cell){ if (cell) cell.draw(scale, cellMode, partType); }); - dmaGlobals.three.render(); + globals.three.render(); }, _updateCellSeparation: function(){ @@ -354,12 +354,12 @@ Lattice = Backbone.Model.extend({ this.get("basePlane").updateXYSeparation(cellSep.xy); var scale = this.get("scale"); - var cellMode = dmaGlobals.appState.get("cellMode"); + var cellMode = globals.appState.get("cellMode"); var partType = this.get("partType"); this._iterCells(this.get("cells"), function(cell){ if (cell) cell.updateForScale(scale, cellMode, partType); }); - dmaGlobals.three.render(); + globals.three.render(); }, _scaleDidChange: function(){ @@ -367,13 +367,13 @@ Lattice = Backbone.Model.extend({ this.get("basePlane").updateScale(scale); this.get("highlighter").updateScale(scale); - var cellMode = dmaGlobals.appState.get("cellMode"); + var cellMode = globals.appState.get("cellMode"); var partType = this.get("partType"); this._iterCells(this.get("cells"), function(cell){ if (cell && cell.updateForScale) cell.updateForScale(scale, cellMode, partType); }); - dmaGlobals.three.render(); + globals.three.render(); }, _gikLengthDidChange: function(){ @@ -385,7 +385,7 @@ Lattice = Backbone.Model.extend({ }, _setCellVisibility: function(){//todo maybe leave wireframes? - if (dmaGlobals.appState.get("cellsVisible")) this.showCells(); + if (globals.appState.get("cellsVisible")) this.showCells(); else this.hideCells(); }, @@ -397,7 +397,7 @@ Lattice = Backbone.Model.extend({ cell.hideForStockSimulation = true; } }); - dmaGlobals.three.render(); + globals.three.render(); }, showCells: function(){ @@ -407,7 +407,7 @@ Lattice = Backbone.Model.extend({ cell.draw(); } }); - dmaGlobals.three.render(); + globals.three.render(); }, showCellAtIndex: function(index){ @@ -495,12 +495,12 @@ Lattice = Backbone.Model.extend({ //} cells[x][y][z] = newCell; }); - dmaGlobals.three.render(); + globals.three.render(); }, _setDefaultCellMode: function(){ - if (!dmaGlobals.appState.get("allPartTypes")[this.get("cellType")][this.get("connectionType")]){ - dmaGlobals.appState.set("cellMode", "cell"); + if (!globals.plist["allPartTypes"][this.get("cellType")][this.get("connectionType")]){ + globals.appState.set("cellMode", "cell"); } }, diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js index ff3c5becee9946bc6c2844ab6086eb06e6eea1a1..a9b98afd46ea596eddc2f4de874c4f8ce4fc06ec 100644 --- a/js/models/LatticeOcta.js +++ b/js/models/LatticeOcta.js @@ -85,7 +85,7 @@ OctaLatticeSubclasses = { var cells = this.get("cells"); cells[0][0].push(this.makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, scale, parentCellPos, parentCellOrient, direction, parentType, type)); this.set("numCells", this.get("numCells")+1); - dmaGlobals.three.render(); + globals.three.render(); }, makeCellForLatticeType: function(index, scale, parentPosition, parentOrientation, direction, parentType, type){ diff --git a/js/models/extrudeVisualizer.js b/js/models/extrudeVisualizer.js index af363dba103403534af7f6ffa3a846d1ed8a7bba..2d31fa5d367acf64db0be13021bee46d9f9d70c2 100644 --- a/js/models/extrudeVisualizer.js +++ b/js/models/extrudeVisualizer.js @@ -18,10 +18,10 @@ function ExtrudeVisualizer(){ mesh.position.x = profilePos.x; mesh.position.y = profilePos.y; mesh.position.z = profilePos.z; -// dmaGlobals.three.sceneAdd(mesh, false); +// globals.three.sceneAdd(mesh, false); meshes.push(mesh); }); - dmaGlobals.three.render(); + globals.three.render(); } function makeHandle(){ @@ -36,7 +36,7 @@ function ExtrudeVisualizer(){ _.each(meshes, function(mesh){ mesh.scale.z = height; }) - dmaGlobals.three.render(); + globals.three.render(); } function renderIntoCells(){ diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index b22a35d6a18ab8739f63667255a504ec4fb592bb..742fef51adaf2a31b732f4183f9a4aa22e7e131b 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -21,7 +21,7 @@ Highlighter = Backbone.View.extend({ vertexColors:THREE.FaceColors })); - dmaGlobals.three.sceneAdd(this.mesh, null); + globals.three.sceneAdd(this.mesh, null); this.updateScale(options.scale); this.hide(); @@ -43,7 +43,7 @@ Highlighter = Backbone.View.extend({ _setVisibility: function(visible, forceRender){ if (forceRender || this.isVisible() != visible){ this.mesh.visible = visible; - dmaGlobals.three.render(); + globals.three.render(); } this.mesh.visible = visible; }, @@ -127,23 +127,23 @@ Highlighter = Backbone.View.extend({ if (shouldAdd){ if (!this.isVisible() || !this.highlightedObject) return; - if (dmaGlobals.lattice.get("connectionType") == "freeformFace"){ + if (globals.lattice.get("connectionType") == "freeformFace"){ //todo make this work for baseplane - dmaGlobals.lattice.addFreeFormCell(this.mesh.position.clone(), this.highlightedObject.getOrientation(), this.direction, this.highlightedObject.getType()); + globals.lattice.addFreeFormCell(this.mesh.position.clone(), this.highlightedObject.getOrientation(), this.direction, this.highlightedObject.getType()); return; } - dmaGlobals.lattice.addCellAtIndex(this._getNextCellPosition()); + globals.lattice.addCellAtIndex(this._getNextCellPosition()); } else { if (!this.highlightedObject) return; if (!(this.highlightedObject instanceof DMACell)) return; - dmaGlobals.lattice.removeCell(this.highlightedObject); + globals.lattice.removeCell(this.highlightedObject); } this.setNothingHighlighted(); }, destroy: function(){ this.setNothingHighlighted(); - dmaGlobals.three.sceneRemove(this.mesh, null); + globals.three.sceneRemove(this.mesh, null); this.mesh = null; this.stopListening(); } @@ -211,7 +211,7 @@ CubeHighlighter = Highlighter.extend({ GIKHighlighter = Highlighter.extend({ updateScale: function(scale){ - this.mesh.scale.set(dmaGlobals.lattice.get("gikLength")*scale, scale, scale); + this.mesh.scale.set(globals.lattice.get("gikLength")*scale, scale, scale); }, _makeGeometry: function(){ @@ -220,11 +220,11 @@ GIKHighlighter = Highlighter.extend({ _setPosition: function(position, direction){ var scale = this.mesh.scale.z/2; - this.mesh.position.set(position.x+scale*direction.x, position.y+scale*direction.y, position.z+dmaGlobals.lattice.zScale()/2*direction.z); + this.mesh.position.set(position.x+scale*direction.x, position.y+scale*direction.y, position.z+globals.lattice.zScale()/2*direction.z); }, _setRotation: function(direction, index){ - var superCellIndex = dmaGlobals.appState.get("superCellIndex"); + var superCellIndex = globals.appState.get("superCellIndex"); var scale = this.mesh.scale.z; if ((index.z%2 == 0 && Math.abs(direction.z) > 0.9) || (index.z%2 != 0 && Math.abs(direction.z) < 0.1)) this.mesh.rotation.set(0, 0, Math.PI/2); else this.mesh.rotation.set(0,0,0); @@ -236,7 +236,7 @@ GIKHighlighter = Highlighter.extend({ if (!this.direction) return; this._setPosition(this.position, this.direction);//position of center point this._setRotation(this.direction, this.index); - dmaGlobals.three.render(); + globals.three.render(); }, addRemoveVoxel: function(shouldAdd){ @@ -244,22 +244,22 @@ GIKHighlighter = Highlighter.extend({ if (shouldAdd){ if (!this.isVisible() || !this.highlightedObject) return; var position = this._getNextCellPosition(); - var index = dmaGlobals.appState.get("superCellIndex"); + var index = globals.appState.get("superCellIndex"); var min, max; if (this.mesh.rotation.z == 0) { - min = {x:position.x-dmaGlobals.lattice.get("gikLength")+1+index, y:position.y, z:position.z}; + min = {x:position.x-globals.lattice.get("gikLength")+1+index, y:position.y, z:position.z}; max = {x:position.x+index, y:position.y, z:position.z}; } else { - min = {x:position.x, y:position.y-dmaGlobals.lattice.get("gikLength")+1+index, z:position.z}; + min = {x:position.x, y:position.y-globals.lattice.get("gikLength")+1+index, z:position.z}; max = {x:position.x, y:position.y+index, z:position.z}; } var range = {min:min, max:max}; - dmaGlobals.lattice.makeSuperCell(range); + globals.lattice.makeSuperCell(range); } else { if (!this.highlightedObject) return; if (!(this.highlightedObject instanceof DMACell)) return; - dmaGlobals.lattice.removeCell(this.highlightedObject); + globals.lattice.removeCell(this.highlightedObject); } this.setNothingHighlighted(); } diff --git a/js/threeViews/ThreeView.js b/js/threeViews/ThreeView.js index f1f8684243303f7f9a8f652e5148b079ddea1ebf..b1fa867d511b4d1b7c285692cca228a14e3a332e 100644 --- a/js/threeViews/ThreeView.js +++ b/js/threeViews/ThreeView.js @@ -30,7 +30,7 @@ ThreeView = Backbone.View.extend({ //bind events this.listenTo(this.appState, "change:deleteMode change:extrudeMode change:shift", this._setControlsEnabled); - this.listenTo(dmaGlobals.lattice, "change:highlighter", this._saveHighlighter); + this.listenTo(globals.lattice, "change:highlighter", this._saveHighlighter); this._saveHighlighter();//need a reference to the highlighter @@ -68,11 +68,11 @@ ThreeView = Backbone.View.extend({ _mouseUp: function(){ this.mouseIsDown = false; - if (dmaGlobals.appState.get("currentTab") == "cam" && dmaGlobals.appState.get("manualSelectOrigin")){ + if (globals.appState.get("currentTab") == "cam" && globals.appState.get("manualSelectOrigin")){ var position = this.highlighter.getHighlightedObjectPosition(); if (position){ - dmaGlobals.assembler.set("originPosition", position); - dmaGlobals.appState.set("manualSelectOrigin", false); + globals.assembler.set("originPosition", position); + globals.appState.set("manualSelectOrigin", false); return; } } @@ -86,7 +86,7 @@ ThreeView = Backbone.View.extend({ _mouseMoved: function(e){ - if (!dmaGlobals.appState.get("highlightMode") && !(dmaGlobals.appState.get("manualSelectOrigin"))) return; + if (!globals.appState.get("highlightMode") && !(globals.appState.get("manualSelectOrigin"))) return; if (this.mouseIsDown && !this.controls.noRotate) {//in the middle of a camera move this.highlighter.setNothingHighlighted(); @@ -134,14 +134,14 @@ ThreeView = Backbone.View.extend({ //////////////////////////////////////////////////////////////////////////////// _saveHighlighter: function(){ - this.highlighter = dmaGlobals.lattice.get("highlighter"); + this.highlighter = globals.lattice.get("highlighter"); }, _setNoPartIntersections: function(){ if (this.currentIntersectedPart){ this.currentIntersectedPart.unhighlight(); this.currentIntersectedPart = null; - dmaGlobals.three.render(); + globals.three.render(); } }, @@ -156,7 +156,7 @@ ThreeView = Backbone.View.extend({ if (this.currentIntersectedPart) this.currentIntersectedPart.unhighlight(); part.highlight(); this.currentIntersectedPart = part; - dmaGlobals.three.render(); + globals.three.render(); } }