From b89380c65ea8bc9231cc98a6ae0e812227c85b3d Mon Sep 17 00:00:00 2001
From: Boris Sekachev <boris.sekachev@intel.com>
Date: Tue, 10 Jul 2018 14:31:13 +0300
Subject: [PATCH] tmp

---
 .../engine/static/engine/js/3rdparty/svg.draggable.js   |  1 +
 cvat/apps/engine/static/engine/js/3rdparty/svg.draw.js  | 17 +++++++++++++++--
 .../apps/engine/static/engine/js/3rdparty/svg.resize.js |  5 +++--
 .../apps/engine/static/engine/js/3rdparty/svg.select.js |  1 +
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/cvat/apps/engine/static/engine/js/3rdparty/svg.draggable.js b/cvat/apps/engine/static/engine/js/3rdparty/svg.draggable.js
index d88abf5..06158f1 100644
--- a/cvat/apps/engine/static/engine/js/3rdparty/svg.draggable.js
+++ b/cvat/apps/engine/static/engine/js/3rdparty/svg.draggable.js
@@ -109,6 +109,7 @@

   // while dragging
   DragHandler.prototype.drag = function(e){
+    this.m = this.el.node.getScreenCTM().inverse();

     var box = this.getBBox()
       , p   = this.transformPoint(e)
diff --git a/cvat/apps/engine/static/engine/js/3rdparty/svg.draw.js b/cvat/apps/engine/static/engine/js/3rdparty/svg.draw.js
index 68dbf2a..9884b75 100644
--- a/cvat/apps/engine/static/engine/js/3rdparty/svg.draw.js
+++ b/cvat/apps/engine/static/engine/js/3rdparty/svg.draw.js
@@ -18,6 +18,7 @@
         this.startPoint = null;
         this.lastUpdateCall = null;
         this.options = {};
+        this.set = new SVG.Set();

         // Merge options and defaults
         for (var i in this.el.draw.defaults) {
@@ -139,6 +140,8 @@
         // Call the calc-function which calculates the new position and size
         this.calc(event);

+        this.m = this.el.node.getScreenCTM().inverse();
+        this.offset = { x: window.pageXOffset, y: window.pageYOffset };
         // Fire the `drawupdate`-event
         this.el.fire('drawupdate', {event:event, p:this.p, m:this.m});
     };
@@ -160,6 +163,16 @@
         this.el.fire('drawcancel');
     };

+    // Undo last drawed point
+    PaintHandler.prototype.undo = function () {
+        if (this.set.length()) {
+            this.set.members.splice(-1, 1)[0].remove();
+            this.el.array().value.splice(-2, 1);
+            this.el.plot(this.el.array());
+            this.el.fire('undopoint');
+        }
+    };
+
     // Calculate the corrected position when using `snapToGrid`
     PaintHandler.prototype.snapToGrid = function (draw) {

@@ -371,14 +384,14 @@

             this.set.clear();

-            for (var i = 0; i < array.length; ++i) {
+            for (var i = 0; i < array.length - 1; ++i) {

                 this.p.x = array[i][0]
                 this.p.y = array[i][1]

                 var p = this.p.matrixTransform(this.parent.node.getScreenCTM().inverse().multiply(this.el.node.getScreenCTM()));

-                this.set.add(this.parent.circle(5).stroke({width: 1}).fill('#ccc').center(p.x, p.y));
+                this.set.add(this.parent.circle(5).stroke({width: 1}).fill('#ccc').center(p.x, p.y)).addClass("svg_draw_point");
             }
         }

diff --git a/cvat/apps/engine/static/engine/js/3rdparty/svg.resize.js b/cvat/apps/engine/static/engine/js/3rdparty/svg.resize.js
index 0c3b63d..fb5dc26 100644
--- a/cvat/apps/engine/static/engine/js/3rdparty/svg.resize.js
+++ b/cvat/apps/engine/static/engine/js/3rdparty/svg.resize.js
@@ -34,8 +34,8 @@
         // Extract a position from a mouse/touch event.
         // Returns { x: .., y: .. }
         return {
-            x: event.clientX || event.touches[0].pageX,
-            y: event.clientY || event.touches[0].pageY
+            x: event.clientX != null ? event.clientX : event.touches[0].clientX,
+            y: event.clientY != null ? event.clientY : event.touches[0].clientY
         };
     };

@@ -343,6 +343,7 @@
             }
             return;
         }
+        this.m = this.el.node.getScreenCTM().inverse();

         // Calculate the difference between the mouseposition at start and now
         var txPt = this._extractPosition(event);
diff --git a/cvat/apps/engine/static/engine/js/3rdparty/svg.select.js b/cvat/apps/engine/static/engine/js/3rdparty/svg.select.js
index 47e07bd..f1d0c02 100644
--- a/cvat/apps/engine/static/engine/js/3rdparty/svg.select.js
+++ b/cvat/apps/engine/static/engine/js/3rdparty/svg.select.js
@@ -160,6 +160,7 @@ SelectHandler.prototype.drawPoints = function () {
                 ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
                 ev.stopPropagation();

+                if (ev.which != 1) return false;
                 var x = ev.pageX || ev.touches[0].pageX;
                 var y = ev.pageY || ev.touches[0].pageY;
                 _this.el.fire('point', {x: x, y: y, i: k, event: ev});
--
2.7.4

