From 7a868b085ac7ed0be5893b69c86cee0c876d1c73 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Tue, 9 Aug 2016 19:41:27 -0700
Subject: [PATCH 1/5] Add icons to buttons and minimal error handling

---
 js/photonic3d.js | 48 ++++++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index 823846a..c2ba993 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -18,6 +18,17 @@ function setPrinterCalibrationSettings(printer) {
 	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
 	var diagonalMM = Math.round(findPythagoreanC(buildVolXmm, buildVolYmm));
 
+	// Update global javascript object with slicer settings
+	$slicerSpeedYes[0].checked = true;
+	$slicerSpeedNo[0].checked = false;
+	$slicerSpeedDelay.val(0);
+	// // Convert mm to microns
+	// $slicerLayerHeight.val(/*slicingProfile.InkConfig.SliceHeight * 1000*/100);
+	// console.log($slicerLayerHeight.val());
+    settings.set('slicer.speed', $slicerSpeedYes[0].checked);
+    settings.set('slicer.speedDelay', $slicerSpeedDelay.val());
+    // settings.set('slicer.layers.height', $slicerLayerHeight.val());
+	
     /* This is part of updateBuildVolumeSettings() from main.js. I only copied
     the necessary code that won't result in geometry error */
     $buildVolumeX.val(buildVolXmm);
@@ -31,6 +42,8 @@ function setPrinterCalibrationSettings(printer) {
 	
 	// After manually checking the mm unit, set the values then update UI
 	$screenDiagonalSize.val(diagonalMM);
+	$screenWidth.val(monitorDriverConfig.DLP_X_Res);
+	$screenHeight.val(monitorDriverConfig.DLP_Y_Res);
 	updateScreenSettings();
 
 	// No error occurred so return false
@@ -39,17 +52,10 @@ function setPrinterCalibrationSettings(printer) {
 
 // Initialize values
 function initializeValues() {
-	$slicerSpeedYes[0].checked = true;
-	$slicerSpeedNo[0].checked = false;
-	$slicerSpeedDelay.val(0);
 	makeButton();
 
-	// Update global javascript object with slicer settings
-    settings.set('slicer.speed', $slicerSpeedYes[0].checked);
-    settings.set('slicer.speedDelay', $slicerSpeedDelay.val());
-	
-	settings.set('#slicer.panel.collapsed', true);
-	$slicerBody.collapse('hide');
+	// settings.set('#slicer.panel.collapsed', true);
+	// $slicerBody.collapse('hide');
 
 	var XYerr = false;
 	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
@@ -60,21 +66,20 @@ function initializeValues() {
 
 	if (XYerr) {
 		// Error handling
+		alert("Your DotsPermmX and DotsPermmY are more than 0.1 mm apart");
 	}
 
-	
-
-	// loader.load(/*insert file here*/);
 }
 
 function makeZip() {
-	if (zipFile) {
+	if (zipFile === null || zipFile === undefined) {
+		alert("You must first slice images to generate a zip file.");
+	} else {
         var name = 'SLAcer';
         if (loadedFile && loadedFile.name) {
             name = loadedFile.name;
         }
-        uploadZip(zipFile.generate({type: 'blob'}), name + '.zip');
-        //window.location = "/printablesPage";
+        uploadZip(zipFile.generate({type: 'blob'}), name + '.zip' + '.zip');
     }
 }
 
@@ -84,13 +89,19 @@ function uploadZip(zipFile, fileName) {
 	form.append("file",blob,fileName);
 	request = new XMLHttpRequest();
 	request.open("POST", "/services/printables/uploadPrintableFile");
-	request.send(form);
+	// When the request is successfully sent, load the tab to printablesPage
+	request.onreadystatechange = function () {
+		if (request.readyState == 4 && request.status == 200) {
+			window.open('/printablesPage', '_self');
+		}
+	}
+    request.send(form);
 }
 
 function makeButton() {
 	//rename original zip button
 	var btn	= document.getElementById("zip-button");
-	btn.innerHTML = "Download Zip";	
+	btn.innerHTML = '<span class="glyphicon glyphicon-compressed"></span> Download ZIP'	
 	//create new zip button
 	var newbtn = document.createElement("BUTTON");
 	newbtn.onclick = function () {
@@ -98,7 +109,8 @@ function makeButton() {
 	}
 	newbtn.id = "new-zip-button";
 	newbtn.className = "btn btn-primary";
-	newbtn.innerHTML = "Upload ZIP To Printables";
+	// $('#new-zip-button').prop('disabled', 'disabled');
+	newbtn.innerHTML = '<span class="glyphicon glyphicon-upload"></span> Upload ZIP To Printables'
 	btn.parentNode.insertBefore(newbtn, btn);
 }
 

From adc4d64946784964236f442aa3c68af71e37e498 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Wed, 10 Aug 2016 00:05:54 -0700
Subject: [PATCH 2/5] Set screen x/y values in UI

---
 js/photonic3d.js | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index c2ba993..f45b121 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -11,6 +11,7 @@ function setPrinterCalibrationSettings(printer) {
 	var dotsPermmX = slicingProfile.DotsPermmX;
 	var dotsPermmY = slicingProfile.DotsPermmY;
 	var dotsPermmXYAverage = (dotsPermmX + dotsPermmY) / 2;
+	// Uncomment when not in testing anymore
 	// if (Math.abs(dotsPermmX - dotsPermmY) >= 0.1) {
 	// 	return true;
 	// }
@@ -22,12 +23,12 @@ function setPrinterCalibrationSettings(printer) {
 	$slicerSpeedYes[0].checked = true;
 	$slicerSpeedNo[0].checked = false;
 	$slicerSpeedDelay.val(0);
-	// // Convert mm to microns
-	// $slicerLayerHeight.val(/*slicingProfile.InkConfig.SliceHeight * 1000*/100);
-	// console.log($slicerLayerHeight.val());
+	// Convert mm to microns
+	$slicerLayerHeight.val(slicingProfile.InkConfig[0].SliceHeight * 1000);
+
     settings.set('slicer.speed', $slicerSpeedYes[0].checked);
     settings.set('slicer.speedDelay', $slicerSpeedDelay.val());
-    // settings.set('slicer.layers.height', $slicerLayerHeight.val());
+    settings.set('slicer.layers.height', $slicerLayerHeight.val());
 	
     /* This is part of updateBuildVolumeSettings() from main.js. I only copied
     the necessary code that won't result in geometry error */
@@ -90,11 +91,11 @@ function uploadZip(zipFile, fileName) {
 	request = new XMLHttpRequest();
 	request.open("POST", "/services/printables/uploadPrintableFile");
 	// When the request is successfully sent, load the tab to printablesPage
-	request.onreadystatechange = function () {
-		if (request.readyState == 4 && request.status == 200) {
-			window.open('/printablesPage', '_self');
-		}
-	}
+	// request.onreadystatechange = function () {
+	// 	if (request.readyState == 4 && request.status == 200) {
+	// 		window.open('/printablesPage', '_self');
+	// 	}
+	// }
     request.send(form);
 }
 

From 7acc378bbde12b07ae916d7ace3aab3626e89764 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Wed, 10 Aug 2016 00:43:33 -0700
Subject: [PATCH 3/5] Fix style of upload zip button and add similar behavior
 to previous buttons

---
 js/photonic3d.js | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index f45b121..ced39d7 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -91,28 +91,36 @@ function uploadZip(zipFile, fileName) {
 	request = new XMLHttpRequest();
 	request.open("POST", "/services/printables/uploadPrintableFile");
 	// When the request is successfully sent, load the tab to printablesPage
-	// request.onreadystatechange = function () {
-	// 	if (request.readyState == 4 && request.status == 200) {
-	// 		window.open('/printablesPage', '_self');
-	// 	}
-	// }
+	request.onreadystatechange = function () {
+		if (request.readyState == 4 && request.status == 200) {
+			// window.open('/printablesPage', '_self');
+			alert("Upload successful! Refresh printables page on Photonic3D to see the file.");
+		}
+	}
     request.send(form);
 }
 
 function makeButton() {
 	//rename original zip button
 	var btn	= document.getElementById("zip-button");
-	btn.innerHTML = '<span class="glyphicon glyphicon-compressed"></span> Download ZIP'	
+	btn.innerHTML = '<span class="glyphicon glyphicon-compressed"></span> ZIP'	
 	//create new zip button
 	var newbtn = document.createElement("BUTTON");
+	btn.parentNode.insertBefore(newbtn, btn.nextSibling);
 	newbtn.onclick = function () {
 	    makeZip();
 	}
 	newbtn.id = "new-zip-button";
 	newbtn.className = "btn btn-primary";
-	// $('#new-zip-button').prop('disabled', 'disabled');
-	newbtn.innerHTML = '<span class="glyphicon glyphicon-upload"></span> Upload ZIP To Printables'
-	btn.parentNode.insertBefore(newbtn, btn);
+	newbtn.disabled = true;
+	newbtn.innerHTML = '<span class="glyphicon glyphicon-upload"></span> Upload ZIP To Photonic3D';
+}
+
+var oldEndSlicing = endSlicing;
+
+endSlicing = function() {
+	oldEndSlicing();
+	$('#new-zip-button').prop('disabled', false);
 }
 
 $(document).ready(initializeValues);

From 536f9db36f2ca223437c05696a3ae7b9803bb973 Mon Sep 17 00:00:00 2001
From: Angela Ko <ako926@berkeley.edu>
Date: Wed, 10 Aug 2016 16:24:32 -0700
Subject: [PATCH 4/5] Spacing of button

---
 js/photonic3d.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index ced39d7..3d34e2b 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -103,9 +103,13 @@ function uploadZip(zipFile, fileName) {
 function makeButton() {
 	//rename original zip button
 	var btn	= document.getElementById("zip-button");
-	btn.innerHTML = '<span class="glyphicon glyphicon-compressed"></span> ZIP'	
+	btn.innerHTML = '<span class="glyphicon glyphicon-compressed"></span> ZIP';
+	
 	//create new zip button
 	var newbtn = document.createElement("BUTTON");
+	$(newbtn).css({
+	   'margin-top' : '10px'
+	});	
 	btn.parentNode.insertBefore(newbtn, btn.nextSibling);
 	newbtn.onclick = function () {
 	    makeZip();

From 6edd1828fa713f68c70c7511524f6a7003c4d8c7 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Wed, 10 Aug 2016 16:29:34 -0700
Subject: [PATCH 5/5] Fix first load problem with screen diagonal size

---
 js/photonic3d.js | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index ced39d7..f10b30c 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -36,16 +36,19 @@ function setPrinterCalibrationSettings(printer) {
     $buildVolumeY.val(buildVolYmm);
     $buildVolumeZ.val(printer.configuration.machineConfig.PlatformZSize);
     updateBuildVolumeSettings();
-
-
-	$('#screen-diagonal-unit-in').prop('checked', false);
-	$('#screen-diagonal-unit-mm').prop('checked', true);
 	
-	// After manually checking the mm unit, set the values then update UI
-	$screenDiagonalSize.val(diagonalMM);
+	var unit = settings.get('screen.diagonal.unit')
+	var convert = unit == 'in';
+	
+	$screenDiagonalSize.val(convert ? parseUnit(diagonalMM, unit) : diagonalMM);
 	$screenWidth.val(monitorDriverConfig.DLP_X_Res);
 	$screenHeight.val(monitorDriverConfig.DLP_Y_Res);
 	updateScreenSettings();
+	if (convert) {
+		$('#screen-diagonal-unit-in').prop('checked', false);
+		$('#screen-diagonal-unit-mm').prop('checked', true);
+		updateScreenSettings();		
+	}
 
 	// No error occurred so return false
 	return false;
@@ -120,7 +123,7 @@ var oldEndSlicing = endSlicing;
 
 endSlicing = function() {
 	oldEndSlicing();
-	$('#new-zip-button').prop('disabled', false);
+	$('#new-zip-button').prop('disabled', !zipFile);
 }
 
 $(document).ready(initializeValues);
