From e9c3edef0f6fd73335f59b33bd271488a9930cc5 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Mon, 1 Aug 2016 01:25:04 -0700
Subject: [PATCH 01/25] Add photonic3d.js and test retrieving config values and
 initializing them

---
 index.html       |  1 +
 js/main.js       |  2 +-
 js/photonic3d.js | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 js/photonic3d.js

diff --git a/index.html b/index.html
index 2c57951..2640e3d 100644
--- a/index.html
+++ b/index.html
@@ -359,5 +359,6 @@ <h3 class="panel-title">Colors</h3>
         <script src="vendor/FileSaver.min.js" type="text/javascript"></script>
         <script src="vendor/jszip.min.js" type="text/javascript"></script>
         <script src="js/main.js" type="text/javascript"></script>
+        <script src="js/photonic3d.js" type="text/javascript"></script>
     </body>
 </html>
diff --git a/js/main.js b/js/main.js
index ecd6b3f..40009e8 100644
--- a/js/main.js
+++ b/js/main.js
@@ -514,7 +514,7 @@ function updateSlicerSettings() {
 
     getSlice($sliderInput.slider('getValue'));
 
-    updateSliderUI();
+    updateSlicerUI();
 }
 
 function flipGeometry() {
diff --git a/js/photonic3d.js b/js/photonic3d.js
new file mode 100644
index 0000000..e847b2c
--- /dev/null
+++ b/js/photonic3d.js
@@ -0,0 +1,43 @@
+// Photonic3D Modifications and Features to SLAcer
+
+// Utils
+function findPythagoreanC(a, b) {
+	return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
+}
+
+function setPrinterCallibrationSettings(printer) {
+	// console.log(printer);
+	var slicingProfile = printer.configuration.slicingProfile;
+	var monitorDriverConfig = printer.configuration.machineConfig.MonitorDriverConfig;
+	var dotsPermmXYAverage = (slicingProfile.DotsPermmX + slicingProfile.DotsPermmY) / 2;
+	var dotsPermmDiagonal = findPythagoreanC(dotsPermmXYAverage, dotsPermmXYAverage);
+	var diagonalNumPixels = findPythagoreanC(monitorDriverConfig.DLP_X_Res, monitorDriverConfig.DLP_Y_Res);
+
+	var diagonalMM = diagonalNumPixels / dotsPermmDiagonal;
+	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
+	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
+
+	// $buildVolumeX.val(buildVolXmm);
+	// $buildVolumeY.val(buildVolYmm);
+	// updateBuildVolumeSettings();
+
+	// $('#screen-diagonal-unit-in').prop('checked', false);
+	// $('#screen-diagonal-unit-mm').prop('checked', true);
+	// $screenDiagonalSize.val(diagonalMM);
+
+}
+
+// Initialize values
+function intializeValues() {
+	$slicerSpeedYes[0].checked = true;
+	$slicerSpeedNo[0].checked = false;
+	updateSlicerSettings();
+
+	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
+		if (data !== null && data !== undefined) {
+			setPrinterCallibrationSettings(data);
+		}
+	});
+}
+
+intializeValues();

From 2acf3f25ceab46e77da9a00896e4baebaa806473 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Wed, 3 Aug 2016 17:27:16 -0700
Subject: [PATCH 02/25] Load default STL file and fix geometry error
 temporarily

---
 js/main.js       |  5 +++--
 js/photonic3d.js | 18 ++++++++++--------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/js/main.js b/js/main.js
index 40009e8..833ea1d 100644
--- a/js/main.js
+++ b/js/main.js
@@ -695,7 +695,7 @@ function updateBuildVolumeSettings() {
     });
 
     viewer3d.setBuildVolume(settings.get('buildVolume'));
-    viewer3d.dropObject(slicer.mesh);
+    slicer.mesh && viewer3d.dropObject(slicer.mesh);
     viewer3d.render();
 
     size && updateMeshInfoUI();
@@ -1046,7 +1046,8 @@ var stl = 'stl/StressTest.stl';
 //var stl = 'stl/SLAcer.stl';
 
 // File url
-var url = 'http://' + window.location.hostname + window.location.pathname + stl;
+// var url = 'http://' + window.location.hostname + window.location.pathname + stl;
+var url = window.location.href + stl;
 
 // Create http request object
 var xmlhttp = new XMLHttpRequest();
diff --git a/js/photonic3d.js b/js/photonic3d.js
index e847b2c..14a3948 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -17,18 +17,18 @@ function setPrinterCallibrationSettings(printer) {
 	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
 	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
 
-	// $buildVolumeX.val(buildVolXmm);
-	// $buildVolumeY.val(buildVolYmm);
-	// updateBuildVolumeSettings();
+	$buildVolumeX.val(buildVolXmm);
+	$buildVolumeY.val(buildVolYmm);
+	updateBuildVolumeSettings();
 
-	// $('#screen-diagonal-unit-in').prop('checked', false);
-	// $('#screen-diagonal-unit-mm').prop('checked', true);
-	// $screenDiagonalSize.val(diagonalMM);
+	$('#screen-diagonal-unit-in').prop('checked', false);
+	$('#screen-diagonal-unit-mm').prop('checked', true);
+	$screenDiagonalSize.val(diagonalMM);
 
 }
 
 // Initialize values
-function intializeValues() {
+function initializeValues() {
 	$slicerSpeedYes[0].checked = true;
 	$slicerSpeedNo[0].checked = false;
 	updateSlicerSettings();
@@ -40,4 +40,6 @@ function intializeValues() {
 	});
 }
 
-intializeValues();
+$(window).bind('load', initializeValues);
+// $(document).ready(initializeValues);
+// initializeValues();

From a66c4b8f6d8be96ee80197b8f65f69e693514487 Mon Sep 17 00:00:00 2001
From: Angela Ko <ako926@berkeley.edu>
Date: Thu, 4 Aug 2016 14:05:27 -0700
Subject: [PATCH 03/25] Hide slicer on default and added error

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

diff --git a/js/photonic3d.js b/js/photonic3d.js
index 14a3948..f6ced17 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -9,10 +9,14 @@ function setPrinterCallibrationSettings(printer) {
 	// console.log(printer);
 	var slicingProfile = printer.configuration.slicingProfile;
 	var monitorDriverConfig = printer.configuration.machineConfig.MonitorDriverConfig;
-	var dotsPermmXYAverage = (slicingProfile.DotsPermmX + slicingProfile.DotsPermmY) / 2;
+	var dotsPermmX = slicingProfile.DotsPermmX;
+	var dotsPermmY = slicingProfile.DotsPermmY;
+	var dotsPermmXYAverage = (dotsPermmX + dotsPermmY) / 2;
+	if (Math.abs(dotsPermmX - dotsrPermmY) >= 0.1) {
+		return true;
+	}
 	var dotsPermmDiagonal = findPythagoreanC(dotsPermmXYAverage, dotsPermmXYAverage);
 	var diagonalNumPixels = findPythagoreanC(monitorDriverConfig.DLP_X_Res, monitorDriverConfig.DLP_Y_Res);
-
 	var diagonalMM = diagonalNumPixels / dotsPermmDiagonal;
 	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
 	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
@@ -24,20 +28,28 @@ function setPrinterCallibrationSettings(printer) {
 	$('#screen-diagonal-unit-in').prop('checked', false);
 	$('#screen-diagonal-unit-mm').prop('checked', true);
 	$screenDiagonalSize.val(diagonalMM);
-
+	return false;
 }
 
 // Initialize values
 function initializeValues() {
 	$slicerSpeedYes[0].checked = true;
 	$slicerSpeedNo[0].checked = false;
-	updateSlicerSettings();
+	$slicerSpeedDelay.val = 0;
+	$settings.set('#slicer.panel.collapsed', true);
+	$slicerBody.collapse('hide');
 
+	updateSlicerSettings();
+	var XYerr = false;
 	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
 		if (data !== null && data !== undefined) {
-			setPrinterCallibrationSettings(data);
+			XYerr = setPrinterCallibrationSettings(data);
 		}
 	});
+
+	if (XYerr) {
+		//error 
+	}
 }
 
 $(window).bind('load', initializeValues);

From cedb31063ca4f15d1b5919e59090814320499797 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 14:16:29 -0700
Subject: [PATCH 04/25] Change way of presetting callibration settings

---
 js/main.js       |  4 +++-
 js/photonic3d.js | 27 +++++++++++++++++++++------
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/js/main.js b/js/main.js
index 833ea1d..25268b0 100644
--- a/js/main.js
+++ b/js/main.js
@@ -695,7 +695,7 @@ function updateBuildVolumeSettings() {
     });
 
     viewer3d.setBuildVolume(settings.get('buildVolume'));
-    slicer.mesh && viewer3d.dropObject(slicer.mesh);
+    viewer3d.dropObject(slicer.mesh);
     viewer3d.render();
 
     size && updateMeshInfoUI();
@@ -1066,3 +1066,5 @@ xmlhttp.onreadystatechange = function() {
 }
 
 xmlhttp.send();
+
+
diff --git a/js/photonic3d.js b/js/photonic3d.js
index 14a3948..9954950 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -17,14 +17,29 @@ function setPrinterCallibrationSettings(printer) {
 	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
 	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
 
-	$buildVolumeX.val(buildVolXmm);
-	$buildVolumeY.val(buildVolYmm);
-	updateBuildVolumeSettings();
+	// $buildVolumeX.val(buildVolXmm);
+	// $buildVolumeY.val(buildVolYmm);
+	// updateBuildVolumeSettings();
+    
+    var unit = $('#build-volume input[type=radio]:checked').val();
+
+    settings.set('buildVolume', {
+        size: {
+            x: buildVolXmm,
+            y: buildVolYmm,
+            z: $buildVolumeZ.val()
+        },
+        unit: unit
+    });
+    viewer3d.setBuildVolume(settings.get('buildVolume'));
+    updateBuildVolumeUI();
+
 
 	$('#screen-diagonal-unit-in').prop('checked', false);
 	$('#screen-diagonal-unit-mm').prop('checked', true);
 	$screenDiagonalSize.val(diagonalMM);
 
+	updateScreenSettings();
 }
 
 // Initialize values
@@ -40,6 +55,6 @@ function initializeValues() {
 	});
 }
 
-$(window).bind('load', initializeValues);
-// $(document).ready(initializeValues);
-// initializeValues();
+// $(window).bind('load', initializeValues);
+$(document).ready(initializeValues);
+// initializeValues();
\ No newline at end of file

From 9b7ef81ed47cbb71e5f5a9339eb2f40842f31894 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 14:51:17 -0700
Subject: [PATCH 05/25] Revert

---
 index.html       |  1 -
 js/main.js       |  2 +-
 js/photonic3d.js | 76 ------------------------------------------------
 3 files changed, 1 insertion(+), 78 deletions(-)
 delete mode 100644 js/photonic3d.js

diff --git a/index.html b/index.html
index 2640e3d..2c57951 100644
--- a/index.html
+++ b/index.html
@@ -359,6 +359,5 @@ <h3 class="panel-title">Colors</h3>
         <script src="vendor/FileSaver.min.js" type="text/javascript"></script>
         <script src="vendor/jszip.min.js" type="text/javascript"></script>
         <script src="js/main.js" type="text/javascript"></script>
-        <script src="js/photonic3d.js" type="text/javascript"></script>
     </body>
 </html>
diff --git a/js/main.js b/js/main.js
index 25268b0..ec91577 100644
--- a/js/main.js
+++ b/js/main.js
@@ -514,7 +514,7 @@ function updateSlicerSettings() {
 
     getSlice($sliderInput.slider('getValue'));
 
-    updateSlicerUI();
+    updateSliderUI();
 }
 
 function flipGeometry() {
diff --git a/js/photonic3d.js b/js/photonic3d.js
deleted file mode 100644
index 899e26e..0000000
--- a/js/photonic3d.js
+++ /dev/null
@@ -1,76 +0,0 @@
-// Photonic3D Modifications and Features to SLAcer
-
-// Utils
-function findPythagoreanC(a, b) {
-	return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
-}
-
-function setPrinterCallibrationSettings(printer) {
-	// console.log(printer);
-	var slicingProfile = printer.configuration.slicingProfile;
-	var monitorDriverConfig = printer.configuration.machineConfig.MonitorDriverConfig;
-	var dotsPermmX = slicingProfile.DotsPermmX;
-	var dotsPermmY = slicingProfile.DotsPermmY;
-	var dotsPermmXYAverage = (dotsPermmX + dotsPermmY) / 2;
-	if (Math.abs(dotsPermmX - dotsrPermmY) >= 0.1) {
-		return true;
-	}
-	var dotsPermmDiagonal = findPythagoreanC(dotsPermmXYAverage, dotsPermmXYAverage);
-	var diagonalNumPixels = findPythagoreanC(monitorDriverConfig.DLP_X_Res, monitorDriverConfig.DLP_Y_Res);
-	var diagonalMM = diagonalNumPixels / dotsPermmDiagonal;
-	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
-	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
-
-	// $buildVolumeX.val(buildVolXmm);
-	// $buildVolumeY.val(buildVolYmm);
-	// updateBuildVolumeSettings();
-    
-    /* This is part of updateBuildVolumeSettings() from main.js. I only copied
-    the necessary code that won't result in geometry error */
-    var unit = $('#build-volume input[type=radio]:checked').val();
-
-    settings.set('buildVolume', {
-        size: {
-            x: buildVolXmm,
-            y: buildVolYmm,
-            z: $buildVolumeZ.val()
-        },
-        unit: unit
-    });
-    viewer3d.setBuildVolume(settings.get('buildVolume'));
-    updateBuildVolumeUI();
-
-
-	$('#screen-diagonal-unit-in').prop('checked', false);
-	$('#screen-diagonal-unit-mm').prop('checked', true);
-	$screenDiagonalSize.val(diagonalMM);
-	updateScreenSettings();
-
-	// No error occurred so return false
-	return false;
-}
-
-// Initialize values
-function initializeValues() {
-	$slicerSpeedYes[0].checked = true;
-	$slicerSpeedNo[0].checked = false;
-	$slicerSpeedDelay.val = 0;
-	$settings.set('#slicer.panel.collapsed', true);
-	$slicerBody.collapse('hide');
-
-	updateSlicerSettings();
-	var XYerr = false;
-	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
-		if (data !== null && data !== undefined) {
-			XYerr = setPrinterCallibrationSettings(data);
-		}
-	});
-
-	if (XYerr) {
-		// Error handling
-	}
-}
-
-// $(window).bind('load', initializeValues);
-$(document).ready(initializeValues);
-// initializeValues();
\ No newline at end of file

From a9bba43b13df6a5cbe0e6dc6770f0dee06964d5a Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 14:58:23 -0700
Subject: [PATCH 06/25] Change url in load example to relative url

---
 js/main.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/js/main.js b/js/main.js
index ec91577..93b3991 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1045,7 +1045,7 @@ loader.onError = errorHandler;
 var stl = 'stl/StressTest.stl';
 //var stl = 'stl/SLAcer.stl';
 
-// File url
+// File url 
 // var url = 'http://' + window.location.hostname + window.location.pathname + stl;
 var url = window.location.href + stl;
 

From 36836fa717ce763cd2557eb4a69072cee9b2c240 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 15:00:16 -0700
Subject: [PATCH 07/25] Add photonic3d.js script in html

---
 index.html | 1 +
 js/main.js | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/index.html b/index.html
index 2c57951..2640e3d 100644
--- a/index.html
+++ b/index.html
@@ -359,5 +359,6 @@ <h3 class="panel-title">Colors</h3>
         <script src="vendor/FileSaver.min.js" type="text/javascript"></script>
         <script src="vendor/jszip.min.js" type="text/javascript"></script>
         <script src="js/main.js" type="text/javascript"></script>
+        <script src="js/photonic3d.js" type="text/javascript"></script>
     </body>
 </html>
diff --git a/js/main.js b/js/main.js
index 93b3991..ec91577 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1045,7 +1045,7 @@ loader.onError = errorHandler;
 var stl = 'stl/StressTest.stl';
 //var stl = 'stl/SLAcer.stl';
 
-// File url 
+// File url
 // var url = 'http://' + window.location.hostname + window.location.pathname + stl;
 var url = window.location.href + stl;
 

From 9d8c73d375ea7db5ea57d2864870b60b2a176874 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 15:00:53 -0700
Subject: [PATCH 08/25] Set callibration settings in SLAcer and fix geometry
 error

---
 js/photonic3d.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 js/photonic3d.js

diff --git a/js/photonic3d.js b/js/photonic3d.js
new file mode 100644
index 0000000..899e26e
--- /dev/null
+++ b/js/photonic3d.js
@@ -0,0 +1,76 @@
+// Photonic3D Modifications and Features to SLAcer
+
+// Utils
+function findPythagoreanC(a, b) {
+	return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
+}
+
+function setPrinterCallibrationSettings(printer) {
+	// console.log(printer);
+	var slicingProfile = printer.configuration.slicingProfile;
+	var monitorDriverConfig = printer.configuration.machineConfig.MonitorDriverConfig;
+	var dotsPermmX = slicingProfile.DotsPermmX;
+	var dotsPermmY = slicingProfile.DotsPermmY;
+	var dotsPermmXYAverage = (dotsPermmX + dotsPermmY) / 2;
+	if (Math.abs(dotsPermmX - dotsrPermmY) >= 0.1) {
+		return true;
+	}
+	var dotsPermmDiagonal = findPythagoreanC(dotsPermmXYAverage, dotsPermmXYAverage);
+	var diagonalNumPixels = findPythagoreanC(monitorDriverConfig.DLP_X_Res, monitorDriverConfig.DLP_Y_Res);
+	var diagonalMM = diagonalNumPixels / dotsPermmDiagonal;
+	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
+	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
+
+	// $buildVolumeX.val(buildVolXmm);
+	// $buildVolumeY.val(buildVolYmm);
+	// updateBuildVolumeSettings();
+    
+    /* This is part of updateBuildVolumeSettings() from main.js. I only copied
+    the necessary code that won't result in geometry error */
+    var unit = $('#build-volume input[type=radio]:checked').val();
+
+    settings.set('buildVolume', {
+        size: {
+            x: buildVolXmm,
+            y: buildVolYmm,
+            z: $buildVolumeZ.val()
+        },
+        unit: unit
+    });
+    viewer3d.setBuildVolume(settings.get('buildVolume'));
+    updateBuildVolumeUI();
+
+
+	$('#screen-diagonal-unit-in').prop('checked', false);
+	$('#screen-diagonal-unit-mm').prop('checked', true);
+	$screenDiagonalSize.val(diagonalMM);
+	updateScreenSettings();
+
+	// No error occurred so return false
+	return false;
+}
+
+// Initialize values
+function initializeValues() {
+	$slicerSpeedYes[0].checked = true;
+	$slicerSpeedNo[0].checked = false;
+	$slicerSpeedDelay.val = 0;
+	$settings.set('#slicer.panel.collapsed', true);
+	$slicerBody.collapse('hide');
+
+	updateSlicerSettings();
+	var XYerr = false;
+	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
+		if (data !== null && data !== undefined) {
+			XYerr = setPrinterCallibrationSettings(data);
+		}
+	});
+
+	if (XYerr) {
+		// Error handling
+	}
+}
+
+// $(window).bind('load', initializeValues);
+$(document).ready(initializeValues);
+// initializeValues();
\ No newline at end of file

From a9a57cc0deb436154725308b9930336b9ae2566f Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 15:17:41 -0700
Subject: [PATCH 09/25] Change url in load example to relative url

---
 js/main.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/js/main.js b/js/main.js
index ecd6b3f..a6f9b1d 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1046,8 +1046,8 @@ var stl = 'stl/StressTest.stl';
 //var stl = 'stl/SLAcer.stl';
 
 // File url
-var url = 'http://' + window.location.hostname + window.location.pathname + stl;
-
+// var url = 'http://' + window.location.hostname + window.location.pathname + stl;
+var url = window.location.href + stl;
 // Create http request object
 var xmlhttp = new XMLHttpRequest();
 

From d5aaa40f6349670cab874162c28d87f90e53203a Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 15:19:30 -0700
Subject: [PATCH 10/25] Add photonic3d.js in html

---
 index.html | 1 +
 js/main.js | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/index.html b/index.html
index 2c57951..2640e3d 100644
--- a/index.html
+++ b/index.html
@@ -359,5 +359,6 @@ <h3 class="panel-title">Colors</h3>
         <script src="vendor/FileSaver.min.js" type="text/javascript"></script>
         <script src="vendor/jszip.min.js" type="text/javascript"></script>
         <script src="js/main.js" type="text/javascript"></script>
+        <script src="js/photonic3d.js" type="text/javascript"></script>
     </body>
 </html>
diff --git a/js/main.js b/js/main.js
index a6f9b1d..ec91577 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1048,6 +1048,7 @@ var stl = 'stl/StressTest.stl';
 // File url
 // var url = 'http://' + window.location.hostname + window.location.pathname + stl;
 var url = window.location.href + stl;
+
 // Create http request object
 var xmlhttp = new XMLHttpRequest();
 
@@ -1065,3 +1066,5 @@ xmlhttp.onreadystatechange = function() {
 }
 
 xmlhttp.send();
+
+

From a457026a3be073388404d2e8f9172ac35c8feef8 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 15:19:50 -0700
Subject: [PATCH 11/25] Create photonic3d.js and set callibration settings in
 UI

---
 js/photonic3d.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 js/photonic3d.js

diff --git a/js/photonic3d.js b/js/photonic3d.js
new file mode 100644
index 0000000..10f6433
--- /dev/null
+++ b/js/photonic3d.js
@@ -0,0 +1,74 @@
+// Photonic3D Modifications and Features to SLAcer
+
+// Utils
+function findPythagoreanC(a, b) {
+	return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
+}
+
+function setPrinterCallibrationSettings(printer) {
+	// console.log(printer);
+	var slicingProfile = printer.configuration.slicingProfile;
+	var monitorDriverConfig = printer.configuration.machineConfig.MonitorDriverConfig;
+	var dotsPermmX = slicingProfile.DotsPermmX;
+	var dotsPermmY = slicingProfile.DotsPermmY;
+	var dotsPermmXYAverage = (dotsPermmX + dotsPermmY) / 2;
+	if (Math.abs(dotsPermmX - dotsrPermmY) >= 0.1) {
+		return true;
+	}
+	var dotsPermmDiagonal = findPythagoreanC(dotsPermmXYAverage, dotsPermmXYAverage);
+	var diagonalNumPixels = findPythagoreanC(monitorDriverConfig.DLP_X_Res, monitorDriverConfig.DLP_Y_Res);
+	var diagonalMM = diagonalNumPixels / dotsPermmDiagonal;
+	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
+	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
+
+	// $buildVolumeX.val(buildVolXmm);
+	// $buildVolumeY.val(buildVolYmm);
+	// updateBuildVolumeSettings();
+    
+    /* This is part of updateBuildVolumeSettings() from main.js. I only copied
+    the necessary code that won't result in geometry error */
+    var unit = $('#build-volume input[type=radio]:checked').val();
+
+    settings.set('buildVolume', {
+        size: {
+            x: buildVolXmm,
+            y: buildVolYmm,
+            z: $buildVolumeZ.val()
+        },
+        unit: unit
+    });
+    viewer3d.setBuildVolume(settings.get('buildVolume'));
+    updateBuildVolumeUI();
+
+
+	$('#screen-diagonal-unit-in').prop('checked', false);
+	$('#screen-diagonal-unit-mm').prop('checked', true);
+	$screenDiagonalSize.val(diagonalMM);
+	updateScreenSettings();
+
+	// No error occurred so return false
+	return false;
+}
+
+// Initialize values
+function initializeValues() {
+	$slicerSpeedYes[0].checked = true;
+	$slicerSpeedNo[0].checked = false;
+	$slicerSpeedDelay.val = 0;
+	$settings.set('#slicer.panel.collapsed', true);
+	$slicerBody.collapse('hide');
+
+	updateSlicerSettings();
+	var XYerr = false;
+	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
+		if (data !== null && data !== undefined) {
+			XYerr = setPrinterCallibrationSettings(data);
+		}
+	});
+
+	if (XYerr) {
+		// Error handling
+	}
+}
+
+$(document).ready(initializeValues);
\ No newline at end of file

From f7ce996341fd9489c238ab60080bf5646e786b64 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilburshi@sbcglobal.net>
Date: Thu, 4 Aug 2016 21:29:33 -0700
Subject: [PATCH 12/25] Set calibration settings by simulating manually
 inputting values on webpage

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

diff --git a/js/photonic3d.js b/js/photonic3d.js
index c983df2..8105dda 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -5,45 +5,51 @@ function findPythagoreanC(a, b) {
 	return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
 }
 
-function setPrinterCallibrationSettings(printer) {
-	// console.log(printer);
+function setPrinterCalibrationSettings(printer) {
 	var slicingProfile = printer.configuration.slicingProfile;
 	var monitorDriverConfig = printer.configuration.machineConfig.MonitorDriverConfig;
 	var dotsPermmX = slicingProfile.DotsPermmX;
 	var dotsPermmY = slicingProfile.DotsPermmY;
 	var dotsPermmXYAverage = (dotsPermmX + dotsPermmY) / 2;
-	if (Math.abs(dotsPermmX - dotsrPermmY) >= 0.1) {
-		return true;
-	}
+	// if (Math.abs(dotsPermmX - dotsPermmY) >= 0.1) {
+	// 	return true;
+	// }
 	var dotsPermmDiagonal = findPythagoreanC(dotsPermmXYAverage, dotsPermmXYAverage);
 	var diagonalNumPixels = findPythagoreanC(monitorDriverConfig.DLP_X_Res, monitorDriverConfig.DLP_Y_Res);
-	var diagonalMM = diagonalNumPixels / dotsPermmDiagonal;
+	var diagonalMM = Math.round(diagonalNumPixels / dotsPermmDiagonal);
 	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
 	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
 
-	// $buildVolumeX.val(buildVolXmm);
-	// $buildVolumeY.val(buildVolYmm);
-	// updateBuildVolumeSettings();
-    
     /* This is part of updateBuildVolumeSettings() from main.js. I only copied
     the necessary code that won't result in geometry error */
-    var unit = $('#build-volume input[type=radio]:checked').val();
-
     settings.set('buildVolume', {
         size: {
             x: buildVolXmm,
             y: buildVolYmm,
             z: $buildVolumeZ.val()
         },
-        unit: unit
+        unit: 'mm'
     });
     viewer3d.setBuildVolume(settings.get('buildVolume'));
+    viewer3d.render();
     updateBuildVolumeUI();
 
 
 	$('#screen-diagonal-unit-in').prop('checked', false);
 	$('#screen-diagonal-unit-mm').prop('checked', true);
-	$screenDiagonalSize.val(diagonalMM);
+	
+	// After manually checking the mm unit, set the values then update UI
+ //    settings.set('screen', {
+ //        width   : $screenWidth.val(),
+ //        height  : $screenHeight.val(),
+ //        diagonal: {
+ //            size: diagonalMM,
+ //            unit: 'mm'
+ //        }
+ //    });
+	// updateScreenUI();
+
+	$screenDiagonalSize.val(100);
 	updateScreenSettings();
 
 	// No error occurred so return false
@@ -54,15 +60,19 @@ function setPrinterCallibrationSettings(printer) {
 function initializeValues() {
 	$slicerSpeedYes[0].checked = true;
 	$slicerSpeedNo[0].checked = false;
-	$slicerSpeedDelay.val = 0;
-	$settings.set('#slicer.panel.collapsed', true);
+	$slicerSpeedDelay.val(0);
+
+	// 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');
 
-	updateSlicerSettings();
 	var XYerr = false;
 	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
 		if (data !== null && data !== undefined) {
-			XYerr = setPrinterCallibrationSettings(data);
+			XYerr = setPrinterCalibrationSettings(data);
 		}
 	});
 

From 381b7a18c8b16b7796f01d9876f7e5470028105c Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Fri, 5 Aug 2016 00:51:54 -0700
Subject: [PATCH 13/25] Change hardcoded diagonalmm value

---
 js/photonic3d.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index 8105dda..326454c 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -49,7 +49,7 @@ function setPrinterCalibrationSettings(printer) {
  //    });
 	// updateScreenUI();
 
-	$screenDiagonalSize.val(100);
+	$screenDiagonalSize.val(diagonalMM);
 	updateScreenSettings();
 
 	// No error occurred so return false

From 065be2b314056c29618ba303bf6924dcf5be74f4 Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Fri, 5 Aug 2016 16:41:39 -0700
Subject: [PATCH 14/25] Add null check for viewer3d.dropObject

---
 js/main.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/js/main.js b/js/main.js
index ec91577..7663611 100644
--- a/js/main.js
+++ b/js/main.js
@@ -695,7 +695,7 @@ function updateBuildVolumeSettings() {
     });
 
     viewer3d.setBuildVolume(settings.get('buildVolume'));
-    viewer3d.dropObject(slicer.mesh);
+    slicer.mesh && viewer3d.dropObject(slicer.mesh);
     viewer3d.render();
 
     size && updateMeshInfoUI();

From 1bd122b2b1f089e7ae596a9fea3ec8a1c34cbd4c Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Fri, 5 Aug 2016 16:48:22 -0700
Subject: [PATCH 15/25] Fix build volume settings

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

diff --git a/js/photonic3d.js b/js/photonic3d.js
index 326454c..e6a1907 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -14,41 +14,22 @@ function setPrinterCalibrationSettings(printer) {
 	// if (Math.abs(dotsPermmX - dotsPermmY) >= 0.1) {
 	// 	return true;
 	// }
-	var dotsPermmDiagonal = findPythagoreanC(dotsPermmXYAverage, dotsPermmXYAverage);
-	var diagonalNumPixels = findPythagoreanC(monitorDriverConfig.DLP_X_Res, monitorDriverConfig.DLP_Y_Res);
-	var diagonalMM = Math.round(diagonalNumPixels / dotsPermmDiagonal);
 	var buildVolXmm = Math.round(monitorDriverConfig.DLP_X_Res / dotsPermmXYAverage);
 	var buildVolYmm = Math.round(monitorDriverConfig.DLP_Y_Res / dotsPermmXYAverage);
+	var diagonalMM = Math.round(findPythagoreanC(buildVolXmm, buildVolYmm));
 
     /* This is part of updateBuildVolumeSettings() from main.js. I only copied
     the necessary code that won't result in geometry error */
-    settings.set('buildVolume', {
-        size: {
-            x: buildVolXmm,
-            y: buildVolYmm,
-            z: $buildVolumeZ.val()
-        },
-        unit: 'mm'
-    });
-    viewer3d.setBuildVolume(settings.get('buildVolume'));
-    viewer3d.render();
-    updateBuildVolumeUI();
+    $buildVolumeX.val(buildVolXmm);
+    $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
- //    settings.set('screen', {
- //        width   : $screenWidth.val(),
- //        height  : $screenHeight.val(),
- //        diagonal: {
- //            size: diagonalMM,
- //            unit: 'mm'
- //        }
- //    });
-	// updateScreenUI();
-
 	$screenDiagonalSize.val(diagonalMM);
 	updateScreenSettings();
 
@@ -79,6 +60,8 @@ function initializeValues() {
 	if (XYerr) {
 		// Error handling
 	}
+
+	// loader.load(/*insert file here*/);
 }
 
 $(document).ready(initializeValues);

From 61721dc4baf7fdebd2c74e6d6c9010012d184541 Mon Sep 17 00:00:00 2001
From: Angela Ko <ako926@berkeley.edu>
Date: Sat, 6 Aug 2016 08:57:26 -0700
Subject: [PATCH 16/25] modified button and sent blob

---
 js/photonic3d.js | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index e6a1907..e7949f9 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -42,6 +42,7 @@ 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);
@@ -61,8 +62,43 @@ function initializeValues() {
 		// Error handling
 	}
 
+	
+
 	// loader.load(/*insert file here*/);
 }
 
+function makeZip() {
+	if (zipFile) {
+        var name = 'SLAcer';
+        if (loadedFile && loadedFile.name) {
+            name = loadedFile.name;
+        }
+        uploadZip(zipFile.generate({type: 'blob'}), name + '.zip');
+        $location.path('/printables');
+    }
+}
+
+function uploadZip(zipFile) {
+	var blob = zipFile,
+    form = new FormData(),
+    request = new XMLHttpRequest();
+	form.append("blob",blob);
+	request.open(
+	            "POST",
+	            "/services/printerables//uploadPrintableFile",
+	            true
+	        );
+	request.send(form);
+}
+
+function makeButton() {
+	var btn	= document.getElementById("zip-button");
+	btn.onclick = function () {
+	    makeZip();
+	};
+	btn.id = "new-zip-button";
+	btn.innerHTML = "New Zip";	
+}
+
 $(document).ready(initializeValues);
 

From 35789f46bf4eff062c5aca8d679824a71e901d21 Mon Sep 17 00:00:00 2001
From: Angela Ko <ako926@berkeley.edu>
Date: Sat, 6 Aug 2016 12:15:41 -0700
Subject: [PATCH 17/25] Upload Zip File Directly To Server + Button

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

diff --git a/js/photonic3d.js b/js/photonic3d.js
index e7949f9..25ec5d3 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -74,30 +74,32 @@ function makeZip() {
             name = loadedFile.name;
         }
         uploadZip(zipFile.generate({type: 'blob'}), name + '.zip');
-        $location.path('/printables');
+        window.location = "/printablesPage";
     }
 }
 
-function uploadZip(zipFile) {
-	var blob = zipFile,
-    form = new FormData(),
-    request = new XMLHttpRequest();
-	form.append("blob",blob);
-	request.open(
-	            "POST",
-	            "/services/printerables//uploadPrintableFile",
-	            true
-	        );
+function uploadZip(zipFile, fileName) {
+	var blob = zipFile;
+    form = new FormData();
+	form.append("file",blob,fileName);
+	request = new XMLHttpRequest();
+	request.open("POST", "/services/printables/uploadPrintableFile");
 	request.send(form);
 }
 
 function makeButton() {
+	//rename original zip button
 	var btn	= document.getElementById("zip-button");
-	btn.onclick = function () {
+	btn.innerHTML = "Download Zip";	
+	//create new zip button
+	var newbtn = document.createElement("BUTTON");
+	newbtn.onclick = function () {
 	    makeZip();
-	};
-	btn.id = "new-zip-button";
-	btn.innerHTML = "New Zip";	
+	}
+	newbtn.id = "new-zip-button";
+	newbtn.className = "btn btn-primary";
+	newbtn.innerHTML = "Upload ZIP To Printables";
+	btn.parentNode.insertBefore(newbtn, btn);
 }
 
 $(document).ready(initializeValues);

From 7527834e7b0ffcd9d1852ce4119c699992ecbdf3 Mon Sep 17 00:00:00 2001
From: Angela Ko <ako926@berkeley.edu>
Date: Sat, 6 Aug 2016 12:30:31 -0700
Subject: [PATCH 18/25] Removed auto redirect back to printables page after
 upload complete

---
 js/photonic3d.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index 25ec5d3..823846a 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -74,7 +74,7 @@ function makeZip() {
             name = loadedFile.name;
         }
         uploadZip(zipFile.generate({type: 'blob'}), name + '.zip');
-        window.location = "/printablesPage";
+        //window.location = "/printablesPage";
     }
 }
 

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 19/25] 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 20/25] 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 21/25] 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 22/25] 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 23/25] 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);

From c28aea90b40f1741c06b710ff1f7b532e1432fad Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Fri, 12 Aug 2016 17:45:10 -0700
Subject: [PATCH 24/25] Error handling for no active printers

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

diff --git a/js/photonic3d.js b/js/photonic3d.js
index e39e515..0de6878 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -19,19 +19,16 @@ 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[0].SliceHeight * 1000);
+	$slicerLayerHeight.val(slicingProfile.InkConfig[slicingProfile.selectedInkConfigIndex].SliceHeight * 1000);
 
     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);
     $buildVolumeY.val(buildVolYmm);
     $buildVolumeZ.val(printer.configuration.machineConfig.PlatformZSize);
@@ -62,10 +59,12 @@ function initializeValues() {
 	// $slicerBody.collapse('hide');
 
 	var XYerr = false;
-	var printer = $.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
+	$.get( "/services/printers/getFirstAvailablePrinter", function( data ) {
 		if (data !== null && data !== undefined) {
 			XYerr = setPrinterCalibrationSettings(data);
 		}
+	}).fail(function (data) {
+		alert("Error: "+ data.responseText);
 	});
 
 	if (XYerr) {
@@ -93,7 +92,7 @@ function uploadZip(zipFile, fileName) {
 	form.append("file",blob,fileName);
 	request = new XMLHttpRequest();
 	request.open("POST", "/services/printables/uploadPrintableFile");
-	// When the request is successfully sent, load the tab to printablesPage
+	// When the request is successfully sent, alert the user
 	request.onreadystatechange = function () {
 		if (request.readyState == 4 && request.status == 200) {
 			// window.open('/printablesPage', '_self');

From 9a5a5c9e1db6862faf06285cc0a258e21c27ffad Mon Sep 17 00:00:00 2001
From: Wilbur Shi <wilbu@DESKTOP-SBHQII6.(none)>
Date: Thu, 18 Aug 2016 17:27:48 -0700
Subject: [PATCH 25/25] Delete redundant .zip in filename when slacer uploads
 image to printable

---
 js/photonic3d.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/js/photonic3d.js b/js/photonic3d.js
index 0de6878..08678ed 100644
--- a/js/photonic3d.js
+++ b/js/photonic3d.js
@@ -82,7 +82,7 @@ function makeZip() {
         if (loadedFile && loadedFile.name) {
             name = loadedFile.name;
         }
-        uploadZip(zipFile.generate({type: 'blob'}), name + '.zip' + '.zip');
+        uploadZip(zipFile.generate({type: 'blob'}), name + '.zip');
     }
 }
 
