From d9cd3d382f05db0bacd07ee99d8ac041891b7713 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Wed, 19 Jul 2017 18:13:58 +0200 Subject: [PATCH] make profile coordinates modifieable in panel --- src/utils.js | 4 +++ src/viewer/potree.css | 10 ++++++ src/viewer/sidebar.js | 71 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index cf7d6984..fbef3d06 100644 --- a/src/utils.js +++ b/src/utils.js @@ -93,6 +93,10 @@ Potree.utils = class{ } return x1 + x2; }; + + static removeCommas(str){ + return str.replace(/,/g, ""); + } /** * create worker from a string diff --git a/src/viewer/potree.css b/src/viewer/potree.css index e6f3cf25..c5539220 100644 --- a/src/viewer/potree.css +++ b/src/viewer/potree.css @@ -780,3 +780,13 @@ label:hover{ width: 100% } +.invalid_value{ + color: #e05e5e; +} + + +//[contenteditable]:focus { +// outline: 1px solid red; +// outline-radius: 2px; +//} + diff --git a/src/viewer/sidebar.js b/src/viewer/sidebar.js index bd01199c..75ffaa39 100644 --- a/src/viewer/sidebar.js +++ b/src/viewer/sidebar.js @@ -1122,7 +1122,76 @@ function initMeasurementDetails(){ update(){ let elCoordiantesContainer = this.elContent.find(".coordinates_table_container"); elCoordiantesContainer.empty(); - elCoordiantesContainer.append(createCoordinatesTable(this.measurement)); + let coordinatesTable = createCoordinatesTable(this.measurement); + + let validate = input => { + return !isNaN(Number(input)); + }; + + let cells = coordinatesTable.find("td"); + cells.attr("contenteditable", "true"); + + cells = cells.toArray(); + + for(let i = 0; i < cells.length; i++){ + let cell = cells[i]; + let measure = this.measurement; + let updateCallback = this._update; + + let assignValue = () => { + let text = Potree.utils.removeCommas($(cell).html()); + + let num = Number(text); + + if(!isNaN(num)){ + $(cell).removeClass("invalid_value"); + + measure.removeEventListener("marker_moved", updateCallback); + + let index = parseInt(i / 3); + let coordinateComponent = i % 3; + + let position = measure.points[index].clone(); + + if(coordinateComponent === 0){ + position.x = num; + } else if(coordinateComponent === 1){ + position.y = num; + } else if(coordinateComponent === 2){ + position.z = num; + } + + measure.setPosition(index, position); + measure.addEventListener("marker_moved", updateCallback); + }else{ + $(cell).addClass("invalid_value"); + } + }; + + $(cell).on("keypress", (e) => { + if(e.which === 13){ + assignValue(); + return false; + } + }); + + $(cell).focusout(() => assignValue()); + + $(cell).on("input", function(e){ + let text = Potree.utils.removeCommas($(this).html()); + + let num = Number(text); + + if(!isNaN(num)){ + $(this).removeClass("invalid_value"); + }else{ + $(this).addClass("invalid_value"); + } + + }); + } + + elCoordiantesContainer.append(coordinatesTable); } download(){