From 993127a0bbf36a709804b6a46b20d19876ccf343 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 25 Sep 2015 13:55:53 -0400 Subject: [PATCH] use api --- js/API/LatticeAPI.js | 44 +++-------------- js/lattice/LatticeBase.js | 64 +++++++++++++++++++++++++ js/menus/MenuWrapperView.js | 12 +++-- js/menus/templates/LatticeMenuView.html | 6 +-- js/models/SerialComm.js | 9 ++-- 5 files changed, 86 insertions(+), 49 deletions(-) diff --git a/js/API/LatticeAPI.js b/js/API/LatticeAPI.js index fe6248ec..c274a65d 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 b3e6938b..757fc4e4 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 2136e931..4e29bc1a 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 c568f159..c58283de 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 32e4384a..3ecfc76f 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(){ -- GitLab