From 8cddff9e23734dd7f53496abd3d339d1f1bd1264 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Mischler=20=28aka=20skarab=29?=
 <skarab@bluewin.ch>
Date: Sat, 6 Aug 2016 08:52:45 +0200
Subject: [PATCH 1/7] Fix: mirror bug on transformations

---
 js/main.js | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/js/main.js b/js/main.js
index ecd6b3f..8735706 100644
--- a/js/main.js
+++ b/js/main.js
@@ -942,10 +942,8 @@ function updateTransformValues() {
     current.y = input.y;
     current.z = input.z;
 
-    //var currentLayer = settings.get('');
-    loadGeometry(slicer.mesh.geometry);
+    loadGeometry(slicer.mesh.geometry, false);
     getSlice($sliderInput.slider('getValue'));
-    //viewer3d.render();
 }
 
 $transformButtons.on('click', function(e) {
@@ -991,7 +989,7 @@ function loadGeometry(geometry, mirror) {
         removeShapes();
 
         // flip geometry
-        if (mirror || settings.get('slicer.mirror')) {
+        if (mirror) {
             geometry.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));
         }
 
@@ -1030,7 +1028,7 @@ function ultraMegaDirtyFix() {
 // On Geometry loaded
 loader.onGeometry = function(geometry) {
     resetTransformValues();
-    loadGeometry(geometry);
+    loadGeometry(geometry, settings.get('slicer.mirror'));
     ultraMegaDirtyFix();
 };
 

From ccc91a364acf7cc07c85f3d2c73b767d14ad148c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Mischler=20=28aka=20skarab=29?=
 <skarab@bluewin.ch>
Date: Sat, 6 Aug 2016 09:51:48 +0200
Subject: [PATCH 2/7] Feature : X/Y translation

---
 index.html |  1 +
 js/main.js | 31 ++++++++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/index.html b/index.html
index 2c57951..5062ef7 100644
--- a/index.html
+++ b/index.html
@@ -62,6 +62,7 @@ <h3 class="panel-title">Transformations</h3>
                             <select id="transform-action" class="form-control input-sm">
                                 <option>scale</option>
                                 <option>rotate</option>
+                                <option>translate</option>
                             </select>
                         </div>
                         <div class="form-group" id="transform-uniform">
diff --git a/js/main.js b/js/main.js
index 8735706..30504dd 100644
--- a/js/main.js
+++ b/js/main.js
@@ -833,8 +833,9 @@ var transformAction, transformations;
 function resetTransformValues() {
     transformAction = 'scale';
     transformations = {
-        scale : { x:1, y:1 , z:1 },
-        rotate: { x:0, y:0 , z:0 }
+        scale    : { x:1, y:1 , z:1 },
+        rotate   : { x:0, y:0 , z:0 },
+        translate: { x:0, y:0 , z:0 }
     };
     updateTransformAction();
 }
@@ -851,13 +852,19 @@ function updateTransformAction() {
         max  = 999;
         step = 0.01;
     }
-    else {
+    else if (transformAction == 'rotate') {
         min  = 0;
         max  = 360;
         step = 1;
     }
+    else {
+        min  = -9999;
+        max  = 9999;
+        step = 1;
+    }
 
     $transformUniform.toggleClass('hidden', transformAction == 'rotate');
+    $transformZ.parent().toggleClass('hidden', transformAction == 'translate');
 
     $transformX.prop('min', min);
     $transformY.prop('min', min);
@@ -925,7 +932,7 @@ function updateTransformValues() {
             input.z / current.z
         );
     }
-    else {
+    else if (transformAction == 'rotate') {
         var deg     = Math.PI / 180;
         var offsets = {
             x: input.x - current.x,
@@ -937,12 +944,26 @@ function updateTransformValues() {
         slicer.mesh.geometry.rotateY(offsets.y * deg);
         slicer.mesh.geometry.rotateZ(offsets.z * deg);
     }
+    else {
+        var offsets = {
+            x: input.x - current.x,
+            y: input.y - current.y
+        };
+
+        slicer.mesh.geometry.translate(offsets.x, offsets.y, 0);
+    }
 
     current.x = input.x;
     current.y = input.y;
     current.z = input.z;
 
-    loadGeometry(slicer.mesh.geometry, false);
+    if (transformAction != 'translate') {
+        loadGeometry(slicer.mesh.geometry, false);
+        // stay at current position
+        var current = transformations['translate'];
+        slicer.mesh.geometry.translate(current.x, current.y, current.z);
+    }
+
     getSlice($sliderInput.slider('getValue'));
 }
 

From dcbbef9887f092778742ecc13cba14e2bfacfa8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Mischler=20=28aka=20skarab=29?=
 <skarab@bluewin.ch>
Date: Sat, 6 Aug 2016 09:56:22 +0200
Subject: [PATCH 3/7] Fix : hide uniform radio button when not in scale mode

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

diff --git a/js/main.js b/js/main.js
index 30504dd..d978635 100644
--- a/js/main.js
+++ b/js/main.js
@@ -863,7 +863,7 @@ function updateTransformAction() {
         step = 1;
     }
 
-    $transformUniform.toggleClass('hidden', transformAction == 'rotate');
+    $transformUniform.toggleClass('hidden', transformAction != 'scale');
     $transformZ.parent().toggleClass('hidden', transformAction == 'translate');
 
     $transformX.prop('min', min);

From dc196c401cf9315fe30d78a3717052be95c1bd3c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Mischler=20=28aka=20skarab=29?=
 <skarab@bluewin.ch>
Date: Sat, 6 Aug 2016 09:59:11 +0200
Subject: [PATCH 4/7] Update : README

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 8620471..28df2da 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
 # Main features
 - Browse or drag/drop STL file.
 - Mesh information: size, volume, cost, etc...
-- Mesh transformation: scale, rotate, mirror.
+- Mesh transformation: scale, rotate, translate, mirror.
 - Live slicing in 2D/3D viewer.
 - Speed mode (slicing only, no delay).
 - Open 2D viewer in new window (popup).

From d34fdc65c46b9f6107e645661924443989808428 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Mischler=20=28aka=20skarab=29?=
 <skarab@bluewin.ch>
Date: Sat, 6 Aug 2016 10:12:38 +0200
Subject: [PATCH 5/7] Moved mirror settings from slicer panel to transformation
 panel

---
 index.html | 12 ++++++------
 js/main.js | 28 ++++++++++++++--------------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/index.html b/index.html
index 5062ef7..4670855 100644
--- a/index.html
+++ b/index.html
@@ -57,6 +57,12 @@
                         <h3 class="panel-title">Transformations</h3>
                     </div>
                     <div id="transform-body" class="panel-body collapse in">
+                        <div class="form-group">
+                            <label for="transform-mirror">Mirror</label>
+                            <input type="radio" name="transform-mirror" id="transform-mirror-yes" value="yes" /> yes
+                            <input type="radio" name="transform-mirror" id="transform-mirror-no" value="no" checked="checked" /> no
+                        </div>
+                        <hr />
                         <div class="form-group">
                             <label for="transform-action">Action</label>
                             <select id="transform-action" class="form-control input-sm">
@@ -179,12 +185,6 @@ <h3 class="panel-title">Slicer</h3>
 
                         <hr />
 
-                        <div class="form-group">
-                            <label for="slicer-mirror">Mirror output</label>
-                            <input type="radio" name="slicer-mirror" id="slicer-mirror-yes" value="yes" /> yes
-                            <input type="radio" name="slicer-mirror" id="slicer-mirror-no" value="no" checked="checked" /> no
-                        </div>
-
                         <div class="form-group">
                             <label for="slicer-image-extension">Output type</label>
                             <input type="radio" name="slicer-image-extension" id="slicer-image-extension-png" value="png" checked="checked" /> png
diff --git a/js/main.js b/js/main.js
index d978635..1a4ec46 100644
--- a/js/main.js
+++ b/js/main.js
@@ -468,9 +468,6 @@ var $slicerLightOn     = $slicerBody.find('#slicer-light-on');
 var $slicerLiftingSpeed  = $slicerBody.find('#slicer-lifting-speed');
 var $slicerLiftingHeight = $slicerBody.find('#slicer-lifting-height');
 
-var $slicerMirrorYes = $slicerBody.find('#slicer-mirror-yes');
-var $slicerMirrorNo  = $slicerBody.find('#slicer-mirror-no');
-
 var $slicerExportPNG = $slicerBody.find('#slicer-image-extension-png');
 var $slicerExportSVG = $slicerBody.find('#slicer-image-extension-svg');
 
@@ -503,8 +500,6 @@ function updateSlicerSettings() {
     settings.set('slicer.lifting.speed', $slicerLiftingSpeed.val());
     settings.set('slicer.lifting.height', $slicerLiftingHeight.val());
 
-    settings.set('slicer.mirror', $slicerMirrorYes[0].checked);
-
     settings.set('slicer.png', $slicerExportPNG[0].checked);
     settings.set('slicer.svg', $slicerExportSVG[0].checked);
 
@@ -517,14 +512,6 @@ function updateSlicerSettings() {
     updateSliderUI();
 }
 
-function flipGeometry() {
-    loadGeometry(slicer.mesh.geometry, true);
-    getSlice($sliderInput.slider('getValue'));
-}
-
-$slicerMirrorYes.on('change', flipGeometry);
-$slicerMirrorNo.on('change', flipGeometry);
-
 var sliceInterval;
 var expectedSliceInterval;
 var currentSliceNumber;
@@ -644,7 +631,6 @@ $abortButton.on('click', function(e) {
 });
 
 $('#slicer-image-extension-' + (settings.get('slicer.png') ? 'png' : 'svg')).prop('checked', true);
-$('#slicer-mirror-' + (settings.get('slicer.mirror') ? 'yes' : 'no')).prop('checked', true);
 $('#slicer-make-zip-' + (settings.get('slicer.zip') ? 'yes' : 'no')).prop('checked', true);
 $('#slicer-speed-' + (settings.get('slicer.speed') ? 'yes' : 'no')).prop('checked', true);
 $('#slicer input').on('input, change', updateSlicerSettings);
@@ -828,6 +814,9 @@ var $transformY       = $transformBody.find('#transform-y');
 var $transformZ       = $transformBody.find('#transform-z');
 var $transformButtons = $transformBody.find('button');
 
+var $transformMirrorYes = $transformBody.find('#transform-mirror-yes');
+var $transformMirrorNo  = $transformBody.find('#transform-mirror-no');
+
 var transformAction, transformations;
 
 function resetTransformValues() {
@@ -978,6 +967,17 @@ $transformButtons.on('click', function(e) {
     updateTransformValues();
 });
 
+function flipGeometry() {
+    console.log('plop');
+    settings.set('slicer.mirror', $transformMirrorYes[0].checked);
+    loadGeometry(slicer.mesh.geometry, true);
+    getSlice($sliderInput.slider('getValue'));
+}
+
+$transformMirrorYes.on('change', flipGeometry);
+$transformMirrorNo.on('change', flipGeometry);
+
+$('#slicer-mirror-' + (settings.get('slicer.mirror') ? 'yes' : 'no')).prop('checked', true);
 $('#transform select').on('change', updateTransformAction);
 $('#transform input').on('change', updateTransformValues);
 resetTransformValues();

From f8f01d3f421ee2af5062a60d79fd78459fb3e40b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Mischler=20=28aka=20skarab=29?=
 <skarab@bluewin.ch>
Date: Sat, 6 Aug 2016 10:22:36 +0200
Subject: [PATCH 6/7] Fix : selector conflict

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

diff --git a/index.html b/index.html
index 4670855..76c8219 100644
--- a/index.html
+++ b/index.html
@@ -57,7 +57,7 @@
                         <h3 class="panel-title">Transformations</h3>
                     </div>
                     <div id="transform-body" class="panel-body collapse in">
-                        <div class="form-group">
+                        <div class="form-group" id="transform-mirror">
                             <label for="transform-mirror">Mirror</label>
                             <input type="radio" name="transform-mirror" id="transform-mirror-yes" value="yes" /> yes
                             <input type="radio" name="transform-mirror" id="transform-mirror-no" value="no" checked="checked" /> no
diff --git a/js/main.js b/js/main.js
index 1a4ec46..3cdf040 100644
--- a/js/main.js
+++ b/js/main.js
@@ -871,13 +871,15 @@ function updateTransformAction() {
 
 function updateTransformValues() {
     var current = transformations[transformAction];
-    var uniform = $('#transform input[type=radio]:checked').val() == 'yes';
+    var uniform = $('#transform-uniform input[type=radio]:checked').val() == 'yes';
     var input   = {
         x: parseFloat($transformX.val()),
         y: parseFloat($transformY.val()),
         z: parseFloat($transformZ.val())
     };
 
+    console.log(uniform)
+
     input.x = isNaN(input.x) ? current.x : input.x;
     input.y = isNaN(input.y) ? current.y : input.y;
     input.z = isNaN(input.z) ? current.z : input.z;

From 1905d9a105d485d552eebf18f0102d3f4bac63e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Mischler=20=28aka=20skarab=29?=
 <skarab@bluewin.ch>
Date: Sat, 6 Aug 2016 10:31:37 +0200
Subject: [PATCH 7/7] Fix : moved mirror settings at right place

---
 js/main.js | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/js/main.js b/js/main.js
index 3cdf040..82973fd 100644
--- a/js/main.js
+++ b/js/main.js
@@ -26,7 +26,6 @@ var settings = new SLAcer.Settings({
             collapsed: false,
             position : 1
         },
-        mirror: false,
         lifting: {
             speed : 50, // mm/min
             height: 3,  // mm
@@ -42,7 +41,8 @@ var settings = new SLAcer.Settings({
         panel: {
             collapsed: false,
             position : 3
-        }
+        },
+        mirror: false
     },
     buildVolume: {
         size     : { x: 100,  y: 100,  z: 100 }, // mm
@@ -878,8 +878,6 @@ function updateTransformValues() {
         z: parseFloat($transformZ.val())
     };
 
-    console.log(uniform)
-
     input.x = isNaN(input.x) ? current.x : input.x;
     input.y = isNaN(input.y) ? current.y : input.y;
     input.z = isNaN(input.z) ? current.z : input.z;
@@ -970,8 +968,7 @@ $transformButtons.on('click', function(e) {
 });
 
 function flipGeometry() {
-    console.log('plop');
-    settings.set('slicer.mirror', $transformMirrorYes[0].checked);
+    settings.set('transform.mirror', $transformMirrorYes[0].checked);
     loadGeometry(slicer.mesh.geometry, true);
     getSlice($sliderInput.slider('getValue'));
 }
@@ -979,7 +976,7 @@ function flipGeometry() {
 $transformMirrorYes.on('change', flipGeometry);
 $transformMirrorNo.on('change', flipGeometry);
 
-$('#slicer-mirror-' + (settings.get('slicer.mirror') ? 'yes' : 'no')).prop('checked', true);
+$('#transform-mirror-' + (settings.get('transform.mirror') ? 'yes' : 'no')).prop('checked', true);
 $('#transform select').on('change', updateTransformAction);
 $('#transform input').on('change', updateTransformValues);
 resetTransformValues();
@@ -1051,7 +1048,7 @@ function ultraMegaDirtyFix() {
 // On Geometry loaded
 loader.onGeometry = function(geometry) {
     resetTransformValues();
-    loadGeometry(geometry, settings.get('slicer.mirror'));
+    loadGeometry(geometry, settings.get('transform.mirror'));
     ultraMegaDirtyFix();
 };
 
