diff --git a/dependencies/jsonfn.js b/dependencies/jsonfn.js new file mode 100755 index 0000000000000000000000000000000000000000..bad4bbebe4eaa7e873e5b8f7ff616b13bb9f961e --- /dev/null +++ b/dependencies/jsonfn.js @@ -0,0 +1,84 @@ +/** +* JSONfn - javascript (both node.js and browser) plugin to stringify, +* parse and clone objects with Functions, Regexp and Date. +* +* Version - 0.60.00 +* Copyright (c) 2012 - 2014 Vadim Kiryukhin +* vkiryukhin @ gmail.com +* http://www.eslinstructor.net/jsonfn/ +* +* Licensed under the MIT license ( http://www.opensource.org/licenses/mit-license.php ) +* +* USAGE: +* browser: +* JSONfn.stringify(obj); +* JSONfn.parse(str[, date2obj]); +* JSONfn.clone(obj[, date2obj]); +* +* nodejs: +* var JSONfn = require('path/to/json-fn'); +* JSONfn.stringify(obj); +* JSONfn.parse(str[, date2obj]); +* JSONfn.clone(obj[, date2obj]); +* +* +* @obj - Object; +* @str - String, which is returned by JSONfn.stringify() function; +* @date2obj - Boolean (optional); if true, date string in ISO8061 format +* is converted into a Date object; otherwise, it is left as a String. +*/ + +"use strict"; + +(function (exports) { + + exports.stringify = function (obj) { + + return JSON.stringify(obj, function (key, value) { + if (value instanceof Function || typeof value == 'function') { + return value.toString(); + } + if (value instanceof RegExp) { + return '_PxEgEr_' + value; + } + return value; + }); + }; + + exports.parse = function (str, date2obj) { + + var iso8061 = date2obj ? /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/ : false; + + return JSON.parse(str, function (key, value) { + var prefix; + + if (typeof value != 'string') { + return value; + } + if (value.length < 8) { + return value; + } + + prefix = value.substring(0, 8); + + if (iso8061 && value.match(iso8061)) { + return new Date(value); + } + if (prefix === 'function') { + return eval('(' + value + ')'); + } + if (prefix === '_PxEgEr_') { + return eval(value.slice(8)); + } + + return value; + }); + }; + + exports.clone = function (obj, date2obj) { + return exports.parse(exports.stringify(obj), date2obj); + }; + +}(typeof exports === 'undefined' ? (window.JSONfn = {}) : exports)); + + diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index 4bc3e4d1535208b7e05580895c8baf1060037eca..8c69af97febe145f773b0dd7e17459b3bbc081fb 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -310,6 +310,17 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' rapidSpeeds: cam.get("rapidSpeeds"), feedRate: cam.get("feedRate") }; + json.customPost = { + customFunctionsContext: this.customFunctionsContext, + customHeader: this.customHeader.toString(), + customFooter: this.customFooter.toString(), + customHome: this.customHome.toString(), + customPickUpStock: this.customPickUpStock.toString(), + customChangeZLayer: this.customChangeZLayer.toString(), + customMoveXY: this.customMoveXY.toString(), + customPlacePart: this.customPlacePart.toString(), + customCalcPositionOffsets: this.customCalcPositionOffsets.toString() + }; return {assembler: json}; }; @@ -328,9 +339,6 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' stock: stockJSON, tree: this.tree || this.buildComponentTree() }); - json.customPost = { - - }; return json; }; diff --git a/js/cam/assemblers/AssemblerPost.js b/js/cam/assemblers/AssemblerPost.js index 11dcec973a9de15db0bdef0bca8fb6efaf16baca..8928b0a7ab3c15e8937671c02591c5a78659e022 100644 --- a/js/cam/assemblers/AssemblerPost.js +++ b/js/cam/assemblers/AssemblerPost.js @@ -20,7 +20,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti // stockPosition: THREE.Vector3 - not used for your machine // units: mm - this.customFunctionsContext = { + this.customFunctionsContext = json.customPost.customFunctionsContext || { zClearHeight: 8,//height above part to clear during assembly zPreload: 0.2, stockWait: 0.75,//seconds @@ -33,6 +33,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti data += this.customHome(exporter, settings, context); return data; }; + this._loadFunction(json.customPost, "customHeader"); this.customFooter = function(exporter, settings, context){ var data = ""; @@ -40,17 +41,23 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti return data; }; + this._loadFunction(json.customPost, "customFooter"); + this.customHome = function(exporter, settings, context){ var data = ""; data += exporter.goHome(settings); return data; }; + this._loadFunction(json.customPost, "customHome"); + this.customPickUpStock = function(exporter, settings, context){//not relevant for your assembler var data = ""; return data; }; + this._loadFunction(json.customPost, "customPickUpStock"); + this.customChangeZLayer = function(currentIndex, lastIndex, exporter, settings, context){ var data = ""; if (lastIndex === null || (currentIndex.z-lastIndex.z)%2 != 0){ @@ -60,6 +67,8 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti return data; }; + this._loadFunction(json.customPost, "customChangeZLayer"); + this.customMoveXY = function(position, lastPosition, index, exporter, settings, context){//already offset for dual heads var data = ""; @@ -83,6 +92,8 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti return data; }; + this._loadFunction(json.customPost, "customMoveXY"); + this.customPlacePart = function(position, index, material, exporter, settings, context){//already offset for dual heads var data = ""; data += exporter.rapidZ(position.z + settings.safeHeight, settings); @@ -103,6 +114,8 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti return data; }; + this._loadFunction(json.customPost, "customPlacePart"); + this.customCalcPositionOffsets = function(index, position, material, settings, context){ //this feeds into moveXY and placePart functions @@ -123,13 +136,13 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti return null; } + position.sub(stock.getPosition().multiplyScalar(settings.scale)); return position; } - - + this._loadFunction(json.customPost, "customCalcPositionOffsets"); } @@ -140,6 +153,16 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti + AssemblerPost.prototype._loadFunction = function(json, name){ + if (json[name] === undefined) return; + var js = "js = " + json[name]; + try{ + eval(js); + this[name] = js; + } catch(error){ + console.log(error.message); + } + }; diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js index f8a418fb0dcab5dacd7debb0a1afe344120d7c36..0073567d746f002dc10c8f421b156ff9e4c1e5a4 100644 --- a/js/cam/assemblers/Component.js +++ b/js/cam/assemblers/Component.js @@ -50,7 +50,6 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ var wrapper = new THREE.Object3D(); wrapper.add(child.getObject3D()); wrapper.position.set(-this.centerOfRotation.x, -this.centerOfRotation.y, -this.centerOfRotation.z); - console.log("here"); this.secondWrapper = new THREE.Object3D(); this.secondWrapper.add(wrapper); this.object3D.add(this.secondWrapper); diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 8fa62bd7c2102c0b6b4224a2078ccb00560326a5..cd23094060b757f994072a788fd3448dcae4f69e 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -90,7 +90,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' DMACell.prototype.getIndex = function(){ if (!this.index) { - console.warn("no index for this cell"); +// console.warn("no index for this cell"); return null; } return this.index.clone(); @@ -98,7 +98,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' DMACell.prototype.getAbsoluteIndex = function(){ if (!this.index) { - console.warn("no index for this cell"); +// console.warn("no index for this cell"); return null; } if (!this.superCell) return this.getIndex(); diff --git a/js/main.js b/js/main.js index 3b139a8c2bd06214f56ad82ae633cf8a09fbe81d..64597bf24ad9f54fc65f4e9083ce39c1c6e403c6 100644 --- a/js/main.js +++ b/js/main.js @@ -16,7 +16,7 @@ require.config({ numeric: '../dependencies/numeric-1.2.6', codeMirrorJS: '../dependencies/codemirror/javascript', codeMirror: '../dependencies/codemirror/codemirror', - acorn: '../dependencies/acorn/acorn', + jsonFn: '../dependencies/jsonfn', //three three: '../dependencies/three', @@ -235,6 +235,9 @@ require.config({ }, 'numeric': { exports: 'numeric' + }, + 'jsonFn': { + exports: 'JSONfn' } } diff --git a/js/menus/ScriptView.js b/js/menus/ScriptView.js index 4b58be1c62b7578af2f4e66c7b4927571cb1d2af..de02d46f9b12769b8237ecda5d6edf1062bf7042 100644 --- a/js/menus/ScriptView.js +++ b/js/menus/ScriptView.js @@ -4,8 +4,8 @@ -define(['jquery', 'underscore', 'backbone', 'appState', 'codeMirror', 'acorn', 'globals', 'text!menus/templates/ScriptView.html', 'codeMirrorJS'], - function($, _, Backbone, appState, CodeMirror, acorn, globals, template){ +define(['jquery', 'underscore', 'backbone', 'appState', 'codeMirror', 'globals', 'text!menus/templates/ScriptView.html', 'codeMirrorJS'], + function($, _, Backbone, appState, CodeMirror, globals, template){ var ScriptView = Backbone.View.extend({ diff --git a/js/menus/templates/AssemblerMenuView.html b/js/menus/templates/AssemblerMenuView.html index 0606364058c5f2648643d67b388ed8521fcab449..9eac7f05cc7fc516a37e5fbd3159c9ed334bd186 100644 --- a/js/menus/templates/AssemblerMenuView.html +++ b/js/menus/templates/AssemblerMenuView.html @@ -32,7 +32,8 @@ Strategy: </ul> </div><br/><br/> <% if (camStrategy == "raster"){ %> - Raster Order: <input value="<%= placementOrder %>" placeholder="Placement Order" class="form-control placementOrder halfWidth" type="text"><br/><br/> + Raster Order: <input value="<%= placementOrder %>" placeholder="Placement Order" class="form-control placementOrder halfWidth" type="text"><br/> + <label>"YXZ" or "X-YZ" etc</label><br/><br/> <% } %> <% if (thisAssembler.numMaterials > -1 && thisAssembler.numMaterials < allCAMMaterialTypes.length){ %> <div class="inlineWarning">Number of materials in assembly exceeds available materials ( <%= thisAssembler.numMaterials %> ) for assembler type.</div> diff --git a/js/models/FileSaver.js b/js/models/FileSaver.js index 70587b3bb6fc5f1174d1709e20e80ada40f0a52b..4b589eac5ec3859440b3d37ed9df79b2643e0d7b 100644 --- a/js/models/FileSaver.js +++ b/js/models/FileSaver.js @@ -6,8 +6,10 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWrapper'], function(_, saveAs, lattice, materials, ribbon, menuWrapper){ function _saveFile(data, name, extension){ - var blob = new Blob([JSON.stringify(data, null, '\t')], {type: "text/plain;charset=utf-8"}); - saveAs(blob, name + extension); +// require(['jsonFn'], function(JSONfn){ + var blob = new Blob([JSON.stringify(data, null, '\t')], {type: "text/plain;charset=utf-8"}); + saveAs(blob, name + extension); +// }); } // function save(name){ diff --git a/js/plists/CamPList.js b/js/plists/CamPList.js index 88c3563758c19218b50ee887c67ed65ea2cee1d0..a8f9271afc595a03251cbe4ce93728711c9f335c 100644 --- a/js/plists/CamPList.js +++ b/js/plists/CamPList.js @@ -133,7 +133,8 @@ define(['three'], function(THREE){ originPosition: new THREE.Vector3(0,0,0), rapidSpeeds:{xy: 250, z: 250}, feedRate:{xy: 6, z: 6} - } + }, + customPost: {} } },