var gcode; var loadedFileName = ""; var editor; var isJogWidget = false; function setWindowTitle(status) { var string = "OpenBuilds CONTROL" if (status) { string += " v" + status.driver.version } else if (laststatus) { string += " v" + laststatus.driver.version } if (loadedFileName.length > 0) { string += " / " + loadedFileName } if (!nostatusyet && laststatus.comms.interfaces.activePort) { string += " / connected to " + laststatus.comms.interfaces.activePort } $('#windowtitle').html(string) document.title = string } function getChangelog() { $("#changelog").empty() var template2 = `` $("#changelog").html(template2); // Update Dialog var template3 = `
Changelog:

` $("#changelogupdate").html(template3); }); } $(document).ready(function() { initDiagnostics(); // run second time to ensure checkboxes are ticked if (!isJogWidget) { init3D(); } if (typeof ace !== 'undefined') { editor = ace.edit("editor"); editor.$blockScrolling = Infinity; editor.session.setMode("ace/mode/cncpro"); editor.setTheme('ace/theme/sqlserver') // editor.setOption('printMarginColumn', 0) editor.setAutoScrollEditorIntoView(true); editor.session.setValue('; No GCODE yet - please Load a GCODE file from the Open GCODE button'); // from samplefile.js editor.setShowPrintMargin(false); editor.getSession().on('change', function() { // parseGcodeInWebWorker(editor.getValue()) }); } function setposition(e) { var bodyOffsets = document.body.getBoundingClientRect(); tempX = e.pageX //- bodyOffsets.left; tempY = e.pageY; // console.log(tempX); var offset = $("#editorContextMenu").offset(); $("#editorContextMenu").css({ display: 'block', left: e.pageX, top: e.pageY }); } if (editor) { editor.container.addEventListener("contextmenu", function(e) { setposition(e); e.preventDefault(); $('.linenumber').html((editor.getSelectionRange().start.row + 1)); // alert('success! - rightclicked line ' + (editor.getSelectionRange().start.row + 1)); }, false); } var fileOpen = document.getElementById('file'); if (fileOpen) { fileOpen.addEventListener('change', readFile, false); } $.get("/gcode").done(function(data) { // console.log(data.length) if (data.length > 2) { editor.session.setValue(data); parseGcodeInWebWorker(data) $('#controlTab').click() if (!webgl) { $('#gcodeviewertab').click(); } else { $('#gcodeeditortab').click() } } }); getChangelog() setTimeout(function() { $('#splash').fadeOut(500); }, 100) setInterval(function() { setWindowTitle(); }, 1000) const element = new Image(); Object.defineProperty(element, 'id', { get: function() { /* Call callback function here */ socket.emit("maximize", true) console.log('%cOpenBuilds CONTROL Devtools', 'font-weight: bold; font-size: 20px;color: rgb(50,80,188); text-shadow: 1px 1px 0 rgb(0,00,39)'); console.log('%c', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%cGeneral: Check for any errors, messages as requested by our support team', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%c', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%cConsole Commands:', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%cAccess the last received feedback data (positions', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%coffsets, probes, comms, queues, etc )', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%claststatus', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%cAccess the Grbl Settings on the controller', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%cgrblParams', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%c; Clears the console screen', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%cconsole.clear()', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%c; Print a log entry/message to the Serial Log', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%cprintLog("string")', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%cAccess the running/last ran gcode via API', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%c$.get("/gcode", function(data) { //do something with gcode data });', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%c; Send a job, ideal for macros, jobs. Can display a message when complete.', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%c; Set isJob to store for access via GET /gcode if needed', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%csocket.emit("runJob", {', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%c data: gcode-commands,', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%c isJob: false,', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%c completedMsg: "message displayed upon completion ",', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%c});', 'font-weight: regular; font-size: 12px;color: black; '); console.log('%c; Send the GCODE string to the controller, ideal for single commands', 'font-weight: bold; font-size: 12px;color: black; '); console.log('%csendGcode("gcode-string")', 'font-weight: regular; font-size: 12px;color: black; '); } }); console.log('%c', element); }); function readFile(evt) { console.group("New FileOpen Event:"); console.log(evt); console.groupEnd(); // Close the menu $("#drop1").dropdown("toggle"); // Files var files = evt.target.files || evt.dataTransfer.files; for (var i = 0; i < files.length; i++) { loadFile(files[i]); } document.getElementById('file').value = ''; } // load file function loadFile(f) { // Filereader if (f) { var r = new FileReader(); // if (f.name.match(/.gcode$/i)) { r.readAsText(f); r.onload = function(event) { editor.session.setValue(this.result); loadedFileName = f.name; setWindowTitle() if (webgl) { printLog('[ GCODE Parser ] GCODE File Loaded, please wait while we render a preview... '); } else { printLog('[ GCODE Parser ] GCODE File Loaded '); } parseGcodeInWebWorker(this.result) }; // } } } function versionCompare(v1, v2, options) { var lexicographical = options && options.lexicographical, zeroExtend = options && options.zeroExtend, v1parts = v1.split('.'), v2parts = v2.split('.'); function isValidPart(x) { return (lexicographical ? /^\d+[A-Za-z]*$/ : /^\d+$/).test(x); } if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) { return NaN; } if (zeroExtend) { while (v1parts.length < v2parts.length) v1parts.push("0"); while (v2parts.length < v1parts.length) v2parts.push("0"); } if (!lexicographical) { v1parts = v1parts.map(Number); v2parts = v2parts.map(Number); } for (var i = 0; i < v1parts.length; ++i) { if (v2parts.length == i) { return 1; } if (v1parts[i] == v2parts[i]) { continue; } else if (v1parts[i] > v2parts[i]) { return 1; } else { return -1; } } if (v1parts.length != v2parts.length) { return -1; } return 0; } var webgl = (function() { if (disable3Dviewer) { return false; } else { // console.log("Testing WebGL") try { return !!window.WebGLRenderingContext && !!document.createElement('canvas').getContext('experimental-webgl'); } catch (e) { return false; } } })(); function saveGcode() { var blob = new Blob([editor.getValue()], { type: "plain/text" }); invokeSaveAsDialog(blob, 'edited-gcode.gcode'); } function invokeSaveAsDialog(file, fileName) { if (!file) { throw 'Blob object is required.'; } if (!file.type) { file.type = 'text/plain'; } var fileExtension = file.type.split('/')[1]; if (fileName && fileName.indexOf('.') !== -1) { var splitted = fileName.split('.'); fileName = splitted[0]; fileExtension = splitted[1]; } var fileFullName = (fileName || (Math.round(Math.random() * 9999999999) + 888888888)) + '.' + fileExtension; if (typeof navigator.msSaveOrOpenBlob !== 'undefined') { return navigator.msSaveOrOpenBlob(file, fileFullName); } else if (typeof navigator.msSaveBlob !== 'undefined') { return navigator.msSaveBlob(file, fileFullName); } var hyperlink = document.createElement('a'); hyperlink.href = URL.createObjectURL(file); // hyperlink.target = '_blank'; hyperlink.download = fileFullName; if (!!navigator.mozGetUserMedia) { hyperlink.onclick = function() { (document.body || document.documentElement).removeChild(hyperlink); }; (document.body || document.documentElement).appendChild(hyperlink); } var evt = new MouseEvent('click', { view: window, bubbles: true, cancelable: true }); hyperlink.dispatchEvent(evt); if (!navigator.mozGetUserMedia) { URL.revokeObjectURL(hyperlink.href); } } // function setViewerDisableUI() { // if (localStorage.getItem('viewerDisable')) { // if (JSON.parse(localStorage.getItem('viewerDisable')) == true) { // $('#viewerdisabled').removeClass("checked"); // } else { // $('#viewerdisabled').addClass("checked"); // } // } else { // $('#viewerdisabled').removeClass("checked"); // return false; // } // return (!JSON.parse(localStorage.getItem('viewerDisable'))) // } // // function viewerdisable() { // console.log("viewerdisable") // if (localStorage.getItem('viewerDisable')) { // if (JSON.parse(localStorage.getItem('viewerDisable')) == true) { // console.log("viewerdisable disabled") // localStorage.setItem('viewerDisable', false); // location.reload(); // } else { // console.log("viewerdisable enabled") // localStorage.setItem('viewerDisable', true); // location.reload(); // } // } else { // console.log("viewerdisable defaulted") // localStorage.setItem('viewerDisable', false); // location.reload(); // } // setViewerDisableUI() // }