From 1a917810667c0e785cacbb9b2eadbc81a6f3ac32 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 27 May 2015 16:09:10 -0700 Subject: [PATCH] material radio --- js/menus/AnimationMenuView.js | 1 + js/menus/AssemblerMenuView.js | 2 +- js/menus/CamMenuView.js | 2 +- js/menus/ImportMenuView.js | 3 ++- js/menus/LatticeMenuView.js | 30 ++++-------------------- js/menus/MaterialMenuView.js | 1 + js/menus/MenuWrapperView.js | 40 ++++++++++++++++++-------------- js/menus/OptimizationMenuView.js | 1 + js/menus/PartMenuView.js | 26 ++++++++++++++++----- js/menus/PhysicsMenuView.js | 1 + js/menus/ScriptMenuView.js | 3 ++- js/menus/SendMenuView.js | 1 + js/menus/SketchMenuView.js | 1 + js/models/AppState.js | 2 ++ 14 files changed, 61 insertions(+), 53 deletions(-) diff --git a/js/menus/AnimationMenuView.js b/js/menus/AnimationMenuView.js index 695561ba..26bb2757 100644 --- a/js/menus/AnimationMenuView.js +++ b/js/menus/AnimationMenuView.js @@ -96,6 +96,7 @@ AnimationMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "animate") return; + if ($("input[type=text]").is(":focus")) return; if (globals.cam.get("needsPostProcessing") && !globals.cam.get("editsMadeToProgram")) globals.cam.postProcess(); this.$el.html(this.template(_.extend(this.model.toJSON(), globals.cam.toJSON()))); this._setEditorHeight(); diff --git a/js/menus/AssemblerMenuView.js b/js/menus/AssemblerMenuView.js index 902f8a29..f415aab4 100644 --- a/js/menus/AssemblerMenuView.js +++ b/js/menus/AssemblerMenuView.js @@ -33,7 +33,7 @@ AssemblerMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "assembler") return; - if ($("input").is(":focus")) return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template(_.extend(this.model.toJSON(), globals.cam.toJSON(), globals.lattice.toJSON(), globals.plist))); }, diff --git a/js/menus/CamMenuView.js b/js/menus/CamMenuView.js index f3c3d537..88023eb2 100644 --- a/js/menus/CamMenuView.js +++ b/js/menus/CamMenuView.js @@ -35,7 +35,7 @@ CamMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "cam") return; - if ($("input").is(":focus")) return; + if ($("input[type=text]").is(":focus")) return; var data = _.extend(this.model.toJSON(), globals.cam.toJSON(), globals.lattice.toJSON(), globals.plist); if (globals.cam.get("stockPositionRelative")){ diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index 07405167..cd0a6ef5 100644 --- a/js/menus/ImportMenuView.js +++ b/js/menus/ImportMenuView.js @@ -83,6 +83,7 @@ ImportMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "import") return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template(_.extend(this.model.toJSON(), this.fillGeometry.toJSON()))); }, @@ -94,7 +95,7 @@ ImportMenuView = Backbone.View.extend({ <a href="#" id="removeFillGeo" class=" btn btn-block btn-lg btn-default">Remove Mesh</a><br/>\ <hr>\ <% } %>\ - <a href="#" class=" btn btn-block btn-lg btn-default clearCells">Clear All Cells</a><br/><br/>\ + <a href="#" class=" btn btn-block btn-lg btn-danger clearCells">Clear All Cells</a><br/><br/>\ <br/><span class="btn btn-default btn-lg btn-file fullWidth">\ Upload STL<input id="importMenuUploadSTL" type="file">\ </span><br/>\ diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 69ff6e80..60d99f1a 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -8,8 +8,6 @@ LatticeMenuView = Backbone.View.extend({ el: "#menuContent", events: { - "change #latticeScale": "_changeScale", - "slideStop #latticeMenuScaleSlider": "_changeScaleSlider" }, @@ -20,28 +18,11 @@ LatticeMenuView = Backbone.View.extend({ this.listenTo(globals.lattice, "change", this.render); }, - _changeScale: function(e){ - e.preventDefault(); - var val = parseFloat($(e.target).val()); - if (isNaN(val)) return; - globals.lattice.set("scale", val); - }, - - _changeScaleSlider: function(e){ - globals.lattice.set("scale", $(e.target)[0].value); - }, - render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "lattice") return; - if ($("input").is(":focus")) return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template(_.extend(globals.lattice.toJSON(), globals.plist))); - - $('#latticeMenuScaleSlider').slider({ - formatter: function(value) { - return value; - } - }); }, template: _.template('\ @@ -89,9 +70,6 @@ LatticeMenuView = Backbone.View.extend({ </div><br/><br/>\ <% } %>\ <br/>\ - Scale: <input data-property="scale" value="<%= scale %>" placeholder="Scale" class="form-control floatInput lattice" type="text"><br/>\ - <input id="latticeMenuScaleSlider" data-slider-id="ex1Slider" type="text" data-slider-min="1" data-slider-max="100" data-slider-step="0.1" data-slider-value="<%= scale %>"/>\ - <br/>\ Units: \ <div class="btn-group">\ <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allUnitTypes[units] %><span class="caret"></span></button>\ @@ -101,9 +79,9 @@ LatticeMenuView = Backbone.View.extend({ <% }); %>\ </ul>\ </div><br/><br/>\ - Num Cells: <%= numCells %><br/><br/>\ - <br/>\ - <a href="#" class="clearCells btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\ + <br/><br/>\ + <a href="#" class="clearCells btn btn-block btn-lg btn-danger">Clear All Cells</a><br/>\ + Num Cells: <%= numCells %><br/>\ ') }); diff --git a/js/menus/MaterialMenuView.js b/js/menus/MaterialMenuView.js index 40f67daa..7aa9d575 100644 --- a/js/menus/MaterialMenuView.js +++ b/js/menus/MaterialMenuView.js @@ -17,6 +17,7 @@ MaterialMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "material") return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template()); }, diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index fb2c2d4b..a1c155f8 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -13,7 +13,8 @@ MenuWrapper = Backbone.View.extend({ "click .clearCells": "_clearCells", "focusout .floatInput": "_renderTab",//force rounding if needed "focusout .intInput": "_renderTab", - "change input:checkbox": "_clickCheckbox" + "change input:checkbox": "_clickCheckbox", + "click input:radio": "_radioSelection" }, initialize: function(){ @@ -84,19 +85,11 @@ MenuWrapper = Backbone.View.extend({ newVal = parseFloat(newVal); if (key){ - if ($target.hasClass("lattice")) { - var value = _.clone(globals.lattice.get(property)); - value[key] = newVal; - globals.lattice.set(property, value); - } else if ($target.hasClass("assembler")) { - var value = _.clone(globals.cam.get(property)); - value[key] = newVal; - globals.cam.set(property, value); - } - return; + var value = _.clone(this._getPropertyOwner($target).get(property)); + value[key] = newVal; + this._getPropertyOwner($target).set(property, value); } - if ($target.hasClass("lattice")) globals.lattice.set(property, newVal); - else if ($target.hasClass("assembler")) globals.cam.set(property, newVal); + this._getPropertyOwner($target).set(property, newVal); }, _makeDropdownSelection: function(e){ @@ -104,8 +97,7 @@ MenuWrapper = Backbone.View.extend({ var property = $target.data("property"); var value = $target.data("value"); if (!property || !value) return; - if ($target.hasClass("lattice")) globals.lattice.set(property, value); - else if ($target.hasClass("assembler")) globals.cam.set(property, value); + this._getPropertyOwner($target).set(property, value); }, _clickCheckbox: function(e){ @@ -117,8 +109,14 @@ MenuWrapper = Backbone.View.extend({ console.warn("no property associated with checkbox input"); return; } - if ($target.hasClass("lattice")) globals.lattice.set(property, !globals.lattice.get(property)); - else if ($target.hasClass("assembler")) globals.cam.set(property, !globals.cam.get(property)); + this._getPropertyOwner($target).set(property, !this._getPropertyOwner($target).get(property)); + }, + + _radioSelection: function(e){ + e.preventDefault(); + var $target = $(e.target); + this._getPropertyOwner($target).set($target.attr("name"), $target.val()); + $target.blur(); }, _clearCells: function(e){ @@ -126,6 +124,14 @@ MenuWrapper = Backbone.View.extend({ globals.lattice.clearCells(); }, + _getPropertyOwner: function($target){ + if ($target.hasClass("lattice")) return globals.lattice; + if ($target.hasClass("assembler")) return globals.cam; + if ($target.hasClass("appState")) return globals.appState; + console.warn("no owner found for " + $target); + return null; + }, + diff --git a/js/menus/OptimizationMenuView.js b/js/menus/OptimizationMenuView.js index f3f5b133..def00e5e 100644 --- a/js/menus/OptimizationMenuView.js +++ b/js/menus/OptimizationMenuView.js @@ -17,6 +17,7 @@ OptimizationMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "optimize") return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template()); }, diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index 1cca9485..79f5ac50 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -15,13 +15,14 @@ PartMenuView = Backbone.View.extend({ //bind events this.listenTo(globals.lattice, "change", this.render); + this.listenTo(globals.appState, "change", this.render); }, render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "part") return; - if ($("input").is(":focus")) return; - this.$el.html(this.template(_.extend(globals.lattice.toJSON(), globals.plist))); + if ($("input[type=text]").is(":focus")) return; + this.$el.html(this.template(_.extend(globals.lattice.toJSON(), globals.appState.toJSON(), globals.plist))); }, template: _.template('\ @@ -34,12 +35,25 @@ PartMenuView = Backbone.View.extend({ <% }); %>\ </ul>\ </div><br/><br/>\ - Cell Separation <% if (connectionType != "freeformFace"){ %>(xy, z): <input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text">\ + <!--Cell Separation <% if (connectionType != "freeformFace"){ %>(xy, z): <input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text">\ <input data-property="cellSeparation" data-key="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control floatInput lattice" type="text">\ <% } else { %>( radial ): <input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text"><% } %>\ - <br/><br/>\ + <br/><br/>--><br/>\ <% if (allMaterialTypes[cellType][connectionType]){ %> \ - Material Type: <div class="btn-group">\ + Materials:<br/>\ + <label class="checkbox" for="realisticColorScheme">\ + <input id="realisticColorScheme" data-property="realisticColorScheme" type="checkbox" <% if (realisticColorScheme){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="appState custom-checkbox">\ + <span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ + Use realistic color scheme</label><br/>\ + \ + <% _.each(_.keys(allMaterialTypes[cellType][connectionType]), function(key){ %>\ + <label class="radio">\ + <input type="radio" <%if (key == materialType){ %>checked<%}%> name="materialType" value="<%= key %>" data-toggle="radio" class="custom-radio lattice"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ + <%= allMaterialTypes[cellType][connectionType][key].name %>\ + </label>\ + <% }); %>\ + <br/><br/>\ + <div class="btn-group">\ <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allMaterialTypes[cellType][connectionType][materialType].name %><span class="caret"></span></button>\ <ul role="menu" class="dropdown-menu">\ <% _.each(_.keys(allMaterialTypes[cellType][connectionType]), function(key){ %>\ @@ -48,7 +62,7 @@ PartMenuView = Backbone.View.extend({ </ul>\ </div><br/><br/>\ <% } %>\ - <br/>todo: generic beam part type, part types for new lattice configurations\ + <br/>\ ') }); \ No newline at end of file diff --git a/js/menus/PhysicsMenuView.js b/js/menus/PhysicsMenuView.js index 9a29ca68..9db79389 100644 --- a/js/menus/PhysicsMenuView.js +++ b/js/menus/PhysicsMenuView.js @@ -17,6 +17,7 @@ PhysicsMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "physics") return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template()); }, diff --git a/js/menus/ScriptMenuView.js b/js/menus/ScriptMenuView.js index 1a7db72b..71ac975e 100644 --- a/js/menus/ScriptMenuView.js +++ b/js/menus/ScriptMenuView.js @@ -17,6 +17,7 @@ ScriptMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "script") return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template(globals.plist)); }, @@ -29,7 +30,7 @@ ScriptMenuView = Backbone.View.extend({ <% }); %>\ </ul>\ </div><br/><br/><!-- /btn-group -->\ - <a href="#" class="clearCells btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\ + <a href="#" class="clearCells btn btn-block btn-lg btn-danger">Clear All Cells</a><br/>\ ') }); \ No newline at end of file diff --git a/js/menus/SendMenuView.js b/js/menus/SendMenuView.js index f6a8b79c..73d0c21d 100644 --- a/js/menus/SendMenuView.js +++ b/js/menus/SendMenuView.js @@ -19,6 +19,7 @@ SendMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "send") return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template(this.model.toJSON())); }, diff --git a/js/menus/SketchMenuView.js b/js/menus/SketchMenuView.js index 56fa2562..c8fbeb89 100644 --- a/js/menus/SketchMenuView.js +++ b/js/menus/SketchMenuView.js @@ -24,6 +24,7 @@ SketchMenuView = Backbone.View.extend({ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if (this.model.get("currentTab") != "sketch") return; + if ($("input[type=text]").is(":focus")) return; this.$el.html(this.template(globals.basePlane.toJSON())); $('#zHeightSlider').slider({ diff --git a/js/models/AppState.js b/js/models/AppState.js index 52bb59f2..c70fe3e0 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -29,6 +29,8 @@ AppState = Backbone.Model.extend({ superCellIndex: 0,//offset of superCell adds todo lattice? + realisticColorScheme: true, + stockSimulationPlaying: false, manualSelectOrigin: false//mode that allows user ot select origin from existing cell }, -- GitLab