diff --git a/js/API/LatticeAPI.js b/js/API/LatticeAPI.js index fe6248ec5b669e2e590e92b43cccf246323a0c72..c274a65d15cea3b1b69d8356ea6e7b4b1abc8ad9 100644 --- a/js/API/LatticeAPI.js +++ b/js/API/LatticeAPI.js @@ -42,59 +42,27 @@ define(['lattice', 'plist'], function(lattice, plist){ //setters setAspectRatio: function(x, y, z){ - if (!x || !y || !z || x<0 || y<0 || z<0) {//no 0, undefined, null, or neg #'s - console.warn("invalid aspect ratio params"); - return; - } - lattice.set("aspectRatio", new THREE.Vector3(x, y, z)); + lattice.setAspectRatio(x, y, z); }, setCellType: function(cellType){ - if (plist.allLattices[cellType] === undefined){ - console.warn("no cell type " + cellType); - return; - } - return lattice.set("cellType", cellType); + lattice.setCellType(cellType); }, setConnectionType: function(connectionType){ - var cellType = lattice.get("cellType"); - var plistCellData = plist.allLattices[cellType]; - if (plistCellData[connectionType] === undefined){ - console.warn("no connection type " + connectionType + " for cell type " + plistCellData.name); - return; - } - return lattice.set("connectionType", connectionType); + lattice.setConnectionType(connectionType); }, setApplicationType: function(applicationType){ - var cellType = lattice.get("cellType"); - var plistCellData = plist.allLattices[cellType]; - var connectionType = lattice.get("connectionType"); - var plistConnectionData = plistCellData[connectionType]; - if (plistConnectionData[applicationType] === undefined){ - console.warn("no application type " + applicationType + " for cell type " + plistCellData.name + " and connection type " + plistConnectionData.name); - return; - } - return lattice.set("applicationType", applicationType); + lattice.setApplicationType(applicationType); }, setPartType: function(partType){ - var cellType = lattice.get("cellType"); - var plistCellData = plist.allLattices[cellType]; - var connectionType = lattice.get("connectionType"); - var plistConnectionData = plistCellData[connectionType]; - var applicationType = lattice.get("applicationType"); - var plistAppData = plistConnectionData[applicationType]; - if (plistConnectionData[applicationType] === undefined){ - console.warn("no part type " + partType + " for cell type " + plistCellData.name + " and connection type " + plistConnectionData.name + " and application type " + plistAppData.name); - return; - } - return lattice.set("partType", partType); + lattice.setPartType(partType); }, setLatticeType: function(cellType, connectionType, applicationType, partType){ - + lattice.setLatticeType(cellType, connectionType, applicationType, partType); }, diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index b3e6938b9af8400be3ddc5c3ec4765d5acb8de3d..757fc4e4803750de2b737554c6f930f6d74e8156 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -36,6 +36,70 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre + //setters + + setAspectRatio: function(aspectRatio){ + if (!aspectRatio.x || !aspectRatio.y || !aspectRatio.z || aspectRatio.x<0 || aspectRatio.y<0 || aspectRatio.z<0) {//no 0, undefined, null, or neg #'s + console.warn("invalid aspect ratio params"); + return; + } + this.set("aspectRatio", new THREE.Vector3(aspectRatio.x, aspectRatio.y, aspectRatio.z)); + }, + + setCellType: function(cellType){ + if (plist.allLattices[cellType] === undefined){ + console.warn("no cell type " + cellType); + return; + } + this.set("cellType", cellType); + }, + + setConnectionType: function(connectionType){ + var cellType = this.get("cellType"); + var plistCellData = plist.allLattices[cellType]; + if (plistCellData[connectionType] === undefined){ + console.warn("no connection type " + connectionType + " for cell type " + plistCellData.name); + return; + } + this.set("connectionType", connectionType); + }, + + setApplicationType: function(applicationType){ + var cellType = this.get("cellType"); + var plistCellData = plist.allLattices[cellType]; + var connectionType = this.get("connectionType"); + var plistConnectionData = plistCellData[connectionType]; + if (plistConnectionData[applicationType] === undefined){ + console.warn("no application type " + applicationType + " for cell type " + plistCellData.name + " and connection type " + plistConnectionData.name); + return; + } + this.set("applicationType", applicationType); + }, + + setPartType: function(partType){ + var cellType = this.get("cellType"); + var plistCellData = plist.allLattices[cellType]; + var connectionType = this.get("connectionType"); + var plistConnectionData = plistCellData[connectionType]; + var applicationType = this.get("applicationType"); + var plistAppData = plistConnectionData[applicationType]; + if (plistConnectionData[applicationType] === undefined){ + console.warn("no part type " + partType + " for cell type " + plistCellData.name + " and connection type " + plistConnectionData.name + " and application type " + plistAppData.name); + return; + } + this.set("partType", partType); + }, + + setLatticeType: function(cellType, connectionType, applicationType, partType){ + //todo check if this causes too many renders + if (cellType) this.setCellType(cellType); + if (connectionType) this.setConnectionType(connectionType); + if (applicationType) this.setApplicationType(applicationType); + if (partType) this.setPartType(partType); + }, + + + //lattice type diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 2136e9314a0f0ef1e226723043b9bf3a8c5643b4..4e29bc1a900156064498ac993138e3080cdd6f16 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -212,10 +212,7 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex _setProperty: function($target, property, newVal, key){ var owner = this._getPropertyOwner($target); if (!owner) return; - if (owner.setProperty){ - owner.setProperty(property, newVal, key); - return; - } + if (newVal === null || newVal === undefined) return; if (key){ var propObject = this._getOwnerProperty(owner, property); if (propObject.clone) propObject = propObject.clone(); @@ -233,13 +230,18 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex }, _setOwnerProperty: function(owner, property, value){ - if (owner instanceof Backbone.Model) owner.set(property, value); + if (owner[this._getSetterName(property)]) owner[this._getSetterName(property)](value); + else if (owner instanceof Backbone.Model) owner.set(property, value); else { owner[property] = value; this.menu.render(); } }, + _getSetterName: function(property){ + return "set" + property.charAt(0).toUpperCase() + property.slice(1); + }, + _deleteExitMenu: function(e){ diff --git a/js/menus/templates/LatticeMenuView.html b/js/menus/templates/LatticeMenuView.html index c568f1599e842195d2362f5f9e74596ea8f9bf03..c58283ded1c53580e0809b78762ce0e681dc3323 100644 --- a/js/menus/templates/LatticeMenuView.html +++ b/js/menus/templates/LatticeMenuView.html @@ -37,9 +37,9 @@ Type: </div><br/><br/> <% } %> Aspect Ratio: - <input data-property="aspectRatio" data-key="x" data-min="0.1" value="<%= aspectRatio.x %>" placeholder="X" class="form-control lattice floatInput" type="text"> - <input data-property="aspectRatio" data-key="y" data-min="0.1" value="<%= aspectRatio.y %>" placeholder="Y" class="form-control lattice floatInput" type="text"> - <input data-property="aspectRatio" data-key="z" data-min="0.1" value="<%= aspectRatio.z %>" placeholder="Z" class="form-control lattice floatInput" type="text"><br/><br/> + <input data-property="aspectRatio" data-key="x" data-min="0" value="<%= aspectRatio.x %>" placeholder="X" class="form-control lattice floatInput" type="text"> + <input data-property="aspectRatio" data-key="y" data-min="0" value="<%= aspectRatio.y %>" placeholder="Y" class="form-control lattice floatInput" type="text"> + <input data-property="aspectRatio" data-key="z" data-min="0" value="<%= aspectRatio.z %>" placeholder="Z" class="form-control lattice floatInput" type="text"><br/><br/> <% if (connectionType == "gik") { %> Part Length: <input data-property="gikLength" value="<%= gikLength %>" placeholder="Length" class="form-control intInput appState" type="text"><br/><br/> <% } %> diff --git a/js/models/SerialComm.js b/js/models/SerialComm.js index 32e4384ad6a4cabe178912057132d3912d1bd112..3ecfc76f948fb9f29121a187db383ca612ab15a3 100644 --- a/js/models/SerialComm.js +++ b/js/models/SerialComm.js @@ -120,9 +120,12 @@ define(['underscore', 'backbone', 'socketio', 'machineState', 'cam', 'lattice', return this.machineState; }, - setProperty: function(property, value){//portName, baudRate - if (property === null || property === undefined || value === null || value === undefined) return; - this.socket.emit(property, value);//always pass user interaction on + setBaudRate: function(value){ + this.socket.emit("baudRate", value); + }, + + setPortName: function(value){ + this.socket.emit("portName", value); }, openSerialMonitor: function(){