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 1/2] 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 2/2] 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();
